Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[Manta] r2152 - in trunk: Core Core/Containers Model/Groups Model/Materials Model/Readers scenes/galileo


Chronological Thread 
  • From: "Thiago Ize" <thiago@sci.utah.edu>
  • To: manta@sci.utah.edu
  • Subject: [Manta] r2152 - in trunk: Core Core/Containers Model/Groups Model/Materials Model/Readers scenes/galileo
  • Date: Thu, 27 Mar 2008 13:08:29 -0600 (MDT)

Author: thiago
Date: Thu Mar 27 13:08:28 2008
New Revision: 2152

Added:
   trunk/Core/Containers/GridArray3.h
Modified:
   trunk/Core/CMakeLists.txt
   trunk/Model/Groups/RecursiveGrid.h
   trunk/Model/Materials/Volume.h
   trunk/Model/Readers/VolumeNRRD.h
   trunk/scenes/galileo/galileo.cc
Log:
Moved the GridArray3 code into its own class in Core/Containers.

Removed more references to GriddedGroup and replaced with GridArray3.h
where appropriate. However, I can't actually compile that code to test to
see if it works due to ifdefs.


Modified: trunk/Core/CMakeLists.txt
==============================================================================
--- trunk/Core/CMakeLists.txt   (original)
+++ trunk/Core/CMakeLists.txt   Thu Mar 27 13:08:28 2008
@@ -1,6 +1,7 @@
 
 SET (CORE_SOURCES)
 SET (CORE_SOURCES ${CORE_SOURCES}
+     Containers/GridArray3.h
      Containers/StringUtil.h
      Containers/StringUtil.cc)
 

Added: trunk/Core/Containers/GridArray3.h
==============================================================================
--- (empty file)
+++ trunk/Core/Containers/GridArray3.h  Thu Mar 27 13:08:28 2008
@@ -0,0 +1,120 @@
+/* This creates a 3D grid of type T in a way that is cache
+ * friendly. Traversing a ray through this grid should result in less
+ * cache misses than traversing in a standard grid since adjacent
+ * cells are usually adjacent in memory (in a standard grid, cells are
+ * only adjacent in memory for one dimension of travel).
+ */
+
+namespace Manta {
+
+  template<typename T>
+  class GridArray3 {
+   public:
+    GridArray3() {
+      nx = ny = nz = extra = 0;
+      xidx = yidx = zidx = 0;
+      data = 0;
+    }
+    GridArray3(int nx, int ny, int nz, int extra = 0) {
+      xidx = yidx = zidx = 0;
+      data = 0;
+      resize(nx, ny, nz, extra);
+    }
+    ~GridArray3() {
+      resize(0, 0, 0);
+    }
+
+    void resize(int newnx, int newny, int newnz, int newextra = 0) {
+      if(xidx)
+        delete[] xidx;
+      if(yidx)
+        delete[] yidx;
+      if(zidx)
+        delete[] zidx;
+      if(data)
+        delete[] data;
+      nx = newnx; ny = newny; nz = newnz; extra = newextra;
+      int total = nx*ny*nz+extra;
+      if(total != 0){
+        data = new T[total];
+        allocateAndInitializeStride(xidx, nx, 1);
+        allocateAndInitializeStride(yidx, ny, nx);
+        allocateAndInitializeStride(zidx, nz, nx*ny);
+      } else {
+        xidx = yidx = zidx = 0;
+        data = 0;
+      }
+    }
+
+    void resizeZMajor(int newnx, int newny, int newnz, int newextra = 0) {
+      if(xidx)
+        delete[] xidx;
+      if(yidx)
+        delete[] yidx;
+      if(zidx)
+        delete[] zidx;
+      if(data)
+        delete[] data;
+      nx = newnx; ny = newny; nz = newnz; extra = newextra;
+      int total = nx*ny*nz+extra;
+      if(total != 0){
+        data = new T[total];
+        allocateAndInitializeStride(xidx, nx, nz*ny);
+        allocateAndInitializeStride(yidx, ny, nz);
+        allocateAndInitializeStride(zidx, nz, 1);
+      } else {
+        xidx = yidx = zidx = 0;
+        data = 0;
+      }
+    }
+
+    void initialize(const T& value) {
+      int total = nx*ny*nz+extra;
+      for(int i=0;i<total;i++)
+        data[i] = value;
+    }
+
+    T& operator()(int x, int y, int z) {
+      return data[xidx[x] + yidx[y] + zidx[z]];
+    }
+    const T& operator()(int x, int y, int z) const {
+      return data[xidx[x] + yidx[y] + zidx[z]];
+    }
+    int getIndex(int x, int y, int z) const {
+      return xidx[x] + yidx[y] + zidx[z];
+    }
+    T& operator[](int idx) {
+      return data[idx];
+    }
+    const T& operator[](int idx) const {
+      return data[idx];
+    }
+
+    int getNx() const {
+      return nx;
+    }
+    int getNy() const {
+      return ny;
+    }
+    int getNz() const {
+      return nz;
+    }
+
+
+   private:
+    GridArray3(const GridArray3&);
+    GridArray3& operator=(const GridArray3&);
+
+    int nx, ny, nz, extra;
+    int* xidx;
+    int* yidx;
+    int* zidx;
+    T* data;
+
+    void allocateAndInitializeStride(int*& idx, int num, int stride) {
+      idx = new int[num];
+      for(int i=0;i<num;i++)
+        idx[i] = stride*i;
+    }
+  };
+};

