From f435a096735ff498b8af22f8047dd4c97d0c3edb Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 22 Mar 2013 18:19:37 -0700 Subject: [PATCH] add method to repair child masks after adding randomly placed voxels --- shared/src/VoxelTree.cpp | 25 +++++++++++++++++++++++++ shared/src/VoxelTree.h | 1 + 2 files changed, 26 insertions(+) diff --git a/shared/src/VoxelTree.cpp b/shared/src/VoxelTree.cpp index 941e6af3dc..005ee33640 100644 --- a/shared/src/VoxelTree.cpp +++ b/shared/src/VoxelTree.cpp @@ -159,6 +159,31 @@ void VoxelTree::readCodeColorBufferToTree(unsigned char *codeColorBuffer) { // give this node its color memcpy(lastCreatedNode->color, codeColorBuffer + octalCodeBytes, 3); lastCreatedNode->color[3] = 1; + + repairChildMasks(rootNode); +} + +int VoxelTree::repairChildMasks(VoxelNode *currentNode) { + + currentNode->childMask = 0; + int grandChildren = 0; + int thisNodeGrandChildren = 0; + + for (int i = 0; i < 8; i++) { + + if (currentNode->children[i] != NULL) { + thisNodeGrandChildren = repairChildMasks(currentNode->children[i]); + + if (thisNodeGrandChildren > 0) { + currentNode->childMask += (1 << (7 - i)); + } + + thisNodeGrandChildren += grandChildren; + } + } + + return grandChildren; + } unsigned char * VoxelTree::loadBitstreamBuffer(unsigned char *& bitstreamBuffer, diff --git a/shared/src/VoxelTree.h b/shared/src/VoxelTree.h index f5b8aeeced..9c5b75df35 100644 --- a/shared/src/VoxelTree.h +++ b/shared/src/VoxelTree.h @@ -29,6 +29,7 @@ public: int levelForViewerPosition(float * position); void readBitstreamToTree(unsigned char * bitstream, int bufferSizeBytes); void readCodeColorBufferToTree(unsigned char *codeColorBuffer); + int repairChildMasks(VoxelNode *currentNode); unsigned char * loadBitstreamBuffer(unsigned char *& bitstreamBuffer, unsigned char * octalCode, VoxelNode *currentVoxelNode,