virtual vector<BSONObj> splitPointsVector() const { vector<BSONObj> ret; BSONArray a = splitPoints(); BSONObjIterator i( a ); while( i.more() ) { ret.push_back( i.next().Obj().getOwned() ); } return ret; }
void TempOctree::createSubTree(TempOctree::Node& node,PointePoint* points,size_t numPoints) { /* Check if the number of points is smaller than the maximum: */ if(numPoints<=size_t(maxNumPointsPerNode)) { /* Make this node a leaf and write the points to the temporary file: */ node.numPoints=numPoints; node.pointsOffset=file.tell(); file.write(points,numPoints); } else { /* Make this node an interior node: */ node.numPoints=numPoints; node.pointsOffset=0; /* Split the point array between the node's children: */ PointePoint* childPoints[8]; size_t childNumPoints[8]; childPoints[0]=points; childNumPoints[0]=numPoints; /* Split the point set along the three dimensions, according to the node's center: */ int numSplits=1; int splitSize=4; for(int i=2;i>=0;--i,numSplits<<=1,splitSize>>=1) { int leftIndex=0; for(int j=0;j<numSplits;++j,leftIndex+=splitSize*2) { size_t leftNumPoints=splitPoints(childPoints[leftIndex],childNumPoints[leftIndex],i,node.domain.getCenter(i)); childPoints[leftIndex+splitSize]=childPoints[leftIndex]+leftNumPoints; childNumPoints[leftIndex+splitSize]=childNumPoints[leftIndex]-leftNumPoints; childNumPoints[leftIndex]=leftNumPoints; } } /* Initialize the child nodes and create their subtrees: */ node.children=new Node[8]; for(int childIndex=0;childIndex<8;++childIndex) { Node& child=node.children[childIndex]; child.domain=Cube(node.domain,childIndex); createSubTree(node.children[childIndex],childPoints[childIndex],childNumPoints[childIndex]); } } }
void TempOctree::createSubTree(TempOctree::Node& node) { /* Check if the number of points is smaller than the maximum: */ if(node.numPoints<=size_t(maxNumPointsPerNode)) { /* Queue up this node to be written to the octree file: */ Threads::MutexCond::Lock writeQueueLock(writeQueueCond); writeQueue.push_back(&node); writeQueueCond.signal(); } else { /* Make this node an interior node: */ node.children=new Node[8]; /* Split the point array between the node's children: */ node.children[0].numPoints=node.numPoints; node.children[0].points=node.points; /* Split the point set along the three dimensions, according to the node's center: */ int numSplits=1; int splitSize=4; for(int i=2;i>=0;--i,numSplits<<=1,splitSize>>=1) { int leftIndex=0; for(int j=0;j<numSplits;++j,leftIndex+=splitSize*2) { size_t leftNumPoints=splitPoints(node.children[leftIndex].points,node.children[leftIndex].numPoints,i,node.domain.getCenter(i)); node.children[leftIndex+splitSize].points=node.children[leftIndex].points+leftNumPoints; node.children[leftIndex+splitSize].numPoints=node.children[leftIndex].numPoints-leftNumPoints; node.children[leftIndex].numPoints=leftNumPoints; } } /* Create the node's children's subtrees: */ for(int childIndex=0;childIndex<8;++childIndex) { Node& child=node.children[childIndex]; child.domain=Cube(node.domain,childIndex); createSubTree(node.children[childIndex]); } node.points=0; } }