Modified: trunk/Model/Groups/RecursiveGrid.h
==============================================================================
--- trunk/Model/Groups/RecursiveGrid.h  (original)
+++ trunk/Model/Groups/RecursiveGrid.h  Thu Mar 27 13:08:28 2008
@@ -3,6 +3,7 @@
 
 #include <Model/Groups/Group.h>
 #include <Model/Groups/Mesh.h>
+#include <Core/Containers/GridArray3.h>
 #include <Core/Geometry/Vector.h>
 #include <Core/Geometry/BBox.h>
 #include <Interface/RayPacket.h>
@@ -11,119 +12,6 @@
 #include <vector>
 
 namespace Manta {
-
-  template<typename T>
-  class GridArray3 {
-   public:
-    GridArray3() {
-      nx = ny = nz = extra = 0;
-      xidx = yidx = zidx = 0;
-      data = 0;
-    }
-    GridArray3(int nx, int ny, int nz, int extra = 0) {
-      xidx = yidx = zidx = 0;
-      data = 0;
-      resize(nx, ny, nz, extra);
-    }
-    ~GridArray3() {
-      resize(0, 0, 0);
-    }
-
-    void resize(int newnx, int newny, int newnz, int newextra = 0) {
-      if(xidx)
-        delete[] xidx;
-      if(yidx)
-        delete[] yidx;
-      if(zidx)
-        delete[] zidx;
-      if(data)
-        delete[] data;
-      nx = newnx; ny = newny; nz = newnz; extra = newextra;
-      int total = nx*ny*nz+extra;
-      if(total != 0){
-        data = new T[total];
-        allocateAndInitializeStride(xidx, nx, 1);
-        allocateAndInitializeStride(yidx, ny, nx);
-        allocateAndInitializeStride(zidx, nz, nx*ny);
-      } else {
-        xidx = yidx = zidx = 0;
-        data = 0;
-      }
-    }
-
-    void resizeZMajor(int newnx, int newny, int newnz, int newextra = 0) {
-      if(xidx)
-        delete[] xidx;
-      if(yidx)
-        delete[] yidx;
-      if(zidx)
-        delete[] zidx;
-      if(data)
-        delete[] data;
-      nx = newnx; ny = newny; nz = newnz; extra = newextra;
-      int total = nx*ny*nz+extra;
-      if(total != 0){
-        data = new T[total];
-        allocateAndInitializeStride(xidx, nx, nz*ny);
-        allocateAndInitializeStride(yidx, ny, nz);
-        allocateAndInitializeStride(zidx, nz, 1);
-      } else {
-        xidx = yidx = zidx = 0;
-        data = 0;
-      }
-    }
-
-    void initialize(const T& value) {
-      int total = nx*ny*nz+extra;
-      for(int i=0;i<total;i++)
-        data[i] = value;
-    }
-
-    T& operator()(int x, int y, int z) {
-      return data[xidx[x] + yidx[y] + zidx[z]];
-    }
-    const T& operator()(int x, int y, int z) const {
-      return data[xidx[x] + yidx[y] + zidx[z]];
-    }
-    int getIndex(int x, int y, int z) const {
-      return xidx[x] + yidx[y] + zidx[z];
-    }
-    T& operator[](int idx) {
-      return data[idx];
-    }
-    const T& operator[](int idx) const {
-      return data[idx];
-    }
-
-    int getNx() const {
-      return nx;
-    }
-    int getNy() const {
-      return ny;
-    }
-    int getNz() const {
-      return nz;
-    }
-
-
-   private:
-    GridArray3(const GridArray3&);
-    GridArray3& operator=(const GridArray3&);
-
-    int nx, ny, nz, extra;
-    int* xidx;
-    int* yidx;
-    int* zidx;
-    T* data;
-
-    void allocateAndInitializeStride(int*& idx, int num, int stride) {
-      idx = new int[num];
-      for(int i=0;i<num;i++)
-        idx[i] = stride*i;
-    }
-  };
-
-
   class RecursiveGrid : public AccelerationStructure {
    public:
     RecursiveGrid(int numLevels = 3);

Modified: trunk/Model/Materials/Volume.h
==============================================================================
--- trunk/Model/Materials/Volume.h      (original)
+++ trunk/Model/Materials/Volume.h      Thu Mar 27 13:08:28 2008
@@ -9,6 +9,7 @@
 #ifndef VOLUME_H
 #define VOLUME_H
 
+#include <Core/Containers/GridArray3.h>
 #include <Core/Geometry/BBox.h>
 #include <Core/Geometry/Vector.h>
 #include <Core/Thread/Barrier.h>
@@ -24,7 +25,6 @@
 #include <Interface/SampleGenerator.h>
 #include <Interface/Scene.h>
 
-#include <Model/Groups/GriddedGroup.h>
 #include <Model/Materials/OpaqueShadower.h>
 #include <Model/Readers/VolumeNRRD.h>
 
@@ -155,7 +155,7 @@
         else
           out << "0";
       }
-       return out;
+    return out;
     }
   };
   struct CellData {

Modified: trunk/Model/Readers/VolumeNRRD.h
==============================================================================
--- trunk/Model/Readers/VolumeNRRD.h    (original)
+++ trunk/Model/Readers/VolumeNRRD.h    Thu Mar 27 13:08:28 2008
@@ -8,7 +8,7 @@
 #define VOLUMENRRD_H
 
 #include <TeemConfig.h>
-#include <Model/Groups/GriddedGroup.h>
+#include <Core/Containers/GridArray3.h>
 #include <iostream>
 #if HAVE_TEEM
 #include <teem/nrrd.h>
@@ -19,24 +19,24 @@
 {
 #if HAVE_TEEM
 template<class T>
-               GridArray3<T>* loadNRRDToGrid(string file)
+        GridArray3<T>* loadNRRDToGrid(string file)
 {
-       GridArray3<T>* grid = new GridArray3<T>();
-       cout << "READING NRRD: " << file << " ";
-       Nrrd *new_nrrd = nrrdNew();
-       
////////////////////////////////////////////////////////////////////////////
+    GridArray3<T>* grid = new GridArray3<T>();
+    cout << "READING NRRD: " << file << " ";
+    Nrrd *new_nrrd = nrrdNew();
+    
////////////////////////////////////////////////////////////////////////////
     // Attempt to open the nrrd
-       if (nrrdLoad( new_nrrd, file.c_str(), 0 )) {
-               char *reason = biffGetDone( NRRD );
-               std::cout << "WARNING Loading Nrrd Failed: " << reason << 
std::endl;
-               exit(__LINE__);
-       }
+    if (nrrdLoad( new_nrrd, file.c_str(), 0 )) {
+        char *reason = biffGetDone( NRRD );
+        std::cout << "WARNING Loading Nrrd Failed: " << reason << std::endl;
+        exit(__LINE__);
+    }
 
     // Check to make sure the nrrd is the proper dimensions.
-       if (new_nrrd->dim != 3) {
-               std::cout << "WARNING Nrrd must three dimension RGB" << 
std::endl;
-               exit(__LINE__);
-       }
+    if (new_nrrd->dim != 3) {
+        std::cout << "WARNING Nrrd must three dimension RGB" << std::endl;
+        exit(__LINE__);
+    }
         
     // Check that the nrrd is the correct type.
     //  if (new_nrrd->type != nrrdTypeFloat) {
@@ -51,58 +51,58 @@
     //  }
 
     //Determine scaling for the volume.
-       Vector size( new_nrrd->axis[0].size * new_nrrd->axis[0].spacing,
-                                        new_nrrd->axis[1].size * 
new_nrrd->axis[1].spacing,
-                                        new_nrrd->axis[2].size * 
new_nrrd->axis[2].spacing );
-       size = Vector(new_nrrd->axis[0].size, new_nrrd->axis[1].size, 
new_nrrd->axis[2].size);
-       cout << "size: " << size.x() << " " << size.y() << " " << size.z() << 
endl;
+    Vector size( new_nrrd->axis[0].size * new_nrrd->axis[0].spacing,
+                     new_nrrd->axis[1].size * new_nrrd->axis[1].spacing,
+                     new_nrrd->axis[2].size * new_nrrd->axis[2].spacing );
+    size = Vector(new_nrrd->axis[0].size, new_nrrd->axis[1].size, 
new_nrrd->axis[2].size);
+    cout << "size: " << size.x() << " " << size.y() << " " << size.z() << 
endl;
     // Rescale.
-       float max_dim = max( size.x(), max( size.y(), size.z() ) );
-       cout << "resizing\n";
-       size /= max_dim;
+    float max_dim = max( size.x(), max( size.y(), size.z() ) );
+    cout << "resizing\n";
+    size /= max_dim;
         
     //_minBound = -size/2.0;
     //_maxBound = size/2.0;
-       cout << "resizing grid\n";      
-       grid->resize(new_nrrd->axis[0].size, new_nrrd->axis[1].size, 
new_nrrd->axis[2].size);
-       cout << "copying nrrd data\n";
-       for(int i=0; i<grid->getNz(); i++)
-               for(int j=0; j<grid->getNy(); j++)
-                       for(int k=0; k<grid->getNx(); k++)
-       {
+    cout << "resizing grid\n";      
+    grid->resize(new_nrrd->axis[0].size, new_nrrd->axis[1].size, 
new_nrrd->axis[2].size);
+    cout << "copying nrrd data\n";
+    for(int i=0; i<grid->getNz(); i++)
+        for(int j=0; j<grid->getNy(); j++)
+            for(int k=0; k<grid->getNx(); k++)
+    {
             //(*grid)(k,j,i) = 0.0;
             //(*grid)(k,j,i) = (*dataPtr)++;
             //void* vd = (void *) (&(idata[((i*ny + j)*nx + k) * 
formatSize]));
-               if (new_nrrd->type == nrrdTypeFloat)
-                       (*grid)(k,j,i) = 
((float*)new_nrrd->data)[(int)(((i*grid->getNy() + j)*grid->getNx() + k))];
-               else if (new_nrrd->type == nrrdTypeChar)
-                       (*grid)(k,j,i) = 
((char*)new_nrrd->data)[(int)(((i*grid->getNy() + j)*grid->getNx() + k))];
-               else if (new_nrrd->type == nrrdTypeDouble)
-                       (*grid)(k,j,i) = 
((double*)new_nrrd->data)[(int)(((i*grid->getNy() + j)*grid->getNx() + k))];
-               else if (new_nrrd->type == nrrdTypeUChar)
-                       (*grid)(k,j,i) = ((unsigned 
char*)new_nrrd->data)[(int)(((i*grid->getNy() + j)*grid->getNx() + k))];
-               else if (new_nrrd->type == nrrdTypeShort)
-                       (*grid)(k,j,i) = 
((short*)new_nrrd->data)[(int)(((i*grid->getNy() + j)*grid->getNx() + k))];
-               else if (new_nrrd->type == nrrdTypeUShort)
-                       (*grid)(k,j,i) = ((unsigned 
short*)new_nrrd->data)[(int)(((i*grid->getNy() + j)*grid->getNx() + k))];
-               else if (new_nrrd->type == nrrdTypeInt)
-                       (*grid)(k,j,i) = 
((int*)new_nrrd->data)[(int)(((i*grid->getNy() + j)*grid->getNx() + k))];
-               else if (new_nrrd->type == nrrdTypeUInt)
-                       (*grid)(k,j,i) = ((unsigned 
int*)new_nrrd->data)[(int)(((i*grid->getNy() + j)*grid->getNx() + k))];
+        if (new_nrrd->type == nrrdTypeFloat)
+            (*grid)(k,j,i) = 
((float*)new_nrrd->data)[(int)(((i*grid->getNy() + j)*grid->getNx() + k))];
+        else if (new_nrrd->type == nrrdTypeChar)
+            (*grid)(k,j,i) = ((char*)new_nrrd->data)[(int)(((i*grid->getNy() 
+ j)*grid->getNx() + k))];
+        else if (new_nrrd->type == nrrdTypeDouble)
+            (*grid)(k,j,i) = 
((double*)new_nrrd->data)[(int)(((i*grid->getNy() + j)*grid->getNx() + k))];
+        else if (new_nrrd->type == nrrdTypeUChar)
+            (*grid)(k,j,i) = ((unsigned 
char*)new_nrrd->data)[(int)(((i*grid->getNy() + j)*grid->getNx() + k))];
+        else if (new_nrrd->type == nrrdTypeShort)
+            (*grid)(k,j,i) = 
((short*)new_nrrd->data)[(int)(((i*grid->getNy() + j)*grid->getNx() + k))];
+        else if (new_nrrd->type == nrrdTypeUShort)
+            (*grid)(k,j,i) = ((unsigned 
short*)new_nrrd->data)[(int)(((i*grid->getNy() + j)*grid->getNx() + k))];
+        else if (new_nrrd->type == nrrdTypeInt)
+            (*grid)(k,j,i) = ((int*)new_nrrd->data)[(int)(((i*grid->getNy() 
+ j)*grid->getNx() + k))];
+        else if (new_nrrd->type == nrrdTypeUInt)
+            (*grid)(k,j,i) = ((unsigned 
int*)new_nrrd->data)[(int)(((i*grid->getNy() + j)*grid->getNx() + k))];
             //                          if (new_nrrd->type == nrrdTypeLong)
             //                                  (*grid)(k,j,i) = 
((long*)new_nrrd->data)[(int)(((i*grid->getNy() + j)*grid->getNx() + k))];
             //                          if (new_nrrd->type == nrrdTypeULong)
             //                                  (*grid)(k,j,i) = ((unsigned 
long*)new_nrrd->data)[(int)(((i*grid->getNy() + j)*grid->getNx() + k))];
-       }
-       cout << "done\n";
-       return grid;
+    }
+    cout << "done\n";
+    return grid;
 }
 #else
 template<class T>
