From c641f1269399c742f24df8cf847d741905a17f16 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 22 Mar 2013 17:59:54 -0700 Subject: [PATCH] some refactoring in for readCodeColorBufferToTree --- shared/src/OctalCode.cpp | 2 +- shared/src/OctalCode.h | 2 +- shared/src/VoxelTree.cpp | 9 +++------ shared/src/VoxelTree.h | 1 + 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/shared/src/OctalCode.cpp b/shared/src/OctalCode.cpp index 3b22879b75..2a687f1cd4 100644 --- a/shared/src/OctalCode.cpp +++ b/shared/src/OctalCode.cpp @@ -43,7 +43,7 @@ int bytesRequiredForCodeLength(unsigned char threeBitCodes) { } } -char branchIndexWithDescendant(unsigned char * ancestorOctalCode, unsigned char * descendantOctalCode) { +int branchIndexWithDescendant(unsigned char * ancestorOctalCode, unsigned char * descendantOctalCode) { int parentSections = numberOfThreeBitSectionsInCode(ancestorOctalCode); int branchStartBit = parentSections * 3; diff --git a/shared/src/OctalCode.h b/shared/src/OctalCode.h index a292116a75..a20cc8dfae 100644 --- a/shared/src/OctalCode.h +++ b/shared/src/OctalCode.h @@ -14,7 +14,7 @@ void printOctalCode(unsigned char * octalCode); int bytesRequiredForCodeLength(unsigned char threeBitCodes); bool isDirectParentOfChild(unsigned char *parentOctalCode, unsigned char * childOctalCode); -char branchIndexWithDescendant(unsigned char * ancestorOctalCode, unsigned char * descendantOctalCode); +int branchIndexWithDescendant(unsigned char * ancestorOctalCode, unsigned char * descendantOctalCode); unsigned char * childOctalCode(unsigned char * parentOctalCode, char childNumber); float * firstVertexForCode(unsigned char * octalCode); diff --git a/shared/src/VoxelTree.cpp b/shared/src/VoxelTree.cpp index dff2787bf8..941e6af3dc 100644 --- a/shared/src/VoxelTree.cpp +++ b/shared/src/VoxelTree.cpp @@ -12,8 +12,6 @@ #include "OctalCode.h" #include "VoxelTree.h" -const int MAX_TREE_SLICE_BYTES = 26; - VoxelTree::VoxelTree() { rootNode = new VoxelNode(); rootNode->octalCode = new unsigned char[1]; @@ -46,9 +44,7 @@ int VoxelTree::levelForViewerPosition(float *position) { VoxelNode * VoxelTree::nodeForOctalCode(VoxelNode *ancestorNode, unsigned char * needleCode) { // find the appropriate branch index based on this ancestorNode - if (*needleCode == 0) { - return ancestorNode; - } else { + if (*needleCode > 0) { int branchForNeedle = branchIndexWithDescendant(ancestorNode->octalCode, needleCode); VoxelNode *childNode = ancestorNode->children[branchForNeedle]; @@ -156,7 +152,8 @@ void VoxelTree::readCodeColorBufferToTree(unsigned char *codeColorBuffer) { // create the node if it does not exist if (*lastCreatedNode->octalCode != *codeColorBuffer) { - lastCreatedNode = createMissingNode(lastCreatedNode, codeColorBuffer); + VoxelNode *parentNode = createMissingNode(lastCreatedNode, codeColorBuffer); + lastCreatedNode = parentNode->children[branchIndexWithDescendant(parentNode->octalCode, codeColorBuffer)]; } // give this node its color diff --git a/shared/src/VoxelTree.h b/shared/src/VoxelTree.h index f75d99d27b..f5b8aeeced 100644 --- a/shared/src/VoxelTree.h +++ b/shared/src/VoxelTree.h @@ -13,6 +13,7 @@ #include "VoxelNode.h" const int MAX_VOXEL_PACKET_SIZE = 1492; +const int MAX_TREE_SLICE_BYTES = 26; class VoxelTree { VoxelNode * nodeForOctalCode(VoxelNode *ancestorNode, unsigned char * needleCode);