亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? kdtree.cpp

?? 用matlab編寫的k-dtree
?? CPP
字號:
#include "kdtree.h"#include <stdio.h>#include <stdlib.h>#include <math.h>#include <string.h>int (*KDTree::logmsg)(const char *,...)=printf;KDTree::KDTree(){  workArr = (int *) NULL;  copyPoints = false;  points = (float *)NULL;	pntsInRange = (int *)0;	nodeMem = (struct _Node *)0;	nodeMemCnt = 0;	nodeMemAlloc = true;	intArrMem = (int *)0;	intArrMemCnt = 0;	verbosity=0;  return;}				// end of constructorKDTree::KDTree(float *setpoints, int N, int setndim){  KDTree();  create(setpoints, N, setndim);  return;}	 // end of constructor// Note: this is copied almost verbatim from the heapsort // wiki page: http://en.wikipedia.org/wiki/Heapsort // 11/9/05int KDTree::heapsort(int dim, int *idx, int len){  unsigned int n = len,i=len/2,parent,child;  int t;  for(;;) {    if(i>0) {      i--;      t = idx[i];    }    else {      n--;      if(n ==0) return 0;      t  = idx[n];      idx[n] = idx[0];    }      parent = i;    child = i*2+1;		    while(child < n) {      if((child +1 < n) &&				 (points[(idx[child+1])*ndim+dim] > 					points[idx[child]*ndim + dim])) {				child++;      }      if(points[idx[child]*ndim+dim] > points[t*ndim+dim]) {				idx[parent] = idx[child];				parent = child;				child = parent*2+1;      }      else {				break;      }    }    idx[parent] = t;  } // end of for loop  return 0;} // end of heapsort        KDTree::~KDTree(){  if (workArr)    delete[]workArr;  if (copyPoints && points) {    // Delete the 1-D array of data    // Delete the pointer to the points    delete[] points;  }	if(pntsInRange) delete[] pntsInRange;	if(nodeMem && nodeMemAlloc) delete[] nodeMem;  return;}				// end of destructorint KDTree::get_serialize_length(int snpnts, int sdim){	return		// The data points to be copied		snpnts*sdim*sizeof(float)+      // The header information (8 bytes only)		sizeof(int)*2+      // The tree has twice as many nodes as points		(snpnts*2*(sizeof(struct _Node)));} // end of get_serialize_lengthKDTree *KDTree::unserialize(void *mem){	char *cmem = (char *)mem;	KDTree *kdtree = new KDTree;	kdtree->npoints = ((int *)mem)[0];	kdtree->ndim = ((int *)mem)[1];	kdtree->points = (float *)(cmem+sizeof(int)*2);	kdtree->nodeMem = (struct _Node *)				(cmem+sizeof(int)*2+sizeof(float)*kdtree->ndim*kdtree->npoints);	kdtree->nodeMemAlloc = false;	kdtree->copyPoints = false;	return kdtree;} // end of unserializestruct _Node *KDTree::node_alloc(){	nodeMemCnt++;	if(nodeMemCnt > npoints*2)		return (struct _Node *)0;	return (struct _Node *)(nodeMem+nodeMemCnt-1);} // end of node_allocint KDTree::create(float *setpoints, int setnpoints, int setndim,									 void *mem){	char *cmem = (char *)mem;	((int *)mem)[0] = setnpoints;	((int *)mem)[1] = setndim;	for(int i=0;i<setnpoints*setndim;i++)		((float *)mem)[i+2] = setpoints[i];	//memcpy(cmem+sizeof(int)*2,setpoints,sizeof(float)*setnpoints*setndim);	return		create((float *)(cmem+sizeof(int)*2),					 setnpoints,setndim,false,					 (struct _Node *)					 (cmem+sizeof(int)*2+sizeof(float)*setnpoints*setndim));} // end of create// This function creates a KD tree with the given// points, array, and lengthint KDTree::create(float *setpoints, int setnpoints, int setndim,									 bool setCopy, struct _Node *setNodeMem){  ndim = setndim;  npoints = setnpoints;  typedef int *intptr;	  // Copy the points from the original array, if necessary  copyPoints = setCopy;  if (copyPoints) {    if(points) delete[] points;    points = new float[ndim*npoints];    memcpy(points,setpoints,sizeof(float)*ndim*npoints);  }  // If we are not copying, just set the pointer  else    points = setpoints;  // Allocate some arrays;  if (workArr)    delete[]workArr;  workArr = new int[npoints];	if(!setNodeMem) {		if(nodeMem) delete[] nodeMem;		nodeMem = new struct _Node[npoints*2+1];		nodeMemAlloc = true;	}	else {		nodeMem = setNodeMem;		nodeMemAlloc = false;	}	nodeMemCnt = 0;	// Alocate array used for indexing	if(intArrMem) delete[] intArrMem;	intArrMem = 		new int[(int)((float)(npoints+4)*									ceil(log((double)npoints)/log(2.0)))];	intArrMemCnt = 0;  // Create the "sortidx" array by   // sorting the range tree points on each dimension  int **sortidx = new intptr[ndim];	if(verbosity>1)		logmsg("KDTree: Sorting points\n");  for (int i = 0; i < ndim; i++) {    // Initialize the sortidx array for this    // dimension    sortidx[i] = new int[npoints];    // Initialize the "tmp" array for the sort    int *tmp = new int[npoints];    for (int j = 0; j < npoints; j++)      tmp[j] = j;    // Sort the points on dimension i, putting    // indexes in array "tmp"    heapsort(i,tmp,npoints);    // sortidx is actually the inverse of the     // index sorts    for (int j = 0; j < npoints; j++)      sortidx[i][tmp[j]] = j;    delete[] tmp;  }	if(verbosity > 1)		logmsg("KDTree: Done sorting points\n");  // Create an initial list of points that references   // all the points  int *pidx = new int[npoints];  for (int i = 0; i < npoints; i++)    pidx[i] = i;  // Build a KD Tree  build_kdtree(sortidx,	// array of sort values							 0,	// The current dimension							 pidx, npoints);	// The list of points  // Delete the sort index  for (int i = 0; i < ndim; i++)    delete[]sortidx[i];  delete[] sortidx;  // Delete the initial list of points  delete[] pidx;	// Delete the sort arrays	delete[] intArrMem;	// delete the work array  if(workArr) {    delete[] workArr;    workArr = (int *)NULL;  }	if(verbosity > 1)		logmsg("KDTree: Done creating tree\n");  return 0;}				// end of create      int *KDTree::int_alloc(int len){	if(!intArrMem) return (int *)0;	int *ret = intArrMem+intArrMemCnt;	intArrMemCnt += len;	return ret;} // end of int_alloc// This function build a node of the kdtree with the// points indexed by pidx with length "len"// sortidx is a pre-computed array using the heapsort// algorithm aboveint KDTree::build_kdtree(int **sortidx, int dim,                                   int *pidx, int len){	int ncnt = nodeMemCnt;  struct _Node *node = node_alloc();  if (len == 1) {    node->leftIdx = -1;    node->rightIdx = -1;    node->pntidx = pidx[0];    node->key = 0;    return ncnt;  }    // If not, we must make a node  int pivot = -1;  int lcnt = 0, rcnt = 0;	int *larray, *rarray;  // Find the pivot (index of median point of available  // points on current dimension).	// If heapsorting the current list of points is quicker than	// iterating through all the points, just do that instead 	// (heapsort if of order n*log(n)	// This test could probably use some fine tuning	if((double)len*log((double)len) < npoints) {		heapsort(dim,pidx,len);		larray = pidx;		rarray = pidx+len/2;		pivot = pidx[len/2];		lcnt = len/2;		rcnt = len/2 + (len%2==0 ? 0 : 1);	}	else {		// Use the previously calculated sort index		// to make this a process linear in npoints		// This gets a little confusing, but it works.		// Sortidx:: sortidx[dim][idx] = val 		// idx = the index to the point		// val = the order in the array		int *parray = workArr;				// Setting parray to -1 indicates we are not using 		// the point		for (int i = 0; i < npoints; i++)			parray[i] = -1;		// Populate "parray" with the points that we		// are using, indexed in the order they occur		// on the current dimension		for (int i = 0; i < len; i++)			parray[sortidx[dim][pidx[i]]] = pidx[i];		int cnt = 0;		larray = int_alloc(len/2+1);		rarray = int_alloc(len/2+1);				// The middle valid value of parray is the pivot,		// the left go to a node on the left, the right		// go to a node on the right.		for (int i = 0; i < npoints; i++) {			if (parray[i] == -1)				continue;			if (cnt == len / 2) {				pivot = parray[i];				rarray[rcnt++] = parray[i];			} else if (cnt > len / 2)				rarray[rcnt++] = parray[i];			else				larray[lcnt++] = parray[i];			cnt++;			if(cnt>len)				break;		}	}  // Create the node  node->pntidx = -1;  node->key = points[pivot*ndim+dim];  // Create nodes to the left	node->leftIdx = 		build_kdtree(sortidx, (dim + 1) % ndim, larray, lcnt);		// Create nodes to the right	node->rightIdx = 		build_kdtree(sortidx, (dim + 1) % ndim, rarray, rcnt);  return ncnt;}				// end of build_kdtree// This function operates a search on a node for points within// the specified range.// It assumes the current node is at a depth corresponding to // dimension "dim"int KDTree::range_search(int nodeIdx, Range * range, int dim){  if (nodeIdx < 0)    return 0;		struct _Node *node = nodeMem+nodeIdx;  // If this is a leaf node, check to see if the   // data is in range.  If so, operate on it.  if (node->pntidx>=0) {    // Return if not in range    for (int i = 0; i < ndim; i++) {			int idx = node->pntidx*ndim + i;      if (points[idx] < range[i][0] || points[idx] > range[i][1])				return 0;    }		pntsInRange[nPntsInRange++] = node->pntidx;    return 0;  }  // Search left, if necessary  if (node->key >= range[dim][0])    range_search(node->leftIdx, range, (dim + 1) % ndim);  // Search right,if necessary  if (node->key <= range[dim][1])    range_search(node->rightIdx, range, (dim + 1) % ndim);  return 0;}				// end of range_search// This is the public function that will call the// function "opFunction" on all points in the array// within "range"int KDTree::get_points_in_range(Range * range){	if(!pntsInRange) 		pntsInRange = new int[npoints];	nPntsInRange = 0;  range_search(0, range, 0);  return 0;}				// end of operate_on_pointsint KDTree::closest_point(float *pnt, int &idx, bool approx){  int dim = 0;  // First, iterate along the path to the point,   // and find the one associated with this point  // on the line	struct _Node *n = nodeMem;  idx = -1;  for (;;) {    // Is this a leaf node    if (n->pntidx >= 0) {      idx = n->pntidx;      break;    }    if (n->key > pnt[dim]) 			n = nodeMem + n->leftIdx;		else 				n = nodeMem + n->rightIdx;;    dim = (dim + 1) % ndim;  }  // Are we getting an approximate value?  if(approx == true) return 0;  float ndistsq = distsq(pnt,points+idx*ndim);	  // Search for possible other nearest neighbors  // by examining adjoining nodes whos children may  // be closer  check_border_distance(0, 0, pnt, ndistsq, idx);  return 0;}				// end of closest_pointint KDTree::check_border_distance(int nodeIdx, int dim,				  float *pnt, float &cdistsq, int &idx){	if(nodeIdx < 0) return 0;  // Are we at a closer leaf node?    // If so, check the distance	struct _Node *node = nodeMem+nodeIdx;  if (node->pntidx >= 0) {    float dsq = distsq(pnt, points+node->pntidx*ndim);    if (dsq < cdistsq) {      cdistsq = dsq;      idx = node->pntidx;    }    return 0;  }  // The distance squared along the current dimension between the  // point and the key  float ndistsq =     (node->key - pnt[dim])*(node->key - pnt[dim]);  // If the distance squared from the key to the current value is   // greater than the nearest distance, we need only look  // in one direction.  if (ndistsq > cdistsq) {    if (node->key > pnt[dim])      check_border_distance(node->leftIdx, (dim + 1) % ndim, pnt, cdistsq, idx);    else      check_border_distance(node->rightIdx, (dim + 1) % ndim, pnt, cdistsq, idx);  }  // If the distance from the key to the current value is   // less than the nearest distance, we still need to look  // in both directions.  else {    check_border_distance(node->leftIdx, (dim + 1) % ndim, pnt, cdistsq, idx);    check_border_distance(node->rightIdx, (dim + 1) % ndim, pnt, cdistsq, idx);  }  return 0;} // end of check_border_distanceinline float KDTree::distsq(float *pnt1, float *pnt2){  float d = 0.0;  for (int i = 0; i < ndim; i++)    d += (pnt1[i] - pnt2[i]) * (pnt1[i] - pnt2[i]);  return d;}				// end if distsq#ifdef _TEST_#include <sys/types.h>#include <sys/stat.h>#include <unistd.h>#include <fcntl.h>#include <stdlib.h>#include <sys/time.h>double gettime(){  struct timeval tv;  gettimeofday(&tv,NULL);  return tv.tv_sec + tv.tv_usec/1.0E6;}int main(int argc, char *argv[]){  int npoints = 150000;  int ndim = 3;  double t1,t2;   float *data = new float[npoints*ndim];  for(int i=0;i<npoints*ndim;i++) {    data[i] = (float)(rand())/(float)(RAND_MAX);    data[i] = i;  }    t1 = gettime();  KDTree *tree = new KDTree;  tree->create(data,npoints,ndim);  t2 = gettime();  float pref[3];  pref[0] = pref[1] = pref[2] = 0.5;  int idx = 0;  float pnts[1000][3];  for(int i=0;i<1000;i++)     for(int j=0;j<3;j++)       pnts[i][j] = (float)rand()/(float)RAND_MAX;  t1 = gettime();  for(int i=0;i<1000;i++) {    tree->closest_point(pnts[i],idx);  }    t2 = gettime();  delete tree;  delete[] data;      return 0;}				// end of main#endif

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产盗摄精品一区二区三区在线| 欧美系列一区二区| 色视频欧美一区二区三区| 欧美一区二区三区视频免费播放 | 欧美日韩中文字幕一区二区| 26uuu国产电影一区二区| 亚洲一区电影777| 99久久久久久| 国产亚洲婷婷免费| 久久aⅴ国产欧美74aaa| 欧美亚洲国产一区在线观看网站| 国产日产欧美一区二区三区| 奇米影视一区二区三区| 欧美三级蜜桃2在线观看| 国产精品女主播av| 国产成人精品亚洲午夜麻豆| 亚洲精品在线观看网站| 亚洲电影你懂得| 91老师片黄在线观看| 国产精品色呦呦| 国内精品在线播放| 欧美一卡二卡三卡| 日韩高清不卡一区二区| 91久久久免费一区二区| 综合在线观看色| 9久草视频在线视频精品| 中文字幕乱码日本亚洲一区二区| 精彩视频一区二区三区| 精品国产sm最大网站免费看| 久久精品国产在热久久| 精品国产伦一区二区三区免费| 日韩高清欧美激情| 日韩一区二区免费高清| 日本最新不卡在线| 91精品国模一区二区三区| 丝袜美腿亚洲综合| 欧美高清你懂得| 国产精品原创巨作av| 91精品久久久久久蜜臀| 91麻豆精品一区二区三区| 香蕉久久夜色精品国产使用方法| 欧美激情一区在线观看| 成人免费在线视频| 亚洲精品一二三| 91麻豆精品国产91久久久资源速度 | 精品一区二区影视| 91精品国产一区二区三区蜜臀| 亚洲国产成人av网| 日韩西西人体444www| 精品一区二区三区在线观看国产| 久久久久亚洲蜜桃| 91亚洲精品久久久蜜桃| 亚洲高清不卡在线观看| 日韩一本二本av| 国产成人在线视频网站| 亚洲色图欧美激情| 欧美日韩成人一区| 国产一区二区看久久| 亚洲欧美一区二区三区久本道91| 欧美日韩精品电影| 国产成人精品一区二区三区网站观看| 国产精品国产三级国产| 欧美日韩一区二区三区在线看| 免费人成精品欧美精品| 国产精品久久久久久久久动漫| 在线视频一区二区免费| 国产综合一区二区| 亚洲欧美日韩国产另类专区| 欧美一区二区在线观看| 不卡在线观看av| 肉丝袜脚交视频一区二区| 久久久久久久性| 在线视频你懂得一区| 久久精品久久综合| 亚洲免费av高清| 久久久久久一二三区| 欧美日韩在线播放一区| 国产+成+人+亚洲欧洲自线| 亚洲一区二区三区小说| 国产日韩欧美精品综合| 日韩视频在线永久播放| 色8久久精品久久久久久蜜 | 欧美成人精品高清在线播放| 91首页免费视频| 极品尤物av久久免费看| 五月天激情综合网| 国产精品久久久久久久久免费丝袜 | 91麻豆免费视频| 精品一区二区综合| 亚洲妇女屁股眼交7| 亚洲天堂2014| 国产欧美一区二区精品仙草咪| 欧美高清一级片在线| 91成人网在线| 成人国产精品免费网站| 国产乱码精品一品二品| 麻豆精品在线看| 亚洲午夜视频在线观看| 伊人色综合久久天天人手人婷| 国产精品美女久久久久久久| 久久蜜桃一区二区| 日韩一级免费一区| 制服丝袜亚洲网站| 欧美日韩在线播放一区| 欧美亚洲动漫另类| 欧美亚洲国产bt| 欧洲av一区二区嗯嗯嗯啊| 一本久久a久久免费精品不卡| www.日韩在线| av电影在线观看完整版一区二区 | 日本成人在线网站| 亚洲国产成人高清精品| 亚洲香肠在线观看| 亚洲国产成人av网| 亚洲va欧美va人人爽午夜| 午夜精品在线视频一区| 亚洲成av人在线观看| 五月天中文字幕一区二区| 日韩电影免费一区| 美国十次综合导航| 国产综合色产在线精品| 国产精品91一区二区| 成人av网站在线观看| 色婷婷亚洲婷婷| 欧美日韩一区二区在线视频| 91精品国产综合久久小美女| 日韩欧美国产系列| 欧美videossexotv100| 国产免费观看久久| 亚洲精品久久7777| 天天综合色天天| 美腿丝袜亚洲综合| 国产裸体歌舞团一区二区| av资源网一区| 欧美日韩一区二区在线观看视频| 日韩一级大片在线观看| 精品国产一区二区三区av性色| 中日韩av电影| 亚洲成人自拍偷拍| 国产一区日韩二区欧美三区| 99精品欧美一区| 51精品视频一区二区三区| 久久嫩草精品久久久久| 伊人婷婷欧美激情| 另类中文字幕网| 91亚洲男人天堂| 91精品视频网| 中文字幕不卡的av| 日韩综合一区二区| 成人黄色电影在线| 91精品一区二区三区久久久久久| 国产日韩成人精品| 性感美女久久精品| 成人一区二区三区视频在线观看| 在线国产亚洲欧美| 国产亚洲va综合人人澡精品| 亚洲成a人在线观看| 成人听书哪个软件好| 欧美剧情电影在线观看完整版免费励志电影 | 欧美午夜不卡在线观看免费| 精品国产乱码久久久久久免费| 国产精品卡一卡二卡三| 日韩国产成人精品| 99精品国产99久久久久久白柏 | 久久这里只有精品首页| 一区二区三区在线观看视频| 狠狠色狠狠色综合系列| 欧美午夜不卡在线观看免费| 国产日韩欧美精品综合| 免费观看成人av| 欧美影视一区二区三区| 久久精品人人做| 日本美女一区二区| 欧美专区日韩专区| 日韩一区有码在线| 国产乱码精品一区二区三区av| 欧美日韩精品专区| 一区二区三区免费看视频| 国产不卡视频在线观看| 日韩欧美电影一二三| 香蕉乱码成人久久天堂爱免费| 色综合久久88色综合天天6| 久久久亚洲综合| 久久精品国产亚洲高清剧情介绍| 欧美日韩国产精品成人| 亚洲一区二区综合| 91热门视频在线观看| 国产精品你懂的| 国产成人精品免费视频网站| 欧美精品一区二区三区在线| 日韩高清中文字幕一区| 欧美久久久久久久久中文字幕| 亚洲午夜精品在线| 在线免费亚洲电影| 亚洲一级电影视频| 欧美日韩国产高清一区二区| 亚洲高清免费观看高清完整版在线观看| 色94色欧美sute亚洲线路一ni| 亚洲欧洲国产日本综合| 99久久国产免费看|