-               GridArray3<T>* loadNRRDToGrid(string file)
+        GridArray3<T>* loadNRRDToGrid(string file)
 {
-       cerr << "Error: " << __FILE__ << ": please link Manta with TEEM\n";   
  
-       return new GridArray3<T>();
+    cerr << "Error: " << __FILE__ << ": please link Manta with TEEM\n";
+    return new GridArray3<T>();
 }
 #endif
 

Modified: trunk/scenes/galileo/galileo.cc
==============================================================================
--- trunk/scenes/galileo/galileo.cc     (original)
+++ trunk/scenes/galileo/galileo.cc     Thu Mar 27 13:08:28 2008
@@ -12,7 +12,6 @@
 #include <Model/AmbientLights/ArcAmbient.h>
 #include <Model/AmbientLights/ConstantAmbient.h>
 #include <Model/Backgrounds/LinearBackground.h>
-#include <Model/Groups/GriddedGroup.h>
 #include <Model/Groups/Group.h>
 #include <Model/Lights/PointLight.h>
 #include <Model/Materials/Lambertian.h>




  • [Manta] r2152 - in trunk: Core Core/Containers Model/Groups Model/Materials Model/Readers scenes/galileo, Thiago Ize, 03/27/2008

Archive powered by MHonArc 2.6.16.

Top of page