Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r814 - in branches/vertical: Interface Model/Intersections Model/Primitives


Chronological Thread 
  • From: sparker@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r814 - in branches/vertical: Interface Model/Intersections Model/Primitives
  • Date: Wed, 4 Jan 2006 11:26:46 -0700 (MST)

Author: sparker
Date: Wed Jan  4 11:26:44 2006
New Revision: 814

Modified:
   branches/vertical/Interface/Parameters.h
   branches/vertical/Interface/RayPacket.h
   branches/vertical/Model/Intersections/AxisAlignedBox.h
   branches/vertical/Model/Primitives/BvhTriangleMesh.cc
   branches/vertical/Model/Primitives/CMakeLists.txt
   branches/vertical/Model/Primitives/Cube.cc
   branches/vertical/Model/Primitives/Cube.h
   branches/vertical/Model/Primitives/Disk.cc
   branches/vertical/Model/Primitives/HeavyTriangle.cc
   branches/vertical/Model/Primitives/Hemisphere.cc
   branches/vertical/Model/Primitives/Hemisphere.h
   branches/vertical/Model/Primitives/ParticleBVH.cc
   branches/vertical/Model/Primitives/Ring.cc
   branches/vertical/Model/Primitives/SuperEllipsoid.cc
   branches/vertical/Model/Primitives/TexTriangle.cc
   branches/vertical/Model/Primitives/Triangle.cc
Log:
More progress toward vertical raypackets


Modified: branches/vertical/Interface/Parameters.h
==============================================================================
--- branches/vertical/Interface/Parameters.h    (original)
+++ branches/vertical/Interface/Parameters.h    Wed Jan  4 11:26:44 2006
@@ -3,8 +3,9 @@
 #define Manta_Interface_Parameters_h
 
 #define MAXCACHELINESIZE 128
-#define T_EPSILON 1.e-3
-#define MAXT 1.e19
+#define T_EPSILON ((Real)1.e-3)
+#define DENOM_EPSILON ((Real)1.e-6)
+#define MAXT ((Real)1.e19)
 
 
 #endif

Modified: branches/vertical/Interface/RayPacket.h
==============================================================================
--- branches/vertical/Interface/RayPacket.h     (original)
+++ branches/vertical/Interface/RayPacket.h     Wed Jan  4 11:26:44 2006
@@ -49,7 +49,7 @@
 
     // Int-based arrays
     int whichEye[Size];
-    int sign[3][Size];
+    int signs[3][Size];
 
     // Char-based arrays
     char scratchpad_data[Size][MaxScratchpadSize];
@@ -234,18 +234,26 @@
         return;
       for(int i=rayBegin;i<rayEnd;i++)
         for(int j = 0; j < 3; j++)
-          data->sign[j][i] = data->direction[j][i] < 0;
+          data->signs[j][i] = data->direction[j][i] < 0;
       flags |= HaveSigns;
       flags &= ~ConstantSigns;
-      int sign[3];
+      int signs[3];
       for(int j=0;j<3;j++)
-        sign[j] = data->sign[j][rayBegin];
+        signs[j] = data->signs[j][rayBegin];
       for(int i=rayBegin+1; i < rayEnd; i++)
         for(int j = 0; j < 3; j++)
-          if(data->sign[j][i] != sign[j])
+          if(data->signs[j][i] != signs[j])
             return;
       flags |= ConstantSigns;
     }
+    VectorT<int, 3> getSigns(int which)
+    {
+      return VectorT<int, 3>(data->signs[0][which], data->signs[1][which], 
data->signs[2][which]);
+    }
+    int getSign(int which, int sign)
+    {
+      return data->signs[sign][which];
+    }
 
     // Hit information
     void resetHits() {
@@ -265,7 +273,7 @@
     }
     bool hit(int which, Real t, const Material* matl, const Primitive* prim,
              const TexCoordMapper* tex) {
-      if(t < (Real)T_EPSILON)
+      if(t < T_EPSILON)
         return false;
       if(t < data->minT[which]){
         data->minT[which] = t;

Modified: branches/vertical/Model/Intersections/AxisAlignedBox.h
==============================================================================
--- branches/vertical/Model/Intersections/AxisAlignedBox.h      (original)
+++ branches/vertical/Model/Intersections/AxisAlignedBox.h      Wed Jan  4 
11:26:44 2006
@@ -12,154 +12,54 @@
 namespace Manta {
   namespace Intersection {
 
-    // This intersection method uses the Amy Williams ray/box intersection 
technique.
-    // http://www.cs.utah.edu/~awilliam/box/box.pdf
-    // The BOX type must define a [] operator for accessing the min/max 
points in
-    // the bounds.
-
-    // NOTE: The inverse direction and ray sign mask are in the 
RayPacket::Element.
+    // This intersection method uses the Amy Williams ray/box intersection
+    // technique.
+    // See http://www.cs.utah.edu/~awilliam/box/box.pdf
+    // The BOX type must define a [] operator for accessing the min/max
+    // points in the bounds.
+    // NOTE: The inverse direction and ray sign mask come from the raypacket
     
     // This is the single ray version.
     template< typename BOX, typename Scalar >
     inline bool intersectAaBox(const BOX &bounds,     // Object implementing 
[]
-
                               Scalar &tmin,          // Output min t.
                               Scalar &tmax,          // Output max t.
-
                               const Ray &r,          // Input Ray.
-                              const int s[3],        // Input Ray mask.
-                              const Vector &d_inv,   // Input 1.0 / ray 
direction.
-
-                              Scalar t0 = 0,         // Input bounding 
interval for t.
+                              const VectorT<int,3>&s,// Input Ray mask.
+                              const Vector &d_inv,   // Input 1.0 / ray 
direction
+                              Scalar t0 = 0,         // Input bounding 
interval for t
                               Scalar t1 = std::numeric_limits<Scalar>::max()
-                              ) {
-
-      Scalar tymin, tymax, tzmin, tzmax;
-      
+                               )
+    {
       tmin  = (bounds[s[0]  ][0] - r.origin()[0]) * d_inv[0];
       tmax  = (bounds[1-s[0]][0] - r.origin()[0]) * d_inv[0];
-      tymin = (bounds[s[1]  ][1] - r.origin()[1]) * d_inv[1];
-      tymax = (bounds[1-s[1]][1] - r.origin()[1]) * d_inv[1];
+      Scalar tymin = (bounds[s[1]  ][1] - r.origin()[1]) * d_inv[1];
+      Scalar tymax = (bounds[1-s[1]][1] - r.origin()[1]) * d_inv[1];
 
       // If boxes are allowed to be inside out.
       // if (tmin > tmax) 
       //       return false;
       
-      if ( (tmin > tymax) || (tymin > tmax) )
+      if ( tmin > tymax || tymin > tmax )
         return false;
       if ( tymin > tmin )
         tmin = tymin;
       if ( tymax < tmax )
         tmax = tymax;
 
-      tzmin = (bounds[s[2]  ][2] - r.origin()[2]) * d_inv[2];
-                       tzmax = (bounds[1-s[2]][2] - r.origin()[2]) * 
d_inv[2];
-                       
-                       if ( (tmin > tzmax) || (tzmin > tmax) )
-                               return false;
-                       if ( tzmin > tmin )
-                               tmin = tzmin;
-                       if ( tzmax < tmax )
-                               tmax = tzmax;
-                       
-                       return ( (tmin < t1) && (tmax > t0) );  
-    }

-               template< typename BOX, typename Scalar >
-    inline bool intersectAaBox2(const BOX &bounds,     // Object 
implementing []
-                                                                             
                                                  
-                                                                             
                                                  Scalar &tmin,          // 
Output min t.
-                                                                             
                                                  Scalar &tmax,          // 
Output max t.
-                                                                             
                                                  
-                                                                             
                                                  const Ray &r,          // 
Input Ray.
-                                                                             
                                                  const int s[3],        // 
Input Ray mask.
-                                                                             
                                                  const Vector &d_inv,   // 
Input 1.0 / ray direction.
-                                                                             
                                                  
-                                                                             
                                                  Scalar t0 = 0,         // 
Input bounding interval for t.
-                                                                             
                                                  Scalar t1 = 
std::numeric_limits<Scalar>::max()
-                                                                             
                                                  ) {
-      Scalar txmin, txmax, tymin, tymax, tzmin, tzmax;
-      tmin = t0;
-                       tmax = t1;
-                       
-      txmin  = (bounds[s[0]  ][0] - r.origin()[0]) * d_inv[0];
-      txmax  = (bounds[1-s[0]][0] - r.origin()[0]) * d_inv[0];
-                       if ( txmin > tmin ) tmin = txmin;
-                       if ( txmax < tmax ) tmax = txmax;
-                       if ( tmin > tmax ) return false;
-                       
-      tymin = (bounds[s[1]  ][1] - r.origin()[1]) * d_inv[1];
-      tymax = (bounds[1-s[1]][1] - r.origin()[1]) * d_inv[1];
-                       if ( tymin > tmin ) tmin = tymin;
-                       if ( tymax < tmax ) tmax = tymax;
-                       if ( tmin > tmax ) return false;
-                       
-                       tzmin = (bounds[s[2]  ][2] - r.origin()[2]) * 
d_inv[2];
-                       tzmax = (bounds[1-s[2]][2] - r.origin()[2]) * 
d_inv[2];
-                       if ( tzmin > tmin ) tmin = tzmin;
-                       if ( tzmax < tmax ) tmax = tzmax;
-                       return ( tmin <= tmax );
-    }
-               
-
-    template< typename BOX, typename Scalar >
-    inline bool intersectAaBox3(const BOX &bounds,     // Object 
implementing []
-                                                                             
                                           
-                                                                             
                                           Scalar &tmin,          // Output 
min t.
-                                                                             
                                           Scalar &tmax,          // Output 
max t.
-                                                                             
                                           
-                                                                             
                                           const Ray &r,          // Input 
Ray.
-                                                                             
                                           const int s[3],        // Input 
Ray mask.
-                                                                             
                                           const Vector &d_inv,   // Input 
1.0 / ray direction.
-                                                                             
                                           
-                                                                             
                                           Scalar t0 = 0,         // Input 
bounding interval for t.
-                                                                             
                                           Scalar t1 = 
std::numeric_limits<Scalar>::max()
-                                                                             
                                           ) {
-                       
-      Scalar txmin, txmax, tymin, tymax, tzmin, tzmax;
-                       tmin = t0;
-                       tmax = t1;
+      Scalar tzmin = (bounds[s[2]  ][2] - r.origin()[2]) * d_inv[2];
+      Scalar tzmax = (bounds[1-s[2]][2] - r.origin()[2]) * d_inv[2];
                        
-                       txmin = (bounds[s[0] ][0] - r.origin()[0]) * d_inv[0];
-                       txmax = (bounds[1-s[0]][0] - r.origin()[0]) * 
d_inv[0];
-                       
-                       if ( (tmin > txmax) || (txmin > tmax) )
-                               return false;
-                       
-                       if ( txmin > tmin )
-                               tmin = txmin;
-                       if ( txmax < tmax )
-                               tmax = txmax;
-                               
-      tymin = (bounds[s[1]  ][1] - r.origin()[1]) * d_inv[1];
-      tymax = (bounds[1-s[1]][1] - r.origin()[1]) * d_inv[1];
-                       
-      // If boxes are allowed to be inside out.
-      // if (tmin > tmax) 
-      //       return false;
-      
-      if ( (tmin > tymax) || (tymin > tmax) )
+      if ( tmin > tzmax || tzmin > tmax )
         return false;
-      if ( tymin > tmin )
-        tmin = tymin;
-      if ( tymax < tmax )
-        tmax = tymax;
-                       
-      tzmin = (bounds[s[2]  ][2] - r.origin()[2]) * d_inv[2];
-                       tzmax = (bounds[1-s[2]][2] - r.origin()[2]) * 
d_inv[2];
-                       
-                       if ( (tmin > tzmax) || (tzmin > tmax) )
-                               return false;
-                       if ( tzmin > tmin )
-                               tmin = tzmin;
-                       if ( tzmax < tmax )
-                               tmax = tzmax;
-                       
-                       return true;  
-    }
-               
-                                             
-  };
-};
+      if ( tzmin > tmin )
+        tmin = tzmin;
+      if ( tzmax < tmax )
+        tmax = tzmax;
+                       
+      return tmin < t1 && tmax > t0;
+    } 
+  }
+}
 
 #endif

