Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[Manta] r1987 - in trunk/scenes/csafe: . python src swig


Chronological Thread 
  • From: brownlee@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [Manta] r1987 - in trunk/scenes/csafe: . python src swig
  • Date: Thu, 10 Jan 2008 18:59:24 -0700 (MST)

Author: brownlee
Date: Thu Jan 10 18:59:23 2008
New Revision: 1987

Removed:
   trunk/scenes/csafe/src/SIMD.hxx
Modified:
   trunk/scenes/csafe/CMakeLists.txt
   trunk/scenes/csafe/python/Configuration.py
   trunk/scenes/csafe/python/TransferF.py
   trunk/scenes/csafe/python/csafe.py
   trunk/scenes/csafe/src/CDGridSpheres.cc
   trunk/scenes/csafe/src/CDGridSpheres.h
   trunk/scenes/csafe/src/CDSWIGIFY.h
   trunk/scenes/csafe/src/CDTest.h
   trunk/scenes/csafe/swig/CMakeLists.txt
Log:
fixed csafe scene compilation issue on leopard.  also cleaned up some code

Modified: trunk/scenes/csafe/CMakeLists.txt
==============================================================================
--- trunk/scenes/csafe/CMakeLists.txt   (original)
+++ trunk/scenes/csafe/CMakeLists.txt   Thu Jan 10 18:59:23 2008
@@ -44,7 +44,7 @@
 # STEP ONE: CMake Options
 #
 
-PROJECT (Manta-project)
+PROJECT (CSAFE)
 
 # Project wide CMake options.
 SET(BUILD_SHARED_LIBS ON)
@@ -69,11 +69,9 @@
 # Additionally several .cmake scripts from the Manta build are executed to 
 # insure a similar build environment will be used by the project.
 INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/CMake/FindManta.cmake)
-#INCLUDE(${MANTA_SOURCE_DIR}/CMake/FindTeem.cmake)
 
 # If certain SCIRun classes are used from Manta it is necessary to define
-# SCI_NOPERSISTENT
-FORCE_ADD_FLAGS(CMAKE_CXX_FLAGS "-DSCI_NOPERSISTENT")
+#FORCE_ADD_FLAGS(CMAKE_CXX_FLAGS "-DSCI_NOPERSISTENT")
 
###############################################################################
 #
 # STEP THREE: Add new code in shared lib.
@@ -85,68 +83,21 @@
 INCLUDE_DIRECTORIES(
   ${CMAKE_CURRENT_SOURCE_DIR}/src
   )
-#INCLUDE_DIRECTORIES( /scratch/cgribble/teem/linux.64/include )
-#INCLUDE_DIRECTORIES(/Users/scerenon/teem/build/include )
 
 # ADD YOUR OWN SOURCE CODE AND CHANGE LIBRARY NAME HERE.
