next up previous contents index Search
Next: 0.3 Sorting Algorithms Up: 0.2.10 Quadtrees and Octrees Previous: 0.2.10 Quadtrees and Octrees

0.2.10.1 Octree Source Code

Many thanks to Lynn Jones for donating octree code to this collection. The following implementation was written in C++ by Lynn Jones in a research project at the University of South Carolina.





// Octree Program -- dataarray.h
 // Lynn Jones, Virginia Tech, lwjones@vt.edu
 
 #ifndef D_ARRAY
 #define D_ARRAY
 
 #include 
 #include "constants.h"
 #include "octreeNode.h"
 
 class DataArray {
 public:
   uchar data[xVal][yVal][zVal];
 
   DataArray(){}
   ~DataArray(){}
   
   void ReadData() {
     for (int i=0; i> data[k][j][i];
 	}
   }
   
   void WriteData() {
     for (int i=0; ivalue = data[fromX][fromY][fromZ];
       return parent;
     }
     //else
     parent = new OctreeNode(INTERNAL);  
     parent->children[0] = BuildTree(fromX, fromY, fromZ, length/2);
     parent->children[1] = BuildTree(fromX, fromY, fromZ+length/2, length/2);
     parent->children[2] = BuildTree(fromX, fromY+length/2,fromZ, length/2);
     parent->children[3] = BuildTree(fromX, fromY+length/2, fromZ+length/2, length/2);
     parent->children[4] = BuildTree(fromX+length/2, fromY, fromZ, length/2);
     parent->children[5] = BuildTree(fromX+length/2, fromY, fromZ+length/2, length/2);
     parent->children[6] = BuildTree(fromX+length/2, fromY+length/2, fromZ, length/2);
     parent->children[7] = BuildTree(fromX+length/2, fromY+length/2, fromZ+length/2, length/2);
     parent->value = parent->AverageChildren();
     return parent;
   }
 };
 #endif
 
 
 // Octtree Program -- octreenode.h
 // Lynn Jones, Virginia Tech, lwjones@vt.edu
 
 #ifndef OCTNODE




Scott Gasch
1999-07-09