// returns tree depth int cisstCovTreeNode::ConstructSubtree(int CountThresh, double DiagThresh) { if (NumData() < CountThresh || Bounds.DiagonalLength() < DiagThresh) { // leaf node #ifdef DebugCovTree fprintf(MyTree->debugFile, "Leaf Node: Ndata=%d\tDiagLen=%f\n", NumData(), Bounds.DiagonalLength()); #endif myDepth = 0; return myDepth; } int topLEq = SortNodeForSplit(); if (topLEq == NumData() || topLEq == 0) { // need this in case count threshold = 1 // TODO: could avoid this case by NumData()<=CountThresh above #ifdef DebugCovTree // NOTE: it sometimes occurs that all data sorts to one node even when multiple // datums are present in the node; this happens because a vertex is chosen // as the datum sort point. Therefore, muliple datums sharing the same // vertex value may all be sorted wrt the same point. A way to prevent this // (if desired) would be to sort each datum by it's centroid position. fprintf(MyTree->debugFile, "WARNING! all data sorts to one node; topLEq=%d\tNdata=%d\tDiagLen=%f\n", topLEq, NumData(), Bounds.DiagonalLength()); #endif myDepth = 0; // stop here and do not split any further return 0; } #ifdef DebugCovTree fprintf(MyTree->debugFile2, "NNodeL=%d\tNNodeR=%d\n", topLEq, NumData() - topLEq); #endif assert(topLEq > 0 && topLEq < NumData()); int depthL, depthR; pLEq = new cisstCovTreeNode(pDataIndices, topLEq, pMyTree, this); pMyTree->NNodes++; depthL = pLEq->ConstructSubtree(CountThresh, DiagThresh); pMore = new cisstCovTreeNode(&pDataIndices[topLEq], NumData() - topLEq, pMyTree, this); pMyTree->NNodes++; depthR = pMore->ConstructSubtree(CountThresh, DiagThresh); this->myDepth = (depthL > depthR ? depthL : depthR) + 1; return myDepth; }
// Build tree from point cloud input // this constructor does not define the noise model for the point cloud; // the user must do this manually by calling the noise model methods of this class PDTree_PointCloud::PDTree_PointCloud( cisstPointCloud &pointCloud, int nThresh, double diagThresh ) : pointCloud(pointCloud) { NData = pointCloud.points.size(); DataIndices = new int[NData]; for (int i = 0; i < NData; i++) { DataIndices[i] = i; } Top = new PDTreeNode(DataIndices, NData, this, NULL); NNodes = 0; NNodes++; treeDepth = Top->ConstructSubtree(nThresh, diagThresh); #ifdef DEBUG_PD_TREE fprintf(debugFile, "Point Cloud Cov Tree built: NNodes=%d NData=%d TreeDepth=%d\n", NumNodes(), NumData(), TreeDepth()); #endif }
cisstCovTree_Mesh::cisstCovTree_Mesh(cisstMesh &mesh, int countThresh, double diagThresh) : MeshP(&mesh) { NData = MeshP->NumTriangles(); DataIndices = new int[NData]; for (int i = 0; i < NData; i++) { DataIndices[i] = i; } Top = new cisstCovTreeNode(DataIndices, NData, this, NULL); NNodes = 0; NNodes++; treeDepth = Top->ConstructSubtree(countThresh, diagThresh); #ifdef DebugCovTree fprintf(debugFile, "Mesh Cov Tree built: NNodes=%d NData=%d TreeDepth=%d\n", NumNodes(), NumData(), TreeDepth()); #endif }
//========================================================================= void EpetraExt_BlockDiagMatrix::PutScalar(double value){ int MaxData=NumData(); for (int i=0;i<MaxData;i++) Values_[i]=value; }