-ADD_LIBRARY(Example
-#src/CDColorMap.cc
-#src/CDColorMap.h
-#src/CDColorMap2.cc
-#src/CDColorMap2.h
-#src/CDVol.cc
-#src/CDVol.h
-#src/CDVolSSE3.cc
-#src/CDVolSSE3.h
-#src/CDVolTest.cc
-#src/Colorimetry.cc
-#src/Colorimetry.h
-#src/ColorMap.cc
-#src/ColorMap.h
-#src/InhomogeneousParticipatingMedium.cc
-#src/InhomogeneousParticipatingMedium.h
-#src/Physics.cc
-#src/Physics.h
-#src/VolumeReader.cc
-#src/VolumeReader.h
+ADD_LIBRARY(CSAFE
 src/CDSWIGIFY.h
-#src/ExampleTexture.cc
-#src/ExampleTexture.h
 src/CDTest.h
-#src/ParticleCGT.h
-#src/ParticleCGT.cc
 src/CDGridSpheres.cc
 src/CDGridSpheres.h
 )
 
-#ADD_LIBRARY(sphereTest
-#src/sphereTest.cc
-#)
-
-#ADD_LIBRARY(volTest
-#src/CDColorMap.cc
-#src/CDColorMap.h
-#src/CDColorMap2.cc
-#src/CDColorMap2.h
-#src/CDVolSSE3.cc
-#src/CDVolSSE3.h
-#src/CDVolTest.cc
-#src/ParticleCGT.h
-#src/ParticleCGT.cc
-#src/CDGridSpheres.h
-#src/CDGridSpheres.cc
-#)
 
 # CHANGE THE NAME OF YOUR LIBRARY HERE.
-TARGET_LINK_LIBRARIES(Example
+TARGET_LINK_LIBRARIES(CSAFE
   ${MANTA_TARGET_LINK_LIBRARIES}
   )
-#TARGET_LINK_LIBRARIES(sphereTest
-#  ${MANTA_TARGET_LINK_LIBRARIES}
-#  )
-#TARGET_LINK_LIBRARIES(volTest
-#  ${MANTA_TARGET_LINK_LIBRARIES}
-#  )
+
 
 
###############################################################################
 #
@@ -158,11 +109,3 @@
 SUBDIRS(
   swig
   )
-
-# Output a helper script for setting up path variables.
-FILE(WRITE ${CMAKE_BINARY_DIR}/bin/pythonpath.csh
-  "setenv PYTHONPATH 
${MANTA_SOURCE_DIR}/SwigInterface:${MANTA_LINK_DIRECTORIES}:${CMAKE_BINARY_DIR}/lib\n\n")
-FILE(WRITE ${CMAKE_BINARY_DIR}/bin/pythonpath.sh
-  "export 
PYTHONPATH=${MANTA_SOURCE_DIR}/SwigInterface:${MANTA_LINK_DIRECTORIES}:${CMAKE_BINARY_DIR}/lib\n\n")
-
-

Modified: trunk/scenes/csafe/python/Configuration.py
==============================================================================
--- trunk/scenes/csafe/python/Configuration.py  (original)
+++ trunk/scenes/csafe/python/Configuration.py  Thu Jan 10 18:59:23 2008
@@ -5,7 +5,7 @@
 import Histogram
 import TransferF
 import wxManta
-from example import *
+from csafe import *
 from manta import *
 
 def WriteConfiguration(scene, filename):

Modified: trunk/scenes/csafe/python/TransferF.py
==============================================================================
--- trunk/scenes/csafe/python/TransferF.py      (original)
+++ trunk/scenes/csafe/python/TransferF.py      Thu Jan 10 18:59:23 2008
@@ -4,12 +4,9 @@
 import random
 import wxManta
 
-# Import the manta module, the mantainterface module which was %import'ed
-# into swig/example.i is automatically included by the manta module.
 from manta import *
 
-# Import your new wrapped code.
-from example import *
+from csafe import *
 
 colors = [] # (pos, r, g, b, a)
 

Modified: trunk/scenes/csafe/python/csafe.py
==============================================================================
--- trunk/scenes/csafe/python/csafe.py  (original)
+++ trunk/scenes/csafe/python/csafe.py  Thu Jan 10 18:59:23 2008
@@ -36,13 +36,10 @@
 import wxManta
 import getopt, sys
 
-# Import the manta module, the mantainterface module which was %import'ed
-# into swig/example.i is automatically included by the manta module.
 from manta import *
 import sys, os, time, traceback, types
 import wx
-# Import your new wrapped code.
-from example import *
+from csafe import *
 
 
 import wx.lib.buttons
@@ -432,7 +429,6 @@
     def OnClickForward(self, evt):
        self.test.forwardAnimation()
 
-# Re:-create the default scene using the example texture.
 def initialize_scene( frame, engine ):
     frame = MyFrame(None, -1, "Histogram")
     frame.Show(True)   

Modified: trunk/scenes/csafe/src/CDGridSpheres.cc
==============================================================================
--- trunk/scenes/csafe/src/CDGridSpheres.cc     (original)
+++ trunk/scenes/csafe/src/CDGridSpheres.cc     Thu Jan 10 18:59:23 2008
@@ -25,600 +25,600 @@
 using namespace Manta;
 
 CDGridSpheres::CDGridSpheres(float* spheres, int nspheres, int nvars, int 
ncells,
-                         int depth, Real radius, int ridx, RGBAColorMap* 
cmap,
-                         int cidx) :
-  spheres(spheres), nspheres(nspheres), nvars(nvars),
-  radius(radius), ridx(ridx), ncells(ncells), depth(depth),
-  cmap(cmap), cidx(cidx)
-{
-  cerr<<"Initializing GridSpheres\n";
-
-  if (radius <= 0) {
-    if (ridx <= 0)
-      cerr<<"Resetting default radius to 1\n";
-    radius=1;
-  }
-
-  // Compute inverses
-  inv_radius=1/static_cast<Real>(radius);
-  inv_ncells=1/static_cast<Real>(ncells);
-
-  cerr<<"Recomputing min/max for GridSpheres\n";
-
-  // Initialize min/max arrays
-  min=new float[nvars];
-  max=new float[nvars];
-  cmin = new float[nvars];
-  cmax = new float[nvars];
-  clipMins = new float[nvars];
-  clipMaxs = new float[nvars];
-
-  for (int j=0; j<nvars; ++j) {
-    min[j]=FLT_MAX;
-    max[j]=-FLT_MAX;
-    clipMins[j] = -FLT_MAX;
-    clipMaxs[j] = FLT_MAX;
-    cmin[j] = min[j];
-    cmax[j] = max[j];
-  }
-
-  // Find min/max values
-  float* data=spheres;
-  for (int i=0; i<nspheres; ++i) {
-    for (int j=0; j<nvars; ++j) {
-      min[j]=Min(min[j], data[j]);
-      max[j]=Max(max[j], data[j]);
-    }
-
-    data += nvars;
-  }
-  for(int j = 0; j<nvars;j++)
-{
-       cmin[j] = min[j];
-       cmax[j] = max[j];
-}
-
-  counts=0;
-  cells=0;
-
+                                                        int depth, Real 
radius, int ridx, RGBAColorMap* cmap,
+                                                        int cidx) :
+spheres(spheres), nspheres(nspheres), nvars(nvars),
+radius(radius), ridx(ridx), ncells(ncells), depth(depth),
+cmap(cmap), cidx(cidx)
+{
+       cerr<<"Initializing GridSpheres\n";
+       
+       if (radius <= 0) {
+               if (ridx <= 0)
+                       cerr<<"Resetting default radius to 1\n";
+               radius=1;
+       }
+       
+       // Compute inverses
+       inv_radius=1/static_cast<Real>(radius);
+       inv_ncells=1/static_cast<Real>(ncells);
+       
+       cerr<<"Recomputing min/max for GridSpheres\n";
+       
+       // Initialize min/max arrays
+       min=new float[nvars];
+       max=new float[nvars];
+       cmin = new float[nvars];
+       cmax = new float[nvars];
+       clipMins = new float[nvars];
+       clipMaxs = new float[nvars];
+       
+       for (int j=0; j<nvars; ++j) {
+               min[j]=FLT_MAX;
+               max[j]=-FLT_MAX;
+               clipMins[j] = -FLT_MAX;
+               clipMaxs[j] = FLT_MAX;
+               cmin[j] = min[j];
+               cmax[j] = max[j];
+       }
+       
+       // Find min/max values
+       float* data=spheres;
+       for (int i=0; i<nspheres; ++i) {
+               for (int j=0; j<nvars; ++j) {
+                       min[j]=Min(min[j], data[j]);
+                       max[j]=Max(max[j], data[j]);
+               }
+               
+               data += nvars;
+       }
+       for(int j = 0; j<nvars;j++)
+       {
+               cmin[j] = min[j];
+               cmax[j] = max[j];
+       }
+       
+       counts=0;
+       cells=0;
+       
 #ifdef USE_FUNCTION_POINER
-  intersectSphere=0;
+       intersectSphere=0;
 #endif
 }
 
 CDGridSpheres::~CDGridSpheres()
 {
-  delete [] min;
-  delete [] max;
-  delete [] cmin;
-  delete [] cmax;
-  delete [] clipMins;
-  delete [] clipMaxs;
-
-  if (counts)
-    delete[] counts;
-
-  if (cells)
-    delete[] cells;
-
-  if (macrocells)
-    delete [] macrocells;
+       delete [] min;
+       delete [] max;
+       delete [] cmin;
+       delete [] cmax;
+       delete [] clipMins;
+       delete [] clipMaxs;
+       
+       if (counts)
+               delete[] counts;
+       
+       if (cells)
+               delete[] cells;
+       
+       if (macrocells)
+               delete [] macrocells;
 }
 
 void CDGridSpheres::preprocess(const PreprocessContext& context)
 {
-  // Preprocess material
-  LitMaterial::preprocess(context);
-
-  // Build grid
-  cerr<<"Building GridSpheres\n";
-
-  WallClockTimer timer;
-  timer.start();
-
-  cerr<<"  min:  ("<<min[0]<<", "<<min[1]<<", "<<min[2]<<")\n";
-  cerr<<"  max:  ("<<max[0]<<", "<<max[1]<<", "<<max[2]<<")\n";
-
-  // Determine the maximum radius
-  float max_radius;
-  if (ridx>0) {
-    cerr<<"  GridSpheres::preprocess - ridx="<<ridx<<'\n';
-    max_radius=max[ridx];
-
-    if (max_radius <= 0) {
-      cerr<<"  max_radius ("<<max_radius<<") <= 0, setting to default radius 
("
-          <<radius<<")\n";
-      max_radius=radius;
-    }
-  } else
-    max_radius=radius;
-
-  // Bound the spheres
-  computeBounds(context, bounds);
-  diagonal=bounds.diagonal();
-  inv_diagonal=Vector(1/diagonal.x(), 1/diagonal.y(), 1/diagonal.z());
-
-  // Determine grid size
-  totalcells=1;
-  for (int i=0; i<=depth; ++i)
-    totalcells *= ncells;
-
-  int totalsize=totalcells*totalcells*totalcells;
-  cerr<<"  Computing "<<totalcells<<'x'<<totalcells<<'x'<<totalcells
-      <<" grid ("<<totalsize<<" cells total)\n";
-
-  // Clear grid data
-  if (counts)
-    delete[] counts;
-
-  if (cells)
-    delete[] cells;
-
-  // Allocate and initialize counts
-  counts=new int[2*totalsize];
-  bzero(counts, 2*totalsize*sizeof(int));
-
-  cerr<<"    0/6:  Allocation took "<<timer.time()<<" seconds\n";
-  
-  // Generate map
-  int* map=new int[totalsize];
-  int idx=0;
-  for (int x=0; x<totalcells; ++x) {
-    for (int y=0; y<totalcells; ++y) {
-      for (int z=0; z<totalcells; ++z) {
-       map[idx++]=mapIdx(x, y, z, depth);
-      }
-    }
-  }
-
-  Real stime=timer.time();
-  cerr<<"    1/6:  Generating map took "<<stime<<" seconds\n";
-  
-  // Compute cell counts
-  float* data=spheres;
-  int tc2=totalcells*totalcells;
-  for (int i=0; i<nspheres; ++i) {
-    Real ctime=timer.time();
-    if (ctime - stime>5.0) {
-      cerr<<i<<"/"<<nspheres<<'\n';
-      stime=ctime;
-    }
-
-    // Compute cell overlap
-    Vector current_radius;
-    if (ridx>0) {
-      if (data[ridx] <= 0)
-        continue;
-
-      current_radius=Vector(data[ridx], data[ridx], data[ridx]);
-    } else {
-      current_radius=Vector(radius, radius, radius);
-    }
-
-    Vector center(data[0], data[1], data[2]);
-    BBox box(center - current_radius, center + current_radius);
-    int sx, sy, sz, ex, ey, ez;
-    transformToLattice(box, sx, sy, sz, ex, ey, ez);
-
-    int idx_x=sx*tc2;
-    for (int x=sx; x<=ex; ++x) {
-      int idx_y=idx_x + sy*totalcells;
-      idx_x += tc2;
-      for (int y=sy; y<=ey; ++y) {
-       int idx=idx_y + sz;
-       idx_y += totalcells;
-       for (int z=sz; z<=ez; ++z) {
-         int aidx=map[idx++];
-         counts[2*aidx + 1]++;
-       }
-      }
-    }
-
-    data += nvars;
-  }
-  
-  cerr<<"    2/6:  Counting cells took "<<timer.time()<<" seconds\n";
-
-  int total=0;
-  for (int i=0; i<totalsize; ++i) {
-    int count=counts[2*i + 1];
-    counts[2*i]=total;
-    total += count;
-  }
-
-  // Allocate cells
-  cerr<<"  Allocating "<<total<<" grid cells ("
-      <<static_cast<Real>(total)/nspheres<<" per object, "
-      <<static_cast<Real>(total)/totalsize<<" per cell)\n";
-
-  cells=new int[total];
-  for (int i=0; i<total; ++i)
-    cells[i]=-1;
-
-  stime=timer.time();
-  cerr<<"    3/6:  Calculating offsets took "<<stime<<" seconds\n";
-
-  // Populate the grid
-  Array1<int> current(totalsize);
-  current.initialize(0);
-  data=spheres;
-  for (int i=0; i<nspheres; ++i) {
-    Real ctime=timer.time();
-    if (ctime - stime>5.0) {
-      cerr<<i<<"/"<<nspheres<<'\n';
-      stime=ctime;
-    }
-
-    // Compute cell overlap
-    Vector current_radius;
-    if (ridx>0) {
-      if (data[ridx] <= 0)
-        continue;
-
-      current_radius=Vector(data[ridx], data[ridx], data[ridx]);
-    } else {
-      current_radius=Vector(radius, radius, radius);
-    }
-
-    Vector center(data[0], data[1], data[2]);
-    BBox box(center - current_radius, center + current_radius);
-    int sx, sy, sz, ex, ey, ez;
-    transformToLattice(box, sx, sy, sz, ex, ey, ez);
-
-    for (int x=sx; x<=ex; ++x) {
-      for (int y=sy; y<=ey; ++y) {
-       int idx=totalcells*(totalcells*x + y) + sz;
-       for (int z=sz; z<=ez; ++z) {
-         int aidx=map[idx++];
-         int cur=current[aidx]++;
-         int pos=counts[2*aidx] + cur;
-         cells[pos]=nvars*i;
-       }
-      }
-    }
-
-    data += nvars;
-  }
-
-  delete [] map;
-
-  cerr<<"    4/6:  Filling grid took "<<timer.time()<<" seconds\n";
-
-  // Verify the grid
-  for (int i=0; i<totalsize; ++i) {
-    if (current[i] != counts[2*i + 1]) {
-      cerr<<"Fatal error:  current="<<current[i]<<", but counts="
-          <<counts[2*i + 1]<<'\n';
-      exit(1);
-    }
-  }
-
-  for (int i=0; i<total; ++i) {
-    if (cells[i]==-1) {
-      cerr<<"Fatal error:  cells["<<i<<"] == -1\n";
-      exit(1);
-    }
-  }
-
-  cerr<<"    5/6:  Verifying grid took "<<timer.time()<<" seconds\n";
-
-  // Build the macrocells
-  if (depth > 0) {
-    macrocells=new MCell*[depth + 1];
-    macrocells[0]=0;
-
-    int size=ncells*ncells*ncells;
-    for (int d=depth; d>=1; d--) {
-      MCell* mcell=new MCell[size];
-      macrocells[d]=mcell;
-
-      float* mm=new float[2*nvars*size];
-      for (int i=0; i<size; ++i) {
-        // Minimum
-       mcell->min=mm;
-       mm += nvars;
-
-        // Maximum
-       mcell->max=mm;
-       mm += nvars;
-
-       mcell++;
-      }
-
-      size *= ncells*ncells*ncells;
-    }
-
-    MCell top;
-    fillMCell(top, depth, 0);
-    if (top.nspheres != total) {
-      cerr<<"Fatal error:  macrocell construction went wrong\n";
-      cerr<<"  Top macrocell:   "<<top.nspheres<<'\n';
-      cerr<<"  Total nspheres:  "<<total<<'\n';
-      exit(1);
-    }
-
-    cerr<<"    6/6:  Calculating macrocells took "<<timer.time()<<" 
seconds\n";
-  } else {
-    macrocells=0;
-    cerr<<"    6/6:  Macrocell hierarchy not built (depth == 0)\n";
-  }
-
-  cerr<<"Done building GridSpheres\n";
+       // Preprocess material
+       LitMaterial::preprocess(context);
+       
+       // Build grid
+       cerr<<"Building GridSpheres\n";
+       
+       WallClockTimer timer;
+       timer.start();
+       
+       cerr<<"  min:  ("<<min[0]<<", "<<min[1]<<", "<<min[2]<<")\n";
+       cerr<<"  max:  ("<<max[0]<<", "<<max[1]<<", "<<max[2]<<")\n";
+       
+       // Determine the maximum radius
+       float max_radius;
+       if (ridx>0) {
+               cerr<<"  GridSpheres::preprocess - ridx="<<ridx<<'\n';
+               max_radius=max[ridx];
+               
+               if (max_radius <= 0) {
+                       cerr<<"  max_radius ("<<max_radius<<") <= 0, setting 
to default radius ("
+                       <<radius<<")\n";
+                       max_radius=radius;
+               }
+       } else
+               max_radius=radius;
+       
+       // Bound the spheres
+       computeBounds(context, bounds);
+       diagonal=bounds.diagonal();
+       inv_diagonal=Vector(1/diagonal.x(), 1/diagonal.y(), 1/diagonal.z());
+       
+       // Determine grid size
+       totalcells=1;
+       for (int i=0; i<=depth; ++i)
+               totalcells *= ncells;
+       
+       int totalsize=totalcells*totalcells*totalcells;
+       cerr<<"  Computing "<<totalcells<<'x'<<totalcells<<'x'<<totalcells
+       <<" grid ("<<totalsize<<" cells total)\n";
+       
+       // Clear grid data
+       if (counts)
+               delete[] counts;
+       
+       if (cells)
+               delete[] cells;
+       
+       // Allocate and initialize counts
+       counts=new int[2*totalsize];
+       bzero(counts, 2*totalsize*sizeof(int));
+       
+       cerr<<"    0/6:  Allocation took "<<timer.time()<<" seconds\n";
+       
+       // Generate map
+       int* map=new int[totalsize];
+       int idx=0;
+       for (int x=0; x<totalcells; ++x) {
+               for (int y=0; y<totalcells; ++y) {
+                       for (int z=0; z<totalcells; ++z) {
+                               map[idx++]=mapIdx(x, y, z, depth);
+                       }
+               }
+       }
+       
+       Real stime=timer.time();
+       cerr<<"    1/6:  Generating map took "<<stime<<" seconds\n";
+       
+       // Compute cell counts
+       float* data=spheres;
+       int tc2=totalcells*totalcells;
+       for (int i=0; i<nspheres; ++i) {
+               Real ctime=timer.time();
+               if (ctime - stime>5.0) {
+                       cerr<<i<<"/"<<nspheres<<'\n';
+                       stime=ctime;
+               }
+               
+               // Compute cell overlap
+               Vector current_radius;
+               if (ridx>0) {
+                       if (data[ridx] <= 0)
+                               continue;
+                       
+                       current_radius=Vector(data[ridx], data[ridx], 
data[ridx]);
+               } else {
+                       current_radius=Vector(radius, radius, radius);
+               }
+               
+               Vector center(data[0], data[1], data[2]);
+               BBox box(center - current_radius, center + current_radius);
+               int sx, sy, sz, ex, ey, ez;
+               transformToLattice(box, sx, sy, sz, ex, ey, ez);
+               
+               int idx_x=sx*tc2;
+               for (int x=sx; x<=ex; ++x) {
+                       int idx_y=idx_x + sy*totalcells;
+                       idx_x += tc2;
+                       for (int y=sy; y<=ey; ++y) {
+                               int idx=idx_y + sz;
+                               idx_y += totalcells;
+                               for (int z=sz; z<=ez; ++z) {
+                                       int aidx=map[idx++];
+                                       counts[2*aidx + 1]++;
+                               }
+                       }
+               }
+               
+               data += nvars;
+       }
+       
+       cerr<<"    2/6:  Counting cells took "<<timer.time()<<" seconds\n";
+       
+       int total=0;
+       for (int i=0; i<totalsize; ++i) {
+               int count=counts[2*i + 1];
+               counts[2*i]=total;
+               total += count;
+       }
+       
+       // Allocate cells
+       cerr<<"  Allocating "<<total<<" grid cells ("
+       <<static_cast<Real>(total)/nspheres<<" per object, "
+       <<static_cast<Real>(total)/totalsize<<" per cell)\n";
+       
+       cells=new int[total];
+       for (int i=0; i<total; ++i)
+               cells[i]=-1;
+       
+       stime=timer.time();
+       cerr<<"    3/6:  Calculating offsets took "<<stime<<" seconds\n";
+       
+       // Populate the grid
+       Array1<int> current(totalsize);
+       current.initialize(0);
+       data=spheres;
+       for (int i=0; i<nspheres; ++i) {
+               Real ctime=timer.time();
+               if (ctime - stime>5.0) {
+                       cerr<<i<<"/"<<nspheres<<'\n';
+                       stime=ctime;
+               }
+               
+               // Compute cell overlap
+               Vector current_radius;
+               if (ridx>0) {
+                       if (data[ridx] <= 0)
+                               continue;
+                       
+                       current_radius=Vector(data[ridx], data[ridx], 
data[ridx]);
+               } else {
+                       current_radius=Vector(radius, radius, radius);
+               }
+               
+               Vector center(data[0], data[1], data[2]);
+               BBox box(center - current_radius, center + current_radius);
+               int sx, sy, sz, ex, ey, ez;
+               transformToLattice(box, sx, sy, sz, ex, ey, ez);
+               
+               for (int x=sx; x<=ex; ++x) {
+                       for (int y=sy; y<=ey; ++y) {
+                               int idx=totalcells*(totalcells*x + y) + sz;
+                               for (int z=sz; z<=ez; ++z) {
+                                       int aidx=map[idx++];
+                                       int cur=current[aidx]++;
+                                       int pos=counts[2*aidx] + cur;
+                                       cells[pos]=nvars*i;
+                               }
+                       }
+               }
+               
+               data += nvars;
+       }
+       
+       delete [] map;
+       
+       cerr<<"    4/6:  Filling grid took "<<timer.time()<<" seconds\n";
+       
+       // Verify the grid
+       for (int i=0; i<totalsize; ++i) {
+               if (current[i] != counts[2*i + 1]) {
+                       cerr<<"Fatal error:  current="<<current[i]<<", but 
counts="
+                       <<counts[2*i + 1]<<'\n';
+                       exit(1);
+               }
+       }
+       
+       for (int i=0; i<total; ++i) {
+               if (cells[i]==-1) {
+                       cerr<<"Fatal error:  cells["<<i<<"] == -1\n";
+                       exit(1);
+               }
+       }
+       
+       cerr<<"    5/6:  Verifying grid took "<<timer.time()<<" seconds\n";
+       
+       // Build the macrocells
+       if (depth > 0) {
+               macrocells=new MCell*[depth + 1];
+               macrocells[0]=0;
+               
+               int size=ncells*ncells*ncells;
+               for (int d=depth; d>=1; d--) {
+                       MCell* mcell=new MCell[size];
+                       macrocells[d]=mcell;
+                       
+                       float* mm=new float[2*nvars*size];
+                       for (int i=0; i<size; ++i) {
+                               // Minimum
+                               mcell->min=mm;
+                               mm += nvars;
+                               
+                               // Maximum
+                               mcell->max=mm;
+                               mm += nvars;
+                               
+                               mcell++;
+                       }
+                       
+                       size *= ncells*ncells*ncells;
+               }
+               
+               MCell top;
+               fillMCell(top, depth, 0);
+               if (top.nspheres != total) {
+                       cerr<<"Fatal error:  macrocell construction went 
wrong\n";
+                       cerr<<"  Top macrocell:   "<<top.nspheres<<'\n';
+                       cerr<<"  Total nspheres:  "<<total<<'\n';
+                       exit(1);
+               }
+               
+               cerr<<"    6/6:  Calculating macrocells took 
"<<timer.time()<<" seconds\n";
+       } else {
+               macrocells=0;
+               cerr<<"    6/6:  Macrocell hierarchy not built (depth == 
0)\n";
+       }
+       
+       cerr<<"Done building GridSpheres\n";
 }
 
 void CDGridSpheres::computeBounds(const PreprocessContext& context,
-                                BBox& bbox) const
+                                                                 BBox& bbox) 
const
 {
-  // Determine the maximum radius
-  float max_radius;
-  if (ridx>0) {
-    max_radius=max[ridx];
-
-    if (max_radius <= 0) {
-      cerr<<"  max_radius ("<<max_radius<<") <= 0, setting to default radius 
("
-          <<radius<<")\n";
-      max_radius=radius;
-    }
-  } else
-    max_radius=radius;
-
-  // Bound the spheres
-  Vector mr(max_radius, max_radius, max_radius);
-  bbox.reset(Vector(min[0], min[1], min[2]) - mr,
-             Vector(max[0], max[1], max[2]) + mr);
-
-  const Vector eps3(1.e-3, 1.e-3, 1.e-3);
-  bbox.extendByPoint(bbox.getMin() - eps3);
-  bbox.extendByPoint(bbox.getMax() + eps3);
-
-  Vector diag(bbox.diagonal());
-  bbox.extendByPoint(bbox.getMin() - diag*eps3);
-  bbox.extendByPoint(bbox.getMax() + diag*eps3);
+       // Determine the maximum radius
+       float max_radius;
+       if (ridx>0) {
+               max_radius=max[ridx];
+               
+               if (max_radius <= 0) {
+                       cerr<<"  max_radius ("<<max_radius<<") <= 0, setting 
to default radius ("
+                       <<radius<<")\n";
+                       max_radius=radius;
+               }
+       } else
+               max_radius=radius;
+       
+       // Bound the spheres
+       Vector mr(max_radius, max_radius, max_radius);
+       bbox.reset(Vector(min[0], min[1], min[2]) - mr,
+                          Vector(max[0], max[1], max[2]) + mr);
+       
+       const Vector eps3(1.e-3, 1.e-3, 1.e-3);
+       bbox.extendByPoint(bbox.getMin() - eps3);
+       bbox.extendByPoint(bbox.getMax() + eps3);
+       
+       Vector diag(bbox.diagonal());
+       bbox.extendByPoint(bbox.getMin() - diag*eps3);
+       bbox.extendByPoint(bbox.getMax() + diag*eps3);
 }
 
 void CDGridSpheres::intersect(const RenderContext& context, RayPacket& rays) 
const
 {
-  Vector bmin=bounds.getMin();
-  Vector bmax=bounds.getMax();
-
-  rays.computeInverseDirections();
-  rays.computeSigns();
-
+       Vector bmin=bounds.getMin();
+       Vector bmax=bounds.getMax();
+       
+       rays.computeInverseDirections();
+       rays.computeSigns();
+       
 #ifdef USE_OPTIMIZED_FCNS
-  // Determine appropriate sphere intersection function for this ray packet
-  SphereIntersectFcn intersectSphere = 
&CDGridSpheres::intersectSphereDefault;
-
-  switch (rays.getAllFlags() & (RayPacket::ConstantOrigin |
-                                RayPacket::NormalizedDirections)) {
-  case RayPacket::ConstantOrigin|RayPacket::NormalizedDirections:
-    // Rays of constant origin and normalized directions
-    intersectSphere=&CDGridSpheres::intersectSphereCOND;
-    break;
-  case RayPacket::ConstantOrigin:
-    // Rays of constant origin for not normalized directions
-    intersectSphere=&CDGridSpheres::intersectSphereCO;
-    break;
-  case RayPacket::NormalizedDirections:
-    // Rays of non-constant origin and normalized directions
-    intersectSphere=&CDGridSpheres::intersectSphereND;
-    break;
-  case 0:
-    // Rays of non-constant origin and non-normalized directions
-    intersectSphere=&CDGridSpheres::intersectSphereDefault;
-    break;
-  }
+       // Determine appropriate sphere intersection function for this ray 
packet
+       SphereIntersectFcn intersectSphere = 
&CDGridSpheres::intersectSphereDefault;
+       
+       switch (rays.getAllFlags() & (RayPacket::ConstantOrigin |
+                                                                 
RayPacket::NormalizedDirections)) {
+               case 
RayPacket::ConstantOrigin|RayPacket::NormalizedDirections:
+                       // Rays of constant origin and normalized directions
+                       intersectSphere=&CDGridSpheres::intersectSphereCOND;
+                       break;
+               case RayPacket::ConstantOrigin:
+                       // Rays of constant origin for not normalized 
directions
+                       intersectSphere=&CDGridSpheres::intersectSphereCO;
+                       break;
+               case RayPacket::NormalizedDirections:
+                       // Rays of non-constant origin and normalized 
directions
+                       intersectSphere=&CDGridSpheres::intersectSphereND;
+                       break;
+               case 0:
+                       // Rays of non-constant origin and non-normalized 
directions
+                       
intersectSphere=&CDGridSpheres::intersectSphereDefault;
+                       break;
+       }
 #endif // USE_OPTIMIZED_FCNS
-
-  for (int i=rays.begin(); i<rays.end(); ++i) {
-    const Vector origin(rays.getOrigin(i));
-    const Vector direction(rays.getDirection(i));
-    const Vector inv_direction(rays.getInverseDirection(i));
-
-    // Intersect ray with bounding box
-    Real tnear, tfar;
-    int di_dx;
-    int ddx;
-    int didx_dx;
-    int stop_x;
-    if (direction.x()>0) {
-      tnear=(bmin.x() - origin.x())*inv_direction.x();
-      tfar=(bmax.x() - origin.x())*inv_direction.x();
-      di_dx=1;
-      ddx=1;
-      didx_dx=ncells*ncells;
-      stop_x=ncells;
-    } else {
-      tnear=(bmax.x() - origin.x())*inv_direction.x();
-      tfar=(bmin.x() - origin.x())*inv_direction.x();
-      di_dx=-1;
-      ddx=0;
-      didx_dx=-ncells*ncells;
-      stop_x=-1;
-    }
-
-    Real y0, y1;
-    int di_dy;
-    int ddy;
-    int didx_dy;
-    int stop_y;
-    if (direction.y()>0) {
-      y0=(bmin.y() - origin.y())*inv_direction.y();
-      y1=(bmax.y() - origin.y())*inv_direction.y();
-      di_dy=1;
-      ddy=1;
-      didx_dy=ncells;
-      stop_y=ncells;
-    } else {
-      y0=(bmax.y() - origin.y())*inv_direction.y();
-      y1=(bmin.y() - origin.y())*inv_direction.y();
-      di_dy=-1;
-      ddy=0;
-      didx_dy=-ncells;
-      stop_y=-1;
-    }
-
-    if (y0>tnear)
-      tnear=y0;
-    if (y1<tfar)
-      tfar=y1;
-    if (tfar<tnear)
-      continue;
-
-    Real z0, z1;
-    int di_dz;
-    int ddz;
-    int didx_dz;
-    int stop_z;
-    if (direction.z()>0) {
-      z0=(bmin.z() - origin.z())*inv_direction.z();
-      z1=(bmax.z() - origin.z())*inv_direction.z();
-      di_dz=1;
-      ddz=1;
-      didx_dz=1;
-      stop_z=ncells;
-    } else {
-      z0=(bmax.z() - origin.z())*inv_direction.z();
-      z1=(bmin.z() - origin.z())*inv_direction.z();
-      di_dz=-1;
-      ddz=0;
-      didx_dz=-1;
-      stop_z=-1;
-    }
-
-    if (z0>tnear)
-      tnear=z0;
-    if (z1<tfar)
-      tfar=z1;
-    if (tfar<tnear)
-      continue;
-    if (tfar<static_cast<Real>(1.e-6))
-      continue;
-    if (tnear < 0)
-      tnear=0;
-
-    // Compute lattice coordinates
-    Vector p=origin + tnear*direction;
-    Vector lattice=(p - bmin)*inv_diagonal;
-    int ix=Clamp(static_cast<int>(lattice.x()*ncells), 0, ncells - 1);
-    int iy=Clamp(static_cast<int>(lattice.y()*ncells), 0, ncells - 1);
-    int iz=Clamp(static_cast<int>(lattice.z()*ncells), 0, ncells - 1);
-
-    // Compute cell index
-    int idx=(ix*ncells + iy)*ncells + iz;
-
-    // Compute delta t in each direction
-    Real dt_dx=di_dx*diagonal.x()*inv_ncells*inv_direction.x();
-    Real dt_dy=di_dy*diagonal.y()*inv_ncells*inv_direction.y();
-    Real dt_dz=di_dz*diagonal.z()*inv_ncells*inv_direction.z();
-
-    // Compute far edges of the cell
-    Vector next(ix + ddx, iy + ddy, iz + ddz);
-    Vector far=diagonal*next*inv_ncells + bmin;
-
-    // Compute t values at far edges of the cell
-    Vector tnext=(far - origin)*inv_direction;
-
-    // Compute cell corner and direction
-    Vector factor(ncells*inv_diagonal);
-    Vector cellcorner((origin - bmin)*factor);
-    Vector celldir(direction*factor);
-
-    // Traverse the hierarchy
-    traverse(i, rays, depth, tnear, ix, iy, iz, idx, dt_dx, dt_dy, dt_dz,
-             tnext.x(), tnext.y(), tnext.z(),
-             cellcorner, celldir,
-             di_dx, di_dy, di_dz, didx_dx, didx_dy, didx_dz,
+       
+       for (int i=rays.begin(); i<rays.end(); ++i) {
+               const Vector origin(rays.getOrigin(i));
+               const Vector direction(rays.getDirection(i));
+               const Vector inv_direction(rays.getInverseDirection(i));
+               
+               // Intersect ray with bounding box
+               Real tnear, tfar;
+               int di_dx;
+               int ddx;
+               int didx_dx;
+               int stop_x;
+               if (direction.x()>0) {
+                       tnear=(bmin.x() - origin.x())*inv_direction.x();
+                       tfar=(bmax.x() - origin.x())*inv_direction.x();
+                       di_dx=1;
+                       ddx=1;
+                       didx_dx=ncells*ncells;
+                       stop_x=ncells;
+               } else {
+                       tnear=(bmax.x() - origin.x())*inv_direction.x();
+                       tfar=(bmin.x() - origin.x())*inv_direction.x();
+                       di_dx=-1;
+                       ddx=0;
+                       didx_dx=-ncells*ncells;
+                       stop_x=-1;
+               }
+               
+               Real y0, y1;
+               int di_dy;
+               int ddy;
+               int didx_dy;
+               int stop_y;
+               if (direction.y()>0) {
+                       y0=(bmin.y() - origin.y())*inv_direction.y();
+                       y1=(bmax.y() - origin.y())*inv_direction.y();
+                       di_dy=1;
+                       ddy=1;
+                       didx_dy=ncells;
+                       stop_y=ncells;
+               } else {
+                       y0=(bmax.y() - origin.y())*inv_direction.y();
+                       y1=(bmin.y() - origin.y())*inv_direction.y();
+                       di_dy=-1;
+                       ddy=0;
+                       didx_dy=-ncells;
+                       stop_y=-1;
+               }
+               
+               if (y0>tnear)
+                       tnear=y0;
+               if (y1<tfar)
+                       tfar=y1;
+               if (tfar<tnear)
+                       continue;
+               
+               Real z0, z1;
+               int di_dz;
+               int ddz;
+               int didx_dz;
+               int stop_z;
+               if (direction.z()>0) {
+                       z0=(bmin.z() - origin.z())*inv_direction.z();
+                       z1=(bmax.z() - origin.z())*inv_direction.z();
+                       di_dz=1;
+                       ddz=1;
+                       didx_dz=1;
+                       stop_z=ncells;
+               } else {
+                       z0=(bmax.z() - origin.z())*inv_direction.z();
+                       z1=(bmin.z() - origin.z())*inv_direction.z();
+                       di_dz=-1;
+                       ddz=0;
+                       didx_dz=-1;
+                       stop_z=-1;
+               }
+               
+               if (z0>tnear)
+                       tnear=z0;
+               if (z1<tfar)
+                       tfar=z1;
+               if (tfar<tnear)
+                       continue;
+               if (tfar<static_cast<Real>(1.e-6))
+                       continue;
+               if (tnear < 0)
+                       tnear=0;
+               
+               // Compute lattice coordinates
+               Vector p=origin + tnear*direction;
+               Vector lattice=(p - bmin)*inv_diagonal;
+               int ix=Clamp(static_cast<int>(lattice.x()*ncells), 0, ncells 
- 1);
+               int iy=Clamp(static_cast<int>(lattice.y()*ncells), 0, ncells 
- 1);
+               int iz=Clamp(static_cast<int>(lattice.z()*ncells), 0, ncells 
- 1);
+               
+               // Compute cell index
+               int idx=(ix*ncells + iy)*ncells + iz;
+               
+               // Compute delta t in each direction
+               Real dt_dx=di_dx*diagonal.x()*inv_ncells*inv_direction.x();
+               Real dt_dy=di_dy*diagonal.y()*inv_ncells*inv_direction.y();
+               Real dt_dz=di_dz*diagonal.z()*inv_ncells*inv_direction.z();
+               
+               // Compute far edges of the cell
+               Vector next(ix + ddx, iy + ddy, iz + ddz);
+               Vector far=diagonal*next*inv_ncells + bmin;
+               
+               // Compute t values at far edges of the cell
+               Vector tnext=(far - origin)*inv_direction;
+               
+               // Compute cell corner and direction
+               Vector factor(ncells*inv_diagonal);
+               Vector cellcorner((origin - bmin)*factor);
+               Vector celldir(direction*factor);
+               
+               // Traverse the hierarchy
+               traverse(i, rays, depth, tnear, ix, iy, iz, idx, dt_dx, 
dt_dy, dt_dz,
+                                tnext.x(), tnext.y(), tnext.z(),
+                                cellcorner, celldir,
+                                di_dx, di_dy, di_dz, didx_dx, didx_dy, 
didx_dz,
 #ifdef USE_OPTIMIZED_FCNS
-             stop_x, stop_y, stop_z, intersectSphere);
+                                stop_x, stop_y, stop_z, intersectSphere);
 #else
-             stop_x, stop_y, stop_z);
+               stop_x, stop_y, stop_z);
 #endif // USE_OPTIMIZED_FCNS
-  }
+       }
 }
 
 void CDGridSpheres::computeNormal(const RenderContext& context,
-                                RayPacket& rays) const
+                                                                 RayPacket& 
rays) const
 {
-  rays.computeHitPositions();
-  for (int i=int(rays.begin()); i<int(rays.end()); ++i) {
-    float* data=spheres + rays.scratchpad<int>(i);
-    Vector n=rays.getHitPosition(i) - Vector(data[0], data[1], data[2]);
-
-    if (ridx>0) {
-      if (data[ridx] <= 0)
-        n *= inv_radius;
-      else
-        n /= data[ridx];
-    } else {
-      n *= inv_radius;
-    }
-
-    rays.setNormal(i, n);
-  }
-
-  rays.setFlag(RayPacket::HaveUnitNormals);
+       rays.computeHitPositions();
+       for (int i=int(rays.begin()); i<int(rays.end()); ++i) {
+               float* data=spheres + rays.scratchpad<int>(i);
+               Vector n=rays.getHitPosition(i) - Vector(data[0], data[1], 
data[2]);
+               
+               if (ridx>0) {
+                       if (data[ridx] <= 0)
+                               n *= inv_radius;
+                       else
+                               n /= data[ridx];
+               } else {
+                       n *= inv_radius;
+               }
+               
+               rays.setNormal(i, n);
+       }
+       
+       rays.setFlag(RayPacket::HaveUnitNormals);
 }
 
 void CDGridSpheres::shade(const RenderContext& context, RayPacket& rays) 
const
 {
-  // Compute ambient light
-  ColorArray ambient;
-  activeLights->getAmbientLight()->computeAmbient(context, rays, ambient);
-
-  // Shade a bunch of rays that have intersected the same particle
-  lambertianShade(context, rays, ambient);
+       // Compute ambient light
+       ColorArray ambient;
+       activeLights->getAmbientLight()->computeAmbient(context, rays, 
ambient);
+       
+       // Shade a bunch of rays that have intersected the same particle
+       lambertianShade(context, rays, ambient);
 }
 
 void CDGridSpheres::lambertianShade(const RenderContext& context, RayPacket& 
rays,
-                                  ColorArray& totalLight) const
+                                                                       
ColorArray& totalLight) const
 {
-  // Compute normals
-  rays.computeNormals(context);
-
-  // Compute colors
-  Packet<Color> diffuse;
-  mapDiffuseColors(diffuse, rays);
-
-  // Normalize directions for proper dot product computation
-  rays.normalizeDirections();
-
-  ShadowAlgorithm::StateBuffer shadowState;
-  do {
-    RayPacketData shadowData;
-    RayPacket shadowRays(shadowData, RayPacket::UnknownShape, 0, 0,
-                         rays.getDepth(), 0);
-
-    // Call the shadow algorithm (SA) to generate shadow rays.  We may not be
-    // able to compute all of them, so we pass along a buffer for the SA
-    // object to store it's state.  The firstTime flag tells the SA to fill
-    // in the state rather than using anything in the state buffer.  Most
-    // SAs will only need to store an int or two in the statebuffer.
-    context.shadowAlgorithm->computeShadows(context, shadowState, 
activeLights,
-                                            rays, shadowRays);
-
-    // Normalize directions for proper dot product computation
-    shadowRays.normalizeDirections();
-
-    for (int i=shadowRays.begin(); i < shadowRays.end(); ++i) {
-      if (!shadowRays.wasHit(i)) {
-        // Not in shadow, so compute the direct and specular contributions
-        Vector normal=rays.getNormal(i);
-        Vector shadowdir=shadowRays.getDirection(i);
-        ColorComponent cos_theta=Dot(shadowdir, normal);
-        Color light=shadowRays.getColor(i);
-        for (int j=0; j < Color::NumComponents; ++j)
-          totalLight[j][i] += light[j]*cos_theta;
-      }
-    }
-  } while(!shadowState.done());
-
-  // Sum up diffuse/specular contributions
-  for (int i=rays.begin(); i < rays.end(); ++i) {
-    Color result;
-    for (int j=0;j<Color::NumComponents; ++j)
-      result[j]=totalLight[j][i]*diffuse.colordata[j][i];
-    rays.setColor(i, result);
-  }
+       // Compute normals
+       rays.computeNormals(context);
+       
+       // Compute colors
+       Packet<Color> diffuse;
+       mapDiffuseColors(diffuse, rays);
+       
+       // Normalize directions for proper dot product computation
+       rays.normalizeDirections();
+       
+       ShadowAlgorithm::StateBuffer shadowState;
+       do {
+               RayPacketData shadowData;
+               RayPacket shadowRays(shadowData, RayPacket::UnknownShape, 0, 
0,
+                                                        rays.getDepth(), 0);
+               
+               // Call the shadow algorithm (SA) to generate shadow rays.  
We may not be
+               // able to compute all of them, so we pass along a buffer for 
the SA
+               // object to store it's state.  The firstTime flag tells the 
SA to fill
+               // in the state rather than using anything in the state 
buffer.  Most
+               // SAs will only need to store an int or two in the 
statebuffer.
+               context.shadowAlgorithm->computeShadows(context, shadowState, 
activeLights,
+                                                                             
                  rays, shadowRays);
+               
+               // Normalize directions for proper dot product computation
+               shadowRays.normalizeDirections();
+               
+               for (int i=shadowRays.begin(); i < shadowRays.end(); ++i) {
+                       if (!shadowRays.wasHit(i)) {
+                               // Not in shadow, so compute the direct and 
specular contributions
+                               Vector normal=rays.getNormal(i);
+                               Vector shadowdir=shadowRays.getDirection(i);
+                               ColorComponent cos_theta=Dot(shadowdir, 
normal);
+                               Color light=shadowRays.getColor(i);
+                               for (int j=0; j < Color::NumComponents; ++j)
+                                       totalLight[j][i] += 
light[j]*cos_theta;
+                       }
+               }
+       } while(!shadowState.done());
+       
+       // Sum up diffuse/specular contributions
+       for (int i=rays.begin(); i < rays.end(); ++i) {
+               Color result;
+               for (int j=0;j<Color::NumComponents; ++j)
+                       result[j]=totalLight[j][i]*diffuse.colordata[j][i];
+               rays.setColor(i, result);
+       }
 }
 
 void CDGridSpheres::computeHistogram(int index, int numBuckets, int* 
histValues)
@@ -642,405 +642,405 @@
 }
 
 void CDGridSpheres::computeTexCoords2(const RenderContext& context,
-                                    RayPacket& rays) const
+                                                                         
RayPacket& rays) const
 {
-  rays.computeHitPositions();
-  rays.computeNormals(context);
-  for(int i=rays.begin();i<rays.end();i++){
-    Vector n=rays.getNormal(i);
-    Real angle=Clamp(n.z(), (Real)-1, (Real)1);
-    Real theta=Acos(angle);
-    Real phi=Atan2(n.y(), n.x());
-    Real x=phi*(Real)(0.5*M_1_PI);
-    if (x < 0)
-      x += 1;
-    Real y=theta*(Real)M_1_PI;
-    rays.setTexCoords(i, Vector(x, y, 0));
-  }
-
-  rays.setFlag(RayPacket::HaveTexture2|RayPacket::HaveTexture3);
+       rays.computeHitPositions();
+       rays.computeNormals(context);
+       for(int i=rays.begin();i<rays.end();i++){
+               Vector n=rays.getNormal(i);
+               Real angle=Clamp(n.z(), (Real)-1, (Real)1);
+               Real theta=Acos(angle);
+               Real phi=Atan2(n.y(), n.x());
+               Real x=phi*(Real)(0.5*M_1_PI);
+               if (x < 0)
+                       x += 1;
+               Real y=theta*(Real)M_1_PI;
+               rays.setTexCoords(i, Vector(x, y, 0));
+       }
+       
+       rays.setFlag(RayPacket::HaveTexture2|RayPacket::HaveTexture3);
 }
 
 void CDGridSpheres::computeTexCoords3(const RenderContext& context,
-                                    RayPacket& rays) const
+                                                                         
RayPacket& rays) const
 {
-  rays.computeHitPositions();
-  rays.computeNormals(context);
-  for(int i=rays.begin();i<rays.end();i++){
-    Vector n=rays.getNormal(i);
-    Real angle=Clamp(n.z(), (Real)-1, (Real)1);
-    Real theta=Acos(angle);
-    Real phi=Atan2(n.y(), n.x());
-    Real x=phi*(Real)(0.5*M_1_PI);
-    if (x < 0)
-      x += 1;
-    Real y=theta*(Real)M_1_PI;
-    rays.setTexCoords(i, Vector(x, y, 0));
-  }
-
-  rays.setFlag(RayPacket::HaveTexture2|RayPacket::HaveTexture3);
+       rays.computeHitPositions();
+       rays.computeNormals(context);
+       for(int i=rays.begin();i<rays.end();i++){
+               Vector n=rays.getNormal(i);
+               Real angle=Clamp(n.z(), (Real)-1, (Real)1);
+               Real theta=Acos(angle);
+               Real phi=Atan2(n.y(), n.x());
+               Real x=phi*(Real)(0.5*M_1_PI);
+               if (x < 0)
+                       x += 1;
+               Real y=theta*(Real)M_1_PI;
+               rays.setTexCoords(i, Vector(x, y, 0));
+       }
+       
+       rays.setFlag(RayPacket::HaveTexture2|RayPacket::HaveTexture3);
 }
 
 void CDGridSpheres::traverse(int ray_idx, RayPacket& rays, int depth, Real 
tnear,
-                           int ix, int iy, int iz, int idx,
-                           Real dt_dx, Real dt_dy, Real dt_dz,
-                           Real tnext_x, Real tnext_y, Real tnext_z,
-                           const Vector& cellcorner, const Vector& celldir,
-                           int di_dx, int di_dy, int di_dz,
-                           int didx_dx, int didx_dy, int didx_dz,
+                                                        int ix, int iy, int 
iz, int idx,
+                                                        Real dt_dx, Real 
dt_dy, Real dt_dz,
+                                                        Real tnext_x, Real 
tnext_y, Real tnext_z,
+                                                        const Vector& 
cellcorner, const Vector& celldir,
+                                                        int di_dx, int 
di_dy, int di_dz,
+                                                        int didx_dx, int 
didx_dy, int didx_dz,
 #ifdef USE_OPTIMIZED_FCNS
-                           int stop_x, int stop_y, int stop_z,
-                           SphereIntersectFcn intersectSphere) const
+                                                        int stop_x, int 
stop_y, int stop_z,
+                                                        SphereIntersectFcn 
intersectSphere) const
 #else
