This commit is contained in:
Atlante45 2014-04-25 13:33:59 -07:00
parent 860766fb49
commit 3143e10bd8
5 changed files with 30 additions and 5 deletions

View file

@ -542,6 +542,19 @@ OctreeElement* Octree::getOctreeElementAt(float x, float y, float z, float s) co
return node;
}
OctreeElement* Octree::getOctreeEnclosingElementAt(float x, float y, float z, float s) const {
unsigned char* octalCode = pointToOctalCode(x,y,z,s);
OctreeElement* node = nodeForOctalCode(_rootNode, octalCode, NULL);
delete[] octalCode; // cleanup memory
#ifdef HAS_AUDIT_CHILDREN
if (node) {
node->auditChildren("Octree::getOctreeElementAt()");
}
#endif // def HAS_AUDIT_CHILDREN
return node;
}
OctreeElement* Octree::getOrCreateChildElementAt(float x, float y, float z, float s) {
return getRoot()->getOrCreateChildElementAt(x, y, z, s);

View file

@ -210,7 +210,15 @@ public:
void reaverageOctreeElements(OctreeElement* startNode = NULL);
void deleteOctreeElementAt(float x, float y, float z, float s);
/// Find the voxel at position x,y,z,s
/// \return pointer to the OctreeElement or NULL if none at x,y,z,s.
OctreeElement* getOctreeElementAt(float x, float y, float z, float s) const;
/// Find the voxel at position x,y,z,s
/// \return pointer to the OctreeElement or to the smallest enclosing parent if none at x,y,z,s.
OctreeElement* getOctreeEnclosingElementAt(float x, float y, float z, float s) const;
OctreeElement* getOrCreateChildElementAt(float x, float y, float z, float s);
void recurseTreeWithOperation(RecurseOctreeOperation operation, void* extraData = NULL);

View file

@ -46,10 +46,7 @@ VoxelTreeElement* VoxelTree::getVoxelAt(float x, float y, float z, float s) cons
}
VoxelTreeElement* VoxelTree::getEnclosingVoxelAt(float x, float y, float z, float s) const {
unsigned char* octalCode = pointToOctalCode(x,y,z,s);
OctreeElement* node = nodeForOctalCode(_rootNode, octalCode, NULL);
return static_cast<VoxelTreeElement*>(node);
return static_cast<VoxelTreeElement*>(getOctreeEnclosingElementAt(x, y, z, s));
}
void VoxelTree::createVoxel(float x, float y, float z, float s,

View file

@ -29,8 +29,15 @@ public:
VoxelTreeElement* getRoot() { return (VoxelTreeElement*)_rootNode; }
void deleteVoxelAt(float x, float y, float z, float s);
/// Find the voxel at position x,y,z,s
/// \return pointer to the VoxelTreeElement or NULL if none at x,y,z,s.
VoxelTreeElement* getVoxelAt(float x, float y, float z, float s) const;
/// Find the voxel at position x,y,z,s
/// \return pointer to the VoxelTreeElement or to the smallest enclosing parent if none at x,y,z,s.
VoxelTreeElement* getEnclosingVoxelAt(float x, float y, float z, float s) const;
void createVoxel(float x, float y, float z, float s,
unsigned char red, unsigned char green, unsigned char blue, bool destructive = false);

View file

@ -22,7 +22,7 @@ struct SendVoxelsOperationArgs {
bool sendVoxelsOperation(OctreeElement* element, void* extraData) {
VoxelTreeElement* voxel = static_cast<VoxelTreeElement*>(element);
SendVoxelsOperationArgs* args = (SendVoxelsOperationArgs*)extraData;
SendVoxelsOperationArgs* args = static_cast<SendVoxelsOperationArgs*>(extraData);
if (voxel->isColored()) {
const unsigned char* nodeOctalCode = voxel->getOctalCode();
unsigned char* codeColorBuffer = NULL;