void CKDTree::BuildTree(KD_Node *parent) { int nSize=parent->m_vecIn.size(); //terminate conditions : size<=3 if (nSize<=3) return; //calculate median x, y; float x_median=0; float y_median=0; for(int i=0; i<nSize; ++i) { x_median+=m_regionArray[parent->m_vecIn[i]].Center().m_x; y_median+=m_regionArray[parent->m_vecIn[i]].Center().m_y; } x_median/=nSize; y_median/=nSize; //calculate variance along x, y; float x_sigma=0; float y_sigma=0; float x_tmp=0, y_tmp=0; for (int i=0; i<nSize; ++i) { x_tmp=x_median-m_regionArray[parent->m_vecIn[i]].Center().m_x; y_tmp=y_median-m_regionArray[parent->m_vecIn[i]].Center().m_y; x_sigma+=x_tmp*x_tmp; y_sigma+=y_tmp*y_tmp; } //split x if (x_sigma>=y_sigma) { if(!SplitX(parent, x_median)) SplitY(parent, y_median); } //split y else { if (!SplitY(parent, y_median)) SplitX(parent,x_median); } //recursive call this function if(parent->m_left!=NULL && parent->m_right!=NULL) { BuildTree(parent->m_left); BuildTree(parent->m_right); } }
/* ------------------------------------------------------------ purpose -- main procedure. if the input region is 1 x 1 x 1, the node is put into the permutation vector. otherwise the region is split into three pieces, two subregions and a separator, and recursive calls are made to order the subregions input -- n1 -- number of points in the first direction n2 -- number of points in the second direction n3 -- number of points in the third direction newToOld -- pointer to the permutation vector west -- west coordinate east -- east coordinate south -- south coordinate north -- north coordinate bottom -- bottom coordinate top -- top coordinate created -- 95nov15, cca ------------------------------------------------------------ */ void mkNDperm ( int n1, int n2, int n3, int newToOld[], int west, int east, int south, int north, int bottom, int top ) { if ( n1 <= 0 || n2 <= 0 || n3 <= 0 || newToOld == NULL || west < 0 || east >= n1 || south < 0 || north >= n2 || bottom < 0 || top >= n3 ) { fprintf(stderr, "\n fatal error in mkNDperm(%d,%d,%d,%p,%d,%d,%d,%d,%d,%d)" "\n bad input data\n", n1, n2, n3, newToOld, west, east, south, north, bottom, top) ; exit(-1) ; } if ( west == east && south == north && bottom == top ) { # if DEBUG > 0 fprintf(stdout, "\n ND : ordering %d", west + south * n1 + bottom * n1 * n2) ; # endif newToOld[0] = west + south * n1 + bottom * n1 * n2 ; } else { switch ( WhichCut(west, east, south, north, bottom, top) ) { case 1 : # if DEBUG > 0 fprintf(stdout, "\n ND : calling Split9X") ; # endif SplitX(n1, n2, n3, newToOld, west, east, south, north, bottom, top) ; break ; case 2 : # if DEBUG > 0 fprintf(stdout, "\n ND : calling Split9Y") ; # endif SplitY(n1, n2, n3, newToOld, west, east, south, north, bottom, top) ; break ; case 3 : # if DEBUG > 0 fprintf(stdout, "\n ND : calling Split9Z") ; # endif SplitZ(n1, n2, n3, newToOld, west, east, south, north, bottom, top) ; break ; } } return ; }
void DragFrameShape::layout(Point size_) { size=size_; Coord dxy=+cfg.frame_dxy; Coord tdy=+cfg.title_dy; Coord bdx=+cfg.btn_dx; Coord bdy=+cfg.btn_dy; Coord btn_len = is_main? 6*bdx+bdx/8 : 4*bdx ; if( size>=Point( 2*dxy+btn_len+bdx/2+Max(tdy,dxy) , dxy+Max(tdy,dxy) ) ) { Pane pane=Pane(Null,size); Pane left=SplitX(dxy,pane); Pane right=SplitX(pane,dxy); dragTopLeft=SplitY(dxy,left); dragBottomLeft=SplitY(left,dxy); dragLeft=left; dragTopRight=SplitY(dxy,right); dragBottomRight=SplitY(right,dxy); dragRight=right; dragBar=SplitY(tdy,pane); dragBottom=SplitY(pane,dxy); client=pane; Coord yb=(tdy-bdy)/2; Coord tx=dragBar.dx-btn_len; if( is_main ) { Coord xb0=dragBar.x+tx; Coord xb1=xb0+bdx+bdx/8; Coord xb2=xb1+bdx+bdx/8; Coord xb3=xb2+bdx+bdx/8; Coord xb4=xb3+bdx+bdx/2; btnAlert=Pane(xb0,yb,bdx,bdy); btnHelp=Pane(xb1,yb,bdx,bdy); btnMin=Pane(xb2,yb,bdx,bdy); btnMax=Pane(xb3,yb,bdx,bdy); btnClose=Pane(xb4,yb,bdx,bdy); } else { Coord xb0=dragBar.x+tx; Coord xb1=xb0+bdx+bdx/8; Coord xb2=xb1+bdx+bdx/2; btnAlert=Empty; btnMin=Empty; btnHelp=Pane(xb0,yb,bdx,bdy); btnMax=Pane(xb1,yb,bdx,bdy); btnClose=Pane(xb2,yb,bdx,bdy); } Coord w=RoundUpLen(+cfg.width); titleBar=Pane(dragBar.x+bdx/4,w,tx-bdx/2,tdy-2*w); } else { dragTopLeft=Empty; dragBottomLeft=Empty; dragLeft=Empty; dragTopRight=Empty; dragBottomRight=Pane(Null,size); dragRight=Empty; dragBar=Empty; dragBottom=Empty; client=Empty; btnAlert=Empty; btnHelp=Empty; btnMin=Empty; btnMax=Empty; btnClose=Empty; titleBar=Empty; } }