-                           int stop_x, int stop_y, int stop_z) const
+int stop_x, int stop_y, int stop_z) const
 #endif // USE_OPTIMIZED_FCNS
 {
-  if (depth>0) {
-    // Traverse the macrocell layers
-    MCell* mcells=macrocells[depth];
-    while (tnear < rays.getMinT(ray_idx)) {
-      MCell& mcell=mcells[idx];
-      if (mcell.nspheres > 0) {
-        // XXX:  Range checking would go here...  Ignore for now
-       for(int j = 0; j < nvars; j++)
-        {
-                if (mcell.min[j] > clipMaxs[j])
+       if (depth>0) {
+               // Traverse the macrocell layers
+               MCell* mcells=macrocells[depth];
+               while (tnear < rays.getMinT(ray_idx)) {
+                       MCell& mcell=mcells[idx];
+                       if (mcell.nspheres > 0) {
+                               // XXX:  Range checking would go here...  
Ignore for now
+                               for(int j = 0; j < nvars; j++)
+                               {
+                                       if (mcell.min[j] > clipMaxs[j])
                         return;
-                if (mcell.max[j] < clipMins[j])
+                                       if (mcell.max[j] < clipMins[j])
                         return;
-        }
-
-        // Compute lattice coordinates
-        int new_ix=Clamp(static_cast<int>((cellcorner.x() + 
tnear*celldir.x() - ix)*ncells), 0, ncells - 1);
-        int new_iy=Clamp(static_cast<int>((cellcorner.y() + 
tnear*celldir.y() - iy)*ncells), 0, ncells - 1);
-        int new_iz=Clamp(static_cast<int>((cellcorner.z() + 
tnear*celldir.z() - iz)*ncells), 0, ncells - 1);
-
-        // Compute new cell index
-        int new_idx=((idx*ncells + new_ix)*ncells + new_iy)*ncells + new_iz;
-
-        // Compute new delta t in each direction
-        Real new_dt_dx=dt_dx*inv_ncells;
-        Real new_dt_dy=dt_dy*inv_ncells;
-        Real new_dt_dz=dt_dz*inv_ncells;
-
-        // Compute new t values at far edges of the cell
-        Vector signs=rays.getSigns(ray_idx);
-        Real new_tnext_x=tnext_x + (1 - 2*signs.x())*new_ix*new_dt_dx +
-          (1 - signs.x())*(new_dt_dx - dt_dx);
-        Real new_tnext_y=tnext_y + (1 - 2*signs.y())*new_iy*new_dt_dy +
-          (1 - signs.y())*(new_dt_dy - dt_dy);
-        Real new_tnext_z=tnext_z + (1 - 2*signs.z())*new_iz*new_dt_dz +
-          (1 - signs.z())*(new_dt_dz - dt_dz);
-      
-        // Compute new cell corner and direction
-        Vector new_cellcorner=(cellcorner - Vector(ix, iy, iz))*ncells;
-        Vector new_celldir=celldir*ncells;
-
-        // Descend to next depth in the hierarchy
-        traverse(ray_idx, rays, depth - 1, tnear,
-                 new_ix, new_iy, new_iz,
-                 new_idx,
-                 new_dt_dx, new_dt_dy, new_dt_dz,
-                 new_tnext_x, new_tnext_y, new_tnext_z,
-                 new_cellcorner, new_celldir,
-                 di_dx, di_dy, di_dz,
-                 didx_dx, didx_dy, didx_dz,
+                               }
+                               
+                               // Compute lattice coordinates
+                               int 
new_ix=Clamp(static_cast<int>((cellcorner.x() + tnear*celldir.x() - 
ix)*ncells), 0, ncells - 1);
+                               int 
new_iy=Clamp(static_cast<int>((cellcorner.y() + tnear*celldir.y() - 
iy)*ncells), 0, ncells - 1);
+                               int 
new_iz=Clamp(static_cast<int>((cellcorner.z() + tnear*celldir.z() - 
iz)*ncells), 0, ncells - 1);
+                               
+                               // Compute new cell index
+                               int new_idx=((idx*ncells + new_ix)*ncells + 
new_iy)*ncells + new_iz;
+                               
+                               // Compute new delta t in each direction
+                               Real new_dt_dx=dt_dx*inv_ncells;
+                               Real new_dt_dy=dt_dy*inv_ncells;
+                               Real new_dt_dz=dt_dz*inv_ncells;
+                               
+                               // Compute new t values at far edges of the 
cell
+                               Vector signs=rays.getSigns(ray_idx);
+                               Real new_tnext_x=tnext_x + (1 - 
2*signs.x())*new_ix*new_dt_dx +
+                               (1 - signs.x())*(new_dt_dx - dt_dx);
+                               Real new_tnext_y=tnext_y + (1 - 
2*signs.y())*new_iy*new_dt_dy +
+                               (1 - signs.y())*(new_dt_dy - dt_dy);
+                               Real new_tnext_z=tnext_z + (1 - 
2*signs.z())*new_iz*new_dt_dz +
+                               (1 - signs.z())*(new_dt_dz - dt_dz);
+                               
+                               // Compute new cell corner and direction
+                               Vector new_cellcorner=(cellcorner - 
Vector(ix, iy, iz))*ncells;
+                               Vector new_celldir=celldir*ncells;
+                               
+                               // Descend to next depth in the hierarchy
+                               traverse(ray_idx, rays, depth - 1, tnear,
+                                                new_ix, new_iy, new_iz,
+                                                new_idx,
+                                                new_dt_dx, new_dt_dy, 
new_dt_dz,
+                                                new_tnext_x, new_tnext_y, 
new_tnext_z,
+                                                new_cellcorner, new_celldir,
+                                                di_dx, di_dy, di_dz,
+                                                didx_dx, didx_dy, didx_dz,
 #ifdef USE_OPTIMIZED_FCNS
-                 stop_x, stop_y, stop_z, intersectSphere);
+                                                stop_x, stop_y, stop_z, 
intersectSphere);
 #else
-                 stop_x, stop_y, stop_z);
+                               stop_x, stop_y, stop_z);
 #endif // USE_OPTIMIZED_FCNS
-      }
-
-      // March to next macrocell at the current depth
-      if (tnext_x<tnext_y && tnext_x<tnext_z) {
-        ix += di_dx;
-        if (ix == stop_x)
-          break;
-        tnear=tnext_x;
-        tnext_x += dt_dx;
-        idx += didx_dx;
-      } else if (tnext_y<tnext_z) {
-        iy += di_dy;
-        if (iy == stop_y)
-          break;
-        tnear=tnext_y;
-        tnext_y += dt_dy;
-        idx += didx_dy;
-      } else {
-        iz += di_dz;
-        if (iz == stop_z)
-          break;
-        tnear=tnext_z;
-        tnext_z += dt_dz;
-        idx += didx_dz;
-      }
-    }
-  } else {
-    // Traverse cells, intersecting spheres along the way as necessary
-    while (tnear < rays.getMinT(ray_idx)) {
-      int start=counts[2*idx];
-      int nsph=counts[2*idx + 1];
-      for (int j=0; j<nsph; ++j) {
-       float* data=spheres + cells[start + j];
-
-        // XXX:  Range checking would go here...  Ignore for now
-       for(int k = 0; k < nvars; k++)
-       {
-               if (data[k] < clipMins[k])
-                       break;
-               if (data[k] > clipMaxs[k])
-                       break;
-       }
-        // Sphere is in range, determine it's radius (squared)
-        float radius2;
-        if (ridx>0) {
-          float current_radius=data[ridx];
-          if (current_radius <= 0)
-            continue;
-          
-          radius2=current_radius*current_radius;
-        } else {
-          radius2=radius*radius;
-        }
-
+                       }
+                       
+                       // March to next macrocell at the current depth
+                       if (tnext_x<tnext_y && tnext_x<tnext_z) {
+                               ix += di_dx;
+                               if (ix == stop_x)
+                                       break;
+                               tnear=tnext_x;
+                               tnext_x += dt_dx;
+                               idx += didx_dx;
+                       } else if (tnext_y<tnext_z) {
+                               iy += di_dy;
+                               if (iy == stop_y)
+                                       break;
+                               tnear=tnext_y;
+                               tnext_y += dt_dy;
+                               idx += didx_dy;
+                       } else {
+                               iz += di_dz;
+                               if (iz == stop_z)
+                                       break;
+                               tnear=tnext_z;
+                               tnext_z += dt_dz;
+                               idx += didx_dz;
+                       }
+               }
+       } else {
+               // Traverse cells, intersecting spheres along the way as 
necessary
+               while (tnear < rays.getMinT(ray_idx)) {
+                       int start=counts[2*idx];
+                       int nsph=counts[2*idx + 1];
+                       for (int j=0; j<nsph; ++j) {
+                               float* data=spheres + cells[start + j];
+                               
+                               // XXX:  Range checking would go here...  
Ignore for now
+                               for(int k = 0; k < nvars; k++)
+                               {
+                                       if (data[k] < clipMins[k])
+                                               break;
+                                       if (data[k] > clipMaxs[k])
+                                               break;
+                               }
+                               // Sphere is in range, determine it's radius 
(squared)
+                               float radius2;
+                               if (ridx>0) {
+                                       float current_radius=data[ridx];
+                                       if (current_radius <= 0)
+                                               continue;
+                                       
+                                       radius2=current_radius*current_radius;
+                               } else {
+                                       radius2=radius*radius;
+                               }
+                               
 #ifdef USE_OPTIMIZED_FCNS
-        // Intersect the sphere using the appropriately optimized function
-        (*this.*intersectSphere)(rays, ray_idx, start + j,
-                                 Vector(data[0], data[1], data[2]), radius2);
+                               // Intersect the sphere using the 
appropriately optimized function
+                               (*this.*intersectSphere)(rays, ray_idx, start 
+ j,
+                                                                             
   Vector(data[0], data[1], data[2]), radius2);
 #else
-        intersectSphereDefault(rays, ray_idx, start + j,
-                               Vector(data[0], data[1], data[2]), radius2);
+                               intersectSphereDefault(rays, ray_idx, start + 
j,
+                                                                          
Vector(data[0], data[1], data[2]), radius2);
 #endif
-      }
-
-      // March to the next cell
-      if (tnext_x < tnext_y && tnext_x < tnext_z) {
-        ix += di_dx;
-        if (ix == stop_x)
-          break;
-        tnear=tnext_x;
-        tnext_x += dt_dx;
-       idx += didx_dx;
-      } else if (tnext_y < tnext_z){
-        iy += di_dy;
-        if (iy == stop_y)
-          break;
-        tnear=tnext_y;
-        tnext_y += dt_dy;
-       idx += didx_dy;
-      } else {
-        iz += di_dz;
-        if (iz == stop_z)
-          break;
-        tnear=tnext_z;
-        tnext_z += dt_dz;
-       idx += didx_dz;
-      }
-    }
-  }
+                       }
+                       
+                       // March to the next cell
+                       if (tnext_x < tnext_y && tnext_x < tnext_z) {
+                               ix += di_dx;
+                               if (ix == stop_x)
+                                       break;
+                               tnear=tnext_x;
+                               tnext_x += dt_dx;
+                               idx += didx_dx;
+                       } else if (tnext_y < tnext_z){
+                               iy += di_dy;
+                               if (iy == stop_y)
+                                       break;
+                               tnear=tnext_y;
+                               tnext_y += dt_dy;
+                               idx += didx_dy;
+                       } else {
+                               iz += di_dz;
+                               if (iz == stop_z)
+                                       break;
+                               tnear=tnext_z;
+                               tnext_z += dt_dz;
+                               idx += didx_dz;
+                       }
+               }
+       }
 }
 
 #ifdef USE_OPTIMIZED_FCNS
 void CDGridSpheres::intersectSphereCOND(RayPacket& rays, int ray_idx, int 
idx,
-                                      const Vector& center, float radius2) 
const
+                                                                             
  const Vector& center, float radius2) const
 {
-//  if (clip(cells[idx]))
-//     return;
-  // Rays of constant origin and normalized directions
-  Vector O(rays.getOrigin(0) - center);
-  Real C=Dot(O, O) - radius2;
-  Vector D(rays.getDirection(ray_idx));
-  Real B=Dot(O, D);
-  Real disc=B*B - C;
-  if (disc >= 0) {
-    Real r=Sqrt(disc);
-    Real t0=-(r + B);
-    if (t0 > T_EPSILON) {
-      if (rays.hit(ray_idx, t0, this, this, this))
-        rays.scratchpad<int>(ray_idx)=cells[idx];
-    } else {
-      Real t1=r - B;
-      if (rays.hit(ray_idx, t1, this, this, this))
-        rays.scratchpad<int>(ray_idx)=cells[idx];
-    }
-  }
+       //  if (clip(cells[idx]))
+       //      return;
+       // Rays of constant origin and normalized directions
+       Vector O(rays.getOrigin(0) - center);
+       Real C=Dot(O, O) - radius2;
+       Vector D(rays.getDirection(ray_idx));
+       Real B=Dot(O, D);
+       Real disc=B*B - C;
+       if (disc >= 0) {
+               Real r=Sqrt(disc);
+               Real t0=-(r + B);
+               if (t0 > T_EPSILON) {
+                       if (rays.hit(ray_idx, t0, this, this, this))
+                               rays.scratchpad<int>(ray_idx)=cells[idx];
+               } else {
+                       Real t1=r - B;
+                       if (rays.hit(ray_idx, t1, this, this, this))
+                               rays.scratchpad<int>(ray_idx)=cells[idx];
+               }
+       }
 }
 
 void CDGridSpheres::intersectSphereCO(RayPacket& rays, int ray_idx, int idx,
-                                    const Vector& center, float radius2) 
const
+                                                                         
const Vector& center, float radius2) const
 {
- // if (clip(cells[idx]))
-//     return;
-  // Rays of constant origin for not normalized directions
-  Vector O(rays.getOrigin(0) - center);
-  Real C=Dot(O, O) - radius2;
-  Vector D(rays.getDirection(ray_idx));
-  Real A=Dot(D, D);
-  Real B=Dot(O, D);
-  Real disc=B*B - A*C;
-  if (disc >= 0) {
-    Real r=Sqrt(disc);
-    Real t0=-(r + B)/A;
-    if (t0 > T_EPSILON) {
-      if (rays.hit(ray_idx, t0, this, this, this))
-        rays.scratchpad<int>(ray_idx)=cells[idx];
-    } else {
-      Real t1=(r - B)/A;
-      if (rays.hit(ray_idx, t1, this, this, this))
-        rays.scratchpad<int>(ray_idx)=cells[idx];
-    }
-  }
+       // if (clip(cells[idx]))
+       //      return;
+       // Rays of constant origin for not normalized directions
+       Vector O(rays.getOrigin(0) - center);
+       Real C=Dot(O, O) - radius2;
+       Vector D(rays.getDirection(ray_idx));
+       Real A=Dot(D, D);
+       Real B=Dot(O, D);
+       Real disc=B*B - A*C;
+       if (disc >= 0) {
+               Real r=Sqrt(disc);
+               Real t0=-(r + B)/A;
+               if (t0 > T_EPSILON) {
+                       if (rays.hit(ray_idx, t0, this, this, this))
+                               rays.scratchpad<int>(ray_idx)=cells[idx];
+               } else {
+                       Real t1=(r - B)/A;
+                       if (rays.hit(ray_idx, t1, this, this, this))
+                               rays.scratchpad<int>(ray_idx)=cells[idx];
+               }
+       }
 }
 
 void CDGridSpheres::intersectSphereND(RayPacket& rays, int ray_idx, int idx,
-                                    const Vector& center, float radius2) 
const
+                                                                         
const Vector& center, float radius2) const
 {
- // if (clip(cells[idx]))
-//     return;
-  // Rays of non-constant origin and normalized directions
-  Vector O(rays.getOrigin(ray_idx) - center);
-  Vector D(rays.getDirection(ray_idx));
-  Real B=Dot(O, D);
-  Real C=Dot(O, O) - radius2;
-  Real disc=B*B - C;
-  if (disc >= 0) {
-    Real r=Sqrt(disc);
-    Real t0=-(r + B);
-    if (t0 > T_EPSILON) {
-      if (rays.hit(ray_idx, t0, this, this, this))
-        rays.scratchpad<int>(ray_idx)=cells[idx];
-    } else {
-      Real t1=r - B;
-      if (rays.hit(ray_idx, t1, this, this, this))
-        rays.scratchpad<int>(ray_idx)=cells[idx];
-    }
-  }
+       // if (clip(cells[idx]))
+       //      return;
+       // Rays of non-constant origin and normalized directions
+       Vector O(rays.getOrigin(ray_idx) - center);
+       Vector D(rays.getDirection(ray_idx));
+       Real B=Dot(O, D);
+       Real C=Dot(O, O) - radius2;
+       Real disc=B*B - C;
+       if (disc >= 0) {
+               Real r=Sqrt(disc);
+               Real t0=-(r + B);
+               if (t0 > T_EPSILON) {
+                       if (rays.hit(ray_idx, t0, this, this, this))
+                               rays.scratchpad<int>(ray_idx)=cells[idx];
+               } else {
+                       Real t1=r - B;
+                       if (rays.hit(ray_idx, t1, this, this, this))
+                               rays.scratchpad<int>(ray_idx)=cells[idx];
+               }
+       }
 }
 #endif // USE_OPTIMIZED_FCNS
 
 void CDGridSpheres::intersectSphereDefault(RayPacket& rays, int ray_idx, int 
idx,
-                                         const Vector& center,
-                                         float radius2) const
+                                                                             
     const Vector& center,
