int COctree::Create(std::vector<CMeshBufferGroup*> &in, int minMeshPerNode) { if(!BuildRootNode(in)) return 0; if(writeNode) ofs.open("octnode.txt"); BuildTree((OCT_NODE*)m_vecOctNode.back(), minMeshPerNode, in); std::cout << "Oct Node: " << m_vecOctNode.size() << " meshBuffer Index: " << m_vecMeshBufferIndexPtr.size() << std::endl; if(writeNode) ofs.close(); return 1; }
int OcTree::Create(Engine* engine, const TRI* tris, int triCount, int trisPerNode) { this->engine = engine; // Build our root node if (!BuildRootNode(tris, triCount)) return 0; // Build tree recursively BuildTree((OctNode*)OctNodeList.GetLast(), trisPerNode, tris, triCount); // Get the table and find neighbors int octCount; OctNode** octTable = (OctNode**)OctNodeList.BuildTable(&octCount); for (int i = 0; i < octCount; i++) { OctNode* node = octTable[i]; for (int j = 0; j < NUM_NEIGHBORS; j++) { int found = NULL_NODE; float foundSize = (float)(unsigned int)(1 << 31); // Max val BoxSide side; side.SetFromBox(node->BBox, j); FindNeighbor(octTable, octTable[0], &side, j, &found, &foundSize); node->NeighborIdx[j] = found; } // for (j) } // for (i) free(octTable); this->triangles = tris; // Get the final tables GetTables(&octreeTable, &octreeCount, &triangleIdxTable, &triangleIdxCount); return 1; }
void MedianCut::BuildTree(CodeBook &Codes, long TreeSize) { bool bFinished = false; TreeNode *pNode, *pLE, *pGT; cbVector *pVect; VectPtr *pList; long Axis, Len, i, Split, Count, NumLeaves, Changed = 0; ResetTree(); BuildRootNode(Codes); if(pRoot == 0) bFinished = true; NumLeaves = LeafList.Count(); while(!bFinished) { pNode = GetFirstLeaf(); Axis = pNode->LongAxis; Len = pNode->AxisLen; if(Len == 0) break; // Couldn't find a split - Finished // Create two new tree nodes pLE = pNode->pLessEqual = GetNewTreeNode(); pGT = pNode->pGreater = GetNewTreeNode(); // Choose a split point for the parent node Split = pNode->SplitPoint; pNode->SplitAxis = (u8)Axis; pNode->SplitPoint = (u8)Split; // Move all nodes from the parent into the two children Count = pNode->CodeList.Count(); pLE->CodeList.Resize(Count); pGT->CodeList.Resize(Count); pList = pNode->CodeList.Addr(0); for(i=0; i<Count; i++) { pVect = pList[i].pVect; if((*pVect)[Axis] <= Split) pLE->CodeList.Append(pList[i]); else pGT->CodeList.Append(pList[i]); } // Compute the min & max values of the two children pLE->ComputeBounds(); pLE->ComputeError(); pGT->ComputeBounds(); pGT->ComputeError(); pNode->CodeList.Resize(0); // Add the children to the leaf list and increment the leaf count LeafList.ExtractInsert( pLE ); LeafList.Insert( pGT ); NumLeaves++; if(NumLeaves == TreeSize) bFinished = true; } // Index the nodes Count = LeafList.Count(); for(i=0; i<Count; i++) { pNode = GetLeaf(i); pNode->Index = i; } }