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 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,
 #ifndef D_ARRAY
 #define D_ARRAY
 #include "constants.h"
 #include "octreeNode.h"
 class DataArray {
   uchar data[xVal][yVal][zVal];
   void ReadData() {
     for (int i=0; i> data[k][j][i];
   void WriteData() {
     for (int i=0; ivalue = data[fromX][fromY][fromZ];
       return parent;
     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;
 // Octtree Program -- octreenode.h
 // Lynn Jones, Virginia Tech,
 #ifndef OCTNODE

Scott Gasch