+                                                                             
     float radius2) const
 {
- // if (clip(cells[idx]))
-//     return;
-  // Rays of non-constant origin and non-normalized directions
-  Vector O(rays.getOrigin(ray_idx) - center);
-  Vector D(rays.getDirection(ray_idx));
-  Real A=Dot(D, D);
-  Real B=Dot(O, D);
-  Real C=Dot(O, O) - radius2;
-  Real disc=B*B - A*C;
-  if (disc >= 0) {
-    Real r=Sqrt(disc);
-    Real t0=-(r + B)/A;
-    if (t0 > T_EPSILON) {
-      if (rays.hit(ray_idx, t0, this, this, this))
-        rays.scratchpad<int>(ray_idx)=cells[idx];
-    } else {
-      Real t1=(r - B)/A;
-      if (rays.hit(ray_idx, t1, this, this, this));
-      rays.scratchpad<int>(ray_idx)=cells[idx];
-    }
-  }
+       // if (clip(cells[idx]))
+       //      return;
+       // Rays of non-constant origin and non-normalized directions
+       Vector O(rays.getOrigin(ray_idx) - center);
+       Vector D(rays.getDirection(ray_idx));
+       Real A=Dot(D, D);
+       Real B=Dot(O, D);
+       Real C=Dot(O, O) - radius2;
+       Real disc=B*B - A*C;
+       if (disc >= 0) {
+               Real r=Sqrt(disc);
+               Real t0=-(r + B)/A;
+               if (t0 > T_EPSILON) {
+                       if (rays.hit(ray_idx, t0, this, this, this))
+                               rays.scratchpad<int>(ray_idx)=cells[idx];
+               } else {
+                       Real t1=(r - B)/A;
+                       if (rays.hit(ray_idx, t1, this, this, this));
+                       rays.scratchpad<int>(ray_idx)=cells[idx];
+               }
+       }
 }
 
 void CDGridSpheres::transformToLattice(const BBox& box, int& sx, int& sy, 
int& sz,
-                                     int& ex, int& ey, int& ez) const
+                                                                          
int& ex, int& ey, int& ez) const
 {
-  Vector s=(box.getMin() - bounds.getMin())*inv_diagonal;
-  sx=static_cast<int>(s.x()*totalcells);
-  sy=static_cast<int>(s.y()*totalcells);
-  sz=static_cast<int>(s.z()*totalcells);
-  Clamp(sx, 0, totalcells - 1);
-  Clamp(sy, 0, totalcells - 1);
-  Clamp(sz, 0, totalcells - 1);
-  
-  Vector e=(box.getMax() - bounds.getMin())*inv_diagonal;
-  ex=static_cast<int>(e.x()*totalcells);
-  ey=static_cast<int>(e.y()*totalcells);
-  ez=static_cast<int>(e.z()*totalcells);
-  Clamp(ex, 0, totalcells - 1);
-  Clamp(ey, 0, totalcells - 1);
-  Clamp(ez, 0, totalcells - 1);
+       Vector s=(box.getMin() - bounds.getMin())*inv_diagonal;
+       sx=static_cast<int>(s.x()*totalcells);
+       sy=static_cast<int>(s.y()*totalcells);
+       sz=static_cast<int>(s.z()*totalcells);
+       Clamp(sx, 0, totalcells - 1);
+       Clamp(sy, 0, totalcells - 1);
+       Clamp(sz, 0, totalcells - 1);
+       
+       Vector e=(box.getMax() - bounds.getMin())*inv_diagonal;
+       ex=static_cast<int>(e.x()*totalcells);
+       ey=static_cast<int>(e.y()*totalcells);
+       ez=static_cast<int>(e.z()*totalcells);
+       Clamp(ex, 0, totalcells - 1);
+       Clamp(ey, 0, totalcells - 1);
+       Clamp(ez, 0, totalcells - 1);
 }
 
 int CDGridSpheres::mapIdx(int ix, int iy, int iz, int depth)
 {
-  if (depth==0) {
-    return (ix*ncells + iy)*ncells + iz;
-  } else {
-    int idx=mapIdx(static_cast<int>(ix*inv_ncells),
-                   static_cast<int>(iy*inv_ncells),
-                   static_cast<int>(iz*inv_ncells),
-                   depth - 1);
-    int nx=ix%ncells;
-    int ny=iy%ncells;
-    int nz=iz%ncells;
-    
-    return ((idx*ncells + nx)*ncells + ny)*ncells + nz;
-  }
+       if (depth==0) {
+               return (ix*ncells + iy)*ncells + iz;
+       } else {
+               int idx=mapIdx(static_cast<int>(ix*inv_ncells),
+                                          static_cast<int>(iy*inv_ncells),
+                                          static_cast<int>(iz*inv_ncells),
+                                          depth - 1);
+               int nx=ix%ncells;
+               int ny=iy%ncells;
+               int nz=iz%ncells;
+               
+               return ((idx*ncells + nx)*ncells + ny)*ncells + nz;
+       }
 }
 
 void CDGridSpheres::fillMCell(MCell& mcell, int depth, int startidx) const
 {
-  mcell.nspheres=0;
-  mcell.min=new float[2*nvars];
-  mcell.max=mcell.min + nvars;
-  
-  // Initialize min/max
-  for (int i=0; i<nvars; ++i) {
-    mcell.min[i]=FLT_MAX;
-    mcell.max[i]=-FLT_MAX;
-  }
-  
-  // Determine min/max
-  int ncells3=ncells*ncells*ncells;
-  if (depth>0) {
-    MCell* mcells=macrocells[depth];
-    for (int i=0; i<ncells3; ++i) {
-      int idx=startidx + i;
-      fillMCell(mcells[idx], depth - 1, idx*ncells*ncells*ncells);
-      mcell.nspheres += mcells[idx].nspheres;
-      for (int j=0; j<nvars; ++j) {
-        if (mcells[idx].min[j]<mcell.min[j])
-          mcell.min[j]=mcells[idx].min[j];
-        if (mcells[idx].max[j]>mcell.max[j])
-          mcell.max[j]=mcells[idx].max[j];
-      }
-    }
-  } else {
-    for (int i=0; i<ncells3; ++i) {
-      int idx=startidx + i;
-      int nsph=counts[2*idx + 1];
-      mcell.nspheres += nsph;
-      int s=counts[2*idx];
-      for (int j=0; j<nsph; ++j) {
-        float* data=spheres + cells[s + j];
-        for (int k=0; k<nvars; ++k) {
-          if (data[k]<mcell.min[k])
-            mcell.min[k]=data[k];
-          if (data[k]>mcell.max[k])
-            mcell.max[k]=data[k];
-        }
-      }
-    }
-  }
+       mcell.nspheres=0;
+       mcell.min=new float[2*nvars];
+       mcell.max=mcell.min + nvars;
+       
+       // Initialize min/max
+       for (int i=0; i<nvars; ++i) {
+               mcell.min[i]=FLT_MAX;
+               mcell.max[i]=-FLT_MAX;
+       }
+       
+       // Determine min/max
+       int ncells3=ncells*ncells*ncells;
+       if (depth>0) {
+               MCell* mcells=macrocells[depth];
+               for (int i=0; i<ncells3; ++i) {
+                       int idx=startidx + i;
+                       fillMCell(mcells[idx], depth - 1, 
idx*ncells*ncells*ncells);
+                       mcell.nspheres += mcells[idx].nspheres;
+                       for (int j=0; j<nvars; ++j) {
+                               if (mcells[idx].min[j]<mcell.min[j])
+                                       mcell.min[j]=mcells[idx].min[j];
+                               if (mcells[idx].max[j]>mcell.max[j])
+                                       mcell.max[j]=mcells[idx].max[j];
+                       }
+               }
+       } else {
+               for (int i=0; i<ncells3; ++i) {
+                       int idx=startidx + i;
+                       int nsph=counts[2*idx + 1];
+                       mcell.nspheres += nsph;
+                       int s=counts[2*idx];
+                       for (int j=0; j<nsph; ++j) {
+                               float* data=spheres + cells[s + j];
+                               for (int k=0; k<nvars; ++k) {
+                                       if (data[k]<mcell.min[k])
+                                               mcell.min[k]=data[k];
+                                       if (data[k]>mcell.max[k])
+                                               mcell.max[k]=data[k];
+                               }
+                       }
+               }
+       }
 }
 
 void CDGridSpheres::mapDiffuseColors(Packet<Color>& diffuse, RayPacket& 
rays) const
 {
-  for (int i=int(rays.begin()); i<int(rays.end()); ++i) {
-    int particle=rays.scratchpad<int>(i);
-    float value=*(spheres + particle + cidx);
-    float minimum=cmin[cidx];
-    float normalized=(value - minimum)/(cmax[cidx] - minimum);
-    //int ncolors=cmap->blended.size() - 1;
-    //int idx=SCIRun::Clamp(static_cast<int>(ncolors*normalized), 0, 
ncolors);
-    //diffuse.set(i, cmap->blended[idx]);
-    diffuse.set(i, cmap->GetColor(normalized).color);
-  }
+       for (int i=int(rays.begin()); i<int(rays.end()); ++i) {
+               int particle=rays.scratchpad<int>(i);
+               float value=*(spheres + particle + cidx);
+               float minimum=cmin[cidx];
+               float normalized=(value - minimum)/(cmax[cidx] - minimum);
+               //int ncolors=cmap->blended.size() - 1;
+               //int idx=SCIRun::Clamp(static_cast<int>(ncolors*normalized), 
0, ncolors);
+               //diffuse.set(i, cmap->blended[idx]);
+               diffuse.set(i, cmap->GetColor(normalized).color);
+       }
 }
 
 bool CDGridSpheres::clip(int s) const

Modified: trunk/scenes/csafe/src/CDGridSpheres.h
==============================================================================
--- trunk/scenes/csafe/src/CDGridSpheres.h      (original)
+++ trunk/scenes/csafe/src/CDGridSpheres.h      Thu Jan 10 18:59:23 2008
@@ -1,7 +1,7 @@
 //! Filename: CDGridSpheres.h
 /*!
-    same as Grispheres, but with small changes to incorporate csafe demo.  
TODO: incorporate changes into main Gridspheres file
-*/
+ same as Grispheres, but with small changes to incorporate csafe demo.  
TODO: incorporate changes into main Gridspheres file
+ */
 
 #ifndef Manta_Model_CDGridSpheres_h
 #define Manta_Model_CDGridSpheres_h
@@ -18,123 +18,123 @@
 #define USE_OPTIMIZED_FCNS
 
 namespace Manta {
-  class RegularColorMap;
-
-  class CDGridSpheres : public PrimitiveCommon, public LitMaterial,
-                      public TexCoordMapper
-  {
-  public:
-    CDGridSpheres(float* spheres, int nspheres, int nvars, int ncells, int 
depth,
-                Real radius, int ridx, RGBAColorMap* cmap, int cidx);
-    ~CDGridSpheres(void);
-
-    void preprocess(const PreprocessContext&);
-
-    void computeBounds(const PreprocessContext& context,
-                       BBox& bbox) const;
-    void intersect(const RenderContext& context, RayPacket& rays) const;
-    void computeNormal(const RenderContext& context, RayPacket& rays) const;
-
-    virtual void shade(const RenderContext& context, RayPacket& rays) const;
-
-    void computeTexCoords2(const RenderContext& context,
-                                  RayPacket& rays) const;
-    void computeTexCoords3(const RenderContext& context,
-                                  RayPacket& rays) const;
-    void setCMinMax(int index, float min, float max) { cmin[index] = min; 
cmax[index] = max; }
-    void getCMinMax(int index, float& min, float& max) { min = cmin[index]; 
max = cmax[index]; }
-    void computeHistogram(int index, int numBuckets, int* histValues); 
//index is data index to use.  histValues should be of size numBuckets
-    void getMinMax(int index, float& dmin, float&dmax)
+       class RegularColorMap;
+       
+       class CDGridSpheres : public PrimitiveCommon, public LitMaterial,
+       public TexCoordMapper
        {
-               dmin = min[index];
-               dmax = max[index];
-       }
-    void setCidx(int cidx) { this->cidx = cidx; }
-    void setCMap(RGBAColorMap* map) { cmap = map; }
-    bool clip(int s) const;
-    void setClipMinMax(int index, float clipMin, float clipMax)
-{
-       clipMins[index] = clipMin;
-       clipMaxs[index] = clipMax;
-}
-  protected:
+       public:
+               CDGridSpheres(float* spheres, int nspheres, int nvars, int 
ncells, int depth,
+                                         Real radius, int ridx, 
RGBAColorMap* cmap, int cidx);
+               ~CDGridSpheres(void);
+               
+               void preprocess(const PreprocessContext&);
+               
+               void computeBounds(const PreprocessContext& context,
+                                                  BBox& bbox) const;
+               void intersect(const RenderContext& context, RayPacket& rays) 
const;
+               void computeNormal(const RenderContext& context, RayPacket& 
rays) const;
+               
+               virtual void shade(const RenderContext& context, RayPacket& 
rays) const;
+               
+               void computeTexCoords2(const RenderContext& context,
+                                                          RayPacket& rays) 
const;
+               void computeTexCoords3(const RenderContext& context,
+                                                          RayPacket& rays) 
const;
+               void setCMinMax(int index, float min, float max) { 
cmin[index] = min; cmax[index] = max; }
+               void getCMinMax(int index, float& min, float& max) { min = 
cmin[index]; max = cmax[index]; }
+               void computeHistogram(int index, int numBuckets, int* 
histValues); //index is data index to use.  histValues should be of size 
numBuckets
+               void getMinMax(int index, float& dmin, float&dmax)
+               {
+                       dmin = min[index];
+                       dmax = max[index];
+               }
+               void setCidx(int cidx) { this->cidx = cidx; }
+               void setCMap(RGBAColorMap* map) { cmap = map; }
+               bool clip(int s) const;
+               void setClipMinMax(int index, float clipMin, float clipMax)
+               {
+                       clipMins[index] = clipMin;
+                       clipMaxs[index] = clipMax;
+               }
+       protected:
 #ifdef USE_OPTIMIZED_FCNS
-    typedef void (CDGridSpheres::*SphereIntersectFcn)(RayPacket&, int, int,
-                                                    const Vector&, float) 
const;
+               typedef void (CDGridSpheres::*SphereIntersectFcn)(RayPacket&, 
int, int,
+                                                                             
                                    const Vector&, float) const;
 #endif
-
-    struct MCell {
-      int nspheres;
-      float* max;
-      float* min;
-    };
-
-    void traverse(int i, RayPacket& rays, int depth,
-                  Real tnear,
-                  int ix, int iy, int iz,
-                  int idx,
-                  Real dt_dx, Real dt_dy, Real dt_dz,
-                  Real tnext_x, Real tnext_y, Real tnext_z,
-                  const Vector& corner, const Vector& celldir,
-                  int di_dx, int di_dy, int di_dz,
-                  int didx_dx, int didx_dy,
+               
+               struct MCell {
+                       int nspheres;
+                       float* max;
+                       float* min;
+               };
+               
+               void traverse(int i, RayPacket& rays, int depth,
+                                         Real tnear,
+                                         int ix, int iy, int iz,
+                                         int idx,
+                                         Real dt_dx, Real dt_dy, Real dt_dz,
+                                         Real tnext_x, Real tnext_y, Real 
tnext_z,
+                                         const Vector& corner, const Vector& 
celldir,
+                                         int di_dx, int di_dy, int di_dz,
+                                         int didx_dx, int didx_dy,
 #ifdef USE_OPTIMIZED_FCNS
-                  int didx_dz, int stop_x, int stop_y, int stop_z,
-                  SphereIntersectFcn intersectSphere) const;
+                                         int didx_dz, int stop_x, int 
stop_y, int stop_z,
+                                         SphereIntersectFcn intersectSphere) 
const;
 #else
-                  int didx_dz, int stop_x, int stop_y, int stop_z) const;
+               int didx_dz, int stop_x, int stop_y, int stop_z) const;
 #endif // USE_OPTIMIZED_FCNS
-    void transformToLattice(const BBox& box, int& sx, int& sy, int& sz,
-                            int& ex, int& ey, int& ez) const;
-    int mapIdx(int ix, int iy, int iz, int depth);
-    void fillMCell(MCell& mcell, int depth, int startidx) const;
-    void mapDiffuseColors(Packet<Color>& diffuse, RayPacket& rays) const;
-
+               void transformToLattice(const BBox& box, int& sx, int& sy, 
int& sz,
+                                                               int& ex, int& 
ey, int& ez) const;
+               int mapIdx(int ix, int iy, int iz, int depth);
+               void fillMCell(MCell& mcell, int depth, int startidx) const;
+               void mapDiffuseColors(Packet<Color>& diffuse, RayPacket& 
rays) const;
+               
 #ifdef USE_OPTIMIZED_FCNS
-    // Sphere intersection functions
-    void intersectSphereCOND(RayPacket& rays, int ray_idx, int idx,
-                             const Vector& center, float radius2) const;
-    void intersectSphereCO(RayPacket& rays, int ray_idx, int idx,
-                           const Vector& center, float radius2) const;
-    void intersectSphereND(RayPacket& rays, int ray_idx, int idx,
-                           const Vector& center, float radius2) const;
+               // Sphere intersection functions
+               void intersectSphereCOND(RayPacket& rays, int ray_idx, int 
idx,
+                                                                const 
Vector& center, float radius2) const;
+               void intersectSphereCO(RayPacket& rays, int ray_idx, int idx,
+                                                          const Vector& 
center, float radius2) const;
+               void intersectSphereND(RayPacket& rays, int ray_idx, int idx,
+                                                          const Vector& 
center, float radius2) const;
 #endif // USE_OPTIMIZED_FCNS
-    void intersectSphereDefault(RayPacket& rays, int ray_idx, int idx,
-                                const Vector& center, float radius2) const;
-
-    void lambertianShade(const RenderContext& context, RayPacket& rays,
-                         ColorArray& totalLight) const;
-
-    float* spheres;
-    int nspheres;
-    int nvars;
-    Real radius;
-    Real inv_radius;
-    int ridx;
-
-    Vector diagonal;
-    Vector inv_diagonal;
-    int totalcells;
-
-    int* counts;
-    int* cells;
-    float* min;
-    float* max;
-    float* cmin;  //specified min/max values to override actual ones(used 
for coloring)
-    float* cmax;  
-    float* clipMins;  //clip data by these values (array of nvars size)
-    float* clipMaxs;
-    BBox bounds;
-
-    int ncells;
-    int depth;
-    Real inv_ncells;
-
-    MCell** macrocells;
-
-    RGBAColorMap* cmap;
-    int cidx;
-  };
+               void intersectSphereDefault(RayPacket& rays, int ray_idx, int 
idx,
+                                                                       const 
Vector& center, float radius2) const;
+               
+               void lambertianShade(const RenderContext& context, RayPacket& 
rays,
+                                                        ColorArray& 
totalLight) const;
+               
+               float* spheres;
+               int nspheres;
+               int nvars;
+               Real radius;
+               Real inv_radius;
+               int ridx;
+               
+               Vector diagonal;
+               Vector inv_diagonal;
+               int totalcells;
+               
+               int* counts;
+               int* cells;
+               float* min;
+               float* max;
+               float* cmin;  //specified min/max values to override actual 
ones(used for coloring)
+               float* cmax;  
+               float* clipMins;  //clip data by these values (array of nvars 
size)
+               float* clipMaxs;
+               BBox bounds;
+               
+               int ncells;
+               int depth;
+               Real inv_ncells;
+               
+               MCell** macrocells;
+               
+               RGBAColorMap* cmap;
+               int cidx;
+       };
 }
 
 #endif

Modified: trunk/scenes/csafe/src/CDSWIGIFY.h
==============================================================================
--- trunk/scenes/csafe/src/CDSWIGIFY.h  (original)
+++ trunk/scenes/csafe/src/CDSWIGIFY.h  Thu Jan 10 18:59:23 2008
@@ -1,8 +1,8 @@
 //! Filename: CDSWIGIFY.h
 /*!
-    these functions are purely to fix weird issues with communicating 
between c++
-    and python using swig.
-*/
+ these functions are purely to fix weird issues with communicating between 
c++
+ and python using swig.
+ */
 
 #include <Interface/MantaInterface.h>
 using namespace Manta;

Modified: trunk/scenes/csafe/src/CDTest.h
==============================================================================
--- trunk/scenes/csafe/src/CDTest.h     (original)
+++ trunk/scenes/csafe/src/CDTest.h     Thu Jan 10 18:59:23 2008
@@ -1,8 +1,8 @@
 //! Filename: CDTest.h
 /*!
-    This file is a "bridge" between python code and c++ code to simplify 
dealing with 
-    templated classes, etc. for the csafe demo.
-*/
+ This file is a "bridge" between python code and c++ code to simplify 
dealing with 
+ templated classes, etc. for the csafe demo.
+ */
 
 #ifndef CDTEST_H
 #define CDTEST_H
@@ -48,549 +48,549 @@
 
 
 /*!
-\class CDTest
-\brief c++ Bridge for running csafe code
-\author Carson Brownlee
-Description: used for running c++ heavy code for csafe demo
-*/
+ \class CDTest
+ \brief c++ Bridge for running csafe code
+ \author Carson Brownlee
+ Description: used for running c++ heavy code for csafe demo
+ */
 class CDTest
-{
-public:
-    //! CDTest constructor
-    /*!
-    \param pass in the scene, or NULL and set it later
-    \param pass in MantaInterface used for rendering
-    */
-       CDTest(Scene* scene, MantaInterface* interface)
        {
-               _scene = scene;
-               _ridx = 6;
-               _cidx = 4;
-               _radius = 0.0003;
-               numFrames = numFrames1 = numFrames2 = 0;
-               //_readContext = context;
-               _manta_interface = interface;
-               _forceDataMin = -FLT_MAX;
-               _forceDataMax = -FLT_MAX;
-       }
-       
-       //! sets the scene object, necessary for initializing scene and 
loading spheres/volume
-       /*!
-    \param scene to set
-       */
-       void setScene(Scene* scene)
-       {
-               _scene = scene;
-       }
-       
-       //! initializes the scene, must do before rendering
-       /*!
-       */
-       void initScene()
-       {
-         _world = new Group();
-       _scene->setBackground(new ConstantBackground(Color(RGB(0, 0, 0)))); 
-        _scene->setObject(_world);
-
-         LightSet* lights = new LightSet();
-       lights->add(new PointLight(Vector(-500, 300, -300), 
Color(RGB(.8,.8,.8))));
-
-       lights->setAmbientLight(new ConstantAmbient(Color(RGB(.4,.4,.4))));
-         _scene->setLights(lights);
-       Group*   group = new Group();
-       Primitive* prim = new Cube( new Lambertian(Color(RGBColor(1,0,0))), 
Vector(-0.1, -0.1, 0.4)*0, Vector(0.1, 0.1, 0.7)*0);  
-               _sphereAnimation= new KeyFrameAnimation();
-               _volAnimation = new KeyFrameAnimation();
- Primitive* prim2 = new Cube( new Lambertian(Color(RGBColor(0,0,1))), 
Vector(-0.1, -0.1, 0.4), Vector(0.1, 0.1, .7));
-               group->add(prim);
-               Group* group2 = new Group();
-               group2->add(prim2);
-               _world->add(_sphereAnimation);
-               _world->add(_volAnimation);
-               _sphereAnimation->setDuration(15);
-               _volAnimation->setDuration(15);
-               duration = 10;
-               numFrames1 = numFrames2 = numFrames = 1;
-
-               _minBound = Vector(-0.001, -0.101, -0.001);
-               _maxBound = Vector( 0.101, 0.201, 0.101);
-
-
-vector<ColorSlice> slices;
-float div = 1.0/255.0;
-float a = 0.1;
-slices.push_back(ColorSlice(0.0f, RGBAColor(Color(RGB(0, 0, 0)) * div, 
0*a)));
-  slices.push_back(ColorSlice(0.109804f, RGBAColor(Color(RGB(52, 0, 0)) * 
div, 0*a)));
-  slices.push_back(ColorSlice(0.01f, RGBAColor(Color(RGB(102, 2, 0)) * div, 
0.1*a)));
-  slices.push_back(ColorSlice(0.328571f, RGBAColor(Color(RGB(153, 18, 0)) * 
div, 0.216667*a)));
-  slices.push_back(ColorSlice(0.4f, RGBAColor(Color(RGB(200, 41, 0)) * div, 
0.23*a)));
-  slices.push_back(ColorSlice(0.5f, RGBAColor(Color(RGB(230, 71, 0)) * div, 
0.27*a)));
-  slices.push_back(ColorSlice(0.618367f, RGBAColor(Color(RGB(255, 120, 0)) * 
div, 0.3375*a)));
-  slices.push_back(ColorSlice(0.68f, RGBAColor(Color(RGB(255, 163, 20)) * 
div, 0.35*a)));
-  slices.push_back(ColorSlice(0.72f, RGBAColor(Color(RGB(255, 204, 55)) * 
div, 0.37*a)));
-  slices.push_back(ColorSlice(0.79f, RGBAColor(Color(RGB(255, 228, 80)) * 
div, 0.39*a)));
-  slices.push_back(ColorSlice(0.85f, RGBAColor(Color(RGB(255, 247, 120)) * 
div, 0.43*a)));
-  slices.push_back(ColorSlice(0.92f, RGBAColor(Color(RGB(255, 255, 180)) * 
div, 0.47*a)));
-  slices.push_back(ColorSlice(1.0f, RGBAColor(Color(RGB(255, 255, 255)) * 
div, 0.5*a)));
-_volCMap = new RGBAColorMap(slices, 64);
-
-
-       }
-       
-       //! add a sphere file to be loaded
-       /*!
-          \param file to be loaded later
-       */
-       void addSphereNrrd(string file)
-       {
-               _nrrdFilenames.push_back(file);
-       }
-       
-       //! clear list of sphere files
-       /*!
-       */
-       void clearSphereNrrds()
-       {
-               _nrrdFilenames.clear();
-               numFrames1 = 0;
-               numFrames = numFrames2;
-       }
-       
-       //! add volume nrrd file to be loaded
-       /*!
-          \param file to add to be loaded later
-       */
-       void addVolNrrd(string file)
-       {
-               _nrrdFilenames2.push_back(file);
-       }
-       
-       //! clear list of volume files
-       /*!
-       */
-       void clearVolNrrds()
-       {
-               _nrrdFilenames2.clear();
-               numFrames2 = 0;
-               numFrames = numFrames1;
-       }
-       
-       //! load list of sphere nrrd files
-       /*!
-          
-       */
-       void loadSphereNrrds()
-       {       
-               LightSet* lights = _scene->getLights();
-               PreprocessContext context(_manta_interface, 0, 1, lights);
-               _nrrds.clear();
-               for(vector<string>::iterator i = _nrrdFilenames.begin(); i != 
_nrrdFilenames.end(); i++)
-               {
-                       cout << "Loading Nrrd file: " << *i << "...\n";
-                       ParticleNRRD* pnrrd = new ParticleNRRD();
-                       pnrrd->readFile(*i);
-                       _spherePNrrds.push_back(pnrrd);
-                       Group* group = new Group();
-                       RGBAColorMap* cmap = new RGBAColorMap(1);
-                       CDGridSpheres* grid = new 
CDGridSpheres(pnrrd->getParticleData(), pnrrd->getNParticles(), 
pnrrd->getNVars(), 6, 2,0.0001, _ridx, cmap , _cidx); 
-                       grid->setCMinMax(4, 299.50411987304688, 
500.59423828125);
-                       //TODO: unhardcode this!
-                       cout << "reprocess\n";
-                       grid->preprocess(context);
-                       cout << "donepreprocess\n";
-                       group->add(grid);
-                       _sphereGrids.push_back(grid);
-                       if (pnrrd->getNVars() > _sphereMins.size())
+       public:
+               //! CDTest constructor
+               /*!
+                \param pass in the scene, or NULL and set it later
+                \param pass in MantaInterface used for rendering
+                */
+               CDTest(Scene* scene, MantaInterface* interface)
+               {
+                       _scene = scene;
+                       _ridx = 6;
+                       _cidx = 4;
+                       _radius = 0.0003;
+                       numFrames = numFrames1 = numFrames2 = 0;
+                       //_readContext = context;
+                       _manta_interface = interface;
+                       _forceDataMin = -FLT_MAX;
+                       _forceDataMax = -FLT_MAX;
+               }
+               
+               //! sets the scene object, necessary for initializing scene 
and loading spheres/volume
+               /*!
+                \param scene to set
+                */
+               void setScene(Scene* scene)
+               {
+                       _scene = scene;
+               }
+               
+               //! initializes the scene, must do before rendering
+               /*!
+                */
+               void initScene()
+               {
+                       _world = new Group();
+                       _scene->setBackground(new 
ConstantBackground(Color(RGB(0, 0, 0)))); 
+                       _scene->setObject(_world);
+                       
+                       LightSet* lights = new LightSet();
+                       lights->add(new PointLight(Vector(-500, 300, -300), 
Color(RGB(.8,.8,.8))));
+                       
+                       lights->setAmbientLight(new 
ConstantAmbient(Color(RGB(.4,.4,.4))));
+                       _scene->setLights(lights);
+                       Group*   group = new Group();
+                       Primitive* prim = new Cube( new 
Lambertian(Color(RGBColor(1,0,0))), Vector(-0.1, -0.1, 0.4)*0, Vector(0.1, 
0.1, 0.7)*0);  
+                       _sphereAnimation= new KeyFrameAnimation();
+                       _volAnimation = new KeyFrameAnimation();
+                       Primitive* prim2 = new Cube( new 
Lambertian(Color(RGBColor(0,0,1))), Vector(-0.1, -0.1, 0.4), Vector(0.1, 0.1, 
.7));
+                       group->add(prim);
+                       Group* group2 = new Group();
+                       group2->add(prim2);
+                       _world->add(_sphereAnimation);
+                       _world->add(_volAnimation);
+                       _sphereAnimation->setDuration(15);
+                       _volAnimation->setDuration(15);
+                       duration = 10;
+                       numFrames1 = numFrames2 = numFrames = 1;
+                       
+                       _minBound = Vector(-0.001, -0.101, -0.001);
+                       _maxBound = Vector( 0.101, 0.201, 0.101);
+                       
+                       
+                       vector<ColorSlice> slices;
+                       float div = 1.0/255.0;
+                       float a = 0.1;
+                       slices.push_back(ColorSlice(0.0f, 
RGBAColor(Color(RGB(0, 0, 0)) * div, 0*a)));
+                       slices.push_back(ColorSlice(0.109804f, 
RGBAColor(Color(RGB(52, 0, 0)) * div, 0*a)));
+                       slices.push_back(ColorSlice(0.01f, 
RGBAColor(Color(RGB(102, 2, 0)) * div, 0.1*a)));
+                       slices.push_back(ColorSlice(0.328571f, 
RGBAColor(Color(RGB(153, 18, 0)) * div, 0.216667*a)));
+                       slices.push_back(ColorSlice(0.4f, 
RGBAColor(Color(RGB(200, 41, 0)) * div, 0.23*a)));
+                       slices.push_back(ColorSlice(0.5f, 
RGBAColor(Color(RGB(230, 71, 0)) * div, 0.27*a)));
+                       slices.push_back(ColorSlice(0.618367f, 
RGBAColor(Color(RGB(255, 120, 0)) * div, 0.3375*a)));
+                       slices.push_back(ColorSlice(0.68f, 
RGBAColor(Color(RGB(255, 163, 20)) * div, 0.35*a)));
+                       slices.push_back(ColorSlice(0.72f, 
RGBAColor(Color(RGB(255, 204, 55)) * div, 0.37*a)));
+                       slices.push_back(ColorSlice(0.79f, 
RGBAColor(Color(RGB(255, 228, 80)) * div, 0.39*a)));
+                       slices.push_back(ColorSlice(0.85f, 
RGBAColor(Color(RGB(255, 247, 120)) * div, 0.43*a)));
+                       slices.push_back(ColorSlice(0.92f, 
RGBAColor(Color(RGB(255, 255, 180)) * div, 0.47*a)));
+                       slices.push_back(ColorSlice(1.0f, 
RGBAColor(Color(RGB(255, 255, 255)) * div, 0.5*a)));
+                       _volCMap = new RGBAColorMap(slices, 64);
+                       
+                       
+               }
+               
+               //! add a sphere file to be loaded
+               /*!
+                \param file to be loaded later
+                */
+               void addSphereNrrd(string file)
+               {
+                       _nrrdFilenames.push_back(file);
+               }
+               
+               //! clear list of sphere files
+               /*!
+                */
+               void clearSphereNrrds()
+               {
+                       _nrrdFilenames.clear();
+                       numFrames1 = 0;
+                       numFrames = numFrames2;
+               }
+               
+               //! add volume nrrd file to be loaded
+               /*!
+                \param file to add to be loaded later
+                */
+               void addVolNrrd(string file)
+               {
+                       _nrrdFilenames2.push_back(file);
+               }
+               
+               //! clear list of volume files
+               /*!
+                */
+               void clearVolNrrds()
+               {
+                       _nrrdFilenames2.clear();
+                       numFrames2 = 0;
+                       numFrames = numFrames1;
+               }
+               
+               //! load list of sphere nrrd files
+               /*!
+                
+                */
+               void loadSphereNrrds()
+               {       
+                       LightSet* lights = _scene->getLights();
+                       PreprocessContext context(_manta_interface, 0, 1, 
lights);
+                       _nrrds.clear();
+                       for(vector<string>::iterator i = 
_nrrdFilenames.begin(); i != _nrrdFilenames.end(); i++)
                        {
-                               for(size_t j = _sphereMins.size(); j < 
pnrrd->getNVars(); j++)
+                               cout << "Loading Nrrd file: " << *i << 
"...\n";
+                               ParticleNRRD* pnrrd = new ParticleNRRD();
+                               pnrrd->readFile(*i);
+                               _spherePNrrds.push_back(pnrrd);
+                               Group* group = new Group();
+                               RGBAColorMap* cmap = new RGBAColorMap(1);
+                               CDGridSpheres* grid = new 
CDGridSpheres(pnrrd->getParticleData(), pnrrd->getNParticles(), 
pnrrd->getNVars(), 6, 2,0.0001, _ridx, cmap , _cidx); 
+                               grid->setCMinMax(4, 299.50411987304688, 
500.59423828125);
+                               //TODO: unhardcode this!
+                               cout << "reprocess\n";
+                               grid->preprocess(context);
+                               cout << "donepreprocess\n";
+                               group->add(grid);
+                               _sphereGrids.push_back(grid);
+                               if (pnrrd->getNVars() > _sphereMins.size())
                                {
-                                       _sphereMins.push_back(FLT_MAX);
-                                       _sphereMaxs.push_back(-FLT_MAX);
+                                       for(size_t j = _sphereMins.size(); j 
< pnrrd->getNVars(); j++)
+                                       {
+                                               
_sphereMins.push_back(FLT_MAX);
+                                               
_sphereMaxs.push_back(-FLT_MAX);
+                                       }
                                }
-                       }
-                       for(int j = 0; j < int(_sphereMins.size()); j++)
+                               for(int j = 0; j < int(_sphereMins.size()); 
j++)
+                               {
+                                       float min,max;
+                                       grid->getMinMax(j, min, max);
+                                       if (_sphereMins[j] > min)
+                                               _sphereMins[j] = min;
+                                       if (_sphereMaxs[j] < max)
+                                               _sphereMaxs[j] = max;
+                               }
+                               _sphereAnimation->push_back(group);
+                               numFrames1++;
+                               //Nrrd *new_nrrd = nrrdNew();
+                               
////////////////////////////////////////////////////////////////////////////
+                               // Attempt to open the nrrd
+                               //if (nrrdLoad( new_nrrd, i->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__);
+                               //  }
+                               
+                               //_nrrds.push_back(new_nrrd);
+                               cout << "Loading " << *i << " done.\n";
+                       } 
+                       updateFrames();
+               }
+               
+               //! clear list of volume files
+               /*!
+                */
+               void loadVolNrrds()
+               {
+                       for(vector<string>::iterator i = 
_nrrdFilenames2.begin(); i != _nrrdFilenames2.end(); i++)
                        {
-                               float min,max;
-                               grid->getMinMax(j, min, max);
-                               if (_sphereMins[j] > min)
-                                       _sphereMins[j] = min;
-                               if (_sphereMaxs[j] < max)
-                                       _sphereMaxs[j] = max;
+                               cout << "Loading Nrrd file: " << *i << 
"...\n";
+                               Group* group = new Group();
+                               Volume<float>* mat = new Volume<float>(*i, 
_volCMap, _minBound, _maxBound, 0.00125, 10, 3, _forceDataMin, _forceDataMax);
+                               Primitive* vol = new Cube(mat, _minBound - 
Vector(0.001, 0.001, 0.001), _maxBound + Vector(0.001, 0.001, 0.001));
+                               group->add(vol);
+                               _volAnimation->push_back(group);
+                               _vols.push_back(mat);
+                               numFrames2++;
+                               //Nrrd *new_nrrd = nrrdNew();
+                               
////////////////////////////////////////////////////////////////////////////
+                               // Attempt to open the nrrd
+                               //if (nrrdLoad( new_nrrd, i->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__);
+                               //  }
+                               cout << "Loading " << *i << " done.\n";
                        }
-                       _sphereAnimation->push_back(group);
-                       numFrames1++;
-                        //Nrrd *new_nrrd = nrrdNew();
-       
////////////////////////////////////////////////////////////////////////////
-       // Attempt to open the nrrd
-       //if (nrrdLoad( new_nrrd, i->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__);
-  //  }
-
-                       //_nrrds.push_back(new_nrrd);
-                       cout << "Loading " << *i << " done.\n";
+                       updateFrames();
+               }
+               
+               //! update the frame cieling
+               /*!
+                */
+               void updateFrames()
+               {
+                       numFrames = std::max(numFrames1, numFrames2);
+               }
+               
+               //! pause animation
+               /*!
+                */
+               void pauseAnimation() { _sphereAnimation->pauseAnimation(); 
_volAnimation->pauseAnimation(); }
+               
+               //! resume animation
+               /*!
+                */
+               void resumeAnimation() { _sphereAnimation->resumeAnimation(); 
_volAnimation->resumeAnimation();}
+               
+               //! go to a time in animation
+               /*!
+                \param time to go to
+                */
+               void gotoFrame(float time) { _sphereAnimation->setTime(time); 
_volAnimation->setTime(time); }
+               
+               //! skip ahead one frame
+               /*!
+                */
+               void forwardAnimation()
+               {
+                       cout << _sphereAnimation->getTime() << endl;
+                       float step;
+                       if (numFrames == 0)
+                               step = 0;
+                       else
+                               step = duration/float(numFrames);
+                       float st = _sphereAnimation->getTime();
+                       st = std::max(st, 0.0f);
+                       float vt = _volAnimation->getTime();
+                       vt = std::max(vt, 0.0f);
+                       
+                       _sphereAnimation->setTime( 
_sphereAnimation->getTime() + step);
+                       _volAnimation->setTime(_volAnimation->getTime()+step);
+               }
+               
+               //! skip back one frame
+               /*!
+                */
+               void backAnimation()
+               {
+                       float step;
+                       if (numFrames == 0)
+                               step = 0;
+                       else
+                               step     = duration/float(numFrames);
+                       _sphereAnimation->setTime( 
_sphereAnimation->getTime() - step);
+                       _volAnimation->setTime(_volAnimation->getTime()-step);
                } 
-               updateFrames();
-       }
-       
-       //! clear list of volume files
-       /*!
-       */
-       void loadVolNrrds()
-       {
-                               for(vector<string>::iterator i = 
_nrrdFilenames2.begin(); i != _nrrdFilenames2.end(); i++)
+               
+               //! get the duration of the animation in seconds
+               /*!
+                \return duration in seconds of animation
+                */
+               float getDuration()
+               {
+                       return duration;
+               }
+               
+               //! set the duration of animation in seconds
+               /*!
+                \param number of seconds animation takes
+                */
+               void setDuration(float time)
+               {
+                       duration = time;
+                       _sphereAnimation->setDuration(time);
+                       _volAnimation->setDuration(time);
+               }
+               
+               //! computes histogram of spherefiles
+               /*!
+                \param index of data to compute histogram of
+                \param number of buckets to compute, ie 100 bars
+                \param an allocated list of ints to store the values, must 
be size numBuckets
+                \param will return min
+                \param will return max
+                */
+               void getHistogram(int index, int numBuckets, int* histValues, 
float* min, float* max)
+               {
+                       for(int i = 0; i < numBuckets; i++)
+                               histValues[i] = 0;
+                       for(size_t i = 0; i < _spherePNrrds.size(); i++)
+                       {
+                               ParticleNRRD* pnrrd = _spherePNrrds[i];
+                               float dataMin = _sphereMins[index];
+                               float dataMax = _sphereMaxs[index];
+                               cout << "histo dataMin/Max: " << dataMin << " 
" << dataMax << endl;
+                               float scale;
+                               if (dataMin != dataMax)
+                                       scale = (numBuckets-1)/(dataMax - 
dataMin);
+                               else
+                                       continue;
+                               for(int j = 0; j < 
int(pnrrd->getNParticles()); j++)
                                {
-                                               cout << "Loading Nrrd file: " 
<< *i << "...\n";
-                                               Group* group = new Group();
-                       Volume<float>* mat = new Volume<float>(*i, _volCMap, 
_minBound, _maxBound, 0.00125, 10, 3, _forceDataMin, _forceDataMax);
-                       Primitive* vol = new Cube(mat, _minBound - 
Vector(0.001, 0.001, 0.001), _maxBound + Vector(0.001, 0.001, 0.001));
-                                               group->add(vol);
-                                               
_volAnimation->push_back(group);
-                       _vols.push_back(mat);
-                                               numFrames2++;
-                                                //Nrrd *new_nrrd = nrrdNew();
-       
////////////////////////////////////////////////////////////////////////////
-       // Attempt to open the nrrd
-       //if (nrrdLoad( new_nrrd, i->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__);
-  //  }
-                                               cout << "Loading " << *i << " 
done.\n";
+                                       float val = 
*(pnrrd->getParticleData() + j*pnrrd->getNVars() + index);
+                                       int bucket = int((val-dataMin)*scale);
+                                       static int count = 0; if (val > 0.06 
&& count++ < 20) cout << "val: " << val << " " << bucket << endl;
+                                       histValues[bucket]++;
                                }
-               updateFrames();
-       }
-       
-       //! update the frame cieling
-       /*!
-       */
-       void updateFrames()
-       {
-               numFrames = std::max(numFrames1, numFrames2);
-       }
-       
-       //! pause animation
-       /*!
-       */
-       void pauseAnimation() { _sphereAnimation->pauseAnimation(); 
_volAnimation->pauseAnimation(); }
-       
-       //! resume animation
-       /*!
-       */
-       void resumeAnimation() { _sphereAnimation->resumeAnimation(); 
_volAnimation->resumeAnimation();}
-       
-       //! go to a time in animation
-       /*!
-          \param time to go to
-       */
-       void gotoFrame(float time) { _sphereAnimation->setTime(time); 
_volAnimation->setTime(time); }
-       
-       //! skip ahead one frame
-       /*!
-       */
-       void forwardAnimation()
-       {
-               cout << _sphereAnimation->getTime() << endl;
-               float step;
-               if (numFrames == 0)
-                       step = 0;
-               else
-                       step = duration/float(numFrames);
-               float st = _sphereAnimation->getTime();
-               st = std::max(st, 0.0f);
-               float vt = _volAnimation->getTime();
-               vt = std::max(vt, 0.0f);
-               
-               _sphereAnimation->setTime( _sphereAnimation->getTime() + 
step);
-               _volAnimation->setTime(_volAnimation->getTime()+step);
-       }
-       
-       //! skip back one frame
-       /*!
-       */
-       void backAnimation()
-       {
-               float step;
-               if (numFrames == 0)
-                       step = 0;
-               else
-                       step     = duration/float(numFrames);
-               _sphereAnimation->setTime( _sphereAnimation->getTime() - 
step);
-               _volAnimation->setTime(_volAnimation->getTime()-step);
-       } 
-       
-       //! get the duration of the animation in seconds
-       /*!
-          \return duration in seconds of animation
-       */
-       float getDuration()
-       {
-               return duration;
-       }
-       
-       //! set the duration of animation in seconds
-       /*!
-          \param number of seconds animation takes
-       */
-       void setDuration(float time)
-       {
-               duration = time;
-               _sphereAnimation->setDuration(time);
-               _volAnimation->setDuration(time);
-       }
-       
-       //! computes histogram of spherefiles
-       /*!
-          \param index of data to compute histogram of
-          \param number of buckets to compute, ie 100 bars
-          \param an allocated list of ints to store the values, must be size 
numBuckets
-          \param will return min
-          \param will return max
-       */
-       void getHistogram(int index, int numBuckets, int* histValues, float* 
min, float* max)
-       {
-               for(int i = 0; i < numBuckets; i++)
-                                               histValues[i] = 0;
-               for(size_t i = 0; i < _spherePNrrds.size(); i++)
-               {
-                       ParticleNRRD* pnrrd = _spherePNrrds[i];
-                       float dataMin = _sphereMins[index];
-                                       float dataMax = _sphereMaxs[index];
-                       cout << "histo dataMin/Max: " << dataMin << " " << 
dataMax << endl;
-                                       float scale;
-                       if (dataMin != dataMax)
-                                       scale = (numBuckets-1)/(dataMax - 
dataMin);
+                       }
+                       if (int(_sphereMins.size()) > index)
+                       {
+                               *min = _sphereMins[index];
+                               *max = _sphereMaxs[index];
+                       }
                        else
+                       {
+                               *min = -FLT_MAX;
+                               *max = FLT_MAX;
+                       }
+               }
+               
+               //! compute histogram for volume data
+               /*!
+                \param number of buckets to compute, ie 100 bars
+                \param an allocated list of ints to store the values, must 
be size numBuckets
+                \param will return min
+                \param will return max
+                */
+               void getVolHistogram(int numBuckets, int* histValues, float* 
min, float* max)
+               {
+                       cout << "computing volume histogram for " << 
_vols.size() << " volumes\n";
+                       *min = FLT_MAX;
+                       *max = -FLT_MAX;
+                       for(int i = 0; i < numBuckets; i++)
+                               histValues[i] = 0;
+                       for (int i = 0; i < int(_vols.size()); i++)
+                       {
+                               if (_vols[i] == NULL)
                                        continue;
-                                        for(int j = 0; j < 
int(pnrrd->getNParticles()); j++)
-                                        {
-                                                                       float 
val = *(pnrrd->getParticleData() + j*pnrrd->getNVars() + index);
-                               int bucket = int((val-dataMin)*scale);
-                                 static int count = 0; if (val > 0.06 && 
count++ < 20) cout << "val: " << val << " " << bucket << endl;
-                                                                       
histValues[bucket]++;
-                                       }
-               }
-               if (int(_sphereMins.size()) > index)
-               {
-                       *min = _sphereMins[index];
-                       *max = _sphereMaxs[index];
-               }
-               else
-               {
-                       *min = -FLT_MAX;
-                       *max = FLT_MAX;
-               }
-       }
-       
-       //! compute histogram for volume data
-       /*!
-          \param number of buckets to compute, ie 100 bars
-          \param an allocated list of ints to store the values, must be size 
numBuckets
-          \param will return min
-          \param will return max
-       */
-       void getVolHistogram(int numBuckets, int* histValues, float* min, 
float* max)
-       {
-               cout << "computing volume histogram for " << _vols.size() << 
" volumes\n";
-               *min = FLT_MAX;
-               *max = -FLT_MAX;
-               for(int i = 0; i < numBuckets; i++)
-                                               histValues[i] = 0;
-               for (int i = 0; i < int(_vols.size()); i++)
-               {
-                       if (_vols[i] == NULL)
-                               continue;
-                       int* histValues2 = new int[numBuckets];
-                       _vols[i]->computeHistogram(numBuckets, histValues2);  
  
-                       for(int j = 0; j < numBuckets; j++)
-                               histValues[j] += histValues2[j];
-                       double nmin, nmax;
-                       _vols[i]->getMinMax(&nmin, &nmax);
-                       *min= std::min(float(nmin), *min);
-                       *max = std::max(float(nmax), *max);
-                       cout << "compared min/max: " << nmin << " " << nmax 
<< endl;
-               }
-               cout << "histogram computed: min/max: " << *min << " " << 
*max << endl;
-       }
-       
-       //! get the colormap used for the volume
-       /*!
-          \return colormap used for volume
-       */
-       RGBAColorMap* getVolCMap() { return _volCMap; }
-       
-       //! set the colormap for volume
-       /*!
-          \param colormap
-       */
-       void setVolCMap(RGBAColorMap* map) { _volCMap = map; }
-       
-       //! set the colormap for spheres
-       /*!
-          \param colormap
-       */
-       void setSphereCMap(RGBAColorMap* map)   {
-               for(int i =0; i < int(_sphereGrids.size()); i++)
-                       _sphereGrids[i]->setCMap(map);
-       }
-       
-       //! set minimum and maximum clipping region for a specific index into 
spheres
-       /*!
-          \param index into data
-          \param min
-          \param max
-       */
-       void setClipMinMax(int index, float min, float max)
-       {
-               if (index >= int(_sphereMins.size()))
-                       return;
-               for(int i = 0; i < int(_sphereGrids.size()); i++)
-                       if (_sphereGrids[i]) 
_sphereGrids[i]->setClipMinMax(index, min, max);
-       }
-       
-       //! set the minimum and maximum data values used for normalizing 
color data
-       /*!
-          \param index into data
-          \param min
-          \param max
-       */
-       void setSphereCMinMax(int index, float min, float max)   //set the 
min max for normalizing color data
-       {
-               if (index >= int(_sphereMins.size()))
-                       return;
-               for(int i =0; i < int(_sphereGrids.size()); i++)
-                       _sphereGrids[i]->setCMinMax(index, min, max);
-       }
-       
-       //! get the min and max being used for normalizing color values
-       /*!
-          \param index into data
-          \param returns min
-          \param returns max
-       */
-       void getSphereCMinMax(int index, float& min, float& max)
-       {
-               if(index >= int(_sphereMins.size()))
+                               int* histValues2 = new int[numBuckets];
+                               _vols[i]->computeHistogram(numBuckets, 
histValues2);    
+                               for(int j = 0; j < numBuckets; j++)
+                                       histValues[j] += histValues2[j];
+                               double nmin, nmax;
+                               _vols[i]->getMinMax(&nmin, &nmax);
+                               *min= std::min(float(nmin), *min);
+                               *max = std::max(float(nmax), *max);
+                               cout << "compared min/max: " << nmin << " " 
<< nmax << endl;
+                       }
+                       cout << "histogram computed: min/max: " << *min << " 
" << *max << endl;
+               }
+               
+               //! get the colormap used for the volume
+               /*!
+                \return colormap used for volume
+                */
+               RGBAColorMap* getVolCMap() { return _volCMap; }
+               
+               //! set the colormap for volume
+               /*!
+                \param colormap
+                */
+               void setVolCMap(RGBAColorMap* map) { _volCMap = map; }
+               
+               //! set the colormap for spheres
+               /*!
+                \param colormap
+                */
+               void setSphereCMap(RGBAColorMap* map)   {
+                       for(int i =0; i < int(_sphereGrids.size()); i++)
+                               _sphereGrids[i]->setCMap(map);
+               }
+               
+               //! set minimum and maximum clipping region for a specific 
index into spheres
+               /*!
+                \param index into data
+                \param min
+                \param max
+                */
+               void setClipMinMax(int index, float min, float max)
                {
-                       min = -FLT_MAX;
-                       max = FLT_MAX;
-                       return;
+                       if (index >= int(_sphereMins.size()))
+                               return;
+                       for(int i = 0; i < int(_sphereGrids.size()); i++)
+                               if (_sphereGrids[i]) 
_sphereGrids[i]->setClipMinMax(index, min, max);
                }
-               for(int i =0;i<int(_sphereGrids.size());i++)
-                       _sphereGrids[i]->getCMinMax(index, min, max);
-
-       }
-       
-       //! set minimum and maximum data values for volume data, should be 
called before loading
-       /*!
-          \param min
-          \param max
-       */
-       void setVolCMinMax(float min, float max)
-       {
-               _forceDataMin = min;
-               _forceDataMax = max;
-       }
-       
-       //! get the min and max data values used for normalizing color values
-       /*!
-          \param returns min
-          \param returns max
-       */
-       void getVolCMinMax(float& min, float& max)
-       {
-               min = FLT_MAX;
-               max = -FLT_MAX;
-               for(int i =0;i<int(_vols.size());i++)
-               {
-                       if (_vols[i] == NULL)
-                               continue;
-                       double min1, max1;
-                       _vols[i]->getMinMax(&min1, &max1);
-                       min = std::min(min, float(min1));
-                       max = std::max(max, float(max1));
+               
+               //! set the minimum and maximum data values used for 
normalizing color data
+               /*!
+                \param index into data
+                \param min
+                \param max
+                */
+               void setSphereCMinMax(int index, float min, float max)   
//set the min max for normalizing color data
+               {
+                       if (index >= int(_sphereMins.size()))
+                               return;
+                       for(int i =0; i < int(_sphereGrids.size()); i++)
+                               _sphereGrids[i]->setCMinMax(index, min, max);
                }
-       }
-
-    //! sets radius index used for spheredata
-       /*!
-          \param radius index
-       */
-       void setRidx(int ridx) { _ridx = ridx; }
-       
-       //! get radius index
-       /*!
-          \return radius index
-       */
-       int getRidx() { return _ridx; }
-       
-       //! set default radius of spheres
-       /*!
-          \param radius
-       */
-       void setRadius(float radius) { _radius = radius; }
-       
-       //! get the default radius of spheres
-       /*!
-          \return default radius
-       */
-       float getRadius() { return _radius; } 
-       
-       //! set color index, what index colormap uses
-       /*!
-          \param color index to use
-       */
-       void setCidx(int cidx) {
-                _cidx = cidx; 
-               for(int i =0; i < int(_sphereGrids.size()); i++)
-                       _sphereGrids[i]->setCidx(cidx); 
-       }
-       
-       //! get color index
-       /*!
-          \return color index
-       */
-       int getCidx() { return _cidx; }
-
-
-       MantaInterface* _manta_interface;
-       RGBAColorMap* _volCMap;
-       Vector _minBound;
-       Vector _maxBound;
-       float _forceDataMin;
-       float _forceDataMax;
-       int _cidx;
-       int _ridx;
-       float _radius;
-       float duration;  //number of seconds for animation
-       int numFrames;   //number of keyframes
-       int numFrames1, numFrames2;
-       ReadContext* _readContext;
-       vector<string> _nrrdFilenames;
-       vector<string> _nrrdFilenames2;
-       vector<Nrrd*> _nrrds;
-       vector<ParticleNRRD*> _spherePNrrds;
-       vector<CDGridSpheres*> _sphereGrids;
-       vector<Volume<float>*> _vols;
-       vector<float> _sphereMins;
-       vector<float> _sphereMaxs;
-       Group* _world;
-       Scene* _scene;
-       KeyFrameAnimation* _sphereAnimation;
-       KeyFrameAnimation* _volAnimation;
-};
+               
+               //! get the min and max being used for normalizing color 
values
+               /*!
+                \param index into data
+                \param returns min
+                \param returns max
+                */
+               void getSphereCMinMax(int index, float& min, float& max)
+               {
+                       if(index >= int(_sphereMins.size()))
+                       {
+                               min = -FLT_MAX;
+                               max = FLT_MAX;
+                               return;
+                       }
+                       for(int i =0;i<int(_sphereGrids.size());i++)
+                               _sphereGrids[i]->getCMinMax(index, min, max);
+                       
+               }
+               
+               //! set minimum and maximum data values for volume data, 
should be called before loading
+               /*!
+                \param min
+                \param max
+                */
+               void setVolCMinMax(float min, float max)
+               {
+                       _forceDataMin = min;
+                       _forceDataMax = max;
+               }
+               
+               //! get the min and max data values used for normalizing 
color values
+               /*!
+                \param returns min
+                \param returns max
+                */
+               void getVolCMinMax(float& min, float& max)
+               {
+                       min = FLT_MAX;
+                       max = -FLT_MAX;
+                       for(int i =0;i<int(_vols.size());i++)
+                       {
+                               if (_vols[i] == NULL)
+                                       continue;
+                               double min1, max1;
+                               _vols[i]->getMinMax(&min1, &max1);
+                               min = std::min(min, float(min1));
+                               max = std::max(max, float(max1));
+                       }
+               }
+               
+               //! sets radius index used for spheredata
+               /*!
+                \param radius index
+                */
+               void setRidx(int ridx) { _ridx = ridx; }
+               
+               //! get radius index
+               /*!
+                \return radius index
+                */
+               int getRidx() { return _ridx; }
+               
+               //! set default radius of spheres
+               /*!
+                \param radius
+                */
+               void setRadius(float radius) { _radius = radius; }
+               
+               //! get the default radius of spheres
+               /*!
+                \return default radius
+                */
+               float getRadius() { return _radius; } 
+               
+               //! set color index, what index colormap uses
+               /*!
+                \param color index to use
+                */
+               void setCidx(int cidx) {
+                       _cidx = cidx; 
+                       for(int i =0; i < int(_sphereGrids.size()); i++)
+                               _sphereGrids[i]->setCidx(cidx); 
+               }
+               
+               //! get color index
+               /*!
+                \return color index
+                */
+               int getCidx() { return _cidx; }
+               
+               
+               MantaInterface* _manta_interface;
+               RGBAColorMap* _volCMap;
+               Vector _minBound;
+               Vector _maxBound;
+               float _forceDataMin;
+               float _forceDataMax;
+               int _cidx;
+               int _ridx;
+               float _radius;
+               float duration;  //number of seconds for animation
+               int numFrames;   //number of keyframes
+               int numFrames1, numFrames2;
+               ReadContext* _readContext;
+               vector<string> _nrrdFilenames;
+               vector<string> _nrrdFilenames2;
+               vector<Nrrd*> _nrrds;
+               vector<ParticleNRRD*> _spherePNrrds;
+               vector<CDGridSpheres*> _sphereGrids;
+               vector<Volume<float>*> _vols;
+               vector<float> _sphereMins;
+               vector<float> _sphereMaxs;
+               Group* _world;
+               Scene* _scene;
+               KeyFrameAnimation* _sphereAnimation;
+               KeyFrameAnimation* _volAnimation;
+       };
 
 #endif

Modified: trunk/scenes/csafe/swig/CMakeLists.txt
==============================================================================
--- trunk/scenes/csafe/swig/CMakeLists.txt      (original)
+++ trunk/scenes/csafe/swig/CMakeLists.txt      Thu Jan 10 18:59:23 2008
@@ -37,24 +37,29 @@
 
 
 # CHANGE NAME OF SWIG INCLUDE FILE HERE.
-SET_SOURCE_FILES_PROPERTIES(example.i PROPERTIES CPLUSPLUS ON)
-SET_SOURCE_FILES_PROPERTIES(example.i 
+SET_SOURCE_FILES_PROPERTIES(csafe.i PROPERTIES CPLUSPLUS ON)
+SET_SOURCE_FILES_PROPERTIES(csafe.i 
   PROPERTIES SWIG_FLAGS 
"-I${CMAKE_SOURCE_DIR}/SwigInterface;-Wall;-DSCI_NOPERSISTENT")
 
-# Add the python module "example" corresponding to shared lib _example.so
+# Add the python module "csafe" corresponding to shared lib _csafe.so
 # CHANGE NAME OF PYTHON MODULE HERE.
-SWIG_ADD_MODULE(example python example.i)
+SWIG_ADD_MODULE(csafe python csafe.i)
 
 # CHANGE NAME OF PYTHON MODULE HERE.
-SWIG_LINK_LIBRARIES(example
+SWIG_LINK_LIBRARIES(csafe
   ${PYTHON_LIBRARIES}
   ${MANTA_TARGET_LINK_LIBRARIES}
   
   # ADD ALL PROJECT SHARED LIBS HERE
-  Example
+  CSAFE
   # swigpy
   )
 
+IF (APPLE_LEOPARD_LD)
+ SET_TARGET_PROPERTIES(_csafe PROPERTIES
+   LINK_FLAGS 
"-Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib"
+   )
+ENDIF (APPLE_LEOPARD_LD)
 
 
 




  • [Manta] r1987 - in trunk/scenes/csafe: . python src swig, brownlee, 01/10/2008

Archive powered by MHonArc 2.6.16.

Top of page