⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 amdb_support.cc

📁 Libgist is an implementation of the Generalized Search Tree, a template index structure that makes i
💻 CC
📖 第 1 页 / 共 3 页
字号:
//     }// }// display a page full of rectanglesvoidamdb_support::displayRects(    gist_predcursor_t& pcursor,    JNIEnv* env,    jint* highlights,    jint numHighlights,    jobject graphicsContext, // Java class: java.awt.Graphics    jobject normalColor,    jobject highlightColor,    jint width,    jint height){    initIds(env, graphicsContext);    // we can only display 2-dim data    int dim = rt_rect::size2dim(pcursor.elems[0].keyLen);        // Uncomment if you care ...    // if (dim != displayDim) return;    // find min/max along each dimension    double min[displayDim];    double max[displayDim];	int i;    for (i = 0; i < pcursor.numElems; i++) {        rt_rect r(dim, (const double *) pcursor.elems[i].key);		int j;	for (j = 0; j < displayDim; j++) {	    if (i == 0) {		min[j] = r.lo(j);		max[j] = r.hi(j);	    } else {		if (min[j] > r.lo(j)) min[j] = r.lo(j);		if (max[j] < r.hi(j)) max[j] = r.hi(j);	    }	}    }    int notok = drawScales(&width, &height, min[0], max[0], min[1], max[1],	env, graphicsContext);        if (notok)	return;    double scales[displayDim];    scales[0] = ((double) width) / (max[0] - min[0]);    scales[1] = ((double) height) / (max[1] - min[1]);    // draw non-highlighted rects    env->CallVoidMethod(graphicsContext, setColorId, normalColor);    int j = 0; // index into hightlights    for (i = 0; i < pcursor.numElems; i++) {	rt_rect r(dim, (const double *) pcursor.elems[i].key);        int x1 = (int) floor((r.lo(0) - min[0]) * scales[0]);        int x2 = (int) floor((r.hi(0) - min[0]) * scales[0]);        int y1 = (int) floor((r.lo(1) - min[1]) * scales[1]);        int y2 = (int) floor((r.hi(1) - min[1]) * scales[1]);	// decide which color to use	if (j < numHighlights && highlights[j] == i) {	    // this is to be highlighted; we'll draw that later	    j++;	} else {	    y1 = height - y1;	    y2 = height - y2;	    env->CallVoidMethod(graphicsContext, drawRectId, x1, y2, x2-x1, 		abs(y2-y1));	}    }    // draw highlighted rects after non-highlighted ones, so we don't obscure    // the highlights    env->CallVoidMethod(graphicsContext, setColorId, highlightColor);    for (i = 0; i < numHighlights; i++) {	rt_rect r(dim, (const double *) pcursor.elems[highlights[i]].key);        int x1 = (int) floor((r.lo(0) - min[0]) * scales[0]);        int x2 = (int) floor((r.hi(0) - min[0]) * scales[0]);        int y1 = (int) floor((r.lo(1) - min[1]) * scales[1]);        int y2 = (int) floor((r.hi(1) - min[1]) * scales[1]);	y1 = height - y1;	y2 = height - y2;	env->CallVoidMethod(graphicsContext, drawRectId, x1, y2, x2-x1, 	    abs(y2-y1));    }}voidamdb_support::displayBoundingSpheres(    gist_predcursor_t& pcursor,    JNIEnv* env,    jint* highlights,    jint numHighlights,    jobject graphicsContext, // Java class: java.awt.Graphics    jobject normalColor,    jobject highlightColor,    jint width,    jint height){    initIds(env, graphicsContext);        // we can only display 2-dim data    int dim = rt_bounding_sphere::size2dim(pcursor.elems[0].keyLen);    // Uncomment if you care ...    // if (dim != displayDim) return;    // find min/max along each dimension    double min[displayDim];    double max[displayDim];    double tmin, tmax;	int i;    for (i = 0; i < pcursor.numElems; i++) {        rt_bounding_sphere s(dim, (const double *) pcursor.elems[i].key);		int j;	for (j = 0; j < displayDim; j++) {	    tmin = s.center.co(j) - s.radius();	    tmax = s.center.co(j) + s.radius();	    if (i == 0) {		min[j] = tmin;		max[j] = tmax;	    } else {		if (min[j] > tmin) min[j] = tmin;		if (max[j] < tmax) max[j] = tmax;	    }	}    }    int notok = drawScales(&width, &height, min[0], max[0], min[1], max[1],	env, graphicsContext);        if (notok)	return;    double scales[displayDim];    scales[0] = ((double) width) / (max[0] - min[0]);    scales[1] = ((double) height) / (max[1] - min[1]);    // draw non-highlighted rects    env->CallVoidMethod(graphicsContext, setColorId, normalColor);    int j = 0; // index into hightlights    int x,y,w,h;    for (i = 0; i < pcursor.numElems; i++) {	rt_bounding_sphere s(dim, (const double *) pcursor.elems[i].key);		x = (int) floor((s.center.co(0) - min[0]) * scales[0]);	y = (int) floor((s.center.co(1) - min[1]) * scales[1]);		w = (int) floor((s.radius()) * scales[0]);	h = (int) floor((s.radius()) * scales[1]);		// decide which color to use	if (j < numHighlights && highlights[j] == i) {	    // this is to be highlighted; we'll draw that later	    j++;	} else {	    y = height - y;	    env->CallVoidMethod(graphicsContext, drawOvalId,		(x - w), (y - h), 2*w, 2*h);	}    }    // draw highlighted rects after non-highlighted ones, so we don't obscure    // the highlights    env->CallVoidMethod(graphicsContext, setColorId, highlightColor);    for (i = 0; i < numHighlights; i++) {	rt_bounding_sphere s(dim, (const double *) pcursor.elems[highlights[i]].key);	x = (int) floor((s.center.co(0) - min[0]) * scales[0]);	y = (int) floor((s.center.co(1) - min[1]) * scales[1]);		w = (int) floor((s.radius()) * scales[0]);	h = (int) floor((s.radius()) * scales[1]);	y = height - y;	env->CallVoidMethod(graphicsContext, drawOvalId, 	    (x - w), (y - h), 2*w, 2*h);    }}voidamdb_support::displayCentroidSpheres(    gist_predcursor_t& pcursor,    JNIEnv* env,    jint* highlights,    jint numHighlights,    jobject graphicsContext, // Java class: java.awt.Graphics    jobject normalColor,    jobject highlightColor,    jint width,    jint height){    initIds(env, graphicsContext);        // we can only display 2-dim data    int dim = rt_centroid_sphere::size2dim(pcursor.elems[0].keyLen);    // Uncomment if you care ...    // if (dim != displayDim) return;        // find min/max along each dimension    double min[displayDim];    double max[displayDim];    double tmin, tmax;	int i;    for (i = 0; i < pcursor.numElems; i++) {        rt_centroid_sphere s(dim, (const double *) pcursor.elems[i].key);		int j;	for (j = 0; j < displayDim; j++) {	    tmin = s.center.co(j) - s.radius();	    tmax = s.center.co(j) + s.radius();	    if (i == 0) {		min[j] = tmin;		max[j] = tmax;	    } else {		if (min[j] > tmin) min[j] = tmin;		if (max[j] < tmax) max[j] = tmax;	    }	}    }    int notok = drawScales(&width, &height, min[0], max[0], min[1], max[1],	env, graphicsContext);        if (notok)	return;    double scales[displayDim];    scales[0] = ((double) width) / (max[0] - min[0]);    scales[1] = ((double) height) / (max[1] - min[1]);    // draw non-highlighted rects    env->CallVoidMethod(graphicsContext, setColorId, normalColor);    int j = 0; // index into hightlights    int x,y,w,h;    for (i = 0; i < pcursor.numElems; i++) {	rt_centroid_sphere s(dim, (const double *) pcursor.elems[i].key);	x = (int) floor((s.center.co(0) - min[0]) * scales[0]);	y = (int) floor((s.center.co(1) - min[1]) * scales[1]);		w = (int) floor((s.radius()) * scales[0]);	h = (int) floor((s.radius()) * scales[1]);		// decide which color to use	if (j < numHighlights && highlights[j] == i) {	    // this is to be highlighted; we'll draw that later	    j++;	} else {	    y = height - y;	    env->CallVoidMethod(graphicsContext, drawOvalId, 		(x - w), (y - h), 2*w, 2*h);	}    }    // draw highlighted rects after non-highlighted ones, so we don't obscure    // the highlights    env->CallVoidMethod(graphicsContext, setColorId, highlightColor);    for (i = 0; i < numHighlights; i++) {	rt_centroid_sphere s(dim, (const double *) pcursor.elems[highlights[i]].key);	x = (int) floor((s.center.co(0) - min[0]) * scales[0]);	y = (int) floor((s.center.co(1) - min[1]) * scales[1]);		w = (int) floor((s.radius()) * scales[0]);	h = (int) floor((s.radius()) * scales[1]);	y = height - y;	env->CallVoidMethod(graphicsContext, drawOvalId, 	    (x - w), (y - h), 2*w, 2*h);    }}voidamdb_support::displaySphereRects(    gist_predcursor_t& pcursor,    JNIEnv* env,    jint* highlights,    jint numHighlights,    jobject graphicsContext, // Java class: java.awt.Graphics    jobject normalColor,    jobject highlightColor,    jint width,    jint height){    initIds(env, graphicsContext);    // we can only display 2-dim data    int dim = rt_sphererect::size2dim(pcursor.elems[0].keyLen);    // Uncomment if you care ...    // if (dim != displayDim) return;        // find min/max along each dimension    double min[displayDim];    double max[displayDim];    double tmin, tmax;	int i;    for (i = 0; i < pcursor.numElems; i++) {	rt_sphererect sr(dim, (const double *) pcursor.elems[i].key);	rt_rect& r = sr.rect;	rt_centroid_sphere& s = sr.sphere;		int j;	for (j = 0; j < displayDim; j++) {	    tmin = s.center.co(j) - s.radius();	    tmax = s.center.co(j) + s.radius();	    if (tmin > r.lo(j))		tmin = r.lo(j);	    if (tmax < r.hi(j))		tmax = r.hi(j);	    if (i == 0) {		min[j] = tmin;		max[j] = tmax;	    } else {		if (min[j] > tmin) min[j] = tmin;		if (max[j] < tmax) max[j] = tmax;	    }	}    }    int notok = drawScales(&width, &height, min[0], max[0], min[1], max[1],	env, graphicsContext);        if (notok)	return;    double scales[displayDim];    scales[0] = ((double) width) / (max[0] - min[0]);    scales[1] = ((double) height) / (max[1] - min[1]);    // draw non-highlighted rects    env->CallVoidMethod(graphicsContext, setColorId, normalColor);    int j = 0; // index into hightlights    int x,y,w,h;    int x1,x2,y1,y2;    for (i = 0; i < pcursor.numElems; i++) {	rt_sphererect sr(dim, (const double *) pcursor.elems[i].key);	rt_rect& r = sr.rect;	rt_centroid_sphere& s = sr.sphere;        x1 = (int) floor((r.lo(0) - min[0]) * scales[0]);	x2 = (int) floor((r.hi(0) - min[0]) * scales[0]);        y1 = height - (int) floor((r.lo(1) - min[1]) * scales[1]);	y2 = height - (int) floor((r.hi(1) - min[1]) * scales[1]);	x = (int) floor((s.center.co(0) - min[0]) * scales[0]);	y = height - (int) floor((s.center.co(1) - min[1]) * scales[1]);		w = (int) floor((s.radius()) * scales[0]);	h = (int) floor((s.radius()) * scales[1]);		// decide which color to use	if (j < numHighlights && highlights[j] == i) {	    // this is to be highlighted; we'll draw that later	    j++;	} else {	    env->CallVoidMethod(graphicsContext, drawOvalId, 		(x - w), (y - h), 2*w, 2*h);	    env->CallVoidMethod(graphicsContext, drawRectId, 		x1, y2, x2-x1, abs(y2-y1));	}    }    // draw highlighted rects after non-highlighted ones, so we don't obscure    // the highlights    env->CallVoidMethod(graphicsContext, setColorId, highlightColor);    for (i = 0; i < numHighlights; i++) {	rt_sphererect sr(dim, (const double *) pcursor.elems[highlights[i]].key);	rt_rect& r = sr.rect;	rt_centroid_sphere& s = sr.sphere;		x1 = (int) floor((r.lo(0) - min[0]) * scales[0]);	x2 = (int) floor((r.hi(0) - min[0]) * scales[0]);        y1 = height - (int) floor((r.lo(1) - min[1]) * scales[1]);        y2 = height - (int) floor((r.hi(1) - min[1]) * scales[1]);	x = (int) floor((s.center.co(0) - min[0]) * scales[0]);	y = height - (int) floor((s.center.co(1) - min[1]) * scales[1]);		w = (int) floor((s.radius()) * scales[0]);	h = (int) floor((s.radius()) * scales[1]);		env->CallVoidMethod(graphicsContext, drawOvalId, 	    (x - w), (y - h), 2*w, 2*h);	env->CallVoidMethod(graphicsContext, drawRectId, 	    x1, y2, x2-x1, abs(y2-y1));    }}rc_tamdb_support::parseGeoQuery(    const char* str,    gist_query_t*& query){    if (strcmp(str, "") == 0) {        // no qualification	query = new rt_query_t(rt_query_t::rt_nooper, 	    rt_query_t::rt_pointarg, NULL);	return RCOK;    }    istrstream s(str, strlen(str));    s >> ws; // remove leading whitespace    char op; // operator (&, <, >, =)    s >> op;    if (s.fail()) return ePARSEERROR;    rt_query_t::rt_oper oper;    switch (op) {	case '&':	    oper = rt_query_t::rt_overlap;	    break;	case '<':	    oper = rt_query_t::rt_contained;	    break;	case '>':	    oper = rt_query_t::rt_contains;	    break;	case '=':	    oper = rt_query_t::rt_equal;	    break;	case '~':	    oper = rt_query_t::rt_nearest;	    break;	case '#':	    oper = rt_query_t::rt_count_overlap;	    break;	case '!':	    oper = rt_query_t::rt_count_sample;	    break;	case '@':	    oper = rt_query_t::rt_count_combo;	    break;	default:	    return ePARSEERROR;    }    s >> ws;    char arg; // point ('p') or rectangle ('r')    s >> arg;    if (s.fail()) return ePARSEERROR;    if ((arg != 'p' && arg != 'r') ||        (arg == 'r' && oper == rt_query_t::rt_nearest)) {	// cannot run NN search with rectangle as center	return ePARSEERROR;    }    double coord[gist_p::max_tup_sz/sizeof(double)];    int len;    if (arg == 'p') {        // construct point argument	parsePoint(s, (void *) coord, len);	int dim = len / sizeof(double);	rt_point* pt = new rt_point(dim);	for (int i = 0; i < dim; i++) {	    pt->co(i) = coord[i];	}	query = new rt_query_t(oper, rt_query_t::rt_pointarg, pt);    } else {        // construct rectangle argument	parseRect(s, (void *) coord, len);	int dim = len / (2 * sizeof(double));	rt_rect* rect = new rt_rect(dim);	for (int i = 0; i < dim; i++) {	    rect->lo(i) = coord[2*i];	    rect->hi(i) = coord[2*i+1];	}	query = new rt_query_t(oper, rt_query_t::rt_rectarg, rect);    }    return RCOK;}// functions which implement display functions with the// new predicate cursor interface ...rc_tamdb_support::display_rt_point_preds(    JNIEnv* env,    jint    width,    jint    height,    jobject graphicsContext, // in: Java class: java.awt.Graphics    jobject colors[], // in: array of java.awt.Color objects    gist_disppredcursor_t& pcursor) // in: predicates to display{    if (pcursor.numPreds() == 0) return RCOK; // nothing to display ...    // cout << "display_rt_point_preds()" << endl;        initIds(env, graphicsContext);    char tempData[gist_p::max_tup_sz];    void *key = (void *) tempData;    int keyLen;    int keyLevel;    int keyColor;    // get initial key so we can determine the number of dims ...    pcursor.getNext(key, keyLen, keyLevel, keyColor);    // we can only display 2-dim data    int dim;    if (keyLevel == 1)	dim = rt_point::size2dim(keyLen);    else	dim = rt_rect::size2dim(keyLen);    //     if (dim != displayDim) {// 	cout << "display() displayDim != dim: " << displayDim << " " << dim << endl;//         return RCOK;//     }    // find min/max along each dimension    double min[displayDim];    double max[displayDim];        int j;    // initialize the ranges along each dimension ...    if (keyLevel == 1) {	rt_point pt(dim, (const double *) key);	for (j = 0; j < displayDim; j++) {	    min[j] = pt.co(j);	    max[j] = pt.co(j);	}    } else {	rt_rect r(dim, (const double *) key);	for (j = 0; j < displayDim; j++) {	    min[j] = r.lo(j);	    max[j] = r.hi(j);	}    }    while (pcursor.getNext(key, keyLen, keyLevel, keyColor) != eEOF) {	// If level is one then its a leaf ... 	if (keyLevel == 1) {	    rt_point pt(dim, (const double *) key);	    for (j = 0; j < displayDim; j++) {		if (min[j] > pt.co(j)) min[j] = pt.co(j);		if (max[j] < pt.co(j)) max[j] = pt.co(j);	    }	} else {	    rt_rect r(dim, (const double *) key);	    for (j = 0; j < displayDim; j++) {		if (min[j] > r.lo(j)) min[j] = r.lo(j);		if (max[j] < r.hi(j)) max[j] = r.hi(j);	    }	}    }     int notok = drawScales(&width, &height, min[0], max[0], min[1], max[1],	env, graphicsContext);        if (notok)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -