Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r952 - in trunk/fox/grid_demo: . Model Model/Groups scenes


Chronological Thread 
  • From: abe@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r952 - in trunk/fox/grid_demo: . Model Model/Groups scenes
  • Date: Wed, 22 Feb 2006 01:51:46 -0700 (MST)

Author: abe
Date: Wed Feb 22 01:51:45 2006
New Revision: 952

Added:
   trunk/fox/grid_demo/
   trunk/fox/grid_demo/CMakeLists.txt
   trunk/fox/grid_demo/Model/
   trunk/fox/grid_demo/Model/Groups/
   trunk/fox/grid_demo/Model/Groups/DyGridData.cc
   trunk/fox/grid_demo/Model/Groups/DyGridData.h
   trunk/fox/grid_demo/Model/Groups/DyGridLoader.cc
   trunk/fox/grid_demo/Model/Groups/DyGridLoader.h
   trunk/fox/grid_demo/Model/Groups/DyGridParallelBuilder.cc
   trunk/fox/grid_demo/Model/Groups/DyGridParallelBuilder.h
   trunk/fox/grid_demo/Model/Groups/DyGridSSE.cc
   trunk/fox/grid_demo/Model/Groups/DyGridSSE.h
   trunk/fox/grid_demo/Model/Groups/DyGridSerialBuilder.h
   trunk/fox/grid_demo/Model/Groups/DyGridSingle.cc
   trunk/fox/grid_demo/Model/Groups/DyGridSingle.h
   trunk/fox/grid_demo/scenes/
   trunk/fox/grid_demo/scenes/CMakeLists.txt
   trunk/fox/grid_demo/scenes/dygrid.cc
Log:

Initial commit for the dynamic grid code. Although the code compiles, thread 
local storage hasn't been added yet so it doesnt run.

Several files are empty place holders until code is written.

Loading functions. Triangles may be read in using the .v3c1 format, just like 
the kd-tree.
A    fox/grid_demo/Model/Groups/DyGridLoader.h
A    fox/grid_demo/Model/Groups/DyGridLoader.cc

Datastructure which holds grid cells, attributes, triangles, normals etc.
A    fox/grid_demo/Model/Groups/DyGridData.cc
A    fox/grid_demo/Model/Groups/DyGridData.h

Parallel grid builder, invoked by one shot callbacks.
A    fox/grid_demo/Model/Groups/DyGridParallelBuilder.cc
A    fox/grid_demo/Model/Groups/DyGridParallelBuilder.h

Single ray grid traversal, non-sse.
A    fox/grid_demo/Model/Groups/DyGridSingle.cc
A    fox/grid_demo/Model/Groups/DyGridSingle.h

Scene file to load the grid.
A    fox/grid_demo/scenes/dygrid.cc

Place holders:
A    fox/grid_demo
A    fox/grid_demo/Model
A    fox/grid_demo/Model/Groups
A    fox/grid_demo/Model/Groups/DyGridSerialBuilder.h
A    fox/grid_demo/Model/Groups/DyGridSSE.cc
A    fox/grid_demo/Model/Groups/DyGridSSE.h
A    fox/grid_demo/scenes
A    fox/grid_demo/scenes/CMakeLists.txt
A    fox/grid_demo/CMakeLists.txt


Added: trunk/fox/grid_demo/CMakeLists.txt
==============================================================================
--- (empty file)
+++ trunk/fox/grid_demo/CMakeLists.txt  Wed Feb 22 01:51:45 2006
@@ -0,0 +1,41 @@
+
+SET(BUILD_DYGRID_DEMO 0 CACHE BOOL "Build Dynamic Grid Demo")
+IF(BUILD_DYGRID_DEMO)
+
+  ##########################################################
+  # Add the disc_demo dependent code.
+
+  SET(DYGRID_SRC
+    Model/Groups/DyGridData.cc
+    Model/Groups/DyGridData.h
+    Model/Groups/DyGridLoader.cc
+    Model/Groups/DyGridLoader.h
+    Model/Groups/DyGridParallelBuilder.cc
+    Model/Groups/DyGridParallelBuilder.h
+    Model/Groups/DyGridSSE.cc
+    Model/Groups/DyGridSSE.h
+    Model/Groups/DyGridSerialBuilder.h
+    Model/Groups/DyGridSingle.cc
+    Model/Groups/DyGridSingle.h
+)
+
+  # Add a library with the code.
+  ADD_LIBRARY( grid_shared
+    ${DYGRID_SRC}
+    )
+
+  TARGET_LINK_LIBRARIES( grid_shared
+    ${MANTA_TARGET_LINK_LIBRARIES}
+    )
+
+  SUBDIRS(
+    StandAlone
+    scenes
+    )
+
+  # Add the demo root directory to the include path.
+  INCLUDE_DIRECTORIES(
+     ${CMAKE_SOURCE_DIR}/fox/grid_demo
+     )
+  
+ENDIF(BUILD_DYGRID_DEMO)

Added: trunk/fox/grid_demo/Model/Groups/DyGridData.cc
==============================================================================
--- (empty file)
+++ trunk/fox/grid_demo/Model/Groups/DyGridData.cc      Wed Feb 22 01:51:45 
2006
@@ -0,0 +1,73 @@
+/*
+  For more information, please see: http://software.sci.utah.edu
+
+  The MIT License
+
+  Copyright (c) 2006
+  Scientific Computing and Imaging Institute, University of Utah
+
+  License for the specific language governing rights and limitations under
+  Permission is hereby granted, free of charge, to any person obtaining a
+  copy of this software and associated documentation files (the "Software"),
+  to deal in the Software without restriction, including without limitation
+  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+  and/or sell copies of the Software, and to permit persons to whom the
+  Software is furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included
+  in all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+  DEALINGS IN THE SOFTWARE.
+*/
+
+#include <Model/Groups/DyGridData.h>
+
+using namespace Manta;
+using namespace Manta::Dygrid;
+
+DyGridData::DyGridData()
+  : data_owned( true )
+{
+  triangle_array = new TriangleArray();
+  normal_array  = new NormalArray();
+  cell_array    = new CellArray();
+}
+
+DyGridData::~DyGridData() {
+
+  if (data_owned) {
+    delete triangle_array;
+    delete normal_array;
+    delete cell_array;
+  }
+}
+
+DyGridData::DyGridData( const DyGridData *grid ) :
+
+  data_owned( false ),
+  
+  // Copy pointers.
+  triangle_array( grid->triangle_array ),
+  normal_array  ( grid->normal_array ),
+  cell_array    ( grid->cell_array ),
+  // macro_cell_array( grid->macro_cell_array ),
+
+  // Copy dimensions.
+  triangle_bounds( grid->triangle_bounds ),
+  bounds( grid->bounds ),
+  N( grid->N ),
+  M( grid->M ),
+  diagonal( grid->diagonal ),
+  // N_mc( grid->N_mc ),
+  // M_mc( grid->M_mc ),
+  scale( grid->scale ),
+  scaleN( grid->scaleN ),
+  scaleM( grid->scaleM )
+{
+}

Added: trunk/fox/grid_demo/Model/Groups/DyGridData.h
==============================================================================
--- (empty file)
+++ trunk/fox/grid_demo/Model/Groups/DyGridData.h       Wed Feb 22 01:51:45 
2006
@@ -0,0 +1,145 @@
+/*
+  For more information, please see: http://software.sci.utah.edu
+
+  The MIT License
+
+  Copyright (c) 2006
+  Scientific Computing and Imaging Institute, University of Utah
+
+  License for the specific language governing rights and limitations under
+  Permission is hereby granted, free of charge, to any person obtaining a
+  copy of this software and associated documentation files (the "Software"),
+  to deal in the Software without restriction, including without limitation
+  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+  and/or sell copies of the Software, and to permit persons to whom the
+  Software is furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included
+  in all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+  DEALINGS IN THE SOFTWARE.
+*/
+
+#ifndef MANTA_DYGRID_DATA__H
+#define MANTA_DYGRID_DATA__H
+
+#include <Core/Geometry/BBox.h>
+#include <Model/Groups/KDTree.h>
+
+#include <SCIRun/Core/Containers/Array1.h>
+
+
+namespace Manta {
+  namespace Dygrid {
+
+    using SCIRun::Array1;
+
+    // Borrow structures from the Kdtree namespace.
+    typedef Kdtree::Triangle       Triangle;
+    typedef Kdtree::TriangleNormal TriangleNormal;
+    typedef Kdtree::TextureCoord   TextureCoord;
+
+    // Index type, depending on number of triangles and duplication.
+    typedef int index_t;
+
+    
///////////////////////////////////////////////////////////////////////////
+    
///////////////////////////////////////////////////////////////////////////
+    // CELL  CELL  CELL  CELL  CELL  CELL  CELL  CELL  CELL  CELL  CELL  
CELL  
+    
///////////////////////////////////////////////////////////////////////////
+    
///////////////////////////////////////////////////////////////////////////
+    struct Cell {
+      // Offsets into an array of triangle id's.
+      Array1<index_t> index_list;
+    };
+
+    
///////////////////////////////////////////////////////////////////////////
+    
///////////////////////////////////////////////////////////////////////////
+    // MACRO CELL  MACRO CELL  MACRO CELL  MACRO CELL  MACRO CELL  MACRO 
CELL  
+    
///////////////////////////////////////////////////////////////////////////
+    
///////////////////////////////////////////////////////////////////////////   
 
+    struct MacroCell {
+      int not_empty;
+    };
+    
+    
///////////////////////////////////////////////////////////////////////////
+    
///////////////////////////////////////////////////////////////////////////
+    // DY GRID DATA  DY GRID DATA  DY GRID DATA  DY GRID DATA  DY GRID DATA  
DY
+    
///////////////////////////////////////////////////////////////////////////
+    
///////////////////////////////////////////////////////////////////////////
+    
+    // Actual Grid data and dimensions. Contains a pointer to the input
+    // triangle data.
+    class DyGridData {
+    public:
+      
+      typedef Kdtree::KDTreeData::ScratchPadInfo ScratchPadInfo;
+      
+      
/////////////////////////////////////////////////////////////////////////
+      // Input triangle data.
+      typedef Array1<Triangle> TriangleArray;
+      typedef Array1<TriangleNormal> NormalArray;
+      
+      TriangleArray  *triangle_array;
+      NormalArray    *normal_array;
+      
+      
/////////////////////////////////////////////////////////////////////////
+      // The Grid itself.
+
+      // Grid cells, contain pairs of offsets into index array.
+      typedef Array1<Cell> CellArray;
+      
+      CellArray      *cell_array;
+      // Array1<MacroCell>   *macro_cell_array;
+
+      // Bounding box for the triangles.
+      BBox triangle_bounds;
+      
+      // Bounding box for the grid, (slightly larger).
+      BBox bounds;
+      
+      // Grid size (in cells).
+      VectorT<index_t,3> N;
+      VectorT<index_t,3> M;
+
+      // Grid size in world units.
+      Vector         diagonal;
+
+      // Macro cell grid size.
+      // VectorT<int,3> N_mc;
+      // VectorT<int,3> M_mc;
+
+      // Grid scale.
+      Vector scale;  // 1.0 / diagonal  ==> 1.0 / (units)
+      Vector scaleN; // N / diagonal    ==> cells per unit.
+      Vector scaleM; //
+
+      Vector cellsize;
+      
+      // Constructors
+      DyGridData();
+      DyGridData( const DyGridData * );
+      virtual ~DyGridData();
+
+      // Accessors.
+      inline index_t get_index( const int x, const int y, const int z ) 
const {
+        return x+N[0]*(y+N[1]*z);
+      }
+
+    private:
+      bool data_owned;
+      
+      DyGridData( const DyGridData & );
+      DyGridData &operator= ( const DyGridData & );
+    };
+        
+  };
+};
+
+#endif
+

Added: trunk/fox/grid_demo/Model/Groups/DyGridLoader.cc
==============================================================================
--- (empty file)
+++ trunk/fox/grid_demo/Model/Groups/DyGridLoader.cc    Wed Feb 22 01:51:45 
2006
@@ -0,0 +1,107 @@
+/*
+  For more information, please see: http://software.sci.utah.edu
+
+  The MIT License
+
+  Copyright (c) 2006
+  Scientific Computing and Imaging Institute, University of Utah
+
+  License for the specific language governing rights and limitations under
+  Permission is hereby granted, free of charge, to any person obtaining a
+  copy of this software and associated documentation files (the "Software"),
+  to deal in the Software without restriction, including without limitation
+  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+  and/or sell copies of the Software, and to permit persons to whom the
+  Software is furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included
+  in all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+  DEALINGS IN THE SOFTWARE.
+*/
+
+#include <Model/Groups/DyGridLoader.h>
+
+#include <Core/Geometry/BBox.h>
+#include <Model/Groups/DyGridData.h>
+#include <Model/Readers/V3C1.h>
+
+#include <iostream>
+
+using namespace Manta;
+using namespace Dygrid;
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+// LOAD  LOAD  LOAD  LOAD  LOAD  LOAD  LOAD  LOAD  LOAD  LOAD  LOAD  LOAD  
LOAD
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+extern "C"
+void Manta::Dygrid::load( DyGridData *data, const string v3c1_file ) {
+
+  // Create a buffer to load the raw v3c1 triangles into.
+  Array1<V3C1Triangle> raw_triangles;
+  
+  // Attempt to load the v3c1 file containing triangles.
+  v3c1_load_triangles( raw_triangles, v3c1_file );
+
+  // Attempt to load the v3c1 file containing normals.
+  bool vertex_normals = true;
+  try {
+    v3c1_load_normals( *(data->normal_array), v3c1_file );
+  }
+  catch (...) {
+    std::cerr << "Could not load normal file. Using face normals.\n";
+    vertex_normals = false;
+
+    // Resize the normal buffer.
+    data->normal_array->resize( raw_triangles.size() );
+  }
+
+  
/////////////////////////////////////////////////////////////////////////////
+  // Copy the v3c1 triangles into grid triangles.
+
+  // Allocate storage for grid triangles.
+  data->triangle_array->resize( raw_triangles.size() );
+  
+  for (int i=0;i<raw_triangles.size();++i) {
+
+    // Extend the triangle bounding box.
+    for (int j=0;j<3;++j) {
+      data->triangle_bounds.extendByPoint( raw_triangles[i].vertex[j] );
+    }
+
+    Triangle &triangle = (*data->triangle_array)[i];
+
+    // Copy vertex 0.
+    triangle.v = raw_triangles[i].vertex[0];
+    
+    // Compute edges.
+    triangle.edge1 = raw_triangles[i].vertex[1] - raw_triangles[i].vertex[0];
+    triangle.edge1 = raw_triangles[i].vertex[2] - raw_triangles[i].vertex[0];
+
+    // Compute face normal if necessary.
+    TriangleNormal &normals = (*data->normal_array)[i];
+    if (vertex_normals) {
+    }
+    else {
+      // Copy out a face normal.
+      Vector face_normal = Cross( triangle.edge1, triangle.edge2 );
+      for (int j=0;j<3;++j) {
+        normals[j] = face_normal;
+      }
+    }
+    
+    // Copy color.
+    triangle.payload = raw_triangles[i].color;
+  }
+  
+}
+
+

Added: trunk/fox/grid_demo/Model/Groups/DyGridLoader.h
==============================================================================
--- (empty file)
+++ trunk/fox/grid_demo/Model/Groups/DyGridLoader.h     Wed Feb 22 01:51:45 
2006
@@ -0,0 +1,51 @@
+/*
+  For more information, please see: http://software.sci.utah.edu
+
+  The MIT License
+
+  Copyright (c) 2006
+  Scientific Computing and Imaging Institute, University of Utah
+
+  License for the specific language governing rights and limitations under
+  Permission is hereby granted, free of charge, to any person obtaining a
+  copy of this software and associated documentation files (the "Software"),
+  to deal in the Software without restriction, including without limitation
+  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+  and/or sell copies of the Software, and to permit persons to whom the
+  Software is furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included
+  in all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+  DEALINGS IN THE SOFTWARE.
+*/
+
+#ifndef MANTA_DYGRID_LOADER__H
+#define MANTA_DYGRID_LOADER__H
+
+#include <string>
+
+namespace Manta {
+  namespace Dygrid {
+
+    class DyGridData;
+
+    // Load triangle data into a DyGridData object. The pointer to this 
triangle
+    // data may be shared with other DyGridData instances who may have other 
actual grids.
+    extern "C"
+    void load( DyGridData *data, const std::string v3c1_file );
+
+    // Store the triangles, grid, or both to .v3c1* files.
+    // enum { StoreTriangles = 0x1, StoreGrid = 0x2 };
+    // void store( DyGridData *data, const string v3c1_file, int which );
+  };
+};
+
+#endif
+

Added: trunk/fox/grid_demo/Model/Groups/DyGridParallelBuilder.cc
==============================================================================
--- (empty file)
+++ trunk/fox/grid_demo/Model/Groups/DyGridParallelBuilder.cc   Wed Feb 22 
01:51:45 2006
@@ -0,0 +1,225 @@
+/*
+  For more information, please see: http://software.sci.utah.edu
+
+  The MIT License
+
+  Copyright (c) 2006
+  Scientific Computing and Imaging Institute, University of Utah
+  
+  License for the specific language governing rights and limitations under
+  Permission is hereby granted, free of charge, to any person obtaining a
+  copy of this software and associated documentation files (the "Software"),
+  to deal in the Software without restriction, including without limitation
+  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+  and/or sell copies of the Software, and to permit persons to whom the
+  Software is furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included
+  in all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+  DEALINGS IN THE SOFTWARE.
+*/
+
+#include <Model/Groups/DyGridParallelBuilder.h>
+
+#include <Model/Groups/DyGridData.h>
+
+
+#include <SCIRun/Core/Thread/Barrier.h>
+
+using namespace Manta;
+using namespace Manta::Dygrid;
+
+using namespace SCIRun;
+
+// Single thread setup callback.
+void DyGridParallelBuilder::setupGridOneShot( int proc, int numProcs ) {
+
+  // This callback should only be invoked by one thread.
+  assert(proc == 0);
+  
+  
/////////////////////////////////////////////////////////////////////////////
+  // Compute the bounds of all triangles.
+  grid->bounds = grid->triangle_bounds;
+
+  // Add some space around the bounds.
+  const static Vector offset( 0.0001, 0.0001, 0.0001 );
+  grid->bounds[0] -= offset;
+  grid->bounds[1] += offset;
+
+  
/////////////////////////////////////////////////////////////////////////////
+  // Compute size of the grid.
+  grid->diagonal = grid->bounds.diagonal();
+  index_t total_triangles = grid->triangle_array->size();
+
+  grid->N[0] = (int)(powf(resolution_factor * total_triangles *
+                          grid->diagonal[0] * grid->diagonal[0] /
+                          (grid->diagonal[1] * grid->diagonal[2]), 1/3.));
+  grid->N[1] = (int)(powf(resolution_factor *
+                          total_triangles * grid->diagonal[1] * 
grid->diagonal[1] /
+                          (grid->diagonal[0] * grid->diagonal[2]), 1/3.));
+  grid->N[2] = (int)(powf(resolution_factor *
+                          total_triangles * grid->diagonal[2] * 
grid->diagonal[2]
+                          / (grid->diagonal[1] * grid->diagonal[0]), 1/3.));
+
+  // Compute N and M
+  grid->N[0] = SCIRun::Max(grid->N[0],3);
+  grid->N[1] = SCIRun::Max(grid->N[1],3);
+  grid->N[2] = SCIRun::Max(grid->N[2],3);
+  
+  grid->M[0] = grid->N[0]-1;
+  grid->M[1] = grid->N[1]-1;
+  grid->M[2] = grid->N[2]-1;
+
+  // Compute grid scales.
+  grid->scale  = grid->diagonal.inverse();
+  
+  grid->scaleN = grid->scale * Vector( grid->N );
+  grid->scaleM = grid->scale * Vector( grid->M );
+
+  grid->cellsize = grid->diagonal / Vector( grid->N );
+  
+  
/////////////////////////////////////////////////////////////////////////////
+  // Determine size of macro cell grid.
+#if 0  
+  #pragma unroll(3)
+  for (int i=0;i<3;++i) {
+    grid->N_mc[i] = ((grid->N[i]-1) / MACRO_CELLS + 1);
+    grid->M_mc[i] = grid->N_mc[i] - 1;
+    grid->N[i]    = grid->N_mc[i] * MACRO_CELLS;
+    grid->M[i]    = grid->N[i] - 1;
+  }
+#endif
+  
+  index_t total_cells       = grid->N[0] * grid->N[1] * grid->N[2];
+  // index_t total_macro_cells = grid->N_mc[0] * grid->N_mc[1] * 
grid->N_mc[2];
+  
+  
/////////////////////////////////////////////////////////////////////////////
+  // Resize the grid if necessary.
+  if (grid->cell_array->size() < total_cells) {
+    grid->cell_array->resize( total_cells );
+  }
+
+  // if (grid->macro_cell_array.size() < total_macro_cells) {
+  //   grid->macro_cell_array.resize( total_macro_cells );
+  // }
+  
+  
/////////////////////////////////////////////////////////////////////////////
+  // Clear the grid.
+  for (int i=0;i<total_cells;++i) {
+    (*grid->cell_array)[i].index_list.remove_all();
+  }
+
+  // for (int i=0;i<total_macro_cells;++i) {
+  //   grid->macro_cell_array[i] = { 0 };
+  // }
+
+  
/////////////////////////////////////////////////////////////////////////////
+  // Request per thread storage.
+}
+
+// Parallel build callback.
+void DyGridParallelBuilder::buildGridOneShot( int proc, int numProcs ) {
+
+  // Obtain a pointer to the per-thread-grid cells for this thread.
+  Array1<Cell> *thread_cells = 0;
+
+  // THE ABOVE LINE CAUSES THE BUILD TO BREAK.
+  
+  
/////////////////////////////////////////////////////////////////////////////
+  // Determine which portion of the triangles to add to this thread's grid.
+  const index_t total_triangles = grid->triangle_array->size();
+  const index_t begin = (total_triangles*proc)/numProcs;
+  const index_t end   = (total_triangles*(proc+1))/numProcs;
+
+  for (int tri=begin;tri<end;++tri) {
+
+    
///////////////////////////////////////////////////////////////////////////
+    // Find the bounds of the triangle.
+    BBox tri_bounds;
+    (*grid->triangle_array)[tri].computeBounds( tri_bounds );
+
+    // Translate the triangle into grid coordinates.
+    tri_bounds[0] = grid->scaleN * (tri_bounds[0] - grid->bounds[0] );
+    tri_bounds[1] = grid->scaleN * (tri_bounds[1] - grid->bounds[0] );
+
+    // Find integer coordinates for the grid bounds.
+    const index_t x0 = (index_t)tri_bounds[0][0];
+    const index_t y0 = (index_t)tri_bounds[0][1];
+    const index_t z0 = (index_t)tri_bounds[0][2];
+
+    const index_t x1 = (index_t)tri_bounds[1][0];
+    const index_t y1 = (index_t)tri_bounds[1][1];
+    const index_t z1 = (index_t)tri_bounds[1][2];
+
+    
///////////////////////////////////////////////////////////////////////////
+    // Add the triangle to the grid.
+    for (int z=z0;z<=z1;++z) {
+      for (int y=y0;y<=y1;++y) {
+        for (int x=x0;x<=x1;++x) {
+
+          // TODO: Avoid using this computation.
+          const int c = grid->get_index( x, y, z );
+
+          // Add the triangle to the cell.
+          (*thread_cells)[c].index_list.add( tri );
+        }
+      }
+    }
+  }
+
+  
/////////////////////////////////////////////////////////////////////////////
+  // Parallel Build Barrier.
+  build_barrier.wait( numProcs );
+
+  
/////////////////////////////////////////////////////////////////////////////
+  // Merge Stage
+  const int startZ = (grid->N[2] * proc)/numProcs;
+  const int endZ   = (grid->N[2] * proc)/numProcs;
+
+  for (int z=startZ; z<endZ; ++z) {
+    for (int y=0;y<grid->N[1];++y) {
+      for (int x=0;x<grid->N[0];++x) {
+
+        const int c = grid->get_index( x, y, z );
+        int new_size = 0;
+
+        // Sum all of the triangles in each thread's grid.
+        for (int i=0;i<builder_cells.size();++i) {
+          new_size += (*builder_cells[i])[c].index_list.size();
+        }
+
+        // Resize the destination cell if necessary.
+        if (new_size > 0) {
+          (*grid->cell_array)[c].index_list.resize( new_size );
+
+          // Copy all of the triangle id's into the destination
+          // index list.
+          
+          // TODO: Have the destination cell array be used by proc 0 and
+          // avoid copying the triangles in it's array.
+          
+          for (int i=0;i<builder_cells.size();++i) {
+            for (int j=0;j<(*builder_cells[i])[c].index_list.size();++j) {
+              (*grid->cell_array)[c].index_list[j] = 
(*builder_cells[i])[c].index_list[j];
+            }
+          }
+        }
+      }
+    }
+  }
+
+  // Wait for all  threads to finish.
+  build_barrier.wait( numProcs );
+  
+  
/////////////////////////////////////////////////////////////////////////////
+  // Construct Macro Cell Grid.
+  // ??
+}
+

Added: trunk/fox/grid_demo/Model/Groups/DyGridParallelBuilder.h
==============================================================================
--- (empty file)
+++ trunk/fox/grid_demo/Model/Groups/DyGridParallelBuilder.h    Wed Feb 22 
01:51:45 2006
@@ -0,0 +1,90 @@
+/*
+  For more information, please see: http://software.sci.utah.edu
+
+  The MIT License
+
+  Copyright (c) 2006
+  Scientific Computing and Imaging Institute, University of Utah
+
+  License for the specific language governing rights and limitations under
+  Permission is hereby granted, free of charge, to any person obtaining a
+  copy of this software and associated documentation files (the "Software"),
+  to deal in the Software without restriction, including without limitation
+  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+  and/or sell copies of the Software, and to permit persons to whom the
+  Software is furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included
+  in all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+  DEALINGS IN THE SOFTWARE.
+*/
+
+#ifndef MANTA_DYGRID_PARALLEL_BUILDER__H
+#define MANTA_DYGRID_PARALLEL_BUILDER__H
+
+#include <Model/Groups/DyGridData.h>
+
+#include <SCIRun/Core/Util/Assert.h>
+#include <SCIRun/Core/Containers/Array1.h>
+#include <SCIRun/Core/Thread/Barrier.h>
+
+
+namespace Manta {
+  namespace Dygrid {
+
+    using SCIRun::Array1;
+    
+    
///////////////////////////////////////////////////////////////////////////
+    
///////////////////////////////////////////////////////////////////////////
+    // DY GRID PARALLEL BUILDER  DY GRID PARALLEL BUILDER  DY GRID PARALLEL 
BUI
+    
///////////////////////////////////////////////////////////////////////////
+    
///////////////////////////////////////////////////////////////////////////
+    class DyGridParallelBuilder {
+    public:
+      // Constructor.
+      DyGridParallelBuilder( DyGridData *target_grid_,
+                             Real resolution_factor_ ) :
+        grid( target_grid_ ),
+        resolution_factor( resolution_factor_ ),
+        build_barrier( "build_barrier" )
+      { };
+
+      
/////////////////////////////////////////////////////////////////////////
+      // One Shot callbacks for rebuilding.
+
+      // Single thread setup callback.
+      void setupGridOneShot( int proc, int numProcs );
+
+      // Parallel build callback.
+      void buildGridOneShot( int proc, int numProcs );
+
+    private:
+
+      // Build parameters.
+      Real resolution_factor;
+
+      // Build barrier.
+      SCIRun::Barrier build_barrier;
+      
+      // Target grid for this builder.
+      DyGridData *grid;
+
+      // Array of pointers to cell arrays, allocated by each builder thread.
+      Array1< Array1<Cell> * > builder_cells;
+
+      DyGridParallelBuilder( const DyGridParallelBuilder & );
+      DyGridParallelBuilder &operator= ( const DyGridParallelBuilder & );
+    };
+    
+  };
+};
+
+#endif
+

Added: trunk/fox/grid_demo/Model/Groups/DyGridSSE.cc
==============================================================================

Added: trunk/fox/grid_demo/Model/Groups/DyGridSSE.h
==============================================================================
--- (empty file)
+++ trunk/fox/grid_demo/Model/Groups/DyGridSSE.h        Wed Feb 22 01:51:45 
2006
@@ -0,0 +1,40 @@
+/*
+  For more information, please see: http://software.sci.utah.edu
+
+  The MIT License
+
+  Copyright (c) 2006
+  Scientific Computing and Imaging Institute, University of Utah
+
+  License for the specific language governing rights and limitations under
+  Permission is hereby granted, free of charge, to any person obtaining a
+  copy of this software and associated documentation files (the "Software"),
+  to deal in the Software without restriction, including without limitation
+  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+  and/or sell copies of the Software, and to permit persons to whom the
+  Software is furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included
+  in all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+  DEALINGS IN THE SOFTWARE.
+*/
+
+#ifndef MANTA_DYGRID_SSE__H
+#define MANTA_DYGRID_SSE__H
+
+namespace Manta {
+  namespace Dygrid {
+
+    
+  };
+};
+
+#endif
+

Added: trunk/fox/grid_demo/Model/Groups/DyGridSerialBuilder.h
==============================================================================
--- (empty file)
+++ trunk/fox/grid_demo/Model/Groups/DyGridSerialBuilder.h      Wed Feb 22 
01:51:45 2006
@@ -0,0 +1,40 @@
+/*
+  For more information, please see: http://software.sci.utah.edu
+
+  The MIT License
+
+  Copyright (c) 2006
+  Scientific Computing and Imaging Institute, University of Utah
+
+  License for the specific language governing rights and limitations under
+  Permission is hereby granted, free of charge, to any person obtaining a
+  copy of this software and associated documentation files (the "Software"),
+  to deal in the Software without restriction, including without limitation
+  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+  and/or sell copies of the Software, and to permit persons to whom the
+  Software is furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included
+  in all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+  DEALINGS IN THE SOFTWARE.
+*/
+
+#ifndef MANTA_DYGRID_SERIAL_BUILDER__H
+#define MANTA_DYGRID_SERIAL_BUILDER__H
+
+namespace Manta {
+  namespace Dygrid {
+
+    // Serial build of a dynamic grid.
+  };
+};
+
+#endif
+

Added: trunk/fox/grid_demo/Model/Groups/DyGridSingle.cc
==============================================================================
--- (empty file)
+++ trunk/fox/grid_demo/Model/Groups/DyGridSingle.cc    Wed Feb 22 01:51:45 
2006
@@ -0,0 +1,262 @@
+/*
+  For more information, please see: http://software.sci.utah.edu
+
+  The MIT License
+
+  Copyright (c) 2006
+  Scientific Computing and Imaging Institute, University of Utah
+
+  License for the specific language governing rights and limitations under
+  Permission is hereby granted, free of charge, to any person obtaining a
+  copy of this software and associated documentation files (the "Software"),
+  to deal in the Software without restriction, including without limitation
+  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+  and/or sell copies of the Software, and to permit persons to whom the
+  Software is furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included
+  in all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+  DEALINGS IN THE SOFTWARE.
+*/
+
+
+#include <Model/Groups/DyGridSingle.h>
+
+#include <Model/Intersections/AxisAlignedBox.h>
+#include <Model/Intersections/TriangleEdge.h>
+
+using namespace Manta;
+using namespace Manta::Dygrid;
+
+DyGridSingle::DyGridSingle( DyGridData *grid_, Material *material_ ) :
+  PrimitiveCommon( material_ ),
+  DyGridData( grid_ )
+{
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+// INTERSECT  INTERSECT  INTERSECT  INTERSECT  INTERSECT  INTERSECT  
INTERSECT 
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void DyGridSingle::intersect(const RenderContext& context, RayPacket& rays) 
const {
+
+  rays.computeInverseDirections();
+
+  // Intersect rays individually.
+  for (int i=rays.begin();i<rays.end();++i) {
+    intersect_ray( context, rays, i );
+  }
+  
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+// INTERSECT RAY  INTERSECT RAY  INTERSECT RAY  INTERSECT RAY  INTERSECT RAY 
 I
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void DyGridSingle::intersect_ray( const RenderContext& context, RayPacket& 
rays,
+                                  const int which ) const {
+  
+  Real t_near, t_far, t_exit, t0, t1;
+
+  Vector dt;   // Delta in t.
+  Vector di;   // Delta in index.
+  Vector stop; // Stopping index.
+  Vector P;    // World space point.
+  Vector L;    // Lattice space point.
+  Vector far_;
+
+  Vector t_next;
+
+  
/////////////////////////////////////////////////////////////////////////////
+  // Determine the starting place for the traversal.
+  P = rays.getOrigin( which );
+
+  Vector inv_direction = rays.getInverseDirection( which );
+  
+  // Check to see if the ray intersects the grid's bounds.
+  if (!Intersection::intersectAaBox( bounds,
+                                     t_near, t_far,
+                                     rays.getRay( which ),
+                                     rays.getSigns( which ),
+                                     inv_direction,
+                                     T_EPSILON,
+                                     rays.getMinT( which ))) {
+    return;
+  }
+
+  // Determine the actual minimum distance.
+  // t_near = SCIRun::Max( t_near, T_EPSILON );
+  // t_far  = SCIRun::Min( t_far, rays.getMinT(i) );
+  
+  // Check to see if a hit is possible.
+  if (t_near > t_far)
+    return;
+
+  // Advance P to t_near.
+  P += (rays.getDirection( which ) * t_near);
+
+  // Compute the integer lattice coordinates of P.
+  L = (P - bounds[0]) * scaleN;
+  L = VectorT<int,3>( L );
+
+  // Snap the lattice coordinates to [0,n)
+  for (int i=0;i<3;++i) {
+    L[i] = SCIRun::Max( (Real)0, SCIRun::Min( L[i], (Real)N[i]-1 ) );
+  }
+  
+  // Determine how the ray marches with the index.
+  // Compute the iteration direction and stoping condition.
+  for (int i=0;i<3;++i) {
+    if ((diagonal[i]*rays.getDirection(which,i)) > 0) {
+      di[i] = 1;
+      stop[i] = N[i];
+    }
+    else
+      di[i] = stop[i] = -1;
+  }
+
+  // Determine how t changes with ray marching (dtdx, dtdy, dtdz..)
+  dt = cellsize * inv_direction;
+
+  // Determine the far edge of the cell.
+  for (int i=0;i<3;++i) {
+               if (di[i] == 1) 
+                       far_[i] = (L[i]+1)*cellsize[i]+bounds[0][i]; 
+               else 
+                       far_[i] = L[i]*cellsize[i]+bounds[0][i];
+  }
+
+  // Determine the t value of the the other side of the cell.
+  t_next = (far_-rays.getOrigin(which)) * inv_direction;
+
+  
/////////////////////////////////////////////////////////////////////////////
+  // Beginning of Traversal Loop
+  while (true) {
+
+    // Compute width of the cell in t. 
+    t_exit = SCIRun::Min( t_next[0], SCIRun::Min( t_next[1], t_next[2] ) );
+
+    // Compute grid cell index.
+    index_t cell_index = get_index( L[0], L[1], L[2] );
+
+    // Intersect ray with triangles in the cell.
+    intersect_triangles( cell_index, rays, which );
+
+    
///////////////////////////////////////////////////////////////////////////
+    // Move to the next cell.
+    if (t_exit == t_next[0]) {
+      t_near = t_exit;
+      t_next[0] += dt[0];
+      L[0] += di[0];
+    }
+    else if (t_exit == t_next[1]) {
+      t_near = t_exit;
+      t_next[1] += dt[1];
+      L[1] += di[1];
+    }
+    else {
+      t_near = t_exit;
+      t_next[2] += dt[2];
+      L[2] += di[2];
+    }
+
+    
///////////////////////////////////////////////////////////////////////////
+    // Termination conditions.
+    
+    if (rays.getMinT( which ) < t_near) {
+      break;
+    }
+    
+    // Check for a stop condition.
+    if ((L[0] == stop[0]) || (L[1] == stop[1]) || (L[2] == stop[2])) {
+      break;
+    }
+    
+  }
+  
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+// INTERSECT TRIANGLES  INTERSECT TRIANGLES  INTERSECT TRIANGLES  INTERSECT 
TRI
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void DyGridSingle::intersect_triangles( index_t cell_index, RayPacket& rays,
+                                        const int which ) const {
+
+  // Obtain the ray origin and direction.
+  const Vector origin    = rays.getOrigin( which );
+  const Vector direction = rays.getDirection( which );
+
+  for (int i=0;i<(*cell_array)[cell_index].index_list.size();++i) {
+
+    // Obtain the triangle index.
+    const index_t tri_index = (*cell_array)[cell_index].index_list[i];
+    const Triangle &tri = (*triangle_array)[tri_index];
+    
+    float t, a, b;
+    if(Intersection::intersect_triangle3_edge( origin.getDataPtr(), 
direction.getDataPtr(),
+                                               tri.v.getDataPtr(),
+                                               &t, &a, &b,
+                                               tri.edge1.getDataPtr(),
+                                               tri.edge2.getDataPtr() )) {
+
+      // Check the hit against the ray hit record.
+      if (rays.hit( which, t, getMaterial(), this, 0 )) {
+
+        // Record the coordinates of the hit and triangle index.
+        ScratchPadInfo& scratch_pad = rays.scratchpad<ScratchPadInfo>(which);
+        scratch_pad.a = a;
+        scratch_pad.b = b;
+        scratch_pad.hit_index = tri_index;
+      }
+    }
+  }
+
+  
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+// COMPUTE NORMAL  COMPUTE NORMAL  COMPUTE NORMAL  COMPUTE NORMAL  COMPUTE 
NORM
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void DyGridSingle::computeNormal(const RenderContext& , RayPacket& rays) 
const {
+
+  typedef VectorT<float,3> Vectorf;
+  
+  for (int i=rays.begin();i<rays.end();++i) {
+
+    // Obtain the scratch pad.
+    const ScratchPadInfo& scratch_pad = rays.scratchpad<ScratchPadInfo>(i);
+    
+    const unsigned int hit_index = scratch_pad.hit_index;
+    
+    const Vectorf &n0 = (*normal_array)[hit_index][0];
+    const Vectorf &n1 = (*normal_array)[hit_index][1];
+    const Vectorf &n2 = (*normal_array)[hit_index][2];
+
+    // Interpolate the normal.
+    const float u = scratch_pad.a;
+    const float v = scratch_pad.b;
+    const Vector normal = (n1 * u) + (n2 * v) + (n0 * (1 - u - v));
+
+    // Set the normal.
+    rays.setNormal(i, normal);
+  }  
+}
+
+void DyGridSingle::computeBounds(const PreprocessContext&, BBox &box_ ) 
const {
+
+  // Extend by the grid bounds.
+  box_.extendByBox( bounds );
+}

Added: trunk/fox/grid_demo/Model/Groups/DyGridSingle.h
==============================================================================
--- (empty file)
+++ trunk/fox/grid_demo/Model/Groups/DyGridSingle.h     Wed Feb 22 01:51:45 
2006
@@ -0,0 +1,71 @@
+/*
+  For more information, please see: http://software.sci.utah.edu
+
+  The MIT License
+
+  Copyright (c) 2006
+  Scientific Computing and Imaging Institute, University of Utah
+
+  License for the specific language governing rights and limitations under
+  Permission is hereby granted, free of charge, to any person obtaining a
+  copy of this software and associated documentation files (the "Software"),
+  to deal in the Software without restriction, including without limitation
+  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+  and/or sell copies of the Software, and to permit persons to whom the
+  Software is furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included
+  in all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+  DEALINGS IN THE SOFTWARE.
+*/
+
+#ifndef MANTA_DYGRID_SINGLE__H
+#define MANTA_DYGRID_SINGLE__H
+
+#include <Model/Primitives/PrimitiveCommon.h>
+#include <Model/Groups/DyGridData.h>
+
+
+namespace Manta {
+
+  class Material;
+  class RenderContext;
+  class PreprocessContext;
+  class RayPacket;
+
+  namespace Dygrid {
+
+    
///////////////////////////////////////////////////////////////////////////
+    // Single ray traversal with a dynamically built grid.
+    class DyGridSingle : public PrimitiveCommon, public DyGridData {
+    public:
+      typedef DyGridData::ScratchPadInfo ScratchPadInfo;
+
+      
/////////////////////////////////////////////////////////////////////////
+      // Constructor.
+      DyGridSingle( DyGridData *grid_, Material *material_ );      
+      virtual ~DyGridSingle() { }
+
+      
/////////////////////////////////////////////////////////////////////////
+      // Primitive Interface.
+      virtual void intersect(const RenderContext& context, RayPacket& rays) 
const;
+      virtual void computeNormal (const RenderContext& context, RayPacket& 
rays) const;
+      virtual void computeBounds (const PreprocessContext&, BBox &box_ ) 
const;
+
+    private:
+      void intersect_ray( const RenderContext& context, RayPacket& rays, 
const int which ) const;
+      void intersect_triangles( index_t cell_index, RayPacket& rays, const 
int which ) const;
+    };
+    
+  };
+};
+
+#endif
+

Added: trunk/fox/grid_demo/scenes/CMakeLists.txt
==============================================================================
--- (empty file)
+++ trunk/fox/grid_demo/scenes/CMakeLists.txt   Wed Feb 22 01:51:45 2006
@@ -0,0 +1,19 @@
+
+############################################################
+# Initial test scenes.
+
+SET(MANTA_SCENE_LINK 
+  grid_shared
+  ${MANTA_TARGET_LINK_LIBRARIES}
+  ${CMAKE_THREAD_LIBS_INIT}
+  ${OPENGL_LIBRARIES} 
+  ${X11_LIBRARIES} 
+  -lm
+  )
+
+SET(SCENE_DYGRID 0 CACHE BOOL "Dynamic Grid.")
+IF(SCENE_DYGRID)
+   ADD_LIBRARY(scene_dygrid dygrid.cc)
+   TARGET_LINK_LIBRARIES(scene_dygrid ${MANTA_SCENE_LINK})
+ENDIF(SCENE_DYGRID)
+

Added: trunk/fox/grid_demo/scenes/dygrid.cc
==============================================================================
--- (empty file)
+++ trunk/fox/grid_demo/scenes/dygrid.cc        Wed Feb 22 01:51:45 2006
@@ -0,0 +1,139 @@
+/*
+ For more information, please see: http://software.sci.utah.edu

+ The MIT License

+ Copyright (c) 2006
+ Scientific Computing and Imaging Institute, University of Utah
+
+ License for the specific language governing rights and limitations under
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:

+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.

+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+ */
+
+#include <Interface/Scene.h>
+#include <Interface/Context.h>
+
+#include <Model/Groups/DyGridData.h>
+#include <Model/Groups/DyGridParallelBuilder.h>
+#include <Model/Groups/DyGridSingle.h>
+#include <Model/Groups/DyGridLoader.h>
+
+#include <string>
+#include <vector>
+
+#include <Core/Geometry/Vector.h>
+#include <Core/Exceptions/IllegalArgument.h>
+#include <Core/Util/Args.h>
+#include <Interface/Context.h>
+#include <Interface/LightSet.h>
+#include <Interface/MantaInterface.h>
+#include <Interface/Scene.h>
+#include <Interface/Primitive.h>
+#include <Model/AmbientLights/ArcAmbient.h>
+#include <Model/Backgrounds/ConstantBackground.h>
+#include <Model/Backgrounds/TextureBackground.h>
+#include <Model/Groups/Group.h>
+#include <Model/Lights/PointLight.h>
+#include <Model/Lights/HeadLight.h>
+#include <Model/Materials/Lambertian.h>
+#include <Model/Materials/MetalMaterial.h>
+#include <Model/Materials/Phong.h>
+#include <Model/Primitives/Parallelogram.h>
+#include <Model/Primitives/Sphere.h>
+#include <Model/Textures/CheckerTexture.h>
+#include <Model/Textures/MarbleTexture.h>
+#include <Model/Textures/NormalTexture.h>
+#include <Model/Textures/TexCoordTexture.h>
+#include <Model/Cameras/PinholeCamera.h>
+#include <Core/Geometry/AffineTransform.h>
+#include <Core/Util/NotFinished.h>
+#include <Model/AmbientLights/ConstantAmbient.h>
+#include <Model/MiscObjects/CuttingPlane.h>
+
+#include <Model/Materials/AmbientOcclusion.h>
+#include <Model/Materials/Flat.h>
+#include <Model/Materials/Transparent.h>
+#include <Model/Textures/Constant.h>
+
+
+#include <SCIRun/Core/Thread/Time.h>
+
+using namespace std;
+using namespace Manta;
+using namespace Manta::Dygrid;
+
+extern "C" 
+Scene* make_scene(const ReadContext& context, const vector<string>& args) {
+
+  // Args.
+  string file_name;
+  float scene_ambient[] = { 0.2, 0.2, 0.2 };
+  float resolution_factor = 1.0;
+
+  // Parse arguments.
+  for (int i=0;i<args.size();++i) {
+    if (args[i] == "-file") {
+      if (!getStringArg(i, args, file_name))
+                               throw IllegalArgument("-file <filename>", i, 
args);
+    }
+    if (args[i] == "-factor") {
+      if (!getArg(i, args, resolution_factor))
+                               throw IllegalArgument("-factor <n>", i, args);
+    }    
+  }
+
+  Scene *scene = new Scene();
+
+  
/////////////////////////////////////////////////////////////////////////////
+       // Add a head light.
+       LightSet *lights = new LightSet();
+       
+       lights->add( new HeadLight( 2.0, Color(RGB(1.0,1.0,1.0)) ));
+       lights->setAmbientLight( new 
ConstantAmbient(Color(RGB(scene_ambient[0],
+                                                         scene_ambient[1],
+                                                         
scene_ambient[2]))));
+       scene->setLights(lights);
+
+  // Set background.
+  scene->setBackground( new ConstantBackground( Color(RGB(0.8, 0.8, 0.8)) ) 
);
+  
+  
/////////////////////////////////////////////////////////////////////////////
+  // Load the input triangles and normals.
+  DyGridData *grid_data = new DyGridData();
+  Dygrid::load( grid_data, file_name.c_str() );
+
+  // Create a single ray traversal grid.
+  DyGridSingle *grid = new DyGridSingle( grid_data, new Flat( new 
NormalTexture ) );
+  scene->setObject( grid );
+
+  // Create a loose parallel builder.
+  DyGridParallelBuilder *builder = new DyGridParallelBuilder( grid, 
resolution_factor );
+  
+  
/////////////////////////////////////////////////////////////////////////////
+  // Add one shot callbacks for grid building.
+  context.manta_interface->addOneShotCallback( MantaInterface::Absolute, 0,
+                                               Callback::create( builder,
+                                                                 
DyGridParallelBuilder::setupGridOneShot ) );
+  context.manta_interface->addParallelOneShotCallback( 
MantaInterface::Absolute, 0,
+                                                       Callback::create( 
builder,
+                                                                         
DyGridParallelBuilder::buildGridOneShot ) );
+  
+  
+  return scene;
+}




  • [MANTA] r952 - in trunk/fox/grid_demo: . Model Model/Groups scenes, abe, 02/22/2006

Archive powered by MHonArc 2.6.16.

Top of page