make addChildAtIndex() use createNewElement() so we get our correct classes

This commit is contained in:
ZappoMan 2013-12-03 20:40:40 -08:00
parent 9faef65ccc
commit d7ae023492
9 changed files with 27 additions and 29 deletions

View file

@ -537,16 +537,6 @@ OctreeElement* Octree::getOctreeElementAt(float x, float y, float z, float s) co
return node;
}
void Octree::createOctreeElement(float x, float y, float z, float s,
unsigned char red, unsigned char green, unsigned char blue, bool destructive) {
// XXXBHG Octree cleanup
//unsigned char* voxelData = pointToVoxel(x,y,z,s,red,green,blue);
//this->readCodeColorBufferToTree(voxelData, destructive);
//delete[] voxelData;
}
// combines the ray cast arguments into a single object
class RayArgs {
public:

View file

@ -191,8 +191,6 @@ public:
void deleteOctreeElementAt(float x, float y, float z, float s);
OctreeElement* getOctreeElementAt(float x, float y, float z, float s) const;
void createOctreeElement(float x, float y, float z, float s,
unsigned char red, unsigned char green, unsigned char blue, bool destructive = false);
void recurseTreeWithOperation(RecurseOctreeOperation operation, void* extraData=NULL);

View file

@ -1108,8 +1108,8 @@ OctreeElement* OctreeElement::addChildAtIndex(int childIndex) {
_voxelNodeLeafCount--;
}
childAt = new OctreeElement(childOctalCode(getOctalCode(), childIndex));
//childAt->setVoxelSystem(getVoxelSystem()); // our child is always part of our voxel system NULL ok
unsigned char* newChildCode = childOctalCode(getOctalCode(), childIndex);
childAt = createNewElement(newChildCode);
setChildAtIndex(childIndex, childAt);
_isDirty = true;

View file

@ -46,6 +46,8 @@ class OctreeElement {
protected:
// can only be constructed by derived implementation
OctreeElement(unsigned char * octalCode = NULL);
virtual OctreeElement* createNewElement(unsigned char * octalCode = NULL) const = 0;
public:
virtual ~OctreeElement();
@ -160,7 +162,7 @@ protected:
void checkStoreFourChildren(OctreeElement* childOne, OctreeElement* childTwo, OctreeElement* childThree, OctreeElement* childFour);
#endif
void calculateAABox();
virtual void init(unsigned char * octalCode);
void init(unsigned char * octalCode);
void notifyDeleteHooks();
void notifyUpdateHooks();

View file

@ -339,6 +339,7 @@ unsigned char* pointToVoxel(float x, float y, float z, float s, unsigned char r,
if (s >= 1.0) {
unsigned char* voxelOut = new unsigned char;
*voxelOut = 0;
return voxelOut;
}
float xTest, yTest, zTest, sTest;

View file

@ -43,11 +43,12 @@ VoxelTreeElement* VoxelTree::getVoxelAt(float x, float y, float z, float s) cons
void VoxelTree::createVoxel(float x, float y, float z, float s,
unsigned char red, unsigned char green, unsigned char blue, bool destructive) {
unsigned char* voxelData = pointToVoxel(x,y,z,s,red,green,blue);
int length = bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(voxelData)) + BYTES_PER_COLOR;
printf("createVoxel()...");
outputBufferBits(voxelData,length);
//int length = bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(voxelData)) + BYTES_PER_COLOR;
//printf("createVoxel()...");
//outputBufferBits(voxelData,length);
this->readCodeColorBufferToTree(voxelData, destructive);
delete[] voxelData;
@ -617,7 +618,7 @@ void VoxelTree::readCodeColorBufferToTreeRecursion(VoxelTreeElement* node, ReadC
}
// Ok, we know we haven't reached our target node yet, so keep looking
printOctalCode(args.codeColorBuffer);
//printOctalCode(args.codeColorBuffer);
int childIndex = branchIndexWithDescendant(node->getOctalCode(), args.codeColorBuffer);
VoxelTreeElement* childNode = node->getChildAtIndex(childIndex);

View file

@ -16,11 +16,14 @@
VoxelTreeElement::VoxelTreeElement(unsigned char* octalCode) : OctreeElement(octalCode) {
// probably need to do all the color init here....
init();
};
OctreeElement* VoxelTreeElement::createNewElement(unsigned char* octalCode) const {
return new VoxelTreeElement(octalCode);
}
void VoxelTreeElement::init(unsigned char* octalCode) {
OctreeElement::init(octalCode);
void VoxelTreeElement::init() {
_falseColored = false; // assume true color
_currentColor[0] = _currentColor[1] = _currentColor[2] = _currentColor[3] = 0;
_trueColor[0] = _trueColor[1] = _trueColor[2] = _trueColor[3] = 0;

View file

@ -30,9 +30,11 @@ class VoxelTreeElement : public OctreeElement {
friend class VoxelTree; // to allow createElement to new us...
VoxelTreeElement(unsigned char* octalCode = NULL);
virtual OctreeElement* createNewElement(unsigned char* octalCode = NULL) const;
public:
virtual void init(unsigned char* octalCode);
void init();
virtual bool hasContent() const { return isColored(); }
virtual void splitChildren();

View file

@ -362,11 +362,12 @@ int main(int argc, const char * argv[])
}
void unitTest(VoxelTree * tree) {
VoxelTreeElement* node = NULL;
printf("unit tests...\n");
unsigned long nodeCount;
// We want our corner voxels to be about 1/2 meter high, and our TREE_SCALE is in meters, so...
float voxelSize = 0.5f;
float voxelSize = 0.5f / TREE_SCALE;
// Here's an example of how to create a voxel.
printf("creating corner points...\n");
@ -375,7 +376,7 @@ void unitTest(VoxelTree * tree) {
// Here's an example of how to test if a voxel exists
VoxelTreeElement* node = tree->getVoxelAt(0, 0, 0, voxelSize);
node = tree->getVoxelAt(0, 0, 0, voxelSize);
if (node) {
// and how to access it's color
printf("CORRECT - corner point 0,0,0 exists... color is (%d,%d,%d) \n",
@ -391,7 +392,7 @@ void unitTest(VoxelTree * tree) {
printf("Nodes at line %d... %ld nodes\n", __LINE__, tree->getOctreeElementsCount());
// Test to see that the delete worked... it should be FALSE...
if (tree->getVoxelAt(0, 0, 0, voxelSize)) {
if ((node = tree->getVoxelAt(0, 0, 0, voxelSize))) {
printf("FAIL corner point 0,0,0 exists...\n");
} else {
printf("CORRECT corner point 0,0,0 does not exists...\n");
@ -400,7 +401,7 @@ void unitTest(VoxelTree * tree) {
printf("Nodes at line %d... %ld nodes\n", __LINE__, tree->getOctreeElementsCount());
tree->createVoxel(0, 0, 0, voxelSize, 255, 255 ,255);
if (tree->getVoxelAt(0, 0, 0, voxelSize)) {
if ((node = tree->getVoxelAt(0, 0, 0, voxelSize))) {
printf("CORRECT - corner point 0,0,0 exists... color is (%d,%d,%d) \n",
node->getColor()[0], node->getColor()[1], node->getColor()[2]);
} else {
@ -410,7 +411,7 @@ void unitTest(VoxelTree * tree) {
printf("Nodes at line %d... %ld nodes\n", __LINE__, tree->getOctreeElementsCount());
tree->createVoxel(voxelSize, 0, 0, voxelSize, 255, 255 ,0);
if (tree->getVoxelAt(voxelSize, 0, 0, voxelSize)) {
if ((node = tree->getVoxelAt(voxelSize, 0, 0, voxelSize))) {
printf("CORRECT - corner point voxelSize,0,0 exists... color is (%d,%d,%d) \n",
node->getColor()[0], node->getColor()[1], node->getColor()[2]);
} else {
@ -420,7 +421,7 @@ void unitTest(VoxelTree * tree) {
printf("Nodes at line %d... %ld nodes\n", __LINE__, tree->getOctreeElementsCount());
tree->createVoxel(0, 0, voxelSize, voxelSize, 255, 0 ,0);
if (tree->getVoxelAt(0, 0, voxelSize, voxelSize)) {
if ((node = tree->getVoxelAt(0, 0, voxelSize, voxelSize))) {
printf("CORRECT - corner point 0, 0, voxelSize exists... color is (%d,%d,%d) \n",
node->getColor()[0], node->getColor()[1], node->getColor()[2]);
} else {
@ -430,7 +431,7 @@ void unitTest(VoxelTree * tree) {
printf("Nodes at line %d... %ld nodes\n", __LINE__, tree->getOctreeElementsCount());
tree->createVoxel(voxelSize, 0, voxelSize, voxelSize, 0, 0 ,255);
if (tree->getVoxelAt(voxelSize, 0, voxelSize, voxelSize)) {
if ((node = tree->getVoxelAt(voxelSize, 0, voxelSize, voxelSize))) {
printf("CORRECT - corner point voxelSize, 0, voxelSize exists... color is (%d,%d,%d) \n",
node->getColor()[0], node->getColor()[1], node->getColor()[2]);
} else {