Modified: branches/vertical/Model/Primitives/BvhTriangleMesh.cc
==============================================================================
--- branches/vertical/Model/Primitives/BvhTriangleMesh.cc       (original)
+++ branches/vertical/Model/Primitives/BvhTriangleMesh.cc       Wed Jan  4 
11:26:44 2006
@@ -48,107 +48,99 @@
 
 void BvhTriangleMesh::intersect_leaf(Node *node,
                                      const RenderContext& /*context*/,
-                                     RayPacket& rays ) const {
+                                     RayPacket& rays ) const
+{
 
-       // Determine the triangle index.
-       int index = node->triangle_index;
+  // Determine the triangle index.
+  int index = node->triangle_index;
        
-       // Intersect each ray in the packet with the triangle.
-       IndexedTriangle &tri = triangle_array[index];
+  // Intersect each ray in the packet with the triangle.
+  IndexedTriangle &tri = triangle_array[index];
        
-       Real hit_t, a, b;
+  Real hit_t, a, b;
        
-       for (int i=0;i<rays.getSize();++i) {
-               RayPacket::Element &e = rays.get(i);
-               
-               // Intersect the ray with a triangle.
-               if (Intersection::intersectTriangleEdge( hit_t, // Output ray 
t parameter.
-                                                                             
                                                                              
                     a, b,  // Output texture coords.
-                                                        
-                                                                             
                                                                              
                     e.ray, // Input ray.
-                                                                             
                                                                              
                     
-                                                                             
                                                                              
                     edge_array[tri.e0], // Input triangle
-                                                                             
                                                                              
                     edge_array[tri.e1],
-                                                                             
                                                                              
                     vertex_array[tri.v0] ))
-               {
-                       // Check to see if the hit is closest so far.
-                       if (e.hitInfo.hit(hit_t, getMaterial(), this, 
getTexCoordMapper())) {
-                       
-                               // Copy over the hit record.
-                               Hit &info = e.hitInfo.scratchpad<Hit>();
-                               
-                               info.tri = tri;
-                               info.a = a;
-                               info.b = b;
-                       }
-               }
-       }
+  for (int i=rays.begin();i<rays.end();++i) {
+    // Intersect the ray with a triangle.
+    if (Intersection::intersectTriangleEdge( hit_t, // Output ray t 
parameter.
+                                             a, b,  // Output texture coords.
+                                             rays.getRay(i), // Input ray.
+                                             edge_array[tri.e0], // Input 
triangle
+                                             edge_array[tri.e1],
+                                             vertex_array[tri.v0] ))
+      {
+        // Check to see if the hit is closest so far.
+        if (rays.hit(i, hit_t, getMaterial(), this, getTexCoordMapper())) {
+          
+          // Copy over the hit record.
+          Hit &info = rays.scratchpad<Hit>(i);
+          
+          info.tri = tri;
+          info.a = a;
+          info.b = b;
+        }
+      }
+  }
 }
 
-void BvhTriangleMesh::intersect_internal(Node *node, const RenderContext& 
context, RayPacket& rays) const {
-
-       // Intersect the ray packet with the bounds of this node.
-       bool bbox_intersect[RayPacket::MaxSize];
-       
-       for(int i=0;i<rays.getSize();i++) {
-               
-               RayPacket::Element& e = rays.get(i);
-               
-               // Check to see if the ray hits this node's bounding box.
-               Real min_t, max_t;
-               bbox_intersect[i] = Intersection::intersectAaBox( 
node->bounds,
-                
-                                                                             
                                                                              
                                                            min_t, max_t, 
e.ray, 
-                                                                             
                                                                              
                                                      e.sign, 
e.inverseDirection,
-                                                                             
                                                                              
                                                            (Real)0,
-                                                                             
                                                                              
                                                            e.hitInfo.minT() 
);
-       }
-       
-       // Find runs of rays which intersect this bounding box and intersect 
those 
-       // with the children.
-       int begin = 0;
-       int end   = 0;
-       int first_child;
-       
-       while (begin < rays.getSize()) {
-               
-               // Find the beginning of a run.
-               while ((begin < rays.getSize()) && (!bbox_intersect[begin]))
-                       ++begin;
-               
-               // Determine the first child for the first ray in the packet.
-               first_child = rays.get( begin ).sign[ node->split_axis ];
-               
-               // Find the end of this run.
-               end = begin;
-               while ((end < rays.getSize()) && (bbox_intersect[end]) && 
-                      (rays.get( begin ).sign[ node->split_axis ] == 
first_child))
-                       ++end;
-               
-               if ((end > begin) && (begin < rays.getSize())) {
-                       
-                       // Create a sub packet.
-                       RayPacket sub_packet( rays, begin, end );
-                       
-                       
/////////////////////////////////////////////////////////////////////////
-                       // Intersect with both children.
-                       
-                       // Check if the node is internal or a leaf.
-                       if (node->child[first_child]->isLeaf())
-                               intersect_leaf( node->child[first_child], 
context, rays );
-                       else
-                               intersect_internal( node->child[first_child], 
context, rays );
-               
-                       // Check if the node is internal or a leaf.
-                       if (node->child[!first_child]->isLeaf())
-                               intersect_leaf( node->child[!first_child], 
context, rays );
-                       else
-                               intersect_internal( 
node->child[!first_child], context, rays );
-               }
-       
-               begin = end;
-       }
+void BvhTriangleMesh::intersect_internal(Node *node, const RenderContext& 
context, RayPacket& rays) const
+{
+  // Intersect the ray packet with the bounds of this node.
+  bool bbox_intersect[RayPacket::MaxSize];
        
+  for(int i=rays.begin();i<rays.end();i++) {
+    // Check to see if the ray hits this node's bounding box.
+    Real min_t, max_t;
+    bbox_intersect[i] = Intersection::intersectAaBox( node->bounds,
+                                                      min_t, max_t,
+                                                      rays.getRay(i),
+                                                      rays.getSigns(i),
+                                                      
rays.getInverseDirection(i),
+                                                      (Real)0,
+                                                      rays.getMinT(i) );
+  }
+  
+  // Find runs of rays which intersect this bounding box and intersect those 
+  // with the children.
+  int begin = rays.begin();
+  
+  while (begin < rays.end()) {
+    
+    // Find the beginning of a run.
+    while ((begin < rays.end()) && (!bbox_intersect[begin]))
+      ++begin;
+    
+    // Determine the first child for the first ray in the packet.
+    int first_child = rays.getSign(begin, node->split_axis );
+    
+    // Find the end of this run.
+    int end = begin;
+    while (end < rays.end() && bbox_intersect[end] && 
+           rays.getSign(begin, node->split_axis) == first_child)
+      ++end;
+    
+    if (end > begin && begin < rays.end()) {
+      
+      // Create a sub packet.
+      RayPacket sub_packet( rays, begin, end );
+      
+      
/////////////////////////////////////////////////////////////////////////
+      // Intersect with both children.
+      
+      // Check if the node is internal or a leaf.
+      if (node->child[first_child]->isLeaf())
+        intersect_leaf( node->child[first_child], context, rays );
+      else
+        intersect_internal( node->child[first_child], context, rays );
+      
+      // Check if the node is internal or a leaf.
+      if (node->child[!first_child]->isLeaf())
+        intersect_leaf( node->child[!first_child], context, rays );
+      else
+        intersect_internal( node->child[!first_child], context, rays );
+    }
+    
+    begin = end;
+  }
 }
 
 
///////////////////////////////////////////////////////////////////////////////
@@ -158,72 +150,73 @@
 
///////////////////////////////////////////////////////////////////////////////
 
 // Rearrange the pointers in the input array around a pivot point.
-int BvhTriangleMesh::qsplit( int *array, int size, Real pivot, int axis ) {
-       
-       int ret_val = 0;
-       for (int i=0; i<size;++i) {
-               
-               // Get the bounds of each individual triangle.
-               BBox bounds;
-               compute_bounds( bounds, array[i] );
-               
-               // Find the centroid of those bounds.
-               Real centroid = (bounds[0][axis] + bounds[1][axis]) * 
(Real)0.5;
-               
-               if (centroid < pivot) {
-                       int tmp = array[i];
-                       array[i]    = array[ret_val];
-                       array[ret_val] = tmp;
-                       ++ret_val;
-               }
-       }
+int BvhTriangleMesh::qsplit( int *array, int size, Real pivot, int axis )
+{
        
-       if ((ret_val == 0) || (ret_val == size)) 
-               ret_val = size / 2;
+  int ret_val = 0;
+  for (int i=0; i<size;++i) {
                
-       return ret_val;
+    // Get the bounds of each individual triangle.
+    BBox bounds;
+    compute_bounds( bounds, array[i] );
+               
+    // Find the centroid of those bounds.
+    Real centroid = (bounds[0][axis] + bounds[1][axis]) * (Real)0.5;
+    
+    if (centroid < pivot) {
+      int tmp = array[i];
+      array[i]    = array[ret_val];
+      array[ret_val] = tmp;
+      ++ret_val;
+    }
+  }
+  
+  if ((ret_val == 0) || (ret_val == size)) 
+    ret_val = size / 2;
+  
+  return ret_val;
 }
 
-BvhTriangleMesh::Node *BvhTriangleMesh::build_branch( int *array, int size, 
int axis ) {
-       
-       assert( size != 0 );
-       
-       // Check two exit conditions.
-       if (size == 1) {
-               return new Node( array[0] );
-       }
-       
-       // Create a new node.
-       Node *new_node = new Node();
-       
-       // Compute the bounds of the entire array of triangles.
-       for (int i=0;i<size;++i) {
-               compute_bounds( new_node->bounds, array[i] );
-       }       
-       
-       if (size == 2) {
-               new_node->child[0] = new Node( array[0] );
-               new_node->child[1] = new Node( array[1] );
-               return new_node;
-       }
-       
-       // Find a pivot point.
-       Point pivot((Vector(new_node->bounds[0]) + 
Vector(new_node->bounds[1])) * 0.5);
-       
-       // Split along the axis.
-       int mid_point = qsplit( array, size, pivot[axis], axis );
-       
-       // save the split axis.
-       new_node->split_axis = axis;
+BvhTriangleMesh::Node *BvhTriangleMesh::build_branch( int *array, int size, 
int axis )
+{
+  assert( size != 0 );
        
-       // Create new left and right children.
-       assert( mid_point != 0 );
-       assert( mid_point != size);
+  // Check two exit conditions.
+  if (size == 1) {
+    return new Node( array[0] );
+  }
+       
+  // Create a new node.
+  Node *new_node = new Node();
+       
+  // Compute the bounds of the entire array of triangles.
+  for (int i=0;i<size;++i) {
+    compute_bounds( new_node->bounds, array[i] );
+  }    
+       
+  if (size == 2) {
+    new_node->child[0] = new Node( array[0] );
+    new_node->child[1] = new Node( array[1] );
+    return new_node;
+  }
+       
+  // Find a pivot point.
+  Point pivot((Vector(new_node->bounds[0]) + Vector(new_node->bounds[1])) * 
0.5);
+       
+  // Split along the axis.
+  int mid_point = qsplit( array, size, pivot[axis], axis );
+       
+  // save the split axis.
+  new_node->split_axis = axis;
+  
+  // Create new left and right children.
+  assert( mid_point != 0 );
+  assert( mid_point != size);
        
-       new_node->child[0] = build_branch( array, mid_point, (axis+1)%3 );
-       new_node->child[1] = build_branch( array+mid_point, size-mid_point, 
(axis+1)%3 );
+  new_node->child[0] = build_branch( array, mid_point, (axis+1)%3 );
+  new_node->child[1] = build_branch( array+mid_point, size-mid_point, 
(axis+1)%3 );
        
-       return new_node;
+  return new_node;
 }
 
 
///////////////////////////////////////////////////////////////////////////////
@@ -234,82 +227,75 @@
 
 // Construct a BVH from an array of objects.
 BvhTriangleMesh::BvhTriangleMesh( Point *vertex_array_, 
-                                                                             
                                                          Vector 
*edge_array_, 
-                                                                             
                                                          Vector 
*normal_array_, 
-                                                                             
                                                          IndexedTriangle 
*triangle_array_, 
-                                                                             
                                                          
-                                                                             
                                                          int *array, int 
size,
-                                                                             
                                                          
-                                                                             
                                                          Material *material 
) :
-       PrimitiveCommon( material ),
-       vertex_array( vertex_array_ ),
-       edge_array  ( edge_array_ ),
-       normal_array( normal_array_ ),
-       triangle_array( triangle_array_ )
-       
-       
+                                  Vector *edge_array_, 
+                                  Vector *normal_array_, 
+                                  IndexedTriangle *triangle_array_, 
+                                  int *array, int size,
+                                  Material *material ) :
+  PrimitiveCommon( material ),
+  vertex_array( vertex_array_ ),
+  edge_array  ( edge_array_ ),
+  normal_array( normal_array_ ),
+  triangle_array( triangle_array_ )
 {
 
-       // Create a new node.
-       root = new Node();
+  // Create a new node.
+  root = new Node();
        
-       // Compute the bounds of the entire array of triangles.
-       for (int i=0;i<size;++i) {
-               compute_bounds( root->bounds, array[i] );
-       }
-       
-       // Find a pivot point.
-       Point pivot((Vector(root->bounds[0]) + Vector(root->bounds[1])) * 
0.5);
-       
-       // Split along the axis.
-       int mid_point = qsplit( array, size, pivot[0], 0 );
-       
-       // save the split axis.
-       root->split_axis = 0;
-       
-       // Create new left and right children.
-       root->child[0] = build_branch( array, mid_point, 1 );
-       root->child[1] = build_branch( array+mid_point, size-mid_point, 1 );
+  // Compute the bounds of the entire array of triangles.
+  for (int i=0;i<size;++i) {
+    compute_bounds( root->bounds, array[i] );
+  }
+       
+  // Find a pivot point.
+  Point pivot((Vector(root->bounds[0]) + Vector(root->bounds[1])) * 0.5);
+       
+  // Split along the axis.
+  int mid_point = qsplit( array, size, pivot[0], 0 );
+       
+  // save the split axis.
+  root->split_axis = 0;
+       
+  // Create new left and right children.
+  root->child[0] = build_branch( array, mid_point, 1 );
+  root->child[1] = build_branch( array+mid_point, size-mid_point, 1 );
 }
 
 // Public interface.
 void BvhTriangleMesh::computeBounds(const PreprocessContext& /*context*/,
-                                    BBox& bbox) const {
-       
-       // The root node contains the bounds for the entire model.
-       bbox.extendByBox( root->bounds );
+                                    BBox& bbox) const
+{
+  // The root node contains the bounds for the entire model.
+  bbox.extendByBox( root->bounds );
 }
 
 void BvhTriangleMesh::computeNormal(const RenderContext& /*context*/,
-                                    RayPacket& rays) const {
+                                    RayPacket& rays) const
+{
 
-       rays.computeHitPositions();
+  rays.computeHitPositions();
 
-       // Iterate over each ray in the packet.
-       for (int i=0;i<rays.getSize();++i) {
-       
-               RayPacket::Element &e = rays.get( i );
+  // Iterate over each ray in the packet.
+  for (int i=rays.begin();i<rays.end();++i) {
+    // Determine the intersected triangle.
+    Hit &hit = rays.scratchpad<Hit>(i);
                
-               // Determine the intersected triangle.
-               Hit &hit = e.hitInfo.scratchpad<Hit>();
+    // Interpolate normals across the face.
+    Real ab = 1 - (hit.a + hit.b);
                
-               // Interpolate normals across the face.
-               Real ab = 1 - (hit.a + hit.b);
-               
-               e.normal = (normal_array[ hit.tri.n0 ] * hit.a) + 
-                          (normal_array[ hit.tri.n1 ] * hit.b) + 
-                                                        (normal_array[ 
hit.tri.n2 ] * ab);
-       }
-
+    rays.setNormal(i, (normal_array[ hit.tri.n0 ] * hit.a) + 
+                      (normal_array[ hit.tri.n1 ] * hit.b) + 
+                      (normal_array[ hit.tri.n2 ] * ab));
+  }
 }
 
-void BvhTriangleMesh::intersect    (const RenderContext& context, RayPacket& 
rays) const {
-
-       rays.computeInverseDirections();
-        rays.computeSigns();
+void BvhTriangleMesh::intersect    (const RenderContext& context, RayPacket& 
rays) const
+{
+  rays.computeInverseDirections();
+  rays.computeSigns();
 
-       // Intersect the ray packet with this mesh.     
-       intersect_internal( root, context, rays );
+  // Intersect the ray packet with this mesh.  
+  intersect_internal( root, context, rays );
 }
 
 

Modified: branches/vertical/Model/Primitives/CMakeLists.txt
==============================================================================
--- branches/vertical/Model/Primitives/CMakeLists.txt   (original)
+++ branches/vertical/Model/Primitives/CMakeLists.txt   Wed Jan  4 11:26:44 
2006
@@ -1,19 +1,19 @@
 
 SET (Manta_Primitives_SRCS
-     #Primitives/BvhTriangleMesh.cc
-     #Primitives/BvhTriangleMesh.h
+     Primitives/BvhTriangleMesh.cc
+     Primitives/BvhTriangleMesh.h
      Primitives/Cone.cc
      Primitives/Cone.h
-     #Primitives/Cube.cc
-     #Primitives/Cube.h
-     #Primitives/Disk.cc
-     #Primitives/Disk.h
+     Primitives/Cube.cc
+     Primitives/Cube.h
+     Primitives/Disk.cc
+     Primitives/Disk.h
      Primitives/HeavyTriangle.cc
      Primitives/HeavyTriangle.h
      Primitives/Heightfield.cc
      Primitives/Heightfield.h
-     #Primitives/Hemisphere.cc
-     #Primitives/Hemisphere.h
+     Primitives/Hemisphere.cc
+     Primitives/Hemisphere.h
      Primitives/Parallelogram.cc
      Primitives/Parallelogram.h
      Primitives/ParticleBVH.cc

Modified: branches/vertical/Model/Primitives/Cube.cc
==============================================================================
--- branches/vertical/Model/Primitives/Cube.cc  (original)
+++ branches/vertical/Model/Primitives/Cube.cc  Wed Jan  4 11:26:44 2006
@@ -10,17 +10,11 @@
 using namespace std;
 using SCIRun::Abs;
 
-Cube::Cube(Material* mat, const Point& anch, double w, double h, double d)
+Cube::Cube(Material* mat, const Point& p0, const Point& p1)
   : PrimitiveCommon(mat)
 {
-
-  bbox[0] = anch;
-  bbox[1] = anch + Vector(w,h,d);
-#if 0
-  xmin = anchor.x(); xmax = xmin + w;
-  ymin = anchor.y(); ymax = ymin + h;
-  zmin = anchor.z(); zmax = zmin + d;
-#endif
+  bbox[0] = Min(p0, p1);
+  bbox[1] = Max(p0, p1);
 }
 
 Cube::~Cube()
@@ -43,129 +37,24 @@
   rays.computeSigns();
 
   // Iterate over each ray.
-  for (int i=0;i<rays.getSize();++i) {
-
-    RayPacket::Element &e = rays.get(i);
+  for (int i=rays.begin();i<rays.end();++i) {
 
-               Real tmin, tmax;
-       
+    Real tmin, tmax;
     // Check for an intersection.
     if (Intersection::intersectAaBox( bbox,
-                                     tmin,
-                                     tmax,
-                                     e.ray,
-                                     e.sign,
-                                     e.inverseDirection/*,
-                                                                             
                                                                   
e.hitInfo.minT()*/)) {
-
-      // Check to see if we are inside the box.
-      if (tmin > T_EPSILON) {
-        e.hitInfo.hit( tmin, getMaterial(), this, getTexCoordMapper() );
-      }
-
+                                      tmin,
+                                      tmax,
+                                      rays.getRay(i),
+                                      rays.getSigns(i),
+                                      rays.getInverseDirection(i))){
+          // Check to see if we are inside the box.
+      if (tmin > T_EPSILON)
+        rays.hit( i, tmin, getMaterial(), this, getTexCoordMapper() );
       // And use the max intersection if we are.
-      else {
-        e.hitInfo.hit( tmax, getMaterial(), this, getTexCoordMapper() );
-      }
-    }
-  }
-  
-
-#if 0
-  using SCIRun::Max;
-  using SCIRun::Min;
-  rays.computeInverseDirections();
-  if(rays.getFlags() & RayPacket::ConstantOrigin && rays.getSize()>1) {
-    RayPacket::Element& e0 = rays.get(0);
-    double xo = e0.ray.origin().x();
-    double yo = e0.ray.origin().y();
-    double zo = e0.ray.origin().z();
-    for(int i=0; i<rays.getSize(); i++) {
-      RayPacket::Element& e = rays.get(i);
-      double tnear, tfar, t1, t2;
-      t1 = (xmin - xo) * e.inverseDirection.x();
-      t2 = (xmax - xo) * e.inverseDirection.x();
-      if(t1>t2) {
-       double temp = t1;
-       t1 = t2;
-       t2 = temp;
-      }
-      tnear = t1;
-      tfar = t2;
-      
-      t1 = (ymin - yo) * e.inverseDirection.y();
-      t2 = (ymax - yo) * e.inverseDirection.y();
-      if(t1>t2) {
-       double temp = t1;
-       t1 = t2;
-       t2 = temp;
-      }
-      tnear = Max(t1, tnear);
-      tfar = Min(t2, tfar);
-      
-      t1 = (zmin - zo) * e.inverseDirection.z();
-      t2 = (zmax - zo) * e.inverseDirection.z();
-      if(t1>t2) {
-       double temp = t1;
-       t1 = t2;
-       t2 = temp;
-      }
-      tnear = Max(t1, tnear);
-      tfar = Min(t2, tfar);
-
-      if(tnear <= tfar)
-      {
-       e.hitInfo.hit(tnear, material, this, tex);
-        e.hitInfo.hit(tfar , material, this, tex);
-      }
+      else
+        rays.hit( i, tmax, getMaterial(), this, getTexCoordMapper() );
     }
   }
-  else {
-    for(int i=0; i<rays.getSize(); i++) {
-      RayPacket::Element& e = rays.get(i);
-      double xo = e.ray.origin().x();
-      double yo = e.ray.origin().y();
-      double zo = e.ray.origin().z();
-      double tnear, tfar, t1, t2;
-      t1 = (xmin - xo) * e.inverseDirection.x();
-      t2 = (xmax - xo) * e.inverseDirection.x();
-      if(t1>t2) {
-       double temp = t1;
-       t1 = t2;
-       t2 = temp;
-      }
-      tnear = t1;
-      tfar = t2;
-      
-      t1 = (ymin - yo) * e.inverseDirection.y();
-      t2 = (ymax - yo) * e.inverseDirection.y();
-      if(t1>t2) {
-       double temp = t1;
-       t1 = t2;
-       t2 = temp;
-      }
-      tnear = Max(t1, tnear);
-      tfar = Min(t2, tfar);
-      
-      t1 = (zmin - zo) * e.inverseDirection.z();
-      t2 = (zmax - zo) * e.inverseDirection.z();
-      if(t1>t2) {
-       double temp = t1;
-       t1 = t2;
-       t2 = temp;
-      }
-      tnear = Max(t1, tnear);
-      tfar = Min(t2, tfar);
-
-      if(tnear <= tfar)
-      {
-       e.hitInfo.hit(tnear, material, this, tex);
-        e.hitInfo.hit(tfar , material, this, tex);
-      }
-    }
-  }
-
-#endif
 }
 
 
@@ -175,21 +64,21 @@
   for(int i=rays.begin(); i<rays.end(); i++) {
     Point hp = rays.getHitPosition(i);
     if (Abs(hp.x() - bbox[0][0]) < 0.0001)
-      e.normal =  Vector(-1, 0, 0 );
+      rays.setNormal(i, Vector(-1, 0, 0 ));
     
     else if (Abs(hp.x() - bbox[1][0]) < 0.0001)
-      e.normal =  Vector( 1, 0, 0 );
+      rays.setNormal(i, Vector( 1, 0, 0 ));
     
     else if (Abs(hp.y() - bbox[0][1]) < 0.0001)
-      e.normal =  Vector( 0,-1, 0 );
+      rays.setNormal(i, Vector( 0,-1, 0 ));
     
     else if (Abs(hp.y() - bbox[1][1]) < 0.0001)
-      e.normal =  Vector( 0, 1, 0 );
+      rays.setNormal(i, Vector( 0, 1, 0 ));
     
     else if (Abs(hp.z() - bbox[0][2]) < 0.0001)
-      e.normal =  Vector( 0, 0,-1 );
+      rays.setNormal(i, Vector( 0, 0,-1 ));
     
     else 
-      e.normal =  Vector( 0, 0, 1 );
+      rays.setNormal(i, Vector( 0, 0, 1 ));
   }
 }

Modified: branches/vertical/Model/Primitives/Cube.h
==============================================================================
--- branches/vertical/Model/Primitives/Cube.h   (original)
+++ branches/vertical/Model/Primitives/Cube.h   Wed Jan  4 11:26:44 2006
@@ -11,9 +11,7 @@
 
   class Cube : public PrimitiveCommon {
   public:
-    Cube(Material* mat, const Point& anch, double w, double h, double d);
-    Cube(Material *mat, const Point &min_, const Point &max_ ) :
-      PrimitiveCommon( mat ), bbox( min_, max_ ) { }
+    Cube(Material *mat, const Point &min_, const Point &max_ );
     ~Cube();
     
     virtual void computeBounds(const PreprocessContext& context,
@@ -23,13 +21,6 @@
     
   private:
     BBox bbox;
-#if 0
-    Point anchor;
-    double w,h,d;
-    double xmin, xmax;
-    double ymin, ymax;
-    double zmin, zmax;
-#endif
   };
 }
 

Modified: branches/vertical/Model/Primitives/Disk.cc
==============================================================================
--- branches/vertical/Model/Primitives/Disk.cc  (original)
+++ branches/vertical/Model/Primitives/Disk.cc  Wed Jan  4 11:26:44 2006
@@ -1,6 +1,8 @@
+
 #include <Model/Primitives/Disk.h>
 #include <Interface/RayPacket.h>
 #include <Core/Geometry/BBox.h>
+#include <Core/Math/Trig.h>
 
 using namespace Manta;
 using namespace std;
@@ -45,7 +47,7 @@
       Vector rayD = rays.getDirection(i);
       Real denom = Dot(_n, rayD);
 
-      if ((denom < -EPSILON) || (denom > EPSILON)) {
+      if (denom < -DENOM_EPSILON || denom > DENOM_EPSILON) {
         Real t = -(_d + nDotO) / denom;
         if (checkBounds(rayO + t * rayD)) {
           rays.hit(i, t, getMaterial(), this, getTexCoordMapper());
@@ -54,11 +56,11 @@
     }
   } else {
     for (int i = rays.begin(); i < rays.end(); i++) {
-      Point rayD = rays.getDirection(i);
-      Vector rayO = rays.getOrigin(i);
+      Point rayO = rays.getOrigin(i);
+      Vector rayD = rays.getDirection(i);
       Real denom = Dot(_n, rayD);
 
-      if ((denom < -EPSILON) || (denom > EPSILON)) {
+      if (denom < -DENOM_EPSILON || denom > DENOM_EPSILON) {
         Real t = -(_d + Dot(_n, rayO)) / denom;
         if (checkBounds(rayO + t * rayD)) {
           rays.hit(i, t, getMaterial(), this, getTexCoordMapper());
@@ -92,8 +94,8 @@
     Real dist = dir.normalize();
     Real theta = Atan2(Dot(_v, dir), Dot(_u, dir));
     if(theta < 0)
-      theta += ??PI;
-    rays.setTexCoords(i, dist/_r, (theta - minTheta) / (_maxTheta - 
minTheta), 0);
+      theta += (Real)M_PI;
+    rays.setTexCoords(i, Point(dist/_r, (theta - _minTheta) / (_maxTheta - 
_minTheta), 0));
   }
 
   // set flag to show texcoords have been computed
@@ -101,23 +103,21 @@
 }
 
 void Disk::computeTexCoords3(const RenderContext& /*context*/,
-                             RayPacket& rays) const {
-  int i, numRays(rays.getSize());
-  Point p;
-
+                             RayPacket& rays) const
+{
   // compute hit locations if necessary
   if (!(rays.getFlag(RayPacket::HaveHitPositions)))
     rays.computeHitPositions();
 
   // set 3-d texture coordinates to be the hit locations
-  for (i = 0; i < numRays; i++) {
+  for (int i = rays.begin(); i < rays.end(); i++) {
     Point p = rays.getHitPosition(i);
     Vector dir = p - _c;
     Real dist = dir.normalize();
     Real theta = Atan2(Dot(_v, dir), Dot(_u, dir));
     if(theta < 0)
-      theta += ??PI;
-    rays.setTexCoords(i, dist/_r, (theta - minTheta) / (_maxTheta - 
minTheta), 0);
+      theta += (Real)M_PI;
+    rays.setTexCoords(i, Point(dist/_r, (theta - _minTheta) / (_maxTheta - 
_minTheta), 0));
   }
 
   // set flag to show texcoords have been computed

Modified: branches/vertical/Model/Primitives/HeavyTriangle.cc
==============================================================================
--- branches/vertical/Model/Primitives/HeavyTriangle.cc (original)
+++ branches/vertical/Model/Primitives/HeavyTriangle.cc Wed Jan  4 11:26:44 
2006
@@ -68,27 +68,16 @@
 {
   rays.computeHitPositions();
 
-  if (rays.getFlag(RayPacket::HaveNormals)) {
-    if (rays.getFlag(RayPacket::HaveUnitNormals))
-       return;
-  }
-  else {
-
-    for(int i=rays.begin(); i<rays.end(); i++) {
-      TriangleHit& th = rays.scratchpad<TriangleHit>(i);
+  for(int i=rays.begin(); i<rays.end(); i++) {
+    TriangleHit& th = rays.scratchpad<TriangleHit>(i);
       
-      Real a = th.a;
-      Real b = th.b;
-      Real c = (1.0 - th.a - th.b);
+    Real a = th.a;
+    Real b = th.b;
+    Real c = (1.0 - th.a - th.b);
     
-      Vector normal = (n[1]*a) + (n[2]*b) + (n[0]*c);
-      normal.normalize();
-      rays.setNormal(i, normal);
-    }
-
-    rays.setFlag(RayPacket::HaveUnitNormals);
+    Vector normal = (n[1]*a) + (n[2]*b) + (n[0]*c);
+    rays.setNormal(i, normal);
   }
-  
 }
 
 void HeavyTriangle::computeBounds(const PreprocessContext& context, BBox& 
bbox) const

Modified: branches/vertical/Model/Primitives/Hemisphere.cc
==============================================================================
--- branches/vertical/Model/Primitives/Hemisphere.cc    (original)
+++ branches/vertical/Model/Primitives/Hemisphere.cc    Wed Jan  4 11:26:44 
2006
@@ -2,7 +2,9 @@
 #include <Model/Primitives/Hemisphere.h>
 #include <Interface/RayPacket.h>
 #include <Core/Geometry/BBox.h>
+#include <Core/Math/Expon.h>
 #include <Core/Math/MiscMath.h>
+#include <Core/Math/Trig.h>
 
 // TODO: tighter bounds
 
@@ -10,123 +12,131 @@
 using namespace std;
 
 Hemisphere::Hemisphere(Material* material, const Point& center, Real radius, 
const Vector& normal)
-  : PrimitiveCommon(material, this), _c(center), _r(radius), _n(normal) {
+  : PrimitiveCommon(material, this), _c(center), _r(radius), _n(normal)
+{
   setupAxes();
+  _inv_r = 1/_inv_r;
 }
 
 Hemisphere::~Hemisphere() {
 }
 
-void Hemisphere::computeBounds(const PreprocessContext&, BBox& bbox) const {
+void Hemisphere::computeBounds(const PreprocessContext&, BBox& bbox) const
+{
   bbox.extendBySphere(_c, _r);
 }
 
-void Hemisphere::intersect(const RenderContext&, RayPacket& rays) const {
-  if (rpFlags == (RayPacket::ConstantOrigin | 
RayPacket::NormalizedDirections)) {
-    // Rays all have the same origin and unit-length directions
-    rayO = rays.get(0).ray.origin();
-    tRayO = rayO - _c;
-    c = Dot(tRayO, tRayO) - _r * _r;
-
-    for (i = 0; i < numRays; i++) {
-      RayPacket::Element& e(rays.get(i));
-      
-      rayD = e.ray.direction();
-      
-      b = Dot(tRayO, rayD);
-      disc = b * b - c;
-      
-      if (disc >= 0.0) {
-       r = sqrt(disc);
-       t = -(b + r);
-       if ((t > 0.0) && checkBounds(rayO + t * rayD)) {
-         e.hitInfo.hit(t, getMaterial(), this, getTexCoordMapper());
-       } else {
-         t = r - b;
-         if ((t > 0.0) && checkBounds(rayO + t * rayD)) {
-           e.hitInfo.hit(t, getMaterial(), this, getTexCoordMapper());
-         }
-       }
+void Hemisphere::intersect(const RenderContext&, RayPacket& rays) const
+{
+  switch(rays.getFlag(RayPacket::ConstantOrigin | 
RayPacket::NormalizedDirections)){
+  case RayPacket::ConstantOrigin | RayPacket::NormalizedDirections:
+    {
+      // Rays all have the same origin and unit-length directions
+      Point rayO = rays.getOrigin(rays.begin());
+      Vector tRayO = rayO - _c;
+      Real c = Dot(tRayO, tRayO) - _r * _r;
+      
+      for (int i = rays.begin(); i < rays.end(); i++) {
+        Vector rayD = rays.getDirection(i);
+        
+        Real b = Dot(tRayO, rayD);
+        Real disc = b * b - c;
+        
+        if (disc >= 0.0) {
+          Real r = Sqrt(disc);
+          Real t = -(b + r);
+          if (t > 0 && checkBounds(rayO + t * rayD)) {
+            rays.hit(i, t, getMaterial(), this, getTexCoordMapper());
+          } else {
+            t = r - b;
+            if (t > 0 && checkBounds(rayO + t * rayD)) {
+              rays.hit(i, t, getMaterial(), this, getTexCoordMapper());
+            }
+          }
+        }
       }
     }
-  } else if (rpFlags == RayPacket::ConstantOrigin) {
-    // Rays all have the same origin
-    rayO = rays.get(0).ray.origin();
-    tRayO = rayO - _c;
-    c = Dot(tRayO, tRayO) - _r * _r;
-
-    for (i = 0; i < numRays; i++) {
-      RayPacket::Element& e(rays.get(i));
-      
-      rayD = e.ray.direction();
-      
-      a = Dot(rayD, rayD);
-      b = Dot(tRayO, rayD);
-      disc = b * b - a * c;
-      
-      if (disc >= 0.0) {
-       r = sqrt(disc);
-       t = -(b + r) / a;
-       if ((t > 0.0) && checkBounds(rayO + t * rayD)) {
-         e.hitInfo.hit(t, getMaterial(), this, getTexCoordMapper());
-       } else {
-         t = (r - b) / a;
-         if ((t > 0.0) && checkBounds(rayO + t * rayD)) {
-           e.hitInfo.hit(t, getMaterial(), this, getTexCoordMapper());
-         }
-       }
+    break;
+  case RayPacket::ConstantOrigin:
+    {
+      // Rays all have the same origin
+      Point rayO = rays.getOrigin(rays.begin());
+      Vector tRayO = rayO - _c;
+      Real c = Dot(tRayO, tRayO) - _r * _r;
+      
+      for (int i = rays.begin(); i < rays.end(); i++) {
+        Vector rayD = rays.getDirection(i);
+        
+        Real a = Dot(rayD, rayD);
+        Real b = Dot(tRayO, rayD);
+        Real disc = b * b - a * c;
+        
+        if (disc >= 0.0) {
+          Real r = Sqrt(disc);
+          Real t = -(b + r) / a;
+          if (t > 0.0 && checkBounds(rayO + t * rayD)) {
+            rays.hit(i, t, getMaterial(), this, getTexCoordMapper());
+          } else {
+            t = (r - b) / a;
+            if (t > 0.0 && checkBounds(rayO + t * rayD)) {
+              rays.hit(i, t, getMaterial(), this, getTexCoordMapper());
+            }
+          }
+        }
       }
     }
-  } else if (rpFlags == RayPacket::NormalizedDirections) {
-    // Rays all have unit-length direction
-    for (i = 0; i < numRays; i++) {
-      RayPacket::Element& e(rays.get(i));
-      
-      rayO = e.ray.origin();
-      rayD = e.ray.direction();
-      tRayO = rayO - _c;
-      
-      b = Dot(tRayO, rayD);
-      c = Dot(tRayO, tRayO) - _r * _r;
-      disc = b * b - c;
-      
-      if (disc >= 0.0) {
-       r = sqrt(disc);
-       t = -(b + r);
-       if ((t > 0.0) && checkBounds(rayO + t * rayD)) {
-         e.hitInfo.hit(t, getMaterial(), this, getTexCoordMapper());
-       } else {
-         t = r - b;
-         if ((t > 0.0) && checkBounds(rayO + t * rayD)) {
-           e.hitInfo.hit(t, getMaterial(), this, getTexCoordMapper());
-         }
-       }
+    break;
+  case RayPacket::NormalizedDirections:
+    {
+      // Rays all have unit-length direction
+      for (int i = rays.begin(); i < rays.end(); i++) {
+        Point rayO = rays.getOrigin(i);
+        Vector rayD = rays.getDirection(i);
+        Vector tRayO = rayO - _c;
+        
+        Real b = Dot(tRayO, rayD);
+        Real c = Dot(tRayO, tRayO) - _r * _r;
+        Real disc = b * b - c;
+        
+        if (disc >= 0.0) {
+          Real r = Sqrt(disc);
+          Real t = -(b + r);
+          if (t > 0.0 && checkBounds(rayO + t * rayD)) {
+            rays.hit(i, t, getMaterial(), this, getTexCoordMapper());
+          } else {
+            t = r - b;
+            if (t > 0.0 && checkBounds(rayO + t * rayD)) {
+              rays.hit(i, t, getMaterial(), this, getTexCoordMapper());
+            }
+          }
+        }
       }
     }
-  } else {
-    // General rays
-    for (i = 0; i < numRays; i++) {
-      RayPacket::Element& e(rays.get(i));
-      
-      rayO = e.ray.origin();
-      rayD = e.ray.direction();
-      tRayO = rayO - _c;
-      
-      a = Dot(rayD, rayD);
-      b = Dot(tRayO, rayD);
-      c = Dot(tRayO, tRayO) - _r * _r;
-      disc = b * b - a * c;
-      
-      if (disc >= 0.0) {
-       r = sqrt(disc);
-       t = -(b + r) / a;
-       if ((t > 0.0) && checkBounds(rayO + t * rayD)) {
-         e.hitInfo.hit(t, getMaterial(), this, getTexCoordMapper());
-       } else {
-         t = (r - b) / a;
-         if ((t > 0.0) && checkBounds(rayO + t * rayD)) {
-           e.hitInfo.hit(t, getMaterial(), this, getTexCoordMapper());
-         }
+    break;
+  case 0:
+    {
+      // General rays
+      for (int i = rays.begin(); i < rays.end(); i++) {
+        Point rayO = rays.getOrigin(i);
+        Vector rayD = rays.getDirection(i);
+        Vector tRayO = rayO - _c;
+        
+        Real a = Dot(rayD, rayD);
+        Real b = Dot(tRayO, rayD);
+        Real c = Dot(tRayO, tRayO) - _r * _r;
+        Real disc = b * b - a * c;
+        
+        if (disc >= 0.0) {
+          Real r = Sqrt(disc);
+          Real t = -(b + r) / a;
+          if ((t > 0.0) && checkBounds(rayO + t * rayD)) {
+            rays.hit(i, t, getMaterial(), this, getTexCoordMapper());
+          } else {
+            t = (r - b) / a;
+            if (t > 0.0 && checkBounds(rayO + t * rayD)) {
+              rays.hit(i, t, getMaterial(), this, getTexCoordMapper());
+            }
+          }
        }
       }
     }
@@ -134,53 +144,43 @@
 }
 
 void Hemisphere::computeNormal(const RenderContext& /*context*/,
-                               RayPacket& rays) const {
-  int i, numRays(rays.getSize());
-
-  if (!(rays.getFlag(RayPacket::HaveHitPositions)))
-    rays.computeHitPositions();
-
-  for (i = 0; i < numRays; i++) {
-    RayPacket::Element& e = rays.get(i);
-    e.normal = e.hitPosition - _c;
-    e.normal.normalize();
-  }
-
-  rays.setFlag(RayPacket::HaveNormals | RayPacket::HaveUnitNormals);
+                               RayPacket& rays) const
+{
+  rays.computeHitPositions();
+
+  for (int i = rays.begin(); i < rays.end(); i++)
+    rays.setNormal(i, (rays.getHitPosition(i) - _c) * _inv_r);
+  rays.setFlag(RayPacket::HaveUnitNormals);
 }
 
-void Hemisphere::computeTexCoords2(const RenderContext& context, RayPacket& 
rays) const {
-  int i, numRays(rays.getSize());
-  Vector n;
-  Real theta, phi;
-
-  if (!(rays.getFlag(RayPacket::HaveUnitNormals)))
+void Hemisphere::computeTexCoords2(const RenderContext& context, RayPacket& 
rays) const
+{
+  if (!(rays.getFlag(RayPacket::HaveNormals & RayPacket::HaveUnitNormals)))
     computeNormal(context, rays);
 
-  for (i = 0; i < numRays; i++) {
-    RayPacket::Element& e(rays.get(i));
-    n = e.normal;
-    theta = acos(Dot(_n, n));
-    phi = atan2(Dot(_u, n), Dot(_v, n));
-    e.texCoords = Point(0.5 * phi / M_PI, 2.0 * theta / M_PI, 0.0);
+  for (int i = rays.begin(); i < rays.end(); i++) {
+    Vector n = rays.getNormal(i);
+    Real theta = Acos(Dot(_n, n));
+    Real phi = Atan2(Dot(_u, n), Dot(_v, n));
+    rays.setTexCoords(i, Point(0.5 * phi / M_PI, 2.0 * theta / M_PI, 0.0));
   }
 
-  rays.setFlag(RayPacket::HaveTexture2);
+  rays.setFlag(RayPacket::HaveTexture2 | RayPacket::HaveTexture3);
 }
 
-void Hemisphere::computeTexCoords3(const RenderContext&, RayPacket& rays) 
const {
-  int i, numRays(rays.getSize());
-  Vector n;
-
-  if (!(rays.getFlag(RayPacket::HaveHitPositions)))
-    rays.computeHitPositions();
+void Hemisphere::computeTexCoords3(const RenderContext& context, RayPacket& 
rays) const
+{
+  if (!(rays.getFlag(RayPacket::HaveNormals & RayPacket::HaveUnitNormals)))
+    computeNormal(context, rays);
 
-  for (i = 0; i < numRays; i++) {
-    RayPacket::Element& e(rays.get(i));
-    e.texCoords = e.hitPosition;
+  for (int i = rays.begin(); i < rays.end(); i++) {
+    Vector n = rays.getNormal(i);
+    Real theta = Acos(Dot(_n, n));
+    Real phi = Atan2(Dot(_u, n), Dot(_v, n));
+    rays.setTexCoords(i, Point(0.5 * phi / M_PI, 2.0 * theta / M_PI, 0.0));
   }
 
-  rays.setFlag(RayPacket::HaveTexture3);
+  rays.setFlag(RayPacket::HaveTexture2 | RayPacket::HaveTexture3);
 }
 
 /**
@@ -189,16 +189,16 @@
  * Given a point p assumed to lie on the sphere, checks to make sure it lies
  * within the correct hemisphere.
  **/
-bool Hemisphere::checkBounds(const Point& p) const {
+bool Hemisphere::checkBounds(const Point& p) const
+{
   return (Dot(_n, p - _c) >= 0.0);
 }
 
-void Hemisphere::setupAxes() {
-  static const Real EPSILON(1.0e-6);
-
+void Hemisphere::setupAxes()
+{
   _u = Vector(1, 0, 0);
   _v = Cross(_n, _u);
-  if (_v.length2() < EPSILON) {
+  if (_v.length2() < T_EPSILON) {
     _u = Vector(0, 1, 0);
     _v = Cross(_n, _u);
   }

Modified: branches/vertical/Model/Primitives/Hemisphere.h
==============================================================================
--- branches/vertical/Model/Primitives/Hemisphere.h     (original)
+++ branches/vertical/Model/Primitives/Hemisphere.h     Wed Jan  4 11:26:44 
2006
@@ -21,6 +21,7 @@
   private:
     Point _c;
     Real _r;
+    Real _inv_r;
     Vector _n, _u, _v;
 
     bool checkBounds(const Point& p) const;

Modified: branches/vertical/Model/Primitives/ParticleBVH.cc
==============================================================================
--- branches/vertical/Model/Primitives/ParticleBVH.cc   (original)
+++ branches/vertical/Model/Primitives/ParticleBVH.cc   Wed Jan  4 11:26:44 
2006
@@ -116,15 +116,16 @@
   bound[ 4 ] = box.getMin().z(); bound[ 5 ] = box.getMax().z();
   for ( int ray = rays.begin(); ray < rays.end(); ++ray ) {
     double maximum_minimum = T_EPSILON;
-    double minimum_maximum = element.hitInfo.minT();
-    Point O = rays.getOrigin(i);
-    Vector id = rays.getInverseDirection(i);
-    double x_minimum = ( bound[     element.sign[ 0 ] ] - O.x() ) * 
element.inverseDirection.x();
-    double x_maximum = ( bound[ 1 - element.sign[ 0 ] ] - O.x() ) * 
element.inverseDirection.x();
-    double y_minimum = ( bound[ 2 + element.sign[ 1 ] ] - O.y() ) * 
element.inverseDirection.y();
-    double y_maximum = ( bound[ 3 - element.sign[ 1 ] ] - O.y() ) * 
element.inverseDirection.y();
-    double z_minimum = ( bound[ 4 + element.sign[ 2 ] ] - O.z() ) * 
element.inverseDirection.z();
-    double z_maximum = ( bound[ 5 - element.sign[ 2 ] ] - O.z() ) * 
element.inverseDirection.z();
+    double minimum_maximum = rays.getMinT(ray);
+    Point O = rays.getOrigin(ray);
+    Vector inverseDirection = rays.getInverseDirection(ray);
+    VectorT<int, 3> signs = rays.getSigns(ray);
+    double x_minimum = ( bound[     signs[ 0 ] ] - O.x() ) * 
inverseDirection.x();
+    double x_maximum = ( bound[ 1 - signs[ 0 ] ] - O.x() ) * 
inverseDirection.x();
+    double y_minimum = ( bound[ 2 + signs[ 1 ] ] - O.y() ) * 
inverseDirection.y();
+    double y_maximum = ( bound[ 3 - signs[ 1 ] ] - O.y() ) * 
inverseDirection.y();
+    double z_minimum = ( bound[ 4 + signs[ 2 ] ] - O.z() ) * 
inverseDirection.z();
+    double z_maximum = ( bound[ 5 - signs[ 2 ] ] - O.z() ) * 
inverseDirection.z();
     if ( minimum_maximum < x_minimum ||
          maximum_minimum > x_maximum )
       continue;
@@ -154,22 +155,21 @@
   for ( int current = first; current < last; ++current ) {
     Particle &particle( particles[ current ] );
     double radius_squared = particle.radius * particle.radius;
-    for ( int ray = 0; ray < rays.getSize(); ray++ ) {
-      RayPacket::Element &element( rays.get( ray ) );
-      Vector offset( element.ray.origin() - particle.center );
-      double B = Dot( offset, element.ray.direction() );
+    for ( int ray = rays.begin(); ray < rays.end(); ray++ ) {
+      Vector offset( rays.getOrigin(ray) - particle.center );
+      double B = Dot( offset, rays.getDirection(ray) );
       double C = Dot( offset, offset ) - radius_squared;
       double discriminant = B * B - C;
       if ( discriminant >= 0.0 ) {
         double r = sqrt( discriminant );
         double t0 = -r - B;
         if( t0 > 0.0 )
-          if ( element.hitInfo.hit( t0, getMaterial(), this, 
getTexCoordMapper() ) )
-            element.hitInfo.scratchpad< int >() = current;
+          if ( rays.hit( ray, t0, getMaterial(), this, getTexCoordMapper() ) 
)
+            rays.scratchpad< int >(ray) = current;
         else {
           double t1 = r - B;
-          if ( element.hitInfo.hit( t1, getMaterial(), this, 
getTexCoordMapper() ) )
-            element.hitInfo.scratchpad< int >() = current;
+          if ( rays.hit( ray, t1, getMaterial(), this, getTexCoordMapper() ) 
)
+            rays.scratchpad< int >(ray) = current;
         }
       }
     }
@@ -186,15 +186,15 @@
   int stack[ maximum_depth ];
   int stack_position = 0;
   int current = 0;
-  RayPacket::Element& element_0( rays.get( 0 ) );
+  VectorT<int, 3> signs = rays.getSigns(rays.begin());
   for ( ; ; ) {
     Node &node( nodes[ current ] );
     if ( testBox( rays, node.bound ) ) {
       if ( node.leaf )
         intersectParticles( rays, node.index, node.index + node.length );
       else {
-        stack[ stack_position++ ] = node.index + 1 - element_0.sign[ 
node.axis ];
-        current = node.index + element_0.sign[ node.axis ];
+        stack[ stack_position++ ] = node.index + 1 - signs[node.axis];
+        current = node.index + signs[ node.axis ];
         continue;
       }
     }
@@ -209,10 +209,9 @@
   RayPacket &rays ) const
 {
   rays.computeHitPositions();
-  for ( int ray = 0; ray < rays.getSize(); ++ray ) {
-    RayPacket::Element &element( rays.get( ray ) );
-    Particle &particle( particles[ element.hitInfo.scratchpad< int >() ] );
-    element.normal = ( element.hitPosition - particle.center ) * 
particle.inverse_radius;
+  for ( int ray = rays.begin(); ray < rays.end(); ++ray ) {
+    Particle &particle( particles[ rays.scratchpad< int >(ray) ] );
+    rays.setNormal(ray, ( rays.getHitPosition(ray) - particle.center ) * 
particle.inverse_radius);
   }
   rays.setFlag( RayPacket::HaveUnitNormals );
 }
@@ -232,6 +231,6 @@
     RayPacket &rays,
     Color results[] ) const
 {
-    for ( int ray = 0; ray < rays.getSize(); ray++ )
-      results[ ray ] = particlebvh->particles[ rays.get( ray 
).hitInfo.scratchpad< int >() ].color;
+  for ( int ray = rays.begin(); ray < rays.end(); ray++ )
+      results[ ray ] = particlebvh->particles[ rays.scratchpad< int >(ray) 
].color;
 }

Modified: branches/vertical/Model/Primitives/Ring.cc
==============================================================================
--- branches/vertical/Model/Primitives/Ring.cc  (original)
+++ branches/vertical/Model/Primitives/Ring.cc  Wed Jan  4 11:26:44 2006
@@ -57,11 +57,10 @@
 void Ring::intersect(const RenderContext&, RayPacket& rays) const
 {
   rays.normalizeDirections();
-  for(int i=0; i<rays.getSize(); i++)
+  for(int i=rays.begin(); i<rays.end(); i++)
   {
-    RayPacket::Element& e = rays.get(i);
-    Vector dir(e.ray.direction());
-    Point orig(e.ray.origin());
+    Vector dir(rays.getDirection(i));
+    Point orig(rays.getOrigin(i));
     Real dt = Dot(dir, normal);
 //     // Check for when the ray is parallel to the plane of the ring.
 //     if(dt < 1.e-6 && dt > -1.e-6)
@@ -76,15 +75,14 @@
     Point hitPosition(orig+dir*t);
     Real l = (hitPosition-center).length2();
     if(l > radius2 && l < outer_radius2)
-      e.hitInfo.hit(t, getMaterial(), this, getTexCoordMapper());
+      rays.hit(i, t, getMaterial(), this, getTexCoordMapper());
   }
 }
 
 
 void Ring::computeNormal(const RenderContext&, RayPacket& rays) const
 {
-  for(int i=0; i<rays.getSize(); i++) {
-    RayPacket::Element& e = rays.get(i);
-    e.normal = normal;
+  for(int i=rays.begin(); i<rays.end(); i++) {
+    rays.setNormal(i, normal);
   }
 }

Modified: branches/vertical/Model/Primitives/SuperEllipsoid.cc
==============================================================================
--- branches/vertical/Model/Primitives/SuperEllipsoid.cc        (original)
+++ branches/vertical/Model/Primitives/SuperEllipsoid.cc        Wed Jan  4 
11:26:44 2006
@@ -86,16 +86,16 @@
 {
 
   rays.computeInverseDirections();
-  for( int i = 0; i < rays.getSize(); ++i ) {
-    RayPacket::Element& e( rays.get(i) );
-    Vector offset_center = e.ray.origin() - center;
+  for( int i = rays.begin(); i < rays.end(); ++i ) {
+    Vector offset_center = rays.getOrigin(i) - center;
 
     // First check if the ray hits the bounding box and whether it could
     // remotely produce a hit of interest.
     // TODO: Maybe factor this out into a common routine?
+    Vector inverseDirection = rays.getInverseDirection(i);
     Real tnear, tfar, t1, t2;
-    t1 = ( -radius - offset_center.x() ) * e.inverseDirection.x();
-    t2 = ( radius - offset_center.x() ) * e.inverseDirection.x();
+    t1 = ( -radius - offset_center.x() ) * inverseDirection.x();
+    t2 = ( radius - offset_center.x() ) * inverseDirection.x();
     if( t1 > t2 ) {
       Real temp = t1;
       t1 = t2;
@@ -103,8 +103,8 @@
     }
     tnear = t1;
     tfar = t2;
-    t1 = ( -radius - offset_center.y() ) * e.inverseDirection.y();
-    t2 = ( radius - offset_center.y() ) * e.inverseDirection.y();
+    t1 = ( -radius - offset_center.y() ) * inverseDirection.y();
+    t2 = ( radius - offset_center.y() ) * inverseDirection.y();
     if( t1 > t2 ) {
       Real temp = t1;
       t1 = t2;
@@ -114,29 +114,31 @@
     using SCIRun::Min;
     tnear = Max( t1, tnear );
     tfar = Min( t2, tfar );
-    t1 = ( -radius - offset_center.z() ) * e.inverseDirection.z();
-    t2 = ( radius - offset_center.z() ) * e.inverseDirection.z();
+    t1 = ( -radius - offset_center.z() ) * inverseDirection.z();
+    t2 = ( radius - offset_center.z() ) * inverseDirection.z();
     if( t1 > t2 ) {
       Real temp = t1;
       t1 = t2;
       t2 = temp;
     }
     tnear = Max( Max( t1, tnear ), (Real)T_EPSILON );
-    tfar = Min( Min( t2, tfar ), e.hitInfo.minT() );
+    tfar = Min( Min( t2, tfar ), rays.getMinT(i) );
 
-    if ( tnear > tfar || tfar <= T_EPSILON || tnear >= e.hitInfo.minT() )
+    if ( tnear > tfar || tfar <= T_EPSILON || tnear >= rays.getMinT(i) )
       continue;
 
     // A few preliminary early exit tests...
     Real near_value, far_value;
+    Point rayO = rays.getOrigin(i);
+    Vector rayD = rays.getDirection(i);
     Real near_deriv = Dot( functionGradient(
-                                 ( e.ray.origin() + tnear * 
e.ray.direction() ),
-                                 near_value ),
-                             e.ray.direction() );
+                                ( rayO + tnear * rayD ),
+                                near_value ),
+                             rayD );
     Real far_deriv = Dot( functionGradient(
-                                ( e.ray.origin() + tfar * e.ray.direction() 
),
+                                ( rayO + tfar * rayD ),
                                 far_value ),
-                            e.ray.direction() );
+                             rayD );
     if ( ( near_value < (Real)T_EPSILON && far_value < (Real)T_EPSILON ) ||
          ( near_value * far_value > 0 && near_deriv * far_deriv > 0 ) )
       continue;
@@ -148,23 +150,23 @@
       Real b_bracket = tfar;
       Real left = GOLDENMEAN * a_bracket + ( 1 - GOLDENMEAN ) * b_bracket;
       Real left_value = functionValue(
-        Point( (offset_center + left * e.ray.direction() ) * inv_radius ));
+        Point( (offset_center + left * rayD ) * inv_radius ));
       Real right = ( 1 - GOLDENMEAN ) * a_bracket + GOLDENMEAN * b_bracket;
       Real right_value = functionValue(
-        Point( (offset_center + right * e.ray.direction() ) * inv_radius ));
+        Point( (offset_center + right * rayD ) * inv_radius ));
       while( SCIRun::Abs( b_bracket - a_bracket ) > BRACKETWIDTH ) {
         if ( left_value < right_value ) {
           b_bracket = right;
           right = left;
           right_value = left_value;
           left = GOLDENMEAN * a_bracket + ( 1 - GOLDENMEAN ) * b_bracket;
-          left_value = functionValue( e.ray.origin() + left * 
e.ray.direction() );
+          left_value = functionValue( rayO + left * rayD );
         } else {
           a_bracket = left;
           left = right;
           left_value = right_value;
           right = ( 1 - GOLDENMEAN ) * a_bracket + GOLDENMEAN * b_bracket;
-          right_value = functionValue( e.ray.origin() + right * 
e.ray.direction() );
+          right_value = functionValue( rayO + right * rayD );
         }
       }
 
@@ -193,9 +195,9 @@
     Real troot = ( tnear + tfar ) * (Real)0.5;
     Real root_value;
     Real root_deriv = Dot( logarithmFunctionGradient(
-                                 e.ray.origin() + troot * e.ray.direction(),
-                                 root_value ),
-                             e.ray.direction() );
+                                                     rayO + troot * rayD,
+                                                     root_value ),
+                           rayD );
     int iterations = 0;
     while ( SCIRun::Abs( tfar - tnear ) >= (Real)T_EPSILON &&
             SCIRun::Abs( root_value ) >= (Real)T_EPSILON &&
@@ -211,13 +213,13 @@
       if ( troot <= tnear || troot >= tfar )
         troot = ( tnear + tfar ) * (Real)0.5;
       root_deriv = Dot( logarithmFunctionGradient(
-                            e.ray.origin() + troot * e.ray.direction(),
+                            rayO + troot * rayD,
                             root_value ),
-                        e.ray.direction() );
+                        rayD );
     }
 
     // Finally, set the hit location
-    e.hitInfo.hit( troot, getMaterial(), this, getTexCoordMapper() );
+    rays.hit( i, troot, getMaterial(), this, getTexCoordMapper() );
 
   }
 
@@ -229,12 +231,8 @@
 {
   Real ignored;
   rays.computeHitPositions();
-  for( int i = 0; i < rays.getSize(); i++ ) {
-    RayPacket::Element &e( rays.get( i ) );
-    e.normal = functionGradient( e.hitPosition, ignored );
-    e.normal.normalize();
-  }
-  rays.setFlag(RayPacket::HaveNormals | RayPacket::HaveUnitNormals);
+  for( int i = rays.begin(); i < rays.end(); i++ )
+    rays.setNormal(i, functionGradient( rays.getHitPosition(i), ignored ));
 }
 
 void SuperEllipsoid::computeTexCoords2(
@@ -242,15 +240,14 @@
   RayPacket &rays ) const
 {
   rays.computeHitPositions();
-  for( int i = 0; i < rays.getSize(); i++ ) {
-    RayPacket::Element &e( rays.get( i ) );
-    Vector n = ( e.hitPosition - center ) * inv_radius;
+  for( int i = rays.begin(); i < rays.end(); i++ ) {
+    Vector n = ( rays.getHitPosition(i) - center ) * inv_radius;
     Real angle = Clamp( n.z(), (Real)-1, (Real)1 );
     Real theta = Acos( angle );
     Real phi = Atan2( n.x(), n.y() );
-    e.texCoords = Point( ( phi + (Real)M_PI ) * (Real)( 0.5 * M_1_PI ),
-                         theta * (Real)M_1_PI,
-                         0. );
+    rays.setTexCoords(i, Point( ( phi + (Real)M_PI ) * (Real)( 0.5 * M_1_PI 
),
+                                theta * (Real)M_1_PI,
+                                0. ));
   }
   rays.setFlag( RayPacket::HaveTexture2 | RayPacket::HaveTexture3 );
 }
@@ -260,15 +257,14 @@
   RayPacket &rays ) const
 {
   rays.computeHitPositions();
-  for( int i = 0; i < rays.getSize(); i++ ) {
-    RayPacket::Element &e = rays.get( i );
-    Vector n = ( e.hitPosition - center ) * inv_radius;
+  for( int i = rays.begin(); i < rays.end(); i++ ) {
+    Vector n = ( rays.getHitPosition(i) - center ) * inv_radius;
     Real angle = Clamp( n.z(), (Real)-1, (Real)1 );
     Real theta = Acos( angle );
     Real phi = Atan2( n.x(), n.y() );
-    e.texCoords = Point( ( phi + (Real)M_PI ) * (Real)( 0.5 * M_1_PI ),
-                         theta * (Real)M_1_PI,
-                         0. );
+    rays.setTexCoords(i, Point( ( phi + (Real)M_PI ) * (Real)( 0.5 * M_1_PI 
),
+                                theta * (Real)M_1_PI,
+                                0. ));
   }
   rays.setFlag( RayPacket::HaveTexture2 | RayPacket::HaveTexture3 );
 }

Modified: branches/vertical/Model/Primitives/TexTriangle.cc
==============================================================================
--- branches/vertical/Model/Primitives/TexTriangle.cc   (original)
+++ branches/vertical/Model/Primitives/TexTriangle.cc   Wed Jan  4 11:26:44 
2006
@@ -13,18 +13,15 @@
 //Performs the exact same operation as computeTexCoords3
 void TexTriangle::computeTexCoords2(const RenderContext& /*context*/, 
RayPacket& rays) const {
 
-  int size = rays.getSize();
-  for(int i=0; i<size; i++) {
-    RayPacket::Element& e = rays.get(i);
-    
-    TriangleHit& th = e.hitInfo.scratchpad<TriangleHit>();
+  for(int i=rays.begin(); i<rays.end(); i++) {
+    TriangleHit& th = rays.scratchpad<TriangleHit>(i);
     Real a = th.a;
     Real b = th.b;
     Real c = (1.0 - a - b);
 
     TexTriangle *t = (TexTriangle *)th.ptr;
     
-    e.texCoords = Point((t->tex[1] * a) + (t->tex[2] * b) +(t->tex[0] * c));
+    rays.setTexCoords(i, Point((t->tex[1] * a) + (t->tex[2] * b) +(t->tex[0] 
* c)));
   }
   rays.setFlag( RayPacket::HaveTexture2|RayPacket::HaveTexture3 );
 }
@@ -34,14 +31,14 @@
 {
   rays.normalizeDirections();
   
-  for(int i=0; i<rays.getSize(); i++) {
-    RayPacket::Element& e = rays.get(i);
+  for(int i=rays.begin(); i<rays.end(); i++) {
     Real t, u, v;
     
-    if (Intersection::intersectTriangleEdge( t, u, v, e.ray, edge[0], 
edge[1], point ) &&
-        e.hitInfo.hit( t, getMaterial(), this, getTexCoordMapper() )) {
+    if (Intersection::intersectTriangleEdge( t, u, v, rays.getRay(i),
+                                             edge[0], edge[1], point ) &&
+        rays.hit( i, t, getMaterial(), this, getTexCoordMapper() )) {
       
-      TriangleHit& th = e.hitInfo.scratchpad<TriangleHit>();
+      TriangleHit& th = rays.scratchpad<TriangleHit>(i);
       th.a = u;
       th.b = v;
       th.ptr = this;

Modified: branches/vertical/Model/Primitives/Triangle.cc
==============================================================================
--- branches/vertical/Model/Primitives/Triangle.cc      (original)
+++ branches/vertical/Model/Primitives/Triangle.cc      Wed Jan  4 11:26:44 
2006
@@ -37,9 +37,8 @@
   Vector _e2 = p3-p1;
   //  Vector _n = Cross(_e1, _e2);
 
-  for(int i=0; i<rays.getSize(); i++) {
-    RayPacket::Element& e = rays.get(i);
-    Vector o(p1 - e.ray.origin());
+  for(int i=rays.begin(); i<rays.end(); i++) {
+    Vector o(p1 - rays.getOrigin(i));
 
 #if 0
     const Vector& dir(e.ray.direction());
@@ -57,10 +56,11 @@
 
           Real t, A, B;
 
-          bool h = Intersection::intersectTriangleEdge( t, A, B, e.ray, _e1, 
_e2, p1 );
+          bool h = Intersection::intersectTriangleEdge( t, A, B, 
rays.getRay(i),
+                                                        _e1, _e2, p1 );
 
-          if (h && e.hitInfo.hit(t, getMaterial(), this, 
getTexCoordMapper())){
-            TriangleHit& th = e.hitInfo.scratchpad<TriangleHit>();
+          if (h && rays.hit(i, t, getMaterial(), this, getTexCoordMapper())){
+            TriangleHit& th = rays.scratchpad<TriangleHit>(i);
             th.a = A;
             th.b = B;
           }
@@ -76,26 +76,8 @@
 void Triangle::computeNormal(const RenderContext&, RayPacket& rays) const
 {
   rays.computeHitPositions();
-
-  if (rays.getFlag(RayPacket::HaveNormals)){
-    if (rays.getFlag(RayPacket::HaveUnitNormals))
-       return;
-
-    int nrays = rays.getSize();
-    for(int i=0; i<nrays; i++){
-       rays.get(i).normal.normalize();
-    }
-    rays.setFlag(RayPacket::HaveUnitNormals);
-  }
-  else{
-    int nrays = rays.getSize();
-    for(int i=0; i<nrays; i++) {
-      RayPacket::Element& e = rays.get(i);
-      e.normal = Cross((p3-p1),(p2-p1));
-      e.normal.normalize();
-    }
-    rays.setFlag(RayPacket::HaveUnitNormals);
-  }
+  for(int i=rays.begin(); i<rays.end(); i++)
+    rays.setNormal(i, Cross((p3-p1),(p2-p1)));
 }
 
 




  • [MANTA] r814 - in branches/vertical: Interface Model/Intersections Model/Primitives, sparker, 01/04/2006

Archive powered by MHonArc 2.6.16.

Top of page