Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r857 - in trunk: . Core/Color Core/Geometry Core/Math Core/XUtils Engine/Control Engine/PixelSamplers Engine/Renderers Engine/Shadows Image Interface Model/AmbientLights Model/Backgrounds Model/Cameras Model/Groups Model/Instances Model/Intersections Model/Lights Model/Materials Model/MiscObjects Model/Primitives Model/TexCoordMappers Model/Textures SCIRun/include/sci_defs StandAlone SwigInterface UserInterface fox/FManta fox/disco_demo/Engine/ImageTraversers fox/disco_demo/Engine/Renderers fox/disco_demo/Engine/Shaders fox/disco_demo/Interface scenes tests/perftest


Chronological Thread 
  • From: bigler@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r857 - in trunk: . Core/Color Core/Geometry Core/Math Core/XUtils Engine/Control Engine/PixelSamplers Engine/Renderers Engine/Shadows Image Interface Model/AmbientLights Model/Backgrounds Model/Cameras Model/Groups Model/Instances Model/Intersections Model/Lights Model/Materials Model/MiscObjects Model/Primitives Model/TexCoordMappers Model/Textures SCIRun/include/sci_defs StandAlone SwigInterface UserInterface fox/FManta fox/disco_demo/Engine/ImageTraversers fox/disco_demo/Engine/Renderers fox/disco_demo/Engine/Shaders fox/disco_demo/Interface scenes tests/perftest
  • Date: Fri, 20 Jan 2006 15:03:17 -0700 (MST)

Author: bigler
Date: Fri Jan 20 15:03:05 2006
New Revision: 857

Added:
   trunk/Image/NRRDFile-stub.cc
      - copied unchanged from r855, branches/vertical/Image/NRRDFile-stub.cc
   trunk/Model/Instances/MPT.h
      - copied unchanged from r855, branches/vertical/Model/Instances/MPT.h
Removed:
   trunk/Interface/HitInfo.cc
   trunk/Interface/HitInfo.h
Modified:
   trunk/CMakeLists.txt
   trunk/Core/Color/ColorSpace.h
   trunk/Core/Color/ColorSpace_fancy.h
   trunk/Core/Geometry/BBox.h
   trunk/Core/Geometry/PointVector.h
   trunk/Core/Math/CatmullRomInterpolator.h
   trunk/Core/XUtils/XHelper.cc
   trunk/Engine/Control/RTRT.cc
   trunk/Engine/Control/RTRT.h
   trunk/Engine/Control/RTRT_register.cc
   trunk/Engine/PixelSamplers/JitterSampler.cc
   trunk/Engine/PixelSamplers/SingleSampler.cc
   trunk/Engine/Renderers/Moire.cc
   trunk/Engine/Renderers/NullRenderer.cc
   trunk/Engine/Renderers/Raytracer.cc
   trunk/Engine/Shadows/BeamShadows.cc
   trunk/Engine/Shadows/BeamShadows.h
   trunk/Engine/Shadows/HardShadows.cc
   trunk/Engine/Shadows/HardShadows.h
   trunk/Engine/Shadows/NoShadows.cc
   trunk/Engine/Shadows/NoShadows.h
   trunk/Image/CMakeLists.txt
   trunk/Image/SimpleImage.h
   trunk/Interface/AmbientLight.h
   trunk/Interface/CMakeLists.txt
   trunk/Interface/Fragment.cc
   trunk/Interface/Light.h
   trunk/Interface/LightSet.h
   trunk/Interface/MantaInterface.h
   trunk/Interface/Parameters.h
   trunk/Interface/RayPacket.h
   trunk/Interface/RenderParameters.h
   trunk/Interface/ShadowAlgorithm.h
   trunk/Interface/TexCoordMapper.h
   trunk/MantaTypes.h
   trunk/Model/AmbientLights/ArcAmbient.cc
   trunk/Model/AmbientLights/ArcAmbient.h
   trunk/Model/AmbientLights/CMakeLists.txt
   trunk/Model/AmbientLights/ConstantAmbient.cc
   trunk/Model/AmbientLights/ConstantAmbient.h
   trunk/Model/Backgrounds/ConstantBackground.cc
   trunk/Model/Backgrounds/LinearBackground.cc
   trunk/Model/Backgrounds/TextureBackground.cc
   trunk/Model/Cameras/EnvironmentCamera.cc
   trunk/Model/Cameras/FisheyeCamera.cc
   trunk/Model/Cameras/OrthogonalCamera.cc
   trunk/Model/Cameras/PinholeCamera.cc
   trunk/Model/Groups/BVH.cc
   trunk/Model/Groups/BVH.h
   trunk/Model/Groups/CMakeLists.txt
   trunk/Model/Groups/GriddedGroup.cc
   trunk/Model/Groups/GriddedGroup.h
   trunk/Model/Groups/KDTree.cc
   trunk/Model/Groups/KDTree.h
   trunk/Model/Groups/RealisticBvh.cc
   trunk/Model/Groups/TransparentKDTree.cc
   trunk/Model/Groups/TransparentKDTree.h
   trunk/Model/Instances/Instance.cc
   trunk/Model/Instances/InstanceRST.cc
   trunk/Model/Instances/InstanceRT.cc
   trunk/Model/Instances/InstanceST.cc
   trunk/Model/Instances/InstanceT.cc
   trunk/Model/Intersections/AxisAlignedBox.h
   trunk/Model/Lights/CMakeLists.txt
   trunk/Model/Lights/HeadLight.cc
   trunk/Model/Lights/HeadLight.h
   trunk/Model/Lights/PointLight.cc
   trunk/Model/Lights/PointLight.h
   trunk/Model/Materials/AmbientOcclusion.cc
   trunk/Model/Materials/AmbientOcclusion.h
   trunk/Model/Materials/Checker.cc
   trunk/Model/Materials/Dielectric.cc
   trunk/Model/Materials/Flat.cc
   trunk/Model/Materials/Lambertian.cc
   trunk/Model/Materials/MetalMaterial.cc
   trunk/Model/Materials/NormalMaterial.cc
   trunk/Model/Materials/Phong.cc
   trunk/Model/MiscObjects/CMakeLists.txt
   trunk/Model/MiscObjects/CuttingPlane.cc
   trunk/Model/MiscObjects/Difference.cc
   trunk/Model/MiscObjects/Intersection.cc
   trunk/Model/Primitives/BvhTriangleMesh.cc
   trunk/Model/Primitives/Cone.cc
   trunk/Model/Primitives/Cone.h
   trunk/Model/Primitives/Cube.cc
   trunk/Model/Primitives/Cube.h
   trunk/Model/Primitives/Disk.cc
   trunk/Model/Primitives/Disk.h
   trunk/Model/Primitives/HeavyTriangle.cc
   trunk/Model/Primitives/Heightfield.cc
   trunk/Model/Primitives/Heightfield.h
   trunk/Model/Primitives/Hemisphere.cc
   trunk/Model/Primitives/Hemisphere.h
   trunk/Model/Primitives/Parallelogram.cc
   trunk/Model/Primitives/ParticleBVH.cc
   trunk/Model/Primitives/Plane.cc
   trunk/Model/Primitives/PrimitiveCommon.h
   trunk/Model/Primitives/Ring.cc
   trunk/Model/Primitives/Sphere.cc
   trunk/Model/Primitives/SuperEllipsoid.cc
   trunk/Model/Primitives/TexTriangle.cc
   trunk/Model/Primitives/Triangle.cc
   trunk/Model/TexCoordMappers/LinearMapper.cc
   trunk/Model/TexCoordMappers/SphericalMapper.cc
   trunk/Model/TexCoordMappers/UniformMapper.cc
   trunk/Model/Textures/CheckerTexture.h
   trunk/Model/Textures/Constant.h
   trunk/Model/Textures/ImageTexture.h
   trunk/Model/Textures/MarbleTexture.h
   trunk/Model/Textures/OakTexture.h
   trunk/Model/Textures/TexCoordTexture.cc
   trunk/Model/Textures/TriVerTexture.cc
   trunk/Model/Textures/WoodTexture.h
   trunk/SCIRun/include/sci_defs/error_defs.h
   trunk/StandAlone/CMakeLists.txt
   trunk/StandAlone/manta.cc
   trunk/SwigInterface/manta.i
   trunk/UserInterface/CameraPathAutomator.cc
   trunk/UserInterface/CameraPathAutomator.h
   trunk/UserInterface/XWindowUI.cc
   trunk/fox/FManta/CMakeLists.txt
   trunk/fox/FManta/FMantaImageFrame.cc
   trunk/fox/FManta/FMantaRecorder.cc
   trunk/fox/disco_demo/Engine/ImageTraversers/DiscoImageTraverser.cc
   trunk/fox/disco_demo/Engine/Renderers/DiscoRayTracer.cc
   trunk/fox/disco_demo/Engine/Shaders/AOShader.cc
   trunk/fox/disco_demo/Interface/PerSampleShader.cc
   trunk/fox/disco_demo/Interface/TilePacket.h
   trunk/scenes/acceltest.cc
   trunk/scenes/objviewer.cc
   trunk/scenes/primtest.cc
   trunk/tests/perftest/CMakeLists.txt
Log:

Merge of the vertical branch:
  svn merge -r 785:855 https://code.sci.utah.edu/svn/branch/vertical ;.

There were some changes to new trunk code that had to be made to get
it to compile.  These are as follows:

CMakeLists.txt
fox/FManta/CMakeLists.txt

  Added TEEM_INSTALL_PATH and FOX_INSTALL_PATH that can be used
  independently of and take precedence over the
  THIRD_PARTY_LIBRARY_PATH.

fox/FManta/FMantaImageFrame.cc
fox/disco_demo/Engine/ImageTraversers/DiscoImageTraverser.cc
fox/disco_demo/Engine/Renderers/DiscoRayTracer.cc
fox/disco_demo/Interface/PerSampleShader.cc
fox/disco_demo/Interface/TilePacket.h

  Updates for new vertical RayPacket API.

fox/FManta/FMantaRecorder.cc

  Use static_cast to reduce a type conversion warning.

fox/disco_demo/Engine/Shaders/AOShader.cc

  Updates for new vertical RayPacket API.

  Orthonormal basis computation is more streamlined.
  
  Call secondary_packet.resetHits() after the ray packet is used.

scenes/acceltest.cc

  rtrt_int is now manta_interface.


Modified: trunk/CMakeLists.txt
==============================================================================
--- trunk/CMakeLists.txt        (original)
+++ trunk/CMakeLists.txt        Fri Jan 20 15:03:05 2006
@@ -213,11 +213,16 @@
   SUBDIRS(fox)
 ENDIF(BUILD_FOX)
 
+##################################################################
 # Look for Teem http://teem.sourceforge.net/
-FIND_LIBRARY( FOUND_TEEM_LIB     NAMES teem        
-                                 PATHS ${THIRD_PARTY_LIBRARY_PATH} 
/usr/local/lib /usr/lib 
+
+# Look for library here before you look in Thirdparty path
+SET(TEEM_INSTALL_PATH "" CACHE STRING "Default search path for Teem install")
+
+FIND_LIBRARY( FOUND_TEEM_LIB     NAMES teem
+                                 PATHS ${TEEM_INSTALL_PATH}/lib 
${THIRD_PARTY_LIBRARY_PATH} /usr/local/lib /usr/lib
                                  DOC "Teem library (This is a path.)" )
-FIND_PATH   ( FOUND_TEEM_INCLUDE teem/nrrd.h ${THIRD_PARTY_INCLUDE_PATH} 
/usr/local/include /usr/include
+FIND_PATH   ( FOUND_TEEM_INCLUDE teem/nrrd.h ${TEEM_INSTALL_PATH}/include 
${THIRD_PARTY_INCLUDE_PATH} /usr/local/include /usr/include
                                  DOC "Teem Include (This is a path.)" )
 
 

Modified: trunk/Core/Color/ColorSpace.h
==============================================================================
--- trunk/Core/Color/ColorSpace.h       (original)
+++ trunk/Core/Color/ColorSpace.h       Fri Jan 20 15:03:05 2006
@@ -12,11 +12,9 @@
 #include <sgi_stl_warnings_on.h>
 
 namespace Manta {
-  template<typename Traits>
-  class ColorSpace {
+  template<typename Traits> class ColorSpace {
   public:
     typedef typename Traits::ComponentType ComponentType;
-    typedef typename Traits::ComponentType ScalarType;
     enum { NumComponents = Traits::NumComponents};
 
     ColorSpace() { }
@@ -36,6 +34,24 @@
     ~ColorSpace() {
     }
 
+#ifndef SWIG
+    // Access individual components
+    const ComponentType& operator[](int i) const
+    {
+      return data[i];
+    }
+    ComponentType& operator[](int i)
+    {
+      return data[i];
+    }
+#else
+    %extend {
+      ComponentType& __getitem__( int i ) {
+        return self->operator[](i);
+      }
+    }
+#endif
+
     // These are the fixpoints, rather than true colors black and white
     // black is the fixpoint under addition
     // white is the fixpoint under multiplication
@@ -154,6 +170,20 @@
       return *this;
     }
 
+    bool operator==(const ColorSpace<Traits>& c) {
+      for(int i=0;i<NumComponents;i++)
+        if(data[i] != c.data[i])
+          return false;
+      return true;
+    }
+    bool operator!=(const ColorSpace<Traits>& c) {
+      for(int i=0;i<NumComponents;i++)
+        if(data[i] != c.data[i])
+          return false;
+      return true;
+    }
+
+
     ComponentType Mean() const
     {
       ComponentType sum = 0;
@@ -177,38 +207,40 @@
     // (the implementation) in another header file called
     // ColorSpace_fancy.h.  If you want to use this function include
     // that header file and it will get instantiated properly.
-    std::string toString() const;
-    
+    std::string toString() const;    
 
-      template<typename Scalar>
-      ColorSpace<Traits> Pow(Scalar exponent) const
-      {
-          using SCIRun::Pow;
-          ColorSpace<Traits> returnValue;
-          for (int i=0; i < NumComponents; i++)
-              returnValue.data[i] = SCIRun::Pow(data[i], exponent);
-          return returnValue;
-      }
+    template<typename Scalar>
+    ColorSpace<Traits> Pow(Scalar exponent) const
+    {
+      using SCIRun::Pow;
+      ColorSpace<Traits> returnValue;
+      for (int i=0; i < NumComponents; i++)
+        returnValue.data[i] = SCIRun::Pow(data[i], exponent);
+      return returnValue;
+    }
 
-      ColorSpace<Traits> Log() const
-      {
-          ColorSpace<Traits> returnValue;
-          for (int i=0; i < NumComponents; i++)
-              returnValue.data[i] = log(data[i]);
-          return returnValue;
-      }
+    ColorSpace<Traits> Log() const
+    {
+      ColorSpace<Traits> returnValue;
+      for (int i=0; i < NumComponents; i++)
+        returnValue.data[i] = log(data[i]);
+      return returnValue;
+    }
 
-      ColorSpace<Traits> attenuate(const ColorSpace<Traits> &scale) const {
-        using SCIRun::Exp;
-        ColorSpace<Traits> returnValue;
-        for(int i=0;i<NumComponents;i++)
-          returnValue.data[i] = Exp(scale.data[i]*data[i]);
-        return returnValue;
-      }
+    ColorSpace<Traits> attenuate(const ColorSpace<Traits> &scale) const
+    {
+      using SCIRun::Exp;
+      ColorSpace<Traits> returnValue;
+      for(int i=0;i<NumComponents;i++)
+        returnValue.data[i] = Exp(scale.data[i]*data[i]);
+      return returnValue;
+    }
+
+    ComponentType luminance() const
+    {
+      return Traits::luminance(data);
+    }
 
-      ComponentType luminance() const {
-        return Traits::luminance(data);
-      }
   protected:
     // DO NOT MAKE THIS PUBLIC!
     ComponentType data[NumComponents];

Modified: trunk/Core/Color/ColorSpace_fancy.h
==============================================================================
--- trunk/Core/Color/ColorSpace_fancy.h (original)
+++ trunk/Core/Color/ColorSpace_fancy.h Fri Jan 20 15:03:05 2006
@@ -19,6 +19,3 @@
   }
 
 } // end namespace Manta
-
-
-

Modified: trunk/Core/Geometry/BBox.h
==============================================================================
--- trunk/Core/Geometry/BBox.h  (original)
+++ trunk/Core/Geometry/BBox.h  Fri Jan 20 15:03:05 2006
@@ -24,6 +24,18 @@
     }
     ~BBox() {
     }
+    BBox(const BBox& copy)
+    {
+      bounds[0] = copy.bounds[0];
+      bounds[1] = copy.bounds[1];
+    }
+    BBox& operator=(const BBox& copy)
+    {
+      bounds[0] = copy.bounds[0];
+      bounds[1] = copy.bounds[1];
+      return *this;
+    }
+
                
     // This resets min and max to an uninitialized state that will
     // accept new bounds [MAX, -MAX].
@@ -107,9 +119,6 @@
     inline const Point &operator[] (int i) const { return bounds[i]; }
     
   private:
-    // BBox(const BBox&);
-    // BBox& operator=(const BBox&);
-
     Point bounds[2];
   };
 }

Modified: trunk/Core/Geometry/PointVector.h
==============================================================================
--- trunk/Core/Geometry/PointVector.h   (original)
+++ trunk/Core/Geometry/PointVector.h   Fri Jan 20 15:03:05 2006
@@ -24,7 +24,7 @@
   template<typename T, int Dim> 
     class VectorT {
   public:
-                       typedef T ScalarType;
+    typedef T ComponentType;
                        
     VectorT() {
     }
@@ -79,8 +79,7 @@
     }
     T &operator[] ( int i ) {
       return data[i];
-    }          
-               const T *operator &() const { return data; }
+    }
                
 #else
     %extend {
@@ -89,6 +88,10 @@
       }
     }
 #endif
+    // One might be tempted to add an "operator &" function, but
+    // that could lead to problems when you want an address to the
+    // object rather than a pointer to data.
+    const T* getDataPtr() const { return data; }
 
     VectorT<T, Dim> operator+(const VectorT<T, Dim>& v) const {
       VectorT<T, Dim> result;
@@ -249,6 +252,9 @@
 
   private:
     T data[Dim];
+
+      // Do not use this function!!!!  Use getDataPtr() instead.
+      //      const T *operator &() const { return data; }
   };
 
 
@@ -325,6 +331,10 @@
       }
     }
 #endif
+    // One might be tempted to add an "operator &" function, but
+    // that could lead to problems when you want an address to the
+    // object rather than a pointer to data.
+    const T* getDataPtr() const { return data; }
 
     VectorT<T, Dim> operator-(const PointT<T, Dim>& p) const {
       VectorT<T, Dim> result;
@@ -393,6 +403,9 @@
 
   private:
     T data[Dim];
+
+      // Do not use this function!!!!  Use getDataPtr() instead.
+      //      const T *operator &() const { return data; }
   };
 
        // Two multiplication by a scalar operators.

Modified: trunk/Core/Math/CatmullRomInterpolator.h
==============================================================================
--- trunk/Core/Math/CatmullRomInterpolator.h    (original)
+++ trunk/Core/Math/CatmullRomInterpolator.h    Fri Jan 20 15:03:05 2006
@@ -45,12 +45,12 @@
     Real t2 = t*t;
     Real t3 = t*t2;
 
-    PointType r0 = (P_i  * 2.0);
-    PointType r1 = (P_im1*-1.0 + P_ip1) * t;
-    PointType r2 = (P_im1* 2.0 + P_i*-5.0 + P_ip1* 4.0 -P_ip2) * t2;
-    PointType r3 = (P_im1*-1.0 + P_i* 3.0 + P_ip1*-3.0 +P_ip2) * t3;
+    PointType r0 = (P_i  * 2);
+    PointType r1 = (P_im1*-1 + P_ip1) * t;
+    PointType r2 = (P_im1* 2 + P_i*-5 + P_ip1* 4 -P_ip2) * t2;
+    PointType r3 = (P_im1*-1 + P_i* 3 + P_ip1*-3 +P_ip2) * t3;
     
-    result = (r0 + r1)*0.5 + (r2 + r3)*0.5;
+    result = (r0 + r1)*(Real)0.5 + (r2 + r3)*(Real)0.5;
   }
   
   

Modified: trunk/Core/XUtils/XHelper.cc
==============================================================================
--- trunk/Core/XUtils/XHelper.cc        (original)
+++ trunk/Core/XUtils/XHelper.cc        Fri Jan 20 15:03:05 2006
@@ -16,8 +16,6 @@
 XFontStruct* XHelper::getX11Font(Display* dpy,
                                  const char* fontstring) {
   // Should we lock X?
-  // cerr << "XHelper::getX11Font: Trying to load in font:\n"
-  //      << fontstring << "\n";
   return XLoadQueryFont(dpy, fontstring);
 }
 

Modified: trunk/Engine/Control/RTRT.cc
==============================================================================
--- trunk/Engine/Control/RTRT.cc        (original)
+++ trunk/Engine/Control/RTRT.cc        Fri Jan 20 15:03:05 2006
@@ -1350,7 +1350,7 @@
   currentRenderer->traceEyeRays( render_context, result_rays );
 
   // Check to see if the ray hit anything.
-  if (result_rays.hitInfo(0).wasHit()) {
+  if (result_rays.wasHit(0)){
 
     // Compute hit positions.
     result_rays.computeHitPositions();
@@ -1359,9 +1359,9 @@
     result_rays.computeNormals( render_context );
 
     // Shade.
-    result_rays.hitInfo(0).hitMaterial()->shade( render_context, result_rays 
);
+    result_rays.getHitMaterial(0)->shade( render_context, result_rays );
   }
-  result_color = result_rays.getResult(0);
+  result_color = result_rays.getColor(0);
 }
 
 

Modified: trunk/Engine/Control/RTRT.h
==============================================================================
--- trunk/Engine/Control/RTRT.h (original)
+++ trunk/Engine/Control/RTRT.h Fri Jan 20 15:03:05 2006
@@ -41,8 +41,8 @@
     // Image Modes (opengl, file, mpeg, etc.)
     virtual int createChannel(const string& modespec, Camera* camera,
                              bool stereo, int xres, int yres);
-               virtual int createChannel(ImageDisplay *image_display, 
Camera* camera,
-                                                                             
                                          bool stereo, int xres, int yres);
+    virtual int createChannel(ImageDisplay *image_display, Camera* camera,
+                              bool stereo, int xres, int yres);
     virtual void registerComponent(const string& name, ImageDisplayCreator 
display);
     virtual listType listImageDisplays() const;
     virtual Camera* getCamera(int channel) const;

Modified: trunk/Engine/Control/RTRT_register.cc
==============================================================================
--- trunk/Engine/Control/RTRT_register.cc       (original)
+++ trunk/Engine/Control/RTRT_register.cc       Fri Jan 20 15:03:05 2006
@@ -79,10 +79,10 @@
     engine->registerComponent("raytracer", &Raytracer::create);
 
     // Register cameras
-    engine->registerComponent("environment", &EnvironmentCamera::create);
+    //engine->registerComponent("environment", &EnvironmentCamera::create);
     engine->registerComponent("pinhole", &PinholeCamera::create);
-    engine->registerComponent("orthogonal", &OrthogonalCamera::create);
-    engine->registerComponent("fisheye", &FisheyeCamera::create);
+    //engine->registerComponent("orthogonal", &OrthogonalCamera::create);
+    //engine->registerComponent("fisheye", &FisheyeCamera::create);
 
     // Register shadow algorithms
     engine->registerComponent("noshadows", &NoShadows::create);
@@ -100,7 +100,7 @@
 
     // Register groups
     engine->registerObject("group", &Group::create);
-    engine->registerObject("grid", &GriddedGroup::create);
-    engine->registerObject("bvh", &BVH::create);
+    //engine->registerObject("grid", &GriddedGroup::create);
+    //engine->registerObject("bvh", &BVH::create);
   }
 }

Modified: trunk/Engine/PixelSamplers/JitterSampler.cc
==============================================================================
--- trunk/Engine/PixelSamplers/JitterSampler.cc (original)
+++ trunk/Engine/PixelSamplers/JitterSampler.cc Fri Jan 20 15:03:05 2006
@@ -98,8 +98,8 @@
   int samples_collected = samples_collected_return;
   int current_fragment = current_fragment_return;
   Color fragment_color = Color::black();
-  for(int sample_index = 0; sample_index < rays.getSize(); sample_index++) {
-    fragment_color += rays.getResult(sample_index);
+  for(int sample_index = rays.begin(); sample_index < rays.end(); 
sample_index++) {
+    fragment_color += rays.getColor(sample_index);
     samples_collected++;
     // We've collected enough samples, so compute the average and
     // assign it to the fragment.
@@ -145,7 +145,7 @@
 
   int depth = 0;
   RayPacketData raydata;
-  RayPacket rays(raydata, RayPacket::MaxSize, depth, flags);
+  RayPacket rays(raydata, 0, RayPacket::MaxSize, depth, flags);
 
   Real inx = (Real)1/nx;
   Real iny = (Real)1/ny;
@@ -202,7 +202,7 @@
             // the RayPacket again.
             sample_count = 0;
             // Make sure we start with a fresh slate
-            rays.resetHit();
+            rays.resetHits();
             rays.setAllFlags(flags);
           }
         } // end sample filling loops

Modified: trunk/Engine/PixelSamplers/SingleSampler.cc
==============================================================================
--- trunk/Engine/PixelSamplers/SingleSampler.cc (original)
+++ trunk/Engine/PixelSamplers/SingleSampler.cc Fri Jan 20 15:03:05 2006
@@ -4,7 +4,6 @@
 #include <Interface/Fragment.h>
 #include <Interface/RayPacket.h>
 #include <Interface/Renderer.h>
-
 using namespace Manta;
 
 PixelSampler* SingleSampler::create(const vector<string>& args)
@@ -65,7 +64,7 @@
     // Create a ray packet
     int depth = 0;
     RayPacketData raydata;
-    RayPacket rays(raydata, size, depth, flags);
+    RayPacket rays(raydata, 0, size, depth, flags);
 
     // Check to see if the fragment is consecutive in x.
     if(fragment.getFlags() & Fragment::ConsecutiveX){
@@ -99,7 +98,7 @@
 
     for(int i=0;i<size;i++){
       Fragment::Element& fe = fragment.get(f+i);
-      fe.color = rays.getResult(i);
+      fe.color = rays.getColor(i);
     }
   }
 }

Modified: trunk/Engine/Renderers/Moire.cc
==============================================================================
--- trunk/Engine/Renderers/Moire.cc     (original)
+++ trunk/Engine/Renderers/Moire.cc     Fri Jan 20 15:03:05 2006
@@ -2,6 +2,7 @@
 #include <Engine/Renderers/Moire.h>
 #include <Core/Color/GrayColor.h>
 #include <Core/Exceptions/IllegalArgument.h>
+#include <Core/Math/Trig.h>
 #include <Core/Util/Args.h>
 #include <Core/Util/Assert.h>
 #include <Interface/Context.h>
@@ -55,11 +56,12 @@
   ASSERT(rays.getFlag(RayPacket::HaveImageCoordinates));
   double phase = context.frameState->frameTime * M_PI;
   double cycles = 100;
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& p = rays.get(i);
-    double dist2 = p.imageX*p.imageX + p.imageY*p.imageY;
-    double val = cos(dist2*2*M_PI*cycles+phase)/2+0.5;
-    p.color = Color(GrayColor(val));
+  for(int i=rays.begin();i<rays.end();i++){
+    Real ix = rays.getImageCoordinates(i, 0);
+    Real iy = rays.getImageCoordinates(i, 1);
+    Real dist2 = ix*ix + iy*iy;
+    Real val = Cos(dist2*2*M_PI*cycles+phase)/2+0.5;
+    rays.setColor(i, Color(GrayColor(val)));
   }
 }
 

Modified: trunk/Engine/Renderers/NullRenderer.cc
==============================================================================
--- trunk/Engine/Renderers/NullRenderer.cc      (original)
+++ trunk/Engine/Renderers/NullRenderer.cc      Fri Jan 20 15:03:05 2006
@@ -38,16 +38,14 @@
 void NullRenderer::traceEyeRays(const RenderContext&, RayPacket& rays)
 {
   ASSERT(rays.getFlag(RayPacket::HaveImageCoordinates));
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& p = rays.get(i);
-    p.color = color;
+  for(int i=rays.begin();i<rays.end();i++){
+    rays.setColor(i, color);
   }
 }
 
 void NullRenderer::traceRays(const RenderContext&, RayPacket& rays)
 {
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& p = rays.get(i);
-    p.color = color;
+  for(int i=rays.begin();i<rays.end();i++){
+    rays.setColor(i, color);
   }
 }

Modified: trunk/Engine/Renderers/Raytracer.cc
==============================================================================
--- trunk/Engine/Renderers/Raytracer.cc (original)
+++ trunk/Engine/Renderers/Raytracer.cc Fri Jan 20 15:03:05 2006
@@ -8,6 +8,8 @@
 #include <Interface/RayPacket.h>
 #include <Interface/Scene.h>
 #include <Core/Util/Assert.h>
+#include <iostream>
+using namespace std;
 
 using namespace Manta;
 
@@ -46,24 +48,24 @@
 
 void Raytracer::traceRays(const RenderContext& context, RayPacket& rays)
 {
-  rays.resetHit();
+  rays.resetHits();
   context.scene->getObject()->intersect(context, rays);
 
   // Go through the ray packet and shade them.  Group rays that hit the
   // same object and material to shade with a single shade call
-  for(int i = 0;i<rays.getSize();){
-    if(rays.hitInfo(i).wasHit()){
-      const Material* hit_matl = rays.hitInfo(i).hitMaterial();
+  for(int i = rays.begin();i<rays.end();){
+    if(rays.wasHit(i)){
+      const Material* hit_matl = rays.getHitMaterial(i);
       int end = i+1;
-      while(end < rays.getSize() && rays.hitInfo(end).wasHit() &&
-            rays.hitInfo(end).hitMaterial() == hit_matl)
+      while(end < rays.end() && rays.wasHit(end) &&
+            rays.getHitMaterial(end) == hit_matl)
        end++;
       RayPacket subPacket(rays, i, end);
       hit_matl->shade(context, subPacket);
       i=end;
     } else {
       int end = i+1;
-      while(end < rays.getSize() && !rays.hitInfo(end).wasHit())
+      while(end < rays.end() && !rays.wasHit(end))
        end++;
       RayPacket subPacket(rays, i, end);
       context.scene->getBackground()->shade(context, subPacket);

Modified: trunk/Engine/Shadows/BeamShadows.cc
==============================================================================
--- trunk/Engine/Shadows/BeamShadows.cc (original)
+++ trunk/Engine/Shadows/BeamShadows.cc Fri Jan 20 15:03:05 2006
@@ -57,9 +57,13 @@
 {
 }
 
-int BeamShadows::computeShadows(const RenderContext& context,
-                              const LightSet* lights, RayPacket& rays,
-                              int start, RayPacket& shadowRays)
+bool BeamShadows::computeShadows(const RenderContext& context,
+                                 const LightSet* lights, 
+                                 RayPacket& rays,              // Input rays.
+                                 int map[],                    // map from 
shadow rays to input rays
+                                 RayPacket& shadowRays,        // Output 
shadow rays, already intersected.
+                                 bool firstTime,
+                                 StateBuffer& stateBuffer)
 {
 #if 0
   int nlights = lights->numLights();

Modified: trunk/Engine/Shadows/BeamShadows.h
==============================================================================
--- trunk/Engine/Shadows/BeamShadows.h  (original)
+++ trunk/Engine/Shadows/BeamShadows.h  Fri Jan 20 15:03:05 2006
@@ -15,8 +15,9 @@
     BeamShadows(const vector<string>& args);
     virtual ~BeamShadows();
 
-    virtual int computeShadows(const RenderContext& context, const LightSet* 
lights,
-                              RayPacket&, int start, RayPacket&);
+    virtual bool computeShadows(const RenderContext& context, const 
LightSet* lights,
+                                RayPacket& source, int map[], RayPacket& 
shadowRays,
+                                bool firstTime, StateBuffer& stateBuffer);
 
     static ShadowAlgorithm* create(const vector<string>& args);
 

Modified: trunk/Engine/Shadows/HardShadows.cc
==============================================================================
--- trunk/Engine/Shadows/HardShadows.cc (original)
+++ trunk/Engine/Shadows/HardShadows.cc Fri Jan 20 15:03:05 2006
@@ -22,110 +22,81 @@
 {
 }
 
-int HardShadows::computeShadows(const RenderContext& context,
-                                                                             
                                                  const LightSet* lights, 
-                                                                             
                                                  RayPacket& rays,            
  // Input rays.
-                                                                             
                                                  int start,                  
  // Offset to start from in input rays?
-                                                                             
                                                  RayPacket& shadow_rays)     
  // Output shadow rays, already intersected.
+bool HardShadows::computeShadows(const RenderContext& context,
+                                 const LightSet* lights, 
+                                 RayPacket& sourceRays,        // Input rays.
+                                 int map[],                    // map from 
shadow rays to input rays
+                                 RayPacket& shadowRays,        // Output 
shadow rays, already intersected.
+                                 bool firstTime,
+                                 StateBuffer& stateBuffer)
 {
   int nlights = lights->numLights();
   
-       // Compute the hit positions.
-       rays.computeHitPositions();
-       rays.computeNormals( context );
-       
-#if 0
-       // Construct a shadow ray packet.
-       // NOTE: this code won't send more then RayPacket::MaxSize shadow 
rays.
-       // Although the old code didn't either.
-       
-       Real   distance [RayPacket::MaxSize];
-       Color  color    [RayPacket::MaxSize];
-       Vector direction[RayPacket::MaxSize];
-
-       int shadow_i = 0; // Iterator over computed shadow rays.
-       int i = start;    // Iterator over initial rays used to compute 
shadow rays.
-       
-       // NEED TO MAKE SURE ORDER MATCHES MATERIAL SHADER!!
-       // WANT ALL RAYS TOWARDS ONE LIGHT TO BE COMMON PACKET.
-       // 
-       
-       // Iterate over the lights and compute directions, colors, distances.
-       for (int light=0; 
-            (light<lights->numLights()) && 
-                        (shadow_i<RayPacket::MaxSize); 
-                        ++light) {
-               
-               // Compute the info for this light.
-               lights->get(light)->getLight( distance, color, direction, 
rays, context );
-               
-               // Compute the shadow rays and append them to the shadow 
packet.
-               
-               // Set the shadow ray.
-               for (int i=0; ((shadow_i+i)<RayPacket::MaxSize) && 
(i<rays.getSize();++i) {
-                       shadow_rays.get(shadow_i+i).ray.set( 
rays[i].hitPosition, direction[i] );
-               }
-               
-               // Copy the light contribution.
-               for (int i=0; ((shadow_i+i)<RayPacket::MaxSize) && 
(i<rays.getSize();++i) {             
-                       shadow_rays.get(shadow_i+i).light = 
lights[light].color;
-               }       
-               
-               // Copy the distance.
-               for (int i=0; ((shadow_i+i)<RayPacket::MaxSize) && 
(i<rays.getSize();++i) {
-                       shadow_rays.get(shadow_i+i).hitInfo.reset( 
distance[i] );
-               }
-               
-               // Move to the next part of the shadow ray packet.
-               shadow_i += rays.getSize();
-       }
-#endif
+  // Compute the hit positions.
+  sourceRays.computeHitPositions();
+  sourceRays.computeNormals( context );
 
   int sidx = 0;
-  int end = start;
-  while(end < rays.getSize() && sidx+nlights <= RayPacket::MaxSize){
-
-    RayPacket::Element& e = rays.get(end++);
+  int starti, j;
+  if(firstTime){
+    starti = sourceRays.begin();
+    j = 0;
+  } else {
+    starti = stateBuffer.i1;
+    j = stateBuffer.i2;
+  }
+  bool done = true;
+  for(; j < nlights; j++){
+    // Compute the contribution for this light.
+    Color lightColors[RayPacket::MaxSize];
+    Vector lightDirections[RayPacket::MaxSize];
+    lights->getLight(j)->computeLight( lightColors, lightDirections, 
context, sourceRays);
 
-               // Specify the beginning index for this ray in the shadow 
packet.
-    e.shadowBegin = sidx;
+    for(int i = starti; i < sourceRays.end(); i++){
+      // Check to see if the light is on the front face.
+      Vector dir = lightDirections[i];
+      if(Dot(dir, sourceRays.getNormal(i)) > 0) {
 
-               // Iterate over the lights and create shadow rays.
-    for(int l=0;l<nlights;l++){
-               
-                       Vector dir;
-                       Color  color;
-               
-                 // Compute the contribution for this light.
-                       lights->getLight(l)->computeLight( color, dir, 
context, e );
-      
-                       // Check to see if the light is on the front face.
-      if(Dot(dir, e.normal) > 0) {
-                       
-                               // If so normalize and compute length.
-                               Real length = dir.normalize();
-                       
-                               // Populate the shadow ray.
-                               RayPacket::Element& s = 
shadow_rays.get(sidx++);
-                               s.ray.set( e.hitPosition, dir );
-                               s.light = color;
-                               s.hitInfo.reset( length );
+        // If so normalize and compute length.
+        Real length = dir.normalize();
+       
+        // Populate the shadow ray.
+        shadowRays.setRay(sidx, sourceRays.getHitPosition(i), dir );
+        shadowRays.setColor(sidx, lightColors[i]);
+        shadowRays.resetHit( sidx, length );
+        map[sidx] = i;
+        if(++sidx >= RayPacket::MaxSize){
+          if(i+1 == sourceRays.end()){
+            if(j+1 == nlights){
+              // Do nothing - we are done
+            } else {
+              // Save our position but start on the next light
+              stateBuffer.i1 = sourceRays.begin();
+              stateBuffer.i2 = j+1;
+              done = false;
+            }
+          } else {
+            stateBuffer.i1 = i+1;
+            stateBuffer.i2 = j;
+            done = false;
+          }
+          // Okay, a goto is nasty, but C++ doesn't have "break 2" and we 
need to get
+          // out of this loop without too much extra work
+          goto break2;
+        }
       }
     }
-    e.shadowEnd = sidx;
+    
+    starti = sourceRays.begin();
   }
+ break2:
+      
+  // Send the shadow rays.
+  shadowRays.setFlag( 
RayPacket::NormalizedDirections|RayPacket::HaveHitRecords );
+  shadowRays.resize ( sidx );
        
-       // Send the shadow rays.
-  shadow_rays.setFlag( 
RayPacket::NormalizedDirections|RayPacket::HaveHitRecords );
-  shadow_rays.resize ( sidx );
-       
-       // Check to see if all of the shadow rays start from the same input 
ray.
-  if(end == start+1)
-    shadow_rays.setFlag( RayPacket::ConstantOrigin );
-  
-       context.scene->getObject()->intersect(context, shadow_rays);
-       
-  return end;
+  context.scene->getObject()->intersect(context, shadowRays);
+  return done;
 }
 
 string HardShadows::getName() const {

Modified: trunk/Engine/Shadows/HardShadows.h
==============================================================================
--- trunk/Engine/Shadows/HardShadows.h  (original)
+++ trunk/Engine/Shadows/HardShadows.h  Fri Jan 20 15:03:05 2006
@@ -15,8 +15,9 @@
     HardShadows(const vector<string>& args);
     virtual ~HardShadows();
 
-    virtual int computeShadows(const RenderContext& context, const LightSet* 
lights,
-                              RayPacket&, int start, RayPacket&);
+    virtual bool computeShadows(const RenderContext& context, const 
LightSet* lights,
+                                RayPacket& source, int map[], RayPacket& 
shadowRays,
+                                bool firstTime, StateBuffer& stateBuffer);
 
     static ShadowAlgorithm* create(const vector<string>& args);
 

Modified: trunk/Engine/Shadows/NoShadows.cc
==============================================================================
--- trunk/Engine/Shadows/NoShadows.cc   (original)
+++ trunk/Engine/Shadows/NoShadows.cc   Fri Jan 20 15:03:05 2006
@@ -19,42 +19,73 @@
 {
 }
 
-int NoShadows::computeShadows(const RenderContext& context,
-                                                                             
                                          const LightSet* lights, RayPacket& 
rays,
-                                                                             
                                          int start, RayPacket& shadowRays)
+bool NoShadows::computeShadows(const RenderContext& context, const LightSet* 
lights,
+                               RayPacket& sourceRays, int map[], RayPacket& 
shadowRays,
+                               bool firstTime, StateBuffer& stateBuffer)
 {
   int nlights = lights->numLights();
-  rays.computeHitPositions();
-       
+  
+  // Compute the hit positions.
+  sourceRays.computeHitPositions();
+  sourceRays.computeNormals( context );
+
   int sidx = 0;
-  while(start < rays.getSize() && sidx+nlights < RayPacket::MaxSize){
-    RayPacket::Element& e = rays.get(start++);
-    e.shadowBegin = sidx;
-    for(int l = 0;l<nlights;l++){
-                       Color color;
-                       Vector dir;
-               
-                       // Compute the direction & color of this light.
-                       
lights->getLight(l)->computeLight(color,dir,context,e);
-               
-                       // Construct the shadow ray.
-      RayPacket::Element& s = shadowRays.get(sidx);
-                       
-      if(Dot(dir, e.normal)  > 0){
-                               sidx++;
-        // Be sure to normalize the normals
-                               s.ray.setDirection(dir.normal());
-                               s.light = color;
+  int starti, j;
+  if(firstTime){
+    starti = sourceRays.begin();
+    j = 0;
+  } else {
+    starti = stateBuffer.i1;
+    j = stateBuffer.i2;
+  }
+  bool done = true;
+  for(; j < nlights; j++){
+    // Compute the contribution for this light.
+    Color lightColors[RayPacket::MaxSize];
+    Vector lightDirections[RayPacket::MaxSize];
+    lights->getLight(j)->computeLight( lightColors, lightDirections, 
context, sourceRays);
+
+    for(int i = starti; i < sourceRays.end(); i++){
+      // Check to see if the light is on the front face.
+      Vector dir = lightDirections[i];
+      if(Dot(dir, sourceRays.getNormal(i)) > 0) {
+
+        // If so normalize and compute length.
+        Real length = dir.normalize();
+       
+        // Populate the direction and color only
+        shadowRays.setDirection(sidx, dir );
+        shadowRays.setColor(sidx, lightColors[i]);
+        map[sidx] = i;
+        if(++sidx >= RayPacket::MaxSize){
+          if(i+1 == sourceRays.end()){
+            if(j+1 == nlights){
+              // Do nothing - we are done
+            } else {
+              // Save our position but start on the next light
+              stateBuffer.i1 = sourceRays.begin();
+              stateBuffer.i2 = j+1;
+              done = false;
+            }
+          } else {
+            stateBuffer.i1 = i+1;
+            stateBuffer.i2 = j;
+            done = false;
+          }
+          // Okay, a goto is nasty, but C++ doesn't have "break 2" and we 
need to get
+          // out of this loop without too much extra work
+          goto break2;
+        }
       }
     }
-    e.shadowEnd = sidx;
+    
+    starti = sourceRays.begin();
   }
-  // We already normalized the rays, so indicate that so we don't do
-  // redundant work.
-  shadowRays.setFlag( RayPacket::NormalizedDirections );
-  shadowRays.resize(sidx);
-  shadowRays.resetHit();
-  return start;
+ break2:
+      
+  shadowRays.resize ( sidx );
+  shadowRays.resetHits();
+  return done;
 }
 
 string NoShadows::getName() const {

Modified: trunk/Engine/Shadows/NoShadows.h
==============================================================================
--- trunk/Engine/Shadows/NoShadows.h    (original)
+++ trunk/Engine/Shadows/NoShadows.h    Fri Jan 20 15:03:05 2006
@@ -15,8 +15,9 @@
     NoShadows(const vector<string>& args);
     virtual ~NoShadows();
 
-    virtual int computeShadows(const RenderContext& context, const LightSet* 
lights,
-                              RayPacket&, int start, RayPacket&);
+    virtual bool computeShadows(const RenderContext& context, const 
LightSet* lights,
+                                RayPacket& source, int map[], RayPacket& 
shadowRays,
+                                bool firstTime, StateBuffer& stateBuffer);
 
     static ShadowAlgorithm* create(const vector<string>& args);
 

Modified: trunk/Image/CMakeLists.txt
==============================================================================
--- trunk/Image/CMakeLists.txt  (original)
+++ trunk/Image/CMakeLists.txt  Fri Jan 20 15:03:05 2006
@@ -9,6 +9,9 @@
   # Add the include directory to the build
   INCLUDE_DIRECTORIES(${FOUND_TEEM_INCLUDE})
 
+ELSE (FOUND_TEEM_INCLUDE)
+  # Add stubs for these functions
+  SET (NRRD_IMAGE_SRC NRRDFile.h NRRDFile-stub.cc)  
 ENDIF (FOUND_TEEM_INCLUDE)
 
 IF (FOUND_TEEM_LIB)

Modified: trunk/Image/SimpleImage.h
==============================================================================
--- trunk/Image/SimpleImage.h   (original)
+++ trunk/Image/SimpleImage.h   Fri Jan 20 15:03:05 2006
@@ -70,10 +70,9 @@
   Image* SimpleImage<Pixel>::create(const std::vector<std::string>& args, 
                                    bool stereo, int xres, int yres)
   {
-    using namespace SCIRun;
     if(args.size() != 0)
-      throw IllegalValue<std::string>("Illegal argument to SimpleImage 
create",
-                                     args[0]);
+      throw SCIRun::IllegalValue<std::string>
+        ("Illegal argument to SimpleImage create", args[0]);
     return new SimpleImage<Pixel>(stereo, xres, yres);
   }
 

Modified: trunk/Interface/AmbientLight.h
==============================================================================
--- trunk/Interface/AmbientLight.h      (original)
+++ trunk/Interface/AmbientLight.h      Fri Jan 20 15:03:05 2006
@@ -2,9 +2,11 @@
 #ifndef Manta_Interface_AmbientLight_h
 #define Manta_Interface_AmbientLight_h
 
+#include <MantaTypes.h>
 #include <sgi_stl_warnings_off.h>
 #include <string>
 #include <sgi_stl_warnings_on.h>
+#include <Interface/RayPacket.h>
 
 namespace Manta {
   class PreprocessContext;
@@ -16,10 +18,8 @@
     virtual ~AmbientLight();
 
     virtual void preprocess(const PreprocessContext& context) = 0;
-    virtual void computeAmbient(const RenderContext& context, RayPacket& 
rays) const = 0;
+    virtual void computeAmbient(const RenderContext& context, RayPacket& 
rays, ColorArray ambient) const = 0;
 
-    // This function will return a newly allocated pointer of a string
-    // representation of the object.  You should delete it yourself.
     virtual std::string toString() const = 0;
   private:
     AmbientLight(const AmbientLight&);

Modified: trunk/Interface/CMakeLists.txt
==============================================================================
--- trunk/Interface/CMakeLists.txt      (original)
+++ trunk/Interface/CMakeLists.txt      Fri Jan 20 15:03:05 2006
@@ -8,7 +8,6 @@
         Camera.cc
         Context.h
         Fragment.h
-        HitInfo.h
         IdleMode.h
         IdleMode.cc
         Image.h

Modified: trunk/Interface/Fragment.cc
==============================================================================
--- trunk/Interface/Fragment.cc (original)
+++ trunk/Interface/Fragment.cc Fri Jan 20 15:03:05 2006
@@ -4,18 +4,3 @@
 
 using namespace Manta;
 
-#if 0
-
-Fragment::Fragment(int y, int xstart, int xend)
-{
-  int nx = xend-xstart;
-  ASSERTRANGE(nx, 0, MaxFragmentSize+1);
-  for(int i=0; i< nx;i++){
-    data[i].x = i+xstart;
-    data[i].y = y;
-  }
-  flags = ConsecutiveX;
-  size = nx;
-}
-
-#endif

Modified: trunk/Interface/Light.h
==============================================================================
--- trunk/Interface/Light.h     (original)
+++ trunk/Interface/Light.h     Fri Jan 20 15:03:05 2006
@@ -17,29 +17,16 @@
     virtual ~Light();
                
     virtual void preprocess( const PreprocessContext& context ) = 0;
-    // virtual const Point& getCenter() const = 0;
-    // virtual const Color& getColor() const = 0;
 
-#if 0          
-               // This method is called on the light by the shadow 
algorithm. The color and direction 
-               // produced by the light may change for each ray in the 
packet, and may change based 
-               // on the render context.
-               virtual void computeLight( Real   
lightDistance[RayPacket::MaxSize], 
-                                          Color  
resultColor[RayPacket::MaxSize], 
-                                                                             
                               Vector lightDirection[RayPacket::MaxSize], 
-                                                                             
                           
-                                                                             
                           RenderContext &context, RayPacket &rays ) = 0;
-#endif
+    // This method is called on the light by the shadow algorithm. The color 
and direction 
+    // produced by the light may change for each ray in the packet, and may 
change based 
+    // on the render context.
+    virtual void computeLight( Color  resultColor[RayPacket::MaxSize], 
+                               Vector lightDirection[RayPacket::MaxSize], 
+                               const RenderContext &context, RayPacket 
&rays) const = 0;
 
-               // This method is called on the light by the shadow algorithm 
to compute
-               // the direction and contribution for one ray packet element.
-               // The direction is not normalized and the distance to the 
light from 
-               // the intersection must be computed.
-               virtual void computeLight( Color &resultColor, Vector 
&lightDirection,
-                                          const RenderContext &context, 
RayPacket::Element &e ) const = 0;
-               
   private:
-               // Lights may not be copied.
+    // Lights may not be copied.
     Light( const Light & );
     Light& operator = ( const Light & );
   };

Modified: trunk/Interface/LightSet.h
==============================================================================
--- trunk/Interface/LightSet.h  (original)
+++ trunk/Interface/LightSet.h  Fri Jan 20 15:03:05 2006
@@ -38,7 +38,7 @@
     // Combine two light sets.
     static LightSet* merge(LightSet* l1, LightSet* l2);
 
-               // Calls preprocess on each light.
+    // Calls preprocess on each light.
     void preprocess(const PreprocessContext&);
 
     string toString();

Modified: trunk/Interface/MantaInterface.h
==============================================================================
--- trunk/Interface/MantaInterface.h    (original)
+++ trunk/Interface/MantaInterface.h    Fri Jan 20 15:03:05 2006
@@ -39,14 +39,14 @@
     virtual int createChannel(const string& modespec, Camera* camera,
                              bool stereo, int xres, int yres) = 0;
                                                
-               // Create a channel given a pointer to the ImageDisplay for 
the channel.
-               virtual int createChannel( ImageDisplay *image_display, 
Camera *camera,
-                                               bool stereo, int xres, int 
yres) = 0;
+    // Create a channel given a pointer to the ImageDisplay for the channel.
+    virtual int createChannel( ImageDisplay *image_display, Camera *camera,
+                               bool stereo, int xres, int yres) = 0;
                                                
     virtual void registerComponent(const string& name, ImageDisplayCreator 
display) = 0;
     virtual listType listImageDisplays() const = 0;
     virtual Camera* getCamera(int channel) const = 0;
-               virtual void    setCamera(int channel, Camera *camera ) = 0;
+    virtual void    setCamera(int channel, Camera *camera ) = 0;
     virtual void getResolution(int channel, bool& stereo, int& xres, int& 
yres) = 0;
     // You can change the resolution of the rendered image without
     // having to change the pipeline.  If you want the pipeline

Modified: trunk/Interface/Parameters.h
==============================================================================
--- trunk/Interface/Parameters.h        (original)
+++ trunk/Interface/Parameters.h        Fri Jan 20 15:03:05 2006
@@ -3,6 +3,9 @@
 #define Manta_Interface_Parameters_h
 
 #define MAXCACHELINESIZE 128
-#define T_EPSILON 1.e-3
+#define T_EPSILON ((Real)1.e-3)
+#define DENOM_EPSILON ((Real)1.e-6)
+#define MAXT ((Real)1.e19)
+
 
 #endif

Modified: trunk/Interface/RayPacket.h
==============================================================================
--- trunk/Interface/RayPacket.h (original)
+++ trunk/Interface/RayPacket.h Fri Jan 20 15:03:05 2006
@@ -4,18 +4,68 @@
 
 #include <Core/Color/Color.h>
 #include <Core/Geometry/Ray.h>
-#include <Interface/HitInfo.h>
+#include <Core/Math/Expon.h>
+#include <Core/Util/Assert.h>
+#include <Interface/Parameters.h>
 #include <Interface/Primitive.h>
 #include <Interface/TexCoordMapper.h>
 #include <algorithm>
 
 namespace Manta {
-  class RayPacketData;
+  class Material;
   class RenderContext;
+  class RayPacketData {
+  public:
+    enum {
+      MaxScratchpadSize = 128,
+      Size            = 32
+    };
+    RayPacketData()
+      {
+      }
+
+    ~RayPacketData()
+      {
+      }
+
+    // Pointer-based arrays
+
+    // SWIG generated some error prone code when we used the types
+    // directly.  Making a typedef seemed to fix it.
+    typedef Primitive const* PrimitiveCP;
+    typedef Material const*  MaterialCP;
+    typedef TexCoordMapper const* TexCoordMapperCP;
+
+    PrimitiveCP hitPrim[Size];
+    MaterialCP hitMatl[Size];
+    TexCoordMapperCP hitTex[Size];
+
+    // Real-based arrays
+    Real image[2][Size];
+    Real origin[3][Size];
+    Real direction[3][Size];
+    Real normal[3][Size];
+    Real hitPosition[3][Size];
+    Real minT[Size];
+    Real texCoords[3][Size];
+    Real inverseDirection[3][Size];
+
+    // Color-based arrays
+    Color::ComponentType color[Manta::Color::NumComponents][Size];
+    Color::ComponentType importance[Manta::Color::NumComponents][Size];   // 
1-attenuation, where eye rays have importance == 1
+
+    // Int-based arrays
+    int whichEye[Size];
+    int signs[3][Size]; // 1=negative, 0=zero, positive
+
+    // Char-based arrays
+    char scratchpad_data[Size][MaxScratchpadSize];
+  };
+
   class RayPacket {
   public:
     enum {
-      MaxSize               = 32,
+      MaxSize               = RayPacketData::Size,
 
       // Flags.
       ConstantOrigin        = 0x0001,
@@ -26,21 +76,29 @@
       HaveHitRecords        = 0x0020,
       HaveTexture3          = 0x0040,
       HaveTexture2          = 0x0080,
-      // HaveFrame          = 0x0100,
+      HaveUnitNormals       = 0x0100, // Used by prims that set
+                                      // whether the normals computed
+                                      // have been normalized.
       HaveNormals           = 0x0200,
-      HaveUnitNormals       = 0x0300,
-
       HaveInverseDirections = 0x0400,
       HaveSigns             = 0x0800,
       ConstantSigns         = 0x1000
     };
 
-    inline RayPacket(RayPacketData& data, int size, int depth, int flags);
+    // Create a "toplevel" raypacket.  You need to call resetHits or
+    // resetHit for every data element in the ray packet before you
+    // start intersecting.  This will initialize minT and hitMatl.
+    RayPacket(RayPacketData& data, int rayBegin, int rayEnd, int depth,
+              int flags)
+      : data(&data), rayBegin(rayBegin), rayEnd(rayEnd), depth(depth),
+        flags(flags)
+      {
+      }
 
     // Create a subset of another raypacket
-    RayPacket(RayPacket& parent, int start, int end)
-      : data(parent.data+start), size(end-start), depth(parent.depth),
-        flags(parent.flags)
+    RayPacket(RayPacket& parent, int rayBegin, int rayEnd)
+      : data(parent.data), rayBegin(rayBegin), rayEnd(rayEnd),
+        depth(parent.depth), flags(parent.flags)
       {
       }
 
@@ -48,6 +106,7 @@
     {
     }
 
+    // Raypacket flags
     int getAllFlags() const
     {
       return flags;
@@ -68,131 +127,278 @@
     void resetFlag(int flag) {
       flags &= ~flag;
     }
-    int getSize() const {
-      return size;
-    }
-    void resetHit() {
-      for(int i=0;i<size;i++)
-        data[i].hitInfo.reset();
-      flags |= HaveHitRecords;
+
+    // Depth of rays for this raypacket
+    int getDepth() const {
+      return depth;
     }
 
+
+    // Raypacket iteration
+    int begin() const {
+      return rayBegin;
+    }
+    int end() const {
+      return rayEnd;
+    }
     void resize(int newSize)
     {
-      size = newSize;
+      rayBegin = 0; rayEnd = newSize;
     }
 
-#ifndef SWIG // SWIG doesn't support nested structs/classes.
-    struct Element {
-      Color  color;
-      Real    imageX;
-      Real    imageY;
-      Ray     ray;
-      HitInfo hitInfo;
-      Vector  normal;
-      Point   hitPosition;
-      Point   texCoords;
-      Vector  inverseDirection;
-      int     sign[3];      // Mask describing ray direction, 1==negative 
0==positive,zero
-      Color   ambientLight;
-      Color   light;
-      Color   importance;  // 1-attenuation, where eye rays have importance 
== 1
 
-      int shadowBegin, shadowEnd;
-      int whichEye;
-    };
-
-    const Element& get(int which) const {
-      return data[which];
+    // Image space
+    void setPixel(int which, int whichEye, Real imageX, Real imageY)
+    {
+      data->image[0][which] = imageX;
+      data->image[1][which] = imageY;
+      data->whichEye[which] = whichEye;
     }
-    Element& get(int which) {
-      return data[which];
+    Real getImageCoordinates(int which, int dim)
+    {
+      return data->image[dim][which];
     }
-#endif // SWIG
-    void setPixel(int which, int whichEye, Real imageX, Real imageY)
+    int getWhichEye(int which) const
     {
-      data[which].imageX = imageX;
-      data[which].imageY = imageY;
-      data[which].whichEye = whichEye;
+      return data->whichEye[which];
     }
 
-    HitInfo& hitInfo(int which) {
-      return data[which].hitInfo;
+    // Rays
+    void setRay(int which, const Point& origin, const Vector& direction)
+    {
+      for(int i=0;i<3;i++)
+        data->origin[i][which] = origin[i];
+      for(int i=0;i<3;i++)
+        data->direction[i][which] = direction[i];
     }
-
-    void setResult(int which, const Color& color)
+    void setRay(int which, const Ray& ray)
     {
-      data[which].color = color;
+      for(int i=0;i<3;i++)
+        data->origin[i][which] = ray.origin()[i];
+      for(int i=0;i<3;i++)
+        data->direction[i][which] = ray.direction()[i];
     }
-    const Color& getResult(int which) const
+    Ray getRay(int which) const
     {
-      return data[which].color;
+      return Ray(Point(data->origin[0][which], data->origin[1][which], 
data->origin[2][which]),
+                 Vector(data->direction[0][which], 
data->direction[1][which], data->direction[2][which]));
+    }
+    void setOrigin(int which, const Point& origin)
+    {
+      for(int i=0;i<3;i++)
+        data->origin[i][which] = origin[i];
+    }
+    void setDirection(int which, const Vector& direction)
+    {
+      for(int i=0;i<3;i++)
+        data->direction[i][which] = direction[i];
+    }
+    Point getOrigin(int which) const
+    {
+      return Point(data->origin[0][which], data->origin[1][which], 
data->origin[2][which]);
+    }
+    Vector getDirection(int which) const
+    {
+      return Vector(data->direction[0][which], data->direction[1][which], 
data->direction[2][which]);
+    }
+    Vector getInverseDirection(int which) const
+    {
+      return Vector(data->inverseDirection[0][which], 
data->inverseDirection[1][which], data->inverseDirection[2][which]);
     }
-
     void normalizeDirections()
     {
       if(flags & NormalizedDirections)
         return;
 
       if(flags & HaveHitRecords){
-        for(int i=0;i<size;i++){
-          Real length = data[i].ray.normalizeDirection();
-          data[i].hitInfo.scaleT(length);
+        for(int i=rayBegin;i<rayEnd;i++){
+          Real sum = 0;
+          for(int j=0;j<3;j++)
+            sum += data->direction[j][i] * data->direction[j][i];
+          Real length = SCIRun::Sqrt(sum);
+          if(data->hitMatl[i] != 0)
+            data->minT[i] *= length;
+          Real scale = 1/length;
+          for(int j=0;j<3;j++)
+            data->direction[j][i] *= scale;
         }
       } else {
-        for(int i=0;i<size;i++)
-          data[i].ray.normalizeDirection();
+        for(int i=rayBegin;i<rayEnd;i++){
+          Real sum = 0;
+          for(int j=0;j<3;j++)
+            sum += data->direction[j][i] * data->direction[j][i];
+          Real scale = 1/SCIRun::Sqrt(sum);
+          for(int j=0;j<3;j++)
+            data->direction[j][i] *= scale;
+        }
       }
       flags |= NormalizedDirections;
       flags &= ~HaveInverseDirections;
     }
-    void computeHitPositions()
-    {
-      if(flags & HaveHitPositions)
-        return;
-      for(int i=0;i<size;i++) {
-        data[i].hitPosition = data[i].ray.origin() +
-          data[i].ray.direction() * data[i].hitInfo.minT();
-      }
-      flags |= HaveHitPositions;
-    }
     void computeInverseDirections()
     {
       if(flags & HaveInverseDirections)
         return;
-      for(int i=0;i<size;i++)
-        data[i].inverseDirection = Vector(1./data[i].ray.direction().x(),
-                                          1./data[i].ray.direction().y(),
-                                          1./data[i].ray.direction().z());
+      for(int i=rayBegin;i<rayEnd;i++)
+        for(int j=0;j<3;j++)
+          data->inverseDirection[j][i] = 1./data->direction[j][i];
       flags |= HaveInverseDirections;
     }
-
     void computeSigns()
     {
       if(flags & HaveSigns)
         return;
-      for(int i=0;i<size;i++)
-      {
-        data[i].sign[0] = data[i].ray.direction().x()<0.0;
-        data[i].sign[1] = data[i].ray.direction().y()<0.0;
-        data[i].sign[2] = data[i].ray.direction().z()<0.0;
-      }
-      flags |= HaveInverseDirections;
+      for(int i=rayBegin;i<rayEnd;i++)
+        for(int j = 0; j < 3; j++)
+          data->signs[j][i] = data->direction[j][i] < 0;
+      flags |= HaveSigns;
       flags &= ~ConstantSigns;
-      for(int i=1;i<size;i++)
-          if (data[i].sign[0]!=data[i-1].sign[0]||
-              data[i].sign[1]!=data[i-1].sign[1]||
-              data[i].sign[2]!=data[i-1].sign[2])
-              return;
+      int signs[3];
+      for(int j=0;j<3;j++)
+        signs[j] = data->signs[j][rayBegin];
+      for(int i=rayBegin+1; i < rayEnd; i++)
+        for(int j = 0; j < 3; 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() {
+      for(int i=rayBegin;i<rayEnd;i++){
+        data->hitMatl[i] = 0;
+        data->minT[i] = MAXT;
+      }
+      flags |= HaveHitRecords;
+    }
+    void resetHit(int which, Real maxt) {
+      data->hitMatl[which] = 0;
+      data->minT[which] = maxt;
+    }
+    Real getMinT(int which) const
+    {
+      return data->minT[which];
+    }
+    void scaleMinT(int which, Real scale)
+    {
+      data->minT[which] *= scale;
+    }
+    void overrideMinT(int which, Real minT)
+    {
+      data->minT[which] = minT;
+    }
+    bool hit(int which, Real t, const Material* matl, const Primitive* prim,
+             const TexCoordMapper* tex) {
+      if(t < T_EPSILON)
+        return false;
+      if(t < data->minT[which]){
+        data->minT[which] = t;
+        data->hitMatl[which] = matl;
+        data->hitPrim[which] = prim;
+        data->hitTex[which] = tex;
+        return true;
+      } else {
+        return false;
+      }
+    }
+    bool wasHit(int which)
+    {
+      return data->hitMatl[which] != 0;
+    }
+
+    void setHitMaterial(int which, const Material* matl)
+    {
+      data->hitMatl[which] = matl;
+    }
+    void setHitPrimitive(int which, const Primitive* prim)
+    {
+      data->hitPrim[which] = prim;
+    }
+    void setHitTexCoordMapper(int which, const TexCoordMapper* tex)
+    {
+      data->hitTex[which] = tex;
+    }
+    const Material* getHitMaterial(int which)
+    {
+      return data->hitMatl[which];
+    }
+    const Primitive* getHitPrimitive(int which)
+    {
+      return data->hitPrim[which];
+    }
+    const TexCoordMapper* getHitTexCoordMapper(int which)
+    {
+      return data->hitTex[which];
+    }
+
+    // Final result
+    void setColor(int which, const Color& color)
+    {
+      for(int i=0;i<Color::NumComponents;i++)
+        data->color[i][which] = color[i];
+    }
+    Color getColor(int which) const
+    {
+      Color result;
+      for(int i=0;i<Color::NumComponents;i++)
+        result[i] = data->color[i][which];
+      return result;
+    }
+
+    // Attenuation for ray tree pruning
+    void setImportance(int which, const Color& importance)
+    {
+      for(int i=0;i<Color::NumComponents;i++)
+        data->importance[i][which] = importance[i];
+    }
+    Color getImportance(int which)
+    {
+      Color result;
+      for(int i=0;i<Color::NumComponents;i++)
+        result[i] = data->importance[i][which];
+      return result;
+    }
+    void initializeImportance()
+    {
+      for(int j=0;j<Color::NumComponents;j++)
+        for(int i=rayBegin;i<rayEnd;i++)
+          data->importance[j][i] = 1;
+    }
+
+    // Texture Coordinates
+    void setTexCoords(int which, const Point& tc)
+    {
+      for(int i=0;i<3;i++)
+        data->texCoords[i][which] = tc[i];
+    }
+    void setTexCoords(int which, const PointT<Real, 2>& tc)
+    {
+      for(int i=0;i<2;i++)
+        data->texCoords[i][which] = tc[i];
+    }
+    Point getTexCoords(int which) const
+    {
+      return Point(data->texCoords[0][which], data->texCoords[1][which], 
data->texCoords[2][which]);
+    }
+    PointT<Real, 2> getTexCoords2(int which) const
+    {
+      return PointT<Real, 2>(data->texCoords[0][which], 
data->texCoords[1][which]);
+    }
+
+    // These aren't right - the texture object may not be consecutive
     void computeTextureCoordinates2(const RenderContext& context)
     {
       if(flags & (HaveTexture2|HaveTexture3))
         return;
-      Element& e0 = data[0];
-      const TexCoordMapper* tex = e0.hitInfo.hitTexCoordMapper();
+      const TexCoordMapper* tex = data->hitTex[rayBegin];
       tex->computeTexCoords2(context, *this);
       flags |= HaveTexture2;
     }
@@ -200,93 +406,113 @@
     {
       if(flags & HaveTexture3)
         return;
-      Element& e0 = data[0];
-      const TexCoordMapper* tex = e0.hitInfo.hitTexCoordMapper();
+      const TexCoordMapper* tex = data->hitTex[rayBegin];
       tex->computeTexCoords3(context, *this);
       flags |= HaveTexture2|HaveTexture3;
     }
-#if 0
-    void computeFrame(const RenderContext& context)
+
+
+    // Normals
+    void setNormal(int which, const Vector& normal)
+    {
+      for(int i=0;i<3;i++)
+        data->normal[i][which] = normal[i];
+    }
+    Vector getNormal(int which) const
     {
-      if(flags & HaveFrame)
-        return;
-      Element& e0 = data[0];
-      const UVMapping* uv = e0.hitInfo.hitPrimitive()->getUVMapping();
-      uv->computeFrame(context, *this);
-      flags |= HaveFrame;
+      return Vector(data->normal[0][which], data->normal[1][which], 
data->normal[2][which]);
     }
-#endif
-
     void computeNormals(const RenderContext& context)
     {
       if(flags & HaveNormals)
         return;
-      
+
       // Compute normals
-      for(int i=0;i<size;){
-        RayPacket::Element& e = data[i];
-        const Primitive* prim = e.hitInfo.hitPrimitive();
-        int end = i+1;
-        while(end < size && data[end].hitInfo.hitPrimitive() == prim)
-          end++;
-        RayPacket subPacket(*this, i, end);
+      for(int i=rayBegin;i<rayEnd;){
+        const Primitive* prim = data->hitPrim[i];
+        int tend = i+1;
+        while(tend < rayEnd && data->hitPrim[tend] == prim)
+          tend++;
+        RayPacket subPacket(*this, i, tend);
         prim->computeNormal(context, subPacket);
-        i=end;
+        // BTW, == has higher precedence than &, so mind the ()'s.
+        if ((subPacket.flags & HaveUnitNormals) == 0) {
+          // Normalize the normals if they haven't been.
+          for(int s=i;s<tend;++s){
+            Real sum = 0;
+            for(int j=0;j<3;++j)
+              sum += data->normal[j][s] * data->normal[j][s];
+            Real scale = 1/SCIRun::Sqrt(sum);
+            for(int j=0;j<3;++j)
+              data->normal[j][s] *= scale;
+          }
+        }
+        i=tend;
       }
-      
-      flags |= HaveNormals;
+
+      flags |= HaveNormals | HaveUnitNormals;
+    }
+
+    // Hit positions
+    Point getHitPosition(int which) const
+    {
+      return Point(data->hitPosition[0][which], data->hitPosition[1][which], 
data->hitPosition[2][which]);
     }
-    void normalizeNormals()
+    Point setHitPosition(int which, const Point& hit) const
     {
-      ASSERT(flags & HaveNormals);
-      if(flags & HaveUnitNormals)
+      for(int i=0;i<3;i++)
+        data->hitPosition[i][which] = hit[which];
+    }
+    void computeHitPositions()
+    {
+      if(flags & HaveHitPositions)
         return;
-      for(int i=0;i<size;i++)
-        data[i].normal.normalize();
-      flags |= HaveUnitNormals;
+      for(int i=rayBegin;i<rayEnd;i++) {
+        for(int j=0;j<3;j++)
+          data->hitPosition[j][i] = data->origin[j][i] + 
data->direction[j][i] * data->minT[i];
+      }
+      flags |= HaveHitPositions;
     }
 
-    int getDepth() const {
-      return depth;
-    }
 
-    void initializeImportance()
-    {
-      for(int i=0;i<size;i++)
-        data[i].importance = Color::white();
+    // Scratchpad isn't quite "vertical" yet...
+    template<class T> T& scratchpad(int which) {
+
+      // This pragma relates to the following expression being
+      // constant (which it is).  Since sizeof(T) is evaluated after
+      // the preprocessor, we can't get around not doing it here like
+      // this.
+
+#     if defined(__sgi) && !defined(__GNUC__)
+#       pragma set woff 1209
+      ASSERT(sizeof(T) <= RayPacketData::MaxScratchpadSize);
+#       pragma set woff 1209
+#     else
+      ASSERT(sizeof(T) <= RayPacketData::MaxScratchpadSize);
+#     endif
+      return *(T*)data->scratchpad_data[which];
+    }
+    // This will copy the contects of the scratchpad from the incoming
+    // RayPacket.
+    void copyScratchpad(int which, RayPacket& copy, int which_copy) {
+      memcpy( data->scratchpad_data[which],
+              copy.data->scratchpad_data[which_copy],
+              RayPacketData::MaxScratchpadSize);
     }
+
   private:
     RayPacket(const RayPacket&);
     RayPacket& operator=(const RayPacket&);
 
-    Element* data;
-    int size;
+    RayPacketData* data;
+    int rayBegin;
+    int rayEnd;
     int depth;
     int flags;
   };
 
-  class RayPacketData {
-  public:
-    RayPacketData()
-    {
-    }
+  typedef Color::ComponentType 
ColorArray[Color::NumComponents][RayPacket::MaxSize];
 
-    ~RayPacketData()
-    {
-    }
-
-  private:
-    RayPacket::Element data[RayPacket::MaxSize];
-    friend class RayPacket;
-  };
-
-  // This is dependent on the RayPacketData struct, so it cannot be defined 
in the
-  // RayPacket class
-  inline RayPacket::RayPacket(RayPacketData& data, int size, int depth, int 
flags)
-    : data(&data.data[0]), size(size), depth(depth), flags(flags)
-    {
-    }
 } // end namespace Manta
-
 
 #endif

Modified: trunk/Interface/RenderParameters.h
==============================================================================
--- trunk/Interface/RenderParameters.h  (original)
+++ trunk/Interface/RenderParameters.h  Fri Jan 20 15:03:05 2006
@@ -8,6 +8,7 @@
   class RenderParameters {
   public:
     RenderParameters() {
+      // These are default values.  The scene can override them.
       maxDepth = 15;
       importanceCutoff = 0.01;
     }

Modified: trunk/Interface/ShadowAlgorithm.h
==============================================================================
--- trunk/Interface/ShadowAlgorithm.h   (original)
+++ trunk/Interface/ShadowAlgorithm.h   Fri Jan 20 15:03:05 2006
@@ -3,6 +3,7 @@
 #ifndef Manta_Interface_ShadowAlgorithm_h
 #define Manta_Interface_ShadowAlgorithm_h
 
+#include <Interface/RayPacket.h>
 #include <sgi_stl_warnings_off.h>
 #include <string>
 #include <sgi_stl_warnings_on.h>
@@ -12,14 +13,42 @@
   class RayPacket;
   class RenderContext;
 
+
   class ShadowAlgorithm {
   public:
     ShadowAlgorithm();
     virtual ~ShadowAlgorithm();
 
-    virtual int computeShadows(const RenderContext& context, const LightSet* 
lights,
-                              RayPacket&, int start, RayPacket&) = 0;
+    struct StateBuffer {
+      // Most shadowAlgorithms will only need to store an int or two in the
+      // state buffer, so we can get alignment guarantees and avoid cast
+      // nastiness by supplying them here.  If you use cast() below, these
+      // are part of the casted object.  Callers of the shadow algorithm
+      // should not assume anything about the data in this object!
+      int i1, i2;
+
+      template<class T> T& cast() {
+
+        // This pragma relates to the following expression being
+        // constant (which it is).  Since sizeof(T) is evaluated after
+        // the preprocessor, we can't get around not doing it here like
+        // this.
+
+#     if defined(__sgi) && !defined(__GNUC__)
+#       pragma set woff 1209
+        ASSERT(sizeof(T) <= sizeof(*this));
+#       pragma set woff 1209
+#     else
+        ASSERT(sizeof(T) <= sizeof(*this));
+#     endif
+        return *(T*)this;
+      }
+    };
 
+    virtual bool computeShadows(const RenderContext& context, const 
LightSet* lights,
+                                RayPacket& source, int map[], RayPacket& 
shadowRays,
+                                bool firstTime, StateBuffer& stateBuffer) = 
0;
+    
     virtual std::string getName() const = 0;
     virtual std::string getSpecs() const = 0;
 

Modified: trunk/Interface/TexCoordMapper.h
==============================================================================
--- trunk/Interface/TexCoordMapper.h    (original)
+++ trunk/Interface/TexCoordMapper.h    Fri Jan 20 15:03:05 2006
@@ -16,8 +16,8 @@
     virtual void computeTexCoords3(const RenderContext& context,
                                   RayPacket& rays) const = 0;
   private:
-    // TexCoordMapper(const TexCoordMapper&);
-    // TexCoordMapper& operator=(const TexCoordMapper&);
+    TexCoordMapper(const TexCoordMapper&);
+    TexCoordMapper& operator=(const TexCoordMapper&);
   };
 }
 

Modified: trunk/MantaTypes.h
==============================================================================
--- trunk/MantaTypes.h  (original)
+++ trunk/MantaTypes.h  Fri Jan 20 15:03:05 2006
@@ -56,6 +56,7 @@
   // Transforms - forward declarations
   template<typename T> class AffineTransformT;
   typedef AffineTransformT<Real> AffineTransform;
+
 }
 
 #endif

Modified: trunk/Model/AmbientLights/ArcAmbient.cc
==============================================================================
--- trunk/Model/AmbientLights/ArcAmbient.cc     (original)
+++ trunk/Model/AmbientLights/ArcAmbient.cc     Fri Jan 20 15:03:05 2006
@@ -27,12 +27,12 @@
 }
 
 void ArcAmbient::computeAmbient(const RenderContext& context,
-                               RayPacket& rays) const
+                                RayPacket& rays,
+                                ColorArray ambient) const
 {
   rays.computeNormals(context);
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    Real cosine = Dot(e.normal, up);
+  for(int i=rays.begin();i<rays.end();i++){
+    Real cosine = Dot(rays.getNormal(i), up);
     Real sine = SCIRun::Sqrt(1-cosine*cosine);
     // So we want to do the computation for w0 and w1 as type Real,
     // because that is what all the other computation will be done,
@@ -46,7 +46,9 @@
       w1= sine/2;
       w0= (1 -  w1);
     }
-    rays.get(i).ambientLight = cup*w1 + cdown*w0;
+    Color ambientLight = cup*w1 + cdown*w0;
+    for(int j=0;j<Color::NumComponents;j++)
+      ambient[j][i] = ambientLight[j];
   }
 }
 

Modified: trunk/Model/AmbientLights/ArcAmbient.h
==============================================================================
--- trunk/Model/AmbientLights/ArcAmbient.h      (original)
+++ trunk/Model/AmbientLights/ArcAmbient.h      Fri Jan 20 15:03:05 2006
@@ -19,7 +19,7 @@
     virtual ~ArcAmbient();
 
     virtual void preprocess(const PreprocessContext&);
-    virtual void computeAmbient(const RenderContext& context, RayPacket& 
rays) const;
+    virtual void computeAmbient(const RenderContext& context, RayPacket& 
rays, ColorArray ambient) const;
 
     virtual std::string toString() const;
   private:

Modified: trunk/Model/AmbientLights/CMakeLists.txt
==============================================================================
--- trunk/Model/AmbientLights/CMakeLists.txt    (original)
+++ trunk/Model/AmbientLights/CMakeLists.txt    Fri Jan 20 15:03:05 2006
@@ -1,4 +1,5 @@
 
 SET (Manta_AmbientLights_SRCS
      AmbientLights/ConstantAmbient.cc
-     AmbientLights/ArcAmbient.cc)
+     AmbientLights/ArcAmbient.cc
+    )

Modified: trunk/Model/AmbientLights/ConstantAmbient.cc
==============================================================================
--- trunk/Model/AmbientLights/ConstantAmbient.cc        (original)
+++ trunk/Model/AmbientLights/ConstantAmbient.cc        Fri Jan 20 15:03:05 
2006
@@ -23,10 +23,12 @@
 }
 
 void ConstantAmbient::computeAmbient(const RenderContext&,
-                                    RayPacket& rays) const
+                                     RayPacket& rays,
+                                     ColorArray ambient) const
 {
-  for(int i=0;i<rays.getSize();i++)
-    rays.get(i).ambientLight = color;
+  for(int i=rays.begin();i<rays.end();i++)
+    for(int j=0;j<Color::NumComponents;j++)
+      ambient[j][i] = color[j];
 }
 
 string ConstantAmbient::toString() const {

Modified: trunk/Model/AmbientLights/ConstantAmbient.h
==============================================================================
--- trunk/Model/AmbientLights/ConstantAmbient.h (original)
+++ trunk/Model/AmbientLights/ConstantAmbient.h Fri Jan 20 15:03:05 2006
@@ -16,7 +16,7 @@
     virtual ~ConstantAmbient();
 
     virtual void preprocess(const PreprocessContext&);
-    virtual void computeAmbient(const RenderContext& context, RayPacket& 
rays) const;
+    virtual void computeAmbient(const RenderContext& context, RayPacket& 
rays, ColorArray ambient) const;
 
     virtual std::string toString() const;
   private:

Modified: trunk/Model/Backgrounds/ConstantBackground.cc
==============================================================================
--- trunk/Model/Backgrounds/ConstantBackground.cc       (original)
+++ trunk/Model/Backgrounds/ConstantBackground.cc       Fri Jan 20 15:03:05 
2006
@@ -19,6 +19,6 @@
 
 void ConstantBackground::shade(const RenderContext&, RayPacket& rays) const
 {
-  for(int i=0;i<rays.getSize();i++)
-    rays.setResult(i, bgcolor);
+  for(int i=rays.begin();i<rays.end();i++)
+    rays.setColor(i, bgcolor);
 }

Modified: trunk/Model/Backgrounds/LinearBackground.cc
==============================================================================
--- trunk/Model/Backgrounds/LinearBackground.cc (original)
+++ trunk/Model/Backgrounds/LinearBackground.cc Fri Jan 20 15:03:05 2006
@@ -23,13 +23,12 @@
 void LinearBackground::shade(const RenderContext&, RayPacket& rays) const
 {
   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++){
     // So we want to do the computation for t as type Real, because
     // that is what all the other computation will be done, but we
     // would like to cast that to type ColorComponent, because we will
     // do operations on the color with this value.
-    ColorComponent t = (Real)0.5 * (1 + Dot(e.ray.direction(), up));
-    rays.setResult(i, cup*t+cdown*(1-t));
+    ColorComponent t = (Real)0.5 * (1 + Dot(rays.getDirection(i), up));
+    rays.setColor(i, cup*t+cdown*(1-t));
   }
 }

Modified: trunk/Model/Backgrounds/TextureBackground.cc
==============================================================================
--- trunk/Model/Backgrounds/TextureBackground.cc        (original)
+++ trunk/Model/Backgrounds/TextureBackground.cc        Fri Jan 20 15:03:05 
2006
@@ -58,15 +58,14 @@
                                           RayPacket& rays) const
 {
   rays.computeHitPositions();
-  for(int i = 0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    Point n = e.hitPosition;
+  for(int i = rays.begin();i<rays.end();i++){
+    Point n = rays.getHitPosition(i);
     Real angle = Clamp(n.z(), (Real)-1, (Real)1);
     Real theta = Acos(angle);
     Real phi = Atan2(n.x(), n.y());
     Real x = (phi+(Real)M_PI)*((Real)0.5*(Real)M_1_PI);
     Real y = theta*(Real)M_1_PI;
-    e.texCoords = Point(x, y, 0);
+    rays.setTexCoords(i, PointT<Real, 2>(x, y));
   }
 }
 
@@ -77,12 +76,11 @@
 
   // Copy the ray directions and set the TexCoordMapper pointer back
   // to this class for 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++){
     // Set the TexCoordMapper pointer.
-    e.hitInfo.set_hit(0,0,0, mapper);
+    rays.setHitTexCoordMapper(i, mapper);
     // Copy the direction from old ray to the new one.
-    e.hitPosition = Point(e.ray.direction());
+    rays.setHitPosition(i, Point(rays.getDirection(i)));
   }
   // Tell the RayPacket that we have the hit positions since we just
   // fed them in there.
@@ -93,9 +91,8 @@
   colortex->mapValues(context, rays, bg_color);
 
   // Copy the colors over.
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    rays.setResult(i, bg_color[i]);
+  for(int i=rays.begin();i<rays.end();i++){
+    rays.setColor(i, bg_color[i]);
   }
 }
 

Modified: trunk/Model/Cameras/EnvironmentCamera.cc
==============================================================================
--- trunk/Model/Cameras/EnvironmentCamera.cc    (original)
+++ trunk/Model/Cameras/EnvironmentCamera.cc    Fri Jan 20 15:03:05 2006
@@ -89,30 +89,28 @@
   ASSERT(rays.getAllFlags() & RayPacket::HaveImageCoordinates);
   rays.setFlag(RayPacket::ConstantOrigin);
   if (normalizeRays) {
-    for (int i=0; i<rays.getSize(); i++) {
-      RayPacket::Element& e=rays.get(i);
-      Real theta = (Real)0.5 * ((Real)M_PI - (Real)M_PI * e.imageY);
-      Real phi = (Real)M_PI * e.imageX + (Real)M_PI;
+    for (int i=rays.begin(); i<rays.end(); i++) {
+      Real theta = (Real)0.5 * ((Real)M_PI - (Real)M_PI * 
rays.getImageCoordinates(i, 1));
+      Real phi = (Real)M_PI * rays.getImageCoordinates(i, 0) + (Real)M_PI;
       Vector xyz(Sin(theta)*Cos(phi), Sin(theta)*Sin(phi),
                  Cos(theta));
       Vector raydir(Dot(xyz, v),
                     Dot(xyz, n),
                     Dot(xyz, u));
       raydir.normalize();
-      e.ray.set(eye, raydir);
+      rays.setRay(i, eye, raydir);
     }
     rays.setFlag(RayPacket::NormalizedDirections);
   } else {
-    for (int i=0; i<rays.getSize(); i++) {
-      RayPacket::Element& e=rays.get(i);
-      Real theta = (Real)0.5 * ((Real)M_PI - (Real)M_PI * e.imageY);
-      Real phi = (Real)M_PI * e.imageX + (Real)M_PI;
+    for (int i=rays.begin(); i<rays.end(); i++) {
+      Real theta = (Real)0.5 * ((Real)M_PI - (Real)M_PI * 
rays.getImageCoordinates(i, 1));
+      Real phi = (Real)M_PI * rays.getImageCoordinates(i, 0) + (Real)M_PI;
       Vector xyz(Sin(theta)*Cos(phi), Sin(theta)*Sin(phi),
                  Cos(theta));
       Vector raydir(Dot(xyz, v),
                     Dot(xyz, n),
                     Dot(xyz, u));
-      e.ray.set(eye, raydir);
+      rays.setRay(i, eye, raydir);
     }
   }
 }

Modified: trunk/Model/Cameras/FisheyeCamera.cc
==============================================================================
--- trunk/Model/Cameras/FisheyeCamera.cc        (original)
+++ trunk/Model/Cameras/FisheyeCamera.cc        Fri Jan 20 15:03:05 2006
@@ -8,12 +8,16 @@
 #include <Core/Geometry/AffineTransform.h>
 #include <Core/Math/MiscMath.h>
 #include <Core/Math/Trig.h>
+#include <Core/Math/Expon.h>
 #include <Core/Util/Assert.h>
+
+#include <sgi_stl_warnings_off.h>
 #include <iostream>
+#include <sgi_stl_warnings_on.h>
 
 using namespace Manta;
+using namespace SCIRun;
 using namespace std;
-using SCIRun::Clamp;
 
 FisheyeCamera::FisheyeCamera(const vector<string>& args)
 {
@@ -82,15 +86,16 @@
 {
   ASSERT(rays.getFlag(RayPacket::HaveImageCoordinates) );
   rays.setFlag(RayPacket::ConstantOrigin|RayPacket::NormalizedDirections);
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    Real z = Sqrt( 2 - e.imageX * e.imageX - e.imageY * e.imageY );
-    Real theta = Atan2( e.imageY, e.imageX );
+  for(int i=rays.begin();i<rays.end();i++){
+    Real imageX = rays.getImageCoordinates(i, 0);
+    Real imageY = rays.getImageCoordinates(i, 1);
+    Real z = Sqrt( 2 - imageX * imageX - imageY * imageY );
+    Real theta = Atan2( imageY, imageX );
     Real phi = Acos( z * (Real)M_SQRT1_2 ) * hfov;
     Real x = Cos( theta ) * Sin( phi );
     Real y = Sin( theta ) * Sin( phi );
     z = Cos( phi );
-    e.ray.set(eye, v*x+u*y+n*z);
+    rays.setRay(i, eye, v*x+u*y+n*z);
   }
 }
 

Modified: trunk/Model/Cameras/OrthogonalCamera.cc
==============================================================================
--- trunk/Model/Cameras/OrthogonalCamera.cc     (original)
+++ trunk/Model/Cameras/OrthogonalCamera.cc     Fri Jan 20 15:03:05 2006
@@ -78,10 +78,9 @@
 {
   ASSERT(rays.getFlag(RayPacket::HaveImageCoordinates));
 
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    Point rayposition(eye+v*e.imageX+u*e.imageY);
-    e.ray.set(rayposition, direction);
+  for(int i=rays.begin();i<rays.end();i++){
+    Point rayposition(eye+v*rays.getImageCoordinates(i, 
0)+u*rays.getImageCoordinates(i, 1));
+    rays.setRay(i, rayposition, direction);
   }
   rays.setFlag(RayPacket::NormalizedDirections);
 }

Modified: trunk/Model/Cameras/PinholeCamera.cc
==============================================================================
--- trunk/Model/Cameras/PinholeCamera.cc        (original)
+++ trunk/Model/Cameras/PinholeCamera.cc        Fri Jan 20 15:03:05 2006
@@ -124,25 +124,19 @@
   stereo_eye[1] = (eye + (v*stereo_offset));
   
   if(normalizeRays){    
-    for(int i=0;i<rays.getSize();i++){
-      RayPacket::Element& e = rays.get(i);
-      Vector raydir(v*e.imageX+u*e.imageY+direction);
+    for(int i=rays.begin();i<rays.end();i++){
+      Vector raydir(v*rays.getImageCoordinates(i, 
0)+u*rays.getImageCoordinates(i, 1)+direction);
       raydir.normalize();
-      e.ray.set(stereo_eye[e.whichEye], raydir);
+      rays.setRay(i, stereo_eye[rays.getWhichEye(i)], raydir);
     }
     rays.setFlag(RayPacket::NormalizedDirections);
 
 
   } else {
-    for(int i=0;i<rays.getSize();i++){
-      RayPacket::Element& e = rays.get(i);
-
-      Vector raydir(v*e.imageX+u*e.imageY+direction);
-
-      e.ray.set(stereo_eye[e.whichEye], raydir);
+    for(int i=rays.begin();i<rays.end();i++){
+      Vector raydir(v*rays.getImageCoordinates(i, 
0)+u*rays.getImageCoordinates(i, 1)+direction);
+      rays.setRay(i, stereo_eye[rays.getWhichEye(i)], raydir);
     }
-
-
   }
 }
 

Modified: trunk/Model/Groups/BVH.cc
==============================================================================
--- trunk/Model/Groups/BVH.cc   (original)
+++ trunk/Model/Groups/BVH.cc   Fri Jan 20 15:03:05 2006
@@ -102,166 +102,166 @@
     //cerr << "top bounds: " << nodes[0].min << " : " << nodes[0].max << 
'\n';
   }
   else if(buildMode == "table")
-  {
-    // build 2D cost table, index table, and bbox of each prim
-    // set up initial table and mark first prims to combine
-    float **costTable = new float*[nprims];
-    float *costCols  = new float[(nprims*nprims-nprims)/2];
-    int *indexTable = new int[nprims];
-    Node *objValues = new Node[nprims];
-    int i;
-
-    {
-      indexTable[0] = -0;
-      BBox box;
-      objs[0]->computeBounds(context,box);
-      objValues[0].min = box.getMin();
-      objValues[0].max = box.getMax();
-    }
-    // setup data structures
-    for(i=1; i<nprims; i++)
-    {
-      costTable[i] = costCols;
-      costCols += i;
-      indexTable[i] = -i; // build index table
-      BBox box;
-      objs[i]->computeBounds(context,box);
-      objValues[i].min = box.getMin();
-      objValues[i].max = box.getMax();
-
-      for(int j=i-1; j>=0; j--)
-      {
-       Point min = Min(objValues[i].min,objValues[j].min);
-       Point max = Max(objValues[i].max,objValues[j].max);
-       //compute area as a cost function
-       float area = computeArea(max,min);
-       //store cost in table
-       costTable[i][j] = area;
-      }
-    }
-
-    /////////////////////////
-
-    // create tree
-    int marki=0,markj=0;
-    float markval;
-    int iindex=1;
-    for(int k=0; k<nprims-1; k++)
     {
-      // search table
-      markval = -1;
-      for(i=1; i<nprims-k; i++)
-      {
-       for(int j=i-1; j>=0; j--)
-       {
-         if((costTable[i][j]<markval) || (markval<0))
-         {
-           markval = costTable[i][j];
-           marki=i;
-           markj=j;
-           
-         }
-       }
-      }
-
-      // make swap and everything
-      if(marki > markj)
-      {
-       int temp = marki;
-       marki = markj;
-       markj = temp;
-      }
-
-      --i; // bring it back to last index.
-      // find out if primitive or not use appropriate array
-      Point markiMin, markiMax;
-      if(indexTable[marki] <= 0)
-      {
-       markiMin = objValues[-indexTable[marki]].min;
-       markiMax = objValues[-indexTable[marki]].max;
-      }
-      else
-      {
-       markiMin = nodes[indexTable[marki]].min;
-       markiMax = nodes[indexTable[marki]].max;
-      }
-      Point markjMin, markjMax;
-      if(indexTable[markj] <= 0)
-      {
-       markjMin = objValues[-indexTable[markj]].min;
-       markjMax = objValues[-indexTable[markj]].max;
-      }
-      else
-      {
-       markjMin = nodes[indexTable[markj]].min;
-       markjMax = nodes[indexTable[markj]].max;
-      }
-
-      ++iindex; // iindex if for the nodes array
-      // swaping index numbers
-      nodes[iindex].left = indexTable[marki]; // set index of nodes
-      nodes[iindex].right = indexTable[markj];
-      nodes[iindex].min = Min(markiMin,markjMin);
-      nodes[iindex].max = Max(markiMax,markjMax);
-
-      // set new indices
-      indexTable[marki] = iindex;
-      indexTable[markj] = indexTable[nprims-k-1];
-      // replace markj with last column
-      costTable[markj] = costTable[i];
-      // rearange data in new cells
-      for(int m=markj+1; m<i; m++)
-       costTable[m][markj] = costTable[i][m];
-
-      // replace new column with new values
-      Point bmin, bmax;
-      Point mmin, mmax;
-      for(int m=0; m<marki; m++)
-      {
-       if(indexTable[m]<=0)
-       {
-         mmin = objValues[-indexTable[m]].min;
-         mmax = objValues[-indexTable[m]].max;
-       }
-       else
-       {
-         mmin = nodes[indexTable[m]].min;
-         mmax = nodes[indexTable[m]].max;
-       }
-       bmin = Min(nodes[iindex].min,mmin);
-       bmax = Max(nodes[iindex].max,mmax);
-       costTable[marki][m] = computeArea(bmax,bmin);
-      }
+      // build 2D cost table, index table, and bbox of each prim
+      // set up initial table and mark first prims to combine
+      float **costTable = new float*[nprims];
+      float *costCols  = new float[(nprims*nprims-nprims)/2];
+      int *indexTable = new int[nprims];
+      Node *objValues = new Node[nprims];
+      int i;
 
-      // replace new row with new values
-      for(int m=markj; m<i; m++)
       {
-       if(indexTable[m]<=0)
-       {
-         mmin = objValues[-indexTable[m]].min;
-         mmax = objValues[-indexTable[m]].max;
-       }
-       else
-       {
-         mmin = nodes[indexTable[m]].min;
-         mmax = nodes[indexTable[m]].max;
-       }
-       bmin = Min(nodes[iindex].min,mmin);
-       bmax = Max(nodes[iindex].max,mmax);
-       costTable[m][marki] = computeArea(bmax,bmin);
-      }
+        indexTable[0] = -0;
+        BBox box;
+        objs[0]->computeBounds(context,box);
+        objValues[0].min = box.getMin();
+        objValues[0].max = box.getMax();
+      }
+      // setup data structures
+      for(i=1; i<nprims; i++)
+        {
+          costTable[i] = costCols;
+          costCols += i;
+          indexTable[i] = -i; // build index table
+          BBox box;
+          objs[i]->computeBounds(context,box);
+          objValues[i].min = box.getMin();
+          objValues[i].max = box.getMax();
+
+          for(int j=i-1; j>=0; j--)
+            {
+              Point min = Min(objValues[i].min,objValues[j].min);
+              Point max = Max(objValues[i].max,objValues[j].max);
+              //compute area as a cost function
+              float area = computeArea(max,min);
+              //store cost in table
+              costTable[i][j] = area;
+            }
+        }
+
+      /////////////////////////
+
+      // create tree
+      int marki=0,markj=0;
+      float markval;
+      int iindex=1;
+      for(int k=0; k<nprims-1; k++)
+        {
+          // search table
+          markval = -1;
+          for(i=1; i<nprims-k; i++)
+            {
+              for(int j=i-1; j>=0; j--)
+                {
+                  if((costTable[i][j]<markval) || (markval<0))
+                    {
+                      markval = costTable[i][j];
+                      marki=i;
+                      markj=j;
+
+                    }
+                }
+            }
+
+          // make swap and everything
+          if(marki > markj)
+            {
+              int temp = marki;
+              marki = markj;
+              markj = temp;
+            }
+
+          --i; // bring it back to last index.
+          // find out if primitive or not use appropriate array
+          Point markiMin, markiMax;
+          if(indexTable[marki] <= 0)
+            {
+              markiMin = objValues[-indexTable[marki]].min;
+              markiMax = objValues[-indexTable[marki]].max;
+            }
+          else
+            {
+              markiMin = nodes[indexTable[marki]].min;
+              markiMax = nodes[indexTable[marki]].max;
+            }
+          Point markjMin, markjMax;
+          if(indexTable[markj] <= 0)
+            {
+              markjMin = objValues[-indexTable[markj]].min;
+              markjMax = objValues[-indexTable[markj]].max;
+            }
+          else
+            {
+              markjMin = nodes[indexTable[markj]].min;
+              markjMax = nodes[indexTable[markj]].max;
+            }
+
+          ++iindex; // iindex if for the nodes array
+          // swaping index numbers
+          nodes[iindex].left = indexTable[marki]; // set index of nodes
+          nodes[iindex].right = indexTable[markj];
+          nodes[iindex].min = Min(markiMin,markjMin);
+          nodes[iindex].max = Max(markiMax,markjMax);
+
+          // set new indices
+          indexTable[marki] = iindex;
+          indexTable[markj] = indexTable[nprims-k-1];
+          // replace markj with last column
+          costTable[markj] = costTable[i];
+          // rearange data in new cells
+          for(int m=markj+1; m<i; m++)
+            costTable[m][markj] = costTable[i][m];
+
+          // replace new column with new values
+          Point bmin, bmax;
+          Point mmin, mmax;
+          for(int m=0; m<marki; m++)
+            {
+              if(indexTable[m]<=0)
+                {
+                  mmin = objValues[-indexTable[m]].min;
+                  mmax = objValues[-indexTable[m]].max;
+                }
+              else
+                {
+                  mmin = nodes[indexTable[m]].min;
+                  mmax = nodes[indexTable[m]].max;
+                }
+              bmin = Min(nodes[iindex].min,mmin);
+              bmax = Max(nodes[iindex].max,mmax);
+              costTable[marki][m] = computeArea(bmax,bmin);
+            }
+
+          // replace new row with new values
+          for(int m=markj; m<i; m++)
+            {
+              if(indexTable[m]<=0)
+                {
+                  mmin = objValues[-indexTable[m]].min;
+                  mmax = objValues[-indexTable[m]].max;
+                }
+              else
+                {
+                  mmin = nodes[indexTable[m]].min;
+                  mmax = nodes[indexTable[m]].max;
+                }
+              bmin = Min(nodes[iindex].min,mmin);
+              bmax = Max(nodes[iindex].max,mmax);
+              costTable[m][marki] = computeArea(bmax,bmin);
+            }
+        }
+
+      // last iteration
+      nodes[1].left = indexTable[0]; // set index of nodes
+      nodes[1].right = indexTable[1];
+      nodes[1].min=Min(nodes[indexTable[0]].min, nodes[indexTable[1]].min);
+      nodes[1].max=Max(nodes[indexTable[0]].max, nodes[indexTable[1]].max);
+
+      delete [] costTable;
+      delete [] indexTable;
+      delete [] objValues;
     }
-
-    // last iteration
-    nodes[1].left = indexTable[0]; // set index of nodes
-    nodes[1].right = indexTable[1];
-    nodes[1].min=Min(nodes[indexTable[0]].min, nodes[indexTable[1]].min);
-    nodes[1].max=Max(nodes[indexTable[0]].max, nodes[indexTable[1]].max);
-
-    delete [] costTable;
-    delete [] indexTable;
-    delete [] objValues;
-  }
   else {
     throw InternalError("Unknown build mode: "+buildMode, __FILE__, __LINE__ 
);
   }
@@ -316,8 +316,8 @@
       Vector t2 = (node->max - e.ray.origin()) * e.inverseDirection;
       Vector tn = Min(t1, t2);
       Vector tf = Max(t1, t2);
-      double tnear = tn.maxComponent();
-      double tfar = tf.minComponent();
+      Real tnear = tn.maxComponent();
+      Real tfar = tf.minComponent();
       if(tnear <= tfar){
         if(node->left <= 0)
           // Hit prim
@@ -340,13 +340,12 @@
   Node* node = nodes+cur.node;
   int total = 0;
   for(int i=cur.start;i<cur.end;i++){
-    RayPacket::Element& e = rays.get(i);
-    Vector t1 = (node->min - e.ray.origin()) * e.inverseDirection;
-    Vector t2 = (node->max - e.ray.origin()) * e.inverseDirection;
+    Vector t1 = (node->min - rays.getOrigin(i)) * 
rays.getInverseDirection(i);
+    Vector t2 = (node->max - rays.getOrigin(i)) * 
rays.getInverseDirection(i);
     Vector tn = Min(t1, t2);
     Vector tf = Max(t1, t2);
-    double tnear = tn.maxComponent();
-    double tfar = tf.minComponent();
+    Real tnear = tn.maxComponent();
+    Real tfar = tf.minComponent();
     bool hit = (tnear <= tfar);
     cur.bv_hit[i] = hit;
     total += (int)hit;
@@ -362,8 +361,8 @@
   int nstack = 0;
 
   stack[nstack].node = 1;
-  stack[nstack].start = 0;
-  stack[nstack].end = rays.getSize();
+  stack[nstack].start = rays.begin();
+  stack[nstack].end = rays.end();
   int numHit = intersect_box(rays, stack[nstack]);
   if(!numHit)
     return;
@@ -379,7 +378,7 @@
       if(cur.bv_hit[start])
         goto out1;
       start++;
-    } 
+    }
     // All missed, pop the stack and continue
     nstack--;
     continue;
@@ -393,7 +392,7 @@
         goto out2;
       }
       end++;
-    } 
+    }
 
     // Pop the stack
     nstack--;
@@ -427,11 +426,11 @@
       int numHit = intersect_box(rays, right);
       if(numHit == 0)
         nstack--;
-    } 
+    }
   }
-  
+
   // default return since there was none there
   //return 0;
-}    
+}
 
 #endif

Modified: trunk/Model/Groups/BVH.h
==============================================================================
--- trunk/Model/Groups/BVH.h    (original)
+++ trunk/Model/Groups/BVH.h    Fri Jan 20 15:03:05 2006
@@ -16,10 +16,11 @@
     virtual ~BVH();
 
     virtual void preprocess(const PreprocessContext&);
-    virtual void intersect(const RenderContext& context, RayPacket& rays) 
const;
+    virtual void intersect(const RenderContext& context,
+                           RayPacket& rays) const;
 
     static Group* create(const vector<string>& args);
-  private: 
+  private:
     struct Node {
       Point min;
       Point max;
@@ -34,19 +35,14 @@
       bool bv_hit[RayPacket::MaxSize];
     };
     inline int intersect_box(RayPacket& rays, StackEntry& cur) const;
-    inline float length(const float i, const float j) const
-      { return fabsf(i-j); }
     inline float computeArea(const Point &max, const Point &min) const
     {
-      float lenx = length(max.x(),min.x());
-      float leny = length(max.y(),min.y());
-      float lenz = length(max.z(),min.z());
-      return (2*((lenx*leny) + (leny*lenz) + (lenx*lenz)));
+      return 2*(max-min).length2();
     }
 
     string buildMode;
 
- };
+  };
 }
 
 #endif

Modified: trunk/Model/Groups/CMakeLists.txt
==============================================================================
--- trunk/Model/Groups/CMakeLists.txt   (original)
+++ trunk/Model/Groups/CMakeLists.txt   Fri Jan 20 15:03:05 2006
@@ -12,13 +12,12 @@
      Groups/TransparentKDTree.cc
      Groups/KDTreeLoader.h
      Groups/KDTreeLoader.cc
-     Groups/FrustumKDTree.h
-     Groups/FrustumKDTree.cc
+     #Groups/FrustumKDTree.h
+     #Groups/FrustumKDTree.cc
      Groups/PsiGammaTable.cc
      Groups/PsiGammaTable.h
      Groups/RealisticBvh.h
      Groups/RealisticBvh.cc
      Groups/VolumeGrid.h
      Groups/varray.h
-
 )

Modified: trunk/Model/Groups/GriddedGroup.cc
==============================================================================
--- trunk/Model/Groups/GriddedGroup.cc  (original)
+++ trunk/Model/Groups/GriddedGroup.cc  Fri Jan 20 15:03:05 2006
@@ -26,7 +26,7 @@
   for(int i=0; i< argc; i++){
     string arg = args[i];
     if(arg == "-cellfactor"){
-      if(!getDoubleArg(i, args, cellfactor))
+      if(!getArg<Real>(i, args, cellfactor))
         throw IllegalArgument("GriddedGroup -cellfactor", i, args);
       gotCellfactor = true;
     } else {
@@ -75,11 +75,11 @@
   max += diag*1.e-5;
   diag = max-min;
 
-  double volume = diag.x()*diag.y()*diag.z();
-  double vol3 = Cbrt(volume);
+  Real volume = diag.x()*diag.y()*diag.z();
+  Real vol3 = Cbrt(volume);
   int numObjects = objs.size();
   int target_numcells = static_cast<int>(numObjects*cellfactor);
-  double avgside = cbrt(static_cast<double>(target_numcells));
+  Real avgside = cbrt(static_cast<Real>(target_numcells));
   int nx = static_cast<int>(diag.x()/vol3 * avgside + 0.8);
   int ny = static_cast<int>(diag.y()/vol3 * avgside + 0.8);
   int nz = static_cast<int>(diag.z()/vol3 * avgside + 0.8);
@@ -164,33 +164,36 @@
 {
 
   rays.computeInverseDirections();
-  for(int i=0; i<rays.getSize(); i++) {
-    RayPacket::Element& e = rays.get(i);
-
-
+  for(int i=rays.begin(); i<rays.end(); i++) {
+    Point origin(rays.getOrigin(i));
+    Vector direction(rays.getOrigin(i));
+    Vector inv_direction(rays.getInverseDirection(i));
     // Step 2
-    Vector v1 = (min-e.ray.origin())*e.inverseDirection;
-    Vector v2 = (max-e.ray.origin())*e.inverseDirection;
+    Vector v1 = (min-origin)*inv_direction;
+    Vector v2 = (max-origin)*inv_direction;
     Vector vmin = Min(v1, v2);
     Vector vmax = Max(v1, v2);
-    double tnear = vmin.maxComponent();
-    double tfar = vmax.minComponent();
+    Real tnear = vmin.maxComponent();
+    Real tfar = vmax.minComponent();
     if(tnear >= tfar)
       return;
-    if(tfar < 1.e-6)
+    if(tfar < (Real)1.e-6)
       return;
     if(tnear < 0)
       tnear = 0;
 
     // Step 3
-    Point p = e.ray.origin() + tnear * e.ray.direction();
+    Point p = origin + tnear * direction;
     Vector L = (p-min)*inv_cellsize;
     int Lx = Clamp(static_cast<int>(L.x()), 0, cells.getNx()-1);
     int Ly = Clamp(static_cast<int>(L.y()), 0, cells.getNy()-1);
     int Lz = Clamp(static_cast<int>(L.z()), 0, cells.getNz()-1);
 
     // Step 4
-    Vector sign = diag*e.ray.direction();
+    // This could be made faster with the new RayPacket::signs.
+    // i.e. int dirs[2] = { 1, -1 };
+    // i.e. dix = dirs[rays.getSign(i,0)]; or 1-rays.getSign(0)*2;
+    Vector sign = diag*direction;
     int dix = sign.x()>0?1:-1;
     int stopx = sign.x()>0?cells.getNx():-1;
     int diy = sign.y()>0?1:-1;
@@ -199,34 +202,36 @@
     int stopz = sign.z()>0?cells.getNz():-1;
 
     // Step 5
-    double dtdx = Abs(cellsize.x()/e.ray.direction().x());
-    double dtdy = Abs(cellsize.y()/e.ray.direction().y());
-    double dtdz = Abs(cellsize.z()/e.ray.direction().z());
+    Real dtdx = Abs(cellsize.x()*inv_direction.x());
+    Real dtdy = Abs(cellsize.y()*inv_direction.y());
+    Real dtdz = Abs(cellsize.z()*inv_direction.z());
 
     // Step 6
-    double far_x;
+    Real far_x;
+    // This could be written as:
+    //    far_x = (Lx+1-rays.getSign(i,0))*cellsize.x() + min.x();
     if(sign.x()>0)
       far_x = (Lx+1)*cellsize.x() + min.x();
     else
       far_x = Lx*cellsize.x() + min.x();
-    double far_y;
+    Real far_y;
     if(sign.y()>0)
       far_y = (Ly+1)*cellsize.y() + min.y();
     else
       far_y = Ly*cellsize.y() + min.y();
-    double far_z;
+    Real far_z;
     if(sign.z()>0)
       far_z = (Lz+1)*cellsize.z() + min.z();
     else
       far_z = Lz*cellsize.z() + min.z();
 
     // Step 7
-    double tnext_x = (far_x - e.ray.origin().x())*e.inverseDirection.x();
-    double tnext_y = (far_y - e.ray.origin().y())*e.inverseDirection.y();
-    double tnext_z = (far_z - e.ray.origin().z())*e.inverseDirection.z();
+    Real tnext_x = (far_x - origin.x())*inv_direction.x();
+    Real tnext_y = (far_y - origin.y())*inv_direction.y();
+    Real tnext_z = (far_z - origin.z())*inv_direction.z();
 
     // Step 8
-    while(tnear < e.hitInfo.minT()){
+    while(tnear < rays.getMinT(i)){
 
       int idx = cells.getIndex(Lx, Ly, Lz);
       int l = cells[idx];

Modified: trunk/Model/Groups/GriddedGroup.h
==============================================================================
--- trunk/Model/Groups/GriddedGroup.h   (original)
+++ trunk/Model/Groups/GriddedGroup.h   Fri Jan 20 15:03:05 2006
@@ -134,7 +134,7 @@
     GriddedGroup(const GriddedGroup&);
     GriddedGroup& operator=(const GriddedGroup&);
 
-    double cellfactor;
+    Real cellfactor;
     Point min, max;
     Vector diag;
     Vector cellsize;

Modified: trunk/Model/Groups/KDTree.cc
==============================================================================
--- trunk/Model/Groups/KDTree.cc        (original)
+++ trunk/Model/Groups/KDTree.cc        Fri Jan 20 15:03:05 2006
@@ -28,12 +28,8 @@
   DEALINGS IN THE SOFTWARE.
 */
 
-#include <iostream>
-
-
-#include <stdio.h>
-#include "varray.h"
-#include "KDTree.h"
+#include <Model/Groups/KDTree.h>
+#include <Model/Groups/varray.h>
 
 #include <Model/Intersections/AxisAlignedBox.h>
 #include <Interface/Context.h>
@@ -43,6 +39,12 @@
 #include <SCIRun/Core/Thread/Runnable.h>
 #include <SCIRun/Core/Thread/Barrier.h>
 
+#include <sgi_stl_warnings_off.h>
+#include <iostream>
+#include <sgi_stl_warnings_off.h>
+
+#include <stdio.h>
+
 using namespace Manta;
 using namespace Manta::Kdtree;
 using namespace SCIRun;
@@ -86,68 +88,49 @@
 // INTERSECT TRIANGLES  INTERSECT TRIANGLES  INTERSECT TRIANGLES  INTERSECT 
TRI
 
///////////////////////////////////////////////////////////////////////////////
 
///////////////////////////////////////////////////////////////////////////////
-int KDTree::intersectTriangles(const Ray* ray,
-                               unsigned int listBegin, int listSize,
-                               float maxDist, void *userData,
-                               const RenderContext& /*context*/,
-                               RayTriangleMailbox &mailbox ) const
+int KDTree::intersectTriangles(const Pointf& origin, const Vectorf& 
direction,
+                               unsigned int listBegin, unsigned int listSize,
+                               float maxDist,
+                               RayTriIntersectUserData& isectData) const
 {
-  int i;
-  RayTriIntersectUserData *ud = (RayTriIntersectUserData*)userData;
   float nearest_u, nearest_v;
   int nearest_tri = -1;
 
-  Vectorf direction = ray->direction();
-  Pointf  origin    = ray->origin();   
-       
-  // Intersect the ray with all the triangles. 
-  int listEnd = listBegin+listSize;
-
-  // if (listSize < 40)
-  //  ud->duplicate = 4;
+  // Intersect the ray with all the triangles.
+  unsigned int listEnd = listBegin+listSize;
 
 #ifndef __sgi
 #pragma swp
 #endif
-  for (i = listBegin; i < listEnd; i++) {
+  for (unsigned int i = listBegin; i < listEnd; ++i) {
     int triIdx = triIndices->get(i);
     Triangle &tri = tris->get(triIdx);
     float t, u, v;
 
-#if SHOW_DUPLICATES
-    //if (!mailbox.only_check( ray, triIdx )) {
-    // global_counter++;
-    //ud->duplicate++;
-    //}
-#endif
-
-    // Insert mailbox check here.
-    // if (intersectTriangle3Edge( direction, origin, tri.edge1, tri.edge2, 
tri[0], t, u, v )) {
-    if (mailbox.not_mapped( (RayTriangleMailbox::RayNumber)ray, triIdx )) {
-      
-      
-      if(/*mailbox.not_mapped( ray, triIdx ) &&*/ intersect_triangle3_edge( 
&origin[0], &direction[0], &tri[0][0], &t, &u, &v, &tri.edge1, &tri.edge2 )) {
-      
-       // Check to see if the t value is closer.
-       if (t < maxDist) {
-         maxDist = t;
-         nearest_u = u;
-         nearest_v = v;
-         nearest_tri = triIdx;    
-       }
+    if(intersect_triangle3_edge( origin.getDataPtr(), direction.getDataPtr(),
+                                 &tri[0][0],
+                                 &t, &u, &v,
+                                 tri.edge1.getDataPtr(),
+                                 tri.edge2.getDataPtr() ))
+      {
+        // Check to see if the t value is closer.
+        if (t < maxDist) {
+          maxDist = t;
+          nearest_u = u;
+          nearest_v = v;
+          nearest_tri = triIdx;
+        }
       }
-    }
-
   }
-       
+
   if (nearest_tri >= 0) {
-    ud->rayHit.t = maxDist; 
-    ud->rayHit.u = nearest_u;
-    ud->rayHit.v = nearest_v;
-    ud->rayHitTriIndex = nearest_tri;
+    isectData.rayHit.t = maxDist;
+    isectData.rayHit.u = nearest_u;
+    isectData.rayHit.v = nearest_v;
+    isectData.rayHitTriIndex = nearest_tri;
     return 1;
                
-  } else { 
+  } else {
     return 0;
   }
 }
@@ -159,37 +142,33 @@
 
///////////////////////////////////////////////////////////////////////////////
 void KDTree::intersect(const RenderContext& context, RayPacket& rays) const
 {
-       
-  // Normalize and compute inverse directions, 
-  // As a side effect this also computes the sign mask for the box 
intersection.
   rays.normalizeDirections();
   rays.computeInverseDirections();
   rays.computeSigns();
-       
+
   RayTriIntersectUserData isectData;
-       
-  for(int i=0;i<rays.getSize();i++) {
-               
-    RayPacket::Element& e = rays.get(i);
+
+  for(int i=rays.begin();i<rays.end();i++) {
+
     Real minDist, maxDist;
-               
+
     // Intersect the ray with the bounding box for the group.
-    if (Intersection::intersectAaBox( bbox, 
-                                     minDist, maxDist, 
-                                     e.ray,
-                                     e.sign, 
-                                     e.inverseDirection )) {
-                       
-      // Determine the actual minimum distance.
-      minDist = SCIRun::Max( minDist, (Real)T_EPSILON );
-      maxDist = SCIRun::Min( maxDist, e.hitInfo.minT() );
-                       
-      // Send the ray to the _intersect function.
-      isectData.rayHitTriIndex = -1;
-      isectData.duplicate = 0;
-      intersect_node( rootNode, &e.ray, e, isectData, context, 
(float)minDist, (float)maxDist);
+    if (Intersection::intersectAaBox( bbox,
+                                      minDist, maxDist,
+                                      rays.getRay(i),
+                                      rays.getSigns(i),
+                                      rays.getInverseDirection(i)))
+      {
+        // Determine the actual minimum distance.
+        minDist = SCIRun::Max( minDist, T_EPSILON );
+        maxDist = SCIRun::Min( maxDist, rays.getMinT(i) );
+
+        // Send the ray to the _intersect function.
+        isectData.rayHitTriIndex = -1;
+        isectData.duplicate = 0;
+        intersect_node( rootNode, rays, i, isectData, context, 
(float)minDist, (float)maxDist);
 
-    }
+      }
   }
 }
 
@@ -198,10 +177,10 @@
 
///////////////////////////////////////////////////////////////////////////////
 void KDTree::computeNormal(const RenderContext& /*context*/,
                            RayPacket& rays) const {
-       
+
   // Copy the normal out of the KDTree::ScratchPadInfo structure.
-  for (int i=0;i<rays.getSize();++i) {
-    rays.get(i).normal = 
rays.get(i).hitInfo.scratchpad<ScratchPadInfo>().normal;
+  for (int i=rays.begin();i<rays.end();++i) {
+    rays.setNormal(i, rays.scratchpad<ScratchPadInfo>(i).normal);
   }
 }
 
@@ -213,145 +192,133 @@
 
 // Traversal Stack Entry.
 struct TravStackEntry {
-  KDTreeNode* node;  // 8 bytes
+  KDTreeNode* node;  // 8 bytes(64 bit builds), 4 bytes(32 bit builds)
   float t;           // 4 bytes
   int prev;          // 4 bytes
 };
 
-void KDTree::intersect_node( KDTreeNode *startNode, 
-                             const Ray* ray, RayPacket::Element &e, 
-                             RayTriIntersectUserData &isectData, 
+void KDTree::intersect_node( KDTreeNode *startNode,
+                             RayPacket& rays, int which,
+                             RayTriIntersectUserData &isectData,
                              const RenderContext &context,
-                            float minDist, float maxDist) const
+                             float minDist, float maxDist) const
 {
-       
-  // Mailbox for this traversal.
-  RayTriangleMailbox mailbox;
-  mailbox.clear();
-  
-  KDTreeNode *nearNode, *farNode;
-  float split;
-  int axis, entryPos, exitPos;
-  int tmp;
-
-  Pointf  origin    = ray->origin();
-  Vectorf direction = ray->direction();
-  
+  KDTreeNode *nearNode = startNode;
+  KDTreeNode *farNode;
+  int entryPos = 0;
+  int exitPos = 1;
+
   // Keep a stack of entry and exit positions into the traversal nodes.
 #ifdef __ia64__
   // __declspec(align(128))
 #endif
-    TravStackEntry travStack[128];
+  TravStackEntry travStack[128];
 
   // Initialize the first two entries on the stack.
-  entryPos = 0;
-  nearNode = startNode;
-  travStack[0].node = startNode; 
-  travStack[0].prev = 1;
-       
-  // Check for the case that the minimum intersection point is behind the 
origin.
-  travStack[entryPos].t = minDist < 0.0f ? 0.0f : minDist;
-       
-  exitPos = 1;
-  travStack[1].node = NULL;
-  travStack[1].t = maxDist;
-  travStack[1].prev = 0;
+  travStack[entryPos].node = startNode;
+  // Check for the case that the minimum intersection point is behind
+  // the origin.
+  travStack[entryPos].t = minDist < 0 ? 0 : minDist;
+  travStack[entryPos].prev = 1;
+
+  travStack[exitPos].node = NULL;
+  travStack[exitPos].t = maxDist;
+  travStack[exitPos].prev = 0;
+
+  Pointf  origin    = rays.getOrigin(which);
+  Vectorf direction = rays.getDirection(which);
+  Vectorf invDirection = rays.getInverseDirection(which);
 
   while (travStack[entryPos].prev) {
-               
+
     // Traverse down until we find a leaf node.
 #ifndef __sgi
 #pragma swp
 #endif
     while (nearNode && nearNode->isInternal()) {
-                       
+
       // Determine the axis and the split point.
-      axis = nearNode->axis();
-      split = nearNode->split();
-                       
-      // Find where along the axis the ray enters and exits. 
-      float entryPos_coord_on_axis = 
-       travStack[entryPos].t*direction[axis] + origin[axis];
-                                                       
-      float exitPos_coord_on_axis = 
-       travStack[exitPos].t*direction[axis] + origin[axis];
-                       
+      int axis = nearNode->axis();
+      float split = nearNode->split();
+
+      // Find where along the axis the ray enters and exits.
+      float entryPos_coord_on_axis =
+        travStack[entryPos].t*direction[axis] + origin[axis];
+      float exitPos_coord_on_axis =
+        travStack[exitPos].t*direction[axis] + origin[axis];
+
       // Check to see which side of the split the ray enters first.
       if (entryPos_coord_on_axis <= split) {
-                       
-       // Check to see if entry and exit are on the 
-       // same side of the split.
-       if (exitPos_coord_on_axis <= split) {
-
-         // Same side of the split, so the original interval is ok.
-         nearNode = nearNode->left();
-         continue;
-       }
-                               
-       // Otherwise update the near and far nodes, and then update
-       // the interval below.
-       farNode = nearNode->right();
-       nearNode = nearNode->left();
+
+        // Check to see if entry and exit are on the
+        // same side of the split.
+        if (exitPos_coord_on_axis <= split) {
+
+          // Same side of the split, so the original interval is ok.
+          nearNode = nearNode->left();
+          continue;
+        }
+
+        // Otherwise update the near and far nodes, and then update
+        // the interval below.
+        farNode = nearNode->right();
+        nearNode = nearNode->left();
       }
       else {
-       // Check to see if entry and exit are on the same side.
-       if (exitPos_coord_on_axis >= split) {
-         nearNode = nearNode->right();
-         continue;
-       }
-                               
-       // Update otherwise.
-       farNode = nearNode->left();
-       nearNode = nearNode->right();
+        // Check to see if entry and exit are on the same side.
+        if (exitPos_coord_on_axis >= split) {
+          nearNode = nearNode->right();
+          continue;
+        }
+
+        // Update otherwise.
+        farNode = nearNode->left();
+        nearNode = nearNode->right();
       }
-                       
+
       // Update location on the traversal stack.
-      tmp = exitPos;
-                       
+      int tmp = exitPos;
+
       // ??? Increment to an unused node ???
       if (++exitPos == entryPos) ++exitPos;
-                       
+
       // Update the far node.
       // Specify a new exit node.
       travStack[exitPos].node = farNode;
-      travStack[exitPos].t = (split - origin[axis])* 
e.inverseDirection[axis];
+      travStack[exitPos].t = (split - origin[axis])* invDirection[axis];
       travStack[exitPos].prev = tmp;
     }
 
     // Check to see if we found a non-empty leaf node.
     if (nearNode) {
-                       
+
       // Intersect the ray with a list of triangles.
-      if (
-          intersectTriangles(ray, nearNode->listBegin(), 
nearNode->listSize(),
-                             /*travStack[exitPos].t,*/ e.hitInfo.minT(),
-                             &isectData,
-                             context, mailbox ) && 
-         (isectData.rayHitTriIndex >= 0)) {
-
-       if (isPickingEnabled()) {
-         pickedTri = isectData.rayHitTriIndex;
-         // cerr << "picked " << pickedTri << "\n";
-         pickedBeginIndex = pickedEndIndex = pickedTri;
-         while (pickedBeginIndex > 0 &&
-                triToGroupMap->get(pickedBeginIndex-1)
-                == triToGroupMap->get(pickedBeginIndex))
-           pickedBeginIndex --;
-         while (pickedEndIndex < tris->getLen()-1 &&
-                triToGroupMap->get(pickedEndIndex+1)
-                == triToGroupMap->get(pickedEndIndex))
-           pickedEndIndex ++;
-         // cerr << "picked begin " << pickedBeginIndex << " end " << 
pickedEndIndex << "\n";
-
-         // cerr << "picked flag: " << (int)pickedFlag << std::endl;
-         for (int i=pickedBeginIndex; i<=pickedEndIndex; i++)
-           triFlags->set(i, pickedFlag);
-       }
-                               
-                               
-                               
-       // Check against the hit record, Note that tex coord mapper is null.
-        if (e.hitInfo.hit(isectData.rayHit.t, getMaterial(), this, 0 )) {
+      if (intersectTriangles(origin, direction,
+                             nearNode->listBegin(), nearNode->listSize(),
+                             rays.getMinT(which), isectData)
+          && (isectData.rayHitTriIndex >= 0)) {
+
+        if (isPickingEnabled()) {
+          pickedTri = isectData.rayHitTriIndex;
+          // cerr << "picked " << pickedTri << "\n";
+          pickedBeginIndex = pickedEndIndex = pickedTri;
+          while (pickedBeginIndex > 0 &&
+                 triToGroupMap->get(pickedBeginIndex-1)
+                 == triToGroupMap->get(pickedBeginIndex))
+            pickedBeginIndex --;
+          while (pickedEndIndex < tris->getLen()-1 &&
+                 triToGroupMap->get(pickedEndIndex+1)
+                 == triToGroupMap->get(pickedEndIndex))
+            pickedEndIndex ++;
+          // cerr << "picked begin " << pickedBeginIndex << " end " << 
pickedEndIndex << "\n";
+
+          // cerr << "picked flag: " << (int)pickedFlag << std::endl;
+          for (int i=pickedBeginIndex; i<=pickedEndIndex; i++)
+            triFlags->set(i, pickedFlag);
+        }
+
+        // Check against the hit record, Note that tex coord mapper is null.
+        if (rays.hit(which, isectData.rayHit.t, getMaterial(), this, 0 )) {
 
           // if (isectData.rayHit.t > t_epsilon) {
           // e.hitInfo.set_hit(isectData.rayHit.t, material, this, 0 );
@@ -368,52 +335,51 @@
           float u = isectData.rayHit.u;
           float v = isectData.rayHit.v;
 
-          e.hitInfo.scratchpad<ScratchPadInfo>().normal = (n1 * u) + (n2 * 
v) + (n0 * (1.0f - u - v));
-          
+          ScratchPadInfo& scratch_pad = 
rays.scratchpad<ScratchPadInfo>(which);
+          scratch_pad.normal = (n1 * u) + (n2 * v) + (n0 * (1 - u - v));
+
 #if SHOW_DUPLICATES
           if (isectData.duplicate == 0)
-            e.hitInfo.scratchpad<ScratchPadInfo>().payload = 
Color(RGB(1.0,1.0,1.0));
+            scratch_pad.payload = Color(RGB(1.0,1.0,1.0));
           else if (isectData.duplicate > 16)
-            e.hitInfo.scratchpad<ScratchPadInfo>().payload = 
Color(RGB(1.0,0.0,1.0));
+            scratch_pad.payload = Color(RGB(1.0,0.0,1.0));
           else if (isectData.duplicate > 8)
-            e.hitInfo.scratchpad<ScratchPadInfo>().payload = 
Color(RGB(1.0,0.0,0.0));
+            scratch_pad.payload = Color(RGB(1.0,0.0,0.0));
           else if (isectData.duplicate > 4)
-            e.hitInfo.scratchpad<ScratchPadInfo>().payload = 
Color(RGB(1.0,1.0,0.0));
+            scratch_pad.payload = Color(RGB(1.0,1.0,0.0));
           else
-            e.hitInfo.scratchpad<ScratchPadInfo>().payload = 
Color(RGB(0.0,0.0,1.0));
-#else          
-         unsigned char flag;
-         if ( pickedTri > 0 &&
-              /*pickedBeginIndex <= isectData.rayHitTriIndex &&
-                isectData.rayHitTriIndex <= pickedEndIndex*/
-              (flag=triFlags->get(isectData.rayHitTriIndex))!=0) 
-           {
-             switch(flag) {
-             case PICK_HIGHLIGHT:
-               e.hitInfo.scratchpad<ScratchPadInfo>().payload = 
Color(RGB(1,1,1))-
-                 tris->get(isectData.rayHitTriIndex).payload;
-               break;
-             case PICK_REMOVE:
-               e.hitInfo.scratchpad<ScratchPadInfo>().payload = 
Color(RGB(0,0,0));
-               break;
-             }
-           } else
-             e.hitInfo.scratchpad<ScratchPadInfo>().payload = 
tris->get(isectData.rayHitTriIndex).payload;
+            scratch_pad.payload = Color(RGB(0.0,0.0,1.0));
+#else
+          unsigned char flag;
+          if ( pickedTri > 0 &&
+               /*pickedBeginIndex <= isectData.rayHitTriIndex &&
+                 isectData.rayHitTriIndex <= pickedEndIndex*/
+               (flag=triFlags->get(isectData.rayHitTriIndex))!=0) 
+            {
+              switch(flag) {
+              case PICK_HIGHLIGHT:
+                scratch_pad.payload = Color(RGB(1,1,1))-
+                  tris->get(isectData.rayHitTriIndex).payload;
+                break;
+              case PICK_REMOVE:
+                scratch_pad.payload = Color(RGB(0,0,0));
+                break;
+              }
+            } else
+              scratch_pad.payload = 
tris->get(isectData.rayHitTriIndex).payload;
 #endif
           // Check to make sure the found hit is inside the current cell.
           // if ((isectData.rayHit.t <= travStack[exitPos].t)/* && 
(isectData.rayHit.t > travStack[entryPos].t)*/)
           // break;
-       }
+        }
       }
     }
 
     // Check to see if the hit is inside the current cell.
-    if (e.hitInfo.minT() <= travStack[exitPos].t)
+    if (rays.getMinT(which) <= travStack[exitPos].t)
       break;
-    
-    
-    
-    // Move to the next 
+
+    // Move to the next
     entryPos = exitPos;
     exitPos = travStack[exitPos].prev;
     nearNode = travStack[entryPos].node;
@@ -649,9 +615,8 @@
 void KDTreeTexture::mapValues(const RenderContext& /*context*/,
                               RayPacket& rays, Color results[]) const {
 
-  for (int i=0;i<rays.getSize();++i) {
-    RayPacket::Element &e = rays.get(i);
-    results[i] = 
e.hitInfo.scratchpad<Kdtree::KDTree::ScratchPadInfo>().payload;
+  for (int i=rays.begin();i<rays.end();++i) {
+    results[i] = rays.scratchpad<Kdtree::KDTree::ScratchPadInfo>(i).payload;
   }
 }
 

Modified: trunk/Model/Groups/KDTree.h
==============================================================================
--- trunk/Model/Groups/KDTree.h (original)
+++ trunk/Model/Groups/KDTree.h Fri Jan 20 15:03:05 2006
@@ -39,9 +39,8 @@
 
 #include <Interface/Texture.h>
 #include <Model/Groups/KDTreeLoader.h>
-#include <Model/Groups/RayTriangleMailbox.h>
 
-#include "varray.h"
+#include <Model/Groups/varray.h>
 
 namespace Manta {
 
@@ -344,20 +343,14 @@
       }
 
       // This method intersects a list of triangles with the ray.
-      int intersectTriangles(const Ray* ray, unsigned int listBegin,
-                             int listSize, float maxDist, void *userData,
-                             const RenderContext &context,
-                             RayTriangleMailbox &mailbox
-                             ) const;
+      int intersectTriangles(const Pointf& origin, const Vectorf& direction,
+                             unsigned int listBegin, unsigned int listSize,
+                             float maxDist,
+                             RayTriIntersectUserData &isectData) const;
 
       // This method is called to intersect a single ray with the kdtree.
-
-      // void _intersect(const Ray* ray, RayPacket::Element &e,
-      //                 RayTriIntersectUserData &isectData,
-      //                 const RenderContext &context,
-      //                 float _minDist=-1, float _maxDist=-1) const;
       void intersect_node( KDTreeNode *startNode,
-                           const Ray* ray, RayPacket::Element &e,
+                           RayPacket& rays, int which,
                            RayTriIntersectUserData &isectData,
                            const RenderContext &context,
                            float minDist, float maxDist) const;

Modified: trunk/Model/Groups/RealisticBvh.cc
==============================================================================
--- trunk/Model/Groups/RealisticBvh.cc  (original)
+++ trunk/Model/Groups/RealisticBvh.cc  Fri Jan 20 15:03:05 2006
@@ -34,6 +34,8 @@
 #include <Model/Groups/RealisticBvh.h>
 #include <Model/Intersections/AxisAlignedBox.h>
 
+#include <iostream>
+using namespace std;
 
 using namespace Manta;
 
@@ -139,7 +141,7 @@
        }
        
        // Find a pivot point.
-       Point pivot((Vector(new_node->bounds[0]) + 
Vector(new_node->bounds[1])) * 0.5);
+       Point pivot((Vector(new_node->bounds[0]) + 
Vector(new_node->bounds[1])) * (Real)0.5);
        
        // Split along the axis.
        int mid_point = qsplit( array, size, pivot[axis], axis );
@@ -174,57 +176,43 @@
 void RealisticBvh::intersect(const RenderContext& context, RayPacket& rays) 
const {
        
        rays.computeInverseDirections();
-        rays.computeSigns();
+  rays.computeSigns();
 
        // 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);
 
+       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( bounds, 
min_t, max_t, e.ray, 
-                                                                             
                                                                              
                                                      e.sign, 
e.inverseDirection,
-                                                                             
                                                                              
                                                            (Real)0,
-                                                                             
                                                                              
                                                            e.hitInfo.minT() 
);
+               bbox_intersect[i]
+      = Intersection::intersectAaBox( 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 = 0;
-       int end   = 0;
-       int first_child;
 
-       while (begin < rays.getSize()) {
-       
+  for(int begin=rays.begin(); begin < rays.end(); ){
                // Find the beginning of a run.
-               while ((begin < rays.getSize()) && (!bbox_intersect[begin]))
+               while ((begin < rays.end()) && (!bbox_intersect[begin]))
                        ++begin;
-       
-               // Determine the first child for the first ray in the packet.
-               first_child = rays.get( begin ).sign[ split_axis ];
-       
-               // Find the end of this run.
-               end = begin;
-               while ((end < rays.getSize()) && (bbox_intersect[end]) && 
-                      (rays.get( begin ).sign[ 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.
-                       child[ first_child]->intersect( context, sub_packet );
-                       child[!first_child]->intersect( context, sub_packet );
-                       
-               }
-               
-               begin = end;
-       }
 
+    if (begin >= rays.end())
+      // No box intersections left
+      return;
+
+    int end = begin+1;
+    int sign = rays.getSign(begin, split_axis);
+    while(end < rays.end()
+          && bbox_intersect[end]
+          && rays.getSign(end, split_axis) == sign)
+      ++end;
+    RayPacket subPacket(rays, begin, end);
+    // Intersect with both children.  sign will be 1 for negative
+    // directions.
+    child[ sign]->intersect( context, subPacket );
+    child[!sign]->intersect( context, subPacket );
+    begin = end;
+  }
 }
 
 

Modified: trunk/Model/Groups/TransparentKDTree.cc
==============================================================================
--- trunk/Model/Groups/TransparentKDTree.cc     (original)
+++ trunk/Model/Groups/TransparentKDTree.cc     Fri Jan 20 15:03:05 2006
@@ -29,12 +29,7 @@
  */
 
 #include <Model/Groups/TransparentKDTree.h>
-
-#include <iostream>
-#include <algorithm>
-
-#include <stdio.h>
-#include "varray.h"
+#include <Model/Groups/varray.h>
 
 
 #include <Model/Intersections/AxisAlignedBox.h>
@@ -44,6 +39,12 @@
 #include <SCIRun/Core/Thread/Thread.h>
 #include <SCIRun/Core/Thread/Runnable.h>
 
+#include <sgi_stl_warnings_off.h>
+#include <iostream>
+#include <algorithm>
+#include <sgi_stl_warnings_off.h>
+
+#include <stdio.h>
 
 using namespace Manta;
 using namespace Manta::Kdtree;
@@ -53,11 +54,24 @@
 using std::endl;
 using std::sort;
 
+///////////////////////////////////////////////////////////
+
+// TODO: Alpha termination needs to be consistent.
+
+// TODO: isectBuffers is not thread safe.  Needs to be moved to member
+// variable.
+
+// TODO: For intersectTrianglesTransparent isectbuf->append() can
+// allocate memory, but only as needed.
+
+///////////////////////////////////////////////////////////
+
 // From Tomas Akenine-Moller's code, included below in this file.
 static int
 intersect_triangle3(const float orig[3],
                     const float dir[3],
-                    const float vert0[3], const float vert1[3], const float 
vert2[3],
+                    const float vert0[3], const float vert1[3],
+                    const float vert2[3],
                     float *t, float *u, float *v );
 
 static inline int
@@ -77,25 +91,25 @@
 // CONSTRUCTOR  CONSTRUCTOR  CONSTRUCTOR  CONSTRUCTOR  CONSTRUCTOR  
CONSTRUCTOR
 
///////////////////////////////////////////////////////////////////////////////
 
///////////////////////////////////////////////////////////////////////////////
-TransparentKDTree::TransparentKDTree( KDTree *kdtree_, Material *material_, 
Real sample_alpha_ ) :
-       PrimitiveCommon( material_ ),
-       rootNode( kdtree_->rootNode ),
-       triIndices( kdtree_->triIndices ),
-       tris( kdtree_->tris ),
-       normals( kdtree_->normals ),
-       sample_alpha( sample_alpha_ ),
-                       triToGroupMap(kdtree_->triToGroupMap),
-                       groupToNameMap(kdtree_->groupToNameMap),
-                       groupNames(kdtree_->groupNames),
-                       __pickingEnabled(kdtree_->__pickingEnabled),
-                       pickingEnabled(kdtree_->pickingEnabled),
-                       pickedTri(kdtree_->pickedTri),
-                       pickedBeginIndex(kdtree_->pickedBeginIndex), 
-                       pickedEndIndex(kdtree_->pickedEndIndex),
-                       triFlags(kdtree_->triFlags),
-                       pickedFlag(kdtree_->pickedFlag)
+TransparentKDTree::TransparentKDTree( KDTree *kdtree_, Material *material_,
+                                      Real sample_alpha_ ) :
+  PrimitiveCommon( material_ ),
+  rootNode( kdtree_->rootNode ),
+  triIndices( kdtree_->triIndices ),
+  tris( kdtree_->tris ),
+  normals( kdtree_->normals ),
+  sample_alpha( sample_alpha_ ),
+  triToGroupMap(kdtree_->triToGroupMap),
+  groupToNameMap(kdtree_->groupToNameMap),
+  groupNames(kdtree_->groupNames),
+  __pickingEnabled(kdtree_->__pickingEnabled),
+  pickingEnabled(kdtree_->pickingEnabled),
+  pickedTri(kdtree_->pickedTri),
+  pickedBeginIndex(kdtree_->pickedBeginIndex),
+  pickedEndIndex(kdtree_->pickedEndIndex),
+  triFlags(kdtree_->triFlags),
+  pickedFlag(kdtree_->pickedFlag)
 {
-       
        bbox.extendByBox( kdtree_->bbox );
 }
 
@@ -104,107 +118,92 @@
 // INTERSECT TRIANGLES  INTERSECT TRIANGLES  INTERSECT TRIANGLES  INTERSECT 
TRI
 
///////////////////////////////////////////////////////////////////////////////
 
//////////////////////////////////////////////////////////////////////////////
+
 VArray<VArray<TransparentKDTree::Isect> *> 
TransparentKDTree::isectBuffers(1024, 0);
 
-int TransparentKDTree::intersectTrianglesTransparent(const Ray* ray, 
RayPacket::Element &e, unsigned int listBegin, int listSize, float maxDist, 
void *userData, const RenderContext &context, bool isFirst) const
+int TransparentKDTree::intersectTrianglesTransparent
+                       (const Pointf& origin, const Vectorf& direction,
+                        ScratchPadInfo& scratch_pad,
+                        unsigned int listBegin, unsigned int listSize,
+                        float maxDist,
+                        RayTriIntersectUserData& userData,
+                        const RenderContext &context) const
 {
-       int i;
-       RayTriIntersectUserData *ud = (RayTriIntersectUserData*)userData;
+  
////////////////////////////////////////////////////////////////////////////
+  // Check to see if the thread buffers array is allocated.
+  if (isectBuffers.getLen() != (context.numProcs+1)) {
+    // One additional buffer is needed for "shootSingleRay" queries
+    // from the gui thread.
+    isectBuffers.setLen( context.numProcs+1, 0 );
+  }
+
+  // Determine the thread number.
+  int threadId = context.proc;
+  VArray<TransparentKDTree::Isect> *isectbuf = isectBuffers.get(threadId);
+
+  // Check to see if the per-thread buffer for this thread is allocated.
+  if (! isectbuf) {
+    isectbuf = new VArray<TransparentKDTree::Isect>(8);
+    isectBuffers.set(threadId, isectbuf);
+  }
+  isectbuf->setLen(0);
+
+  
////////////////////////////////////////////////////////////////////////////
+  // Intersect the ray with all the triangles.
+  Real sample_t = scratch_pad.sample_t;
 
-       Vectorf direction = ray->direction();
-       Pointf  origin    = ray->origin();      
+  unsigned int listEnd = listBegin+listSize;
 
-       
////////////////////////////////////////////////////////////////////////////
-       // Check to see if the thread buffers array is allocated.
-       if (isectBuffers.getLen() != (context.numProcs+1)) {
-               // One additional buffer is needed for "shootSingleRay" 
queries from the gui thread.
-               isectBuffers.setLen( context.numProcs+1, 0 );
-       }
-       
-       // Determine the thread number.
-       int threadId = context.proc;
-       VArray<TransparentKDTree::Isect> *isectbuf = 
isectBuffers.get(threadId);
-       
-       // Check to see if the per-thread buffer for this thread is allocated.
-       if (! isectbuf) {
-               isectbuf = new VArray<TransparentKDTree::Isect>(8);
-               isectBuffers.set(threadId, isectbuf);
-       }
-       isectbuf->setLen(0);
-        
-       
////////////////////////////////////////////////////////////////////////////
-       // Intersect the ray with all the triangles. 
-       Real &sample_t = e.hitInfo.scratchpad<ScratchPadInfo>().sample_t;
-       
-       int listEnd = listBegin+listSize;
-       
 #ifndef __sgi
 #pragma swp
 #endif
-       for (i = listBegin; i < listEnd; i++) {
-               int triIdx = triIndices->get(i);
-               Triangle &tri = tris->get(triIdx);
-               float t, u, v;
-               
-               // if (intersectTriangle3Edge( direction, origin, tri.edge1, 
tri.edge2, tri[0], t, u, v )) {
-               if(intersect_triangle3_edge( &origin[0], &direction[0], 
&tri[0][0], &t, &u, &v, &tri.edge1, &tri.edge2 )) {
-               
-                       // Check to see if the t value is closer.
-                       if ((t > sample_t) && (t < maxDist)) {
-                               Isect &isect = isectbuf->append();
-                               isect.t = t;
-                               isect.u = u;
-                               isect.v = v;
-                               isect.triIdx = triIdx;
-                       }
-               }
-       }

-       
////////////////////////////////////////////////////////////////////////////
-       // Check to see if any triangles need to be blended.
-       if (isectbuf->getLen()) {
-               
-               // sort the intersections
-               Isect *array = isectbuf->getArray();
-               std::sort(array, array+isectbuf->getLen());
-
-               // Modify the hit record color directly.
-               Color &ray_color = 
e.hitInfo.scratchpad<ScratchPadInfo>().payload;
-               Real  &ray_alpha = 
e.hitInfo.scratchpad<ScratchPadInfo>().alpha;                
-               
-               // Check to see if this is the first triangle the ray hit.
-               if (ray_alpha == 0.0) {
-                       ud->rayHit.t = array[0].t;
-                       ud->rayHit.u = array[0].u;
-                       ud->rayHit.v = array[0].v;
-                       ud->rayHitTriIndex = array[0].triIdx;
-               }               
-               
-               Real sample_alpha__ = sample_alpha;
-               
-               // combine  color and opacity 
-               Color c;
-               for (int i=0; (i<isectbuf->getLen()) && (ray_alpha < 
(Real)0.95); i++) {
-                       
-                       Color *triangle_color = &tris->get( array[i].triIdx 
).payload;
-                       unsigned char flag;
-                       if (pickedTri > 0 &&
-                                /*pickedBeginIndex <= array[i].triIdx &&
-                                               array[i].triIdx <= 
pickedEndIndex*/
-                               (flag = triFlags->get(array[i].triIdx)) != 0 
-                       ) {
-                               switch(flag) {
-                               case KDTree::PICK_HIGHLIGHT:
-                               c = Color(RGB(1,1,1)) - *triangle_color;
-                               triangle_color = &c;
-                               break;
-                               case KDTree::PICK_REMOVE:
-                               c = Color(RGB(0,0,0));
-                               triangle_color = &c;
-                               sample_alpha__ = 0;
-                               break;
-                               }
-                       }
+  for (unsigned int i = listBegin; i < listEnd; i++) {
+    int triIdx = triIndices->get(i);
+    Triangle &tri = tris->get(triIdx);
+    float t, u, v;
+
+    // if (intersectTriangle3Edge( direction, origin, tri.edge1, tri.edge2, 
tri[0], t, u, v )) {
+    if(intersect_triangle3_edge( origin.getDataPtr(), direction.getDataPtr(),
+                                 &tri[0][0],
+                                 &t, &u, &v,
+                                 tri.edge1.getDataPtr(),
+                                 tri.edge2.getDataPtr() ))
+      {
+        // Check to see if the t value is closer.
+        if ((t > sample_t) && (t < maxDist)) {
+          Isect &isect = isectbuf->append();
+          isect.t = t;
+          isect.u = u;
+          isect.v = v;
+          isect.triIdx = triIdx;
+        }
+      }
+  }
+
+  
////////////////////////////////////////////////////////////////////////////
+  // Check to see if any triangles need to be blended.
+  if (isectbuf->getLen()) {
+
+    // sort the intersections
+    Isect *array = isectbuf->getArray();
+    std::sort(array, array+isectbuf->getLen());
+
+    // Make a copy of the hitrecord stuff and then store it back later
+    Color ray_color = scratch_pad.payload;
+    Real  ray_alpha = scratch_pad.alpha;
+
+    // Check to see if this is the first triangle the ray hit.
+    if (ray_alpha == 0.0) {
+      userData.rayHit.t = array[0].t;
+      userData.rayHit.u = array[0].u;
+      userData.rayHit.v = array[0].v;
+      userData.rayHitTriIndex = array[0].triIdx;
+    }
+
+    Real sample_alpha__ = sample_alpha;
+
+    // combine  color and opacity
+    for (int i=0; (i<isectbuf->getLen()) && (ray_alpha < (Real)0.95); i++) {
 
       // Interpolate the normal.
       Vectorf &n0 = normals[array[i].triIdx][0];
@@ -214,26 +213,52 @@
       float u = array[i].u;
       float v = array[i].v;
 
-      Vectorf normal = (n1 * u) + (n2 * v) + (n0 * (1.0f - u - v)); 
-                        
+      Vectorf normal = (n1 * u) + (n2 * v) + (n0 * (1.0f - u - v));
+
       Real scale = Abs(Dot( normal, direction ));
-                       scale *= (Real)0.75;
-                       scale += (Real)0.25;
-                       
-                       Color sample_color = (*triangle_color * scale);
-                        
-                       ray_color += (sample_color*sample_alpha__) * (1 - 
ray_alpha);
-                       ray_alpha += sample_alpha__ * (1 - ray_alpha);
-               }
-               
-               // Update sample t to the last triangle composited.
-               sample_t = array[isectbuf->getLen()-1].t;
+      scale *= (Real)0.75;
+      scale += (Real)0.25;
 
-               return 1;
-       }
-       else { 
-               return 0;
-       }
+      Color triangle_color;
+      unsigned char flag;
+      if (pickedTri > 0 && (flag = triFlags->get(array[i].triIdx)) != 0) {
+        switch(flag) {
+        case KDTree::PICK_HIGHLIGHT:
+          // Create an inverted color
+          triangle_color = Color::white() - 
tris->get(array[i].triIdx).payload;
+          break;
+        case KDTree::PICK_REMOVE:
+          // Just stick something in triangle_color.  It doesn't
+          // matter what, since it will get multiplied by zero.
+          triangle_color = Color::black();
+          sample_alpha__ = 0;
+          break;
+        }
+      }
+      else {
+        triangle_color = tris->get( array[i].triIdx ).payload;
+      }
+
+      // Make sure you do all the scalar multiplication first so that
+      // the number of Color*Real operations are minimized.
+      Real blend = sample_alpha__ * (1 - ray_alpha);
+      ray_color += triangle_color * (scale * blend);
+      ray_alpha += blend;
+    }
+
+    // Update sample t to the last triangle composited.
+    sample_t = array[isectbuf->getLen()-1].t;
+
+    // Put the stuff back
+    scratch_pad.sample_t = sample_t;
+    scratch_pad.payload = ray_color;
+    scratch_pad.alpha = ray_alpha;
+
+    return 1;
+  }
+  else {
+    return 0;
+  }
 }
 
 
///////////////////////////////////////////////////////////////////////////////
@@ -241,36 +266,33 @@
 // This is the Manta interface method.
 
///////////////////////////////////////////////////////////////////////////////
 
///////////////////////////////////////////////////////////////////////////////
-void TransparentKDTree::intersect(const RenderContext& context, RayPacket& 
rays) const
+void TransparentKDTree::intersect(const RenderContext& context,
+                                  RayPacket& rays) const
 {
-       
-  // Normalize and compute inverse directions, 
-  // As a side effect this also computes the sign mask for the box 
intersection.
   rays.normalizeDirections();
   rays.computeInverseDirections();
   rays.computeSigns();
-       
+
        RayTriIntersectUserData isectData;
-       
-       for(int i=0;i<rays.getSize();i++) {
-               
-               RayPacket::Element& e = rays.get(i);
+
+       for(int i=rays.begin();i<rays.end();++i) {
+
                Real minDist, maxDist;
-               
+
                // Intersect the ray with the bounding box for the group.
-               if (Intersection::intersectAaBox( bbox, 
-                                                                             
                                                                          
minDist, maxDist, 
-                                                                             
                                                                          
e.ray,
-                                                                             
                                                                          
e.sign, 
-                                                                             
                                                                          
e.inverseDirection )) {
-                       
-                       // Determine the actual minimum distance.
-                       minDist = SCIRun::Max( minDist, (Real)T_EPSILON );
-                       maxDist = SCIRun::Min( maxDist, e.hitInfo.minT() );
-                       
-                       // Send the ray to the _intersect function.
-                       isectData.rayHitTriIndex = -1;
-                       _intersect( &e.ray, e, isectData, context, 
(float)minDist, (float)maxDist);
+    if (Intersection::intersectAaBox( bbox,
+                                      minDist, maxDist,
+                                      rays.getRay(i),
+                                      rays.getSigns(i),
+                                      rays.getInverseDirection(i)))
+      {
+        // Determine the actual minimum distance.
+        minDist = SCIRun::Max( minDist, T_EPSILON );
+        maxDist = SCIRun::Min( maxDist, rays.getMinT(i) );
+
+        // Send the ray to the intersect_node function.
+        isectData.rayHitTriIndex = -1;
+        intersect_node( rootNode, rays, i, isectData, context, 
(float)minDist, (float)maxDist);
 
                }
        }
@@ -281,11 +303,11 @@
 
///////////////////////////////////////////////////////////////////////////////
 void TransparentKDTree::computeNormal(const RenderContext& /*context*/,
                                       RayPacket& rays) const {
-       
+
        // Copy the normal out of the TransparentKDTree::ScratchPadInfo 
structure.
-       for (int i=0;i<rays.getSize();++i) {
-               rays.get(i).normal = 
rays.get(i).hitInfo.scratchpad<ScratchPadInfo>().normal;
-       }
+  for (int i=rays.begin();i<rays.end();++i) {
+    rays.setNormal(i, rays.scratchpad<ScratchPadInfo>(i).normal);
+  }
 }
 
 
///////////////////////////////////////////////////////////////////////////////
@@ -298,156 +320,160 @@
 struct TravStackEntry {
        KDTreeNode* node;  //8 bytes
        float t;           // 4 bytes
-                                                                             
   // float point[3]; // 4*3=12 bytes
        int prev;          // 4 bytes
 };
 
-void TransparentKDTree::_intersect(const Ray* ray, RayPacket::Element &e, 
RayTriIntersectUserData &isectData, const RenderContext &context,
-                                                                             
                  float minDist, float maxDist) const
+void TransparentKDTree::intersect_node(KDTreeNode *startNode,
+                                       RayPacket& rays, int which,
+                                       RayTriIntersectUserData &isectData,
+                                       const RenderContext &context,
+                                       float minDist, float maxDist) const
 {
-       // Set the ray color to black, alpha to 1.0.
-       e.hitInfo.scratchpad<ScratchPadInfo>().reset();
-       
-       Color &ray_color = e.hitInfo.scratchpad<ScratchPadInfo>().payload;
-       Real  &ray_alpha = e.hitInfo.scratchpad<ScratchPadInfo>().alpha;
-       
-       KDTreeNode *nearNode, *farNode;
-       float split;
-       int axis, entryPos, exitPos;
-       int tmp;
-       
-  Pointf  origin    = ray->origin();
-  Vectorf direction = ray->direction();
-  
+  ScratchPadInfo& scratch_pad = rays.scratchpad<ScratchPadInfo>(which);
+  // Set the ray color to black, alpha to 1.0.
+  scratch_pad.reset();
+
+  Color &ray_color = scratch_pad.payload;
+  Real  &ray_alpha = scratch_pad.alpha;
+
+  KDTreeNode *nearNode = startNode;
+  KDTreeNode *farNode;
+  int entryPos = 0;
+  int exitPos = 1;
+
   // Keep a stack of entry and exit positions into the traversal nodes.
 #ifdef __ia64__
-       // __declspec(align(128))
+  // __declspec(align(128))
 #endif
-    TravStackEntry travStack[128];
-       
-       // Initialize the first two entries on the stack.
-       entryPos = 0;
-       nearNode = travStack[entryPos].node = rootNode; 
-       travStack[entryPos].prev = 1;
-       travStack[entryPos].t = minDist < 0.0f ? 0.0f : minDist;
-       
-       exitPos = 1;
-       travStack[exitPos].node = NULL;
-       travStack[exitPos].t = maxDist;
-       travStack[exitPos].prev = 0;
-       
-       while (travStack[entryPos].prev) {
-               
-               // Traverse down until we find a leaf node.
-               while (nearNode && nearNode->isInternal()) {
-                       
-                       // Determine the axis and the split point.
-                       axis = nearNode->axis();
-                       split = nearNode->split();
-                       
-                       // Find where along the axis the ray enters and 
exits. 
-                       float entryPos_coord_on_axis =  
-                                                       
travStack[entryPos].t*direction[axis] + origin[axis];
-                                                       
-                       float exitPos_coord_on_axis = 
-                                                       
travStack[exitPos].t*direction[axis] + origin[axis];
-                       
-                       // Check to see which side of the split the ray 
enters first.
-                       if (entryPos_coord_on_axis <= split) {
-                               // Check to see if entry and exit are on the 
-                               // same side of the split.
-                               if (exitPos_coord_on_axis <= split) {
-                                       // Same side of the split, so the 
original interval is ok.
-                                       nearNode = nearNode->left();
-                                       continue;
-                               }
-                               // Otherwise update the near and far nodes, 
and then update
-                               // the interval below.
-                               farNode = nearNode->right();
-                               nearNode = nearNode->left();
-                       }
-                       else {
-                               // Check to see if entry and exit are on the 
same side.
-                               if (exitPos_coord_on_axis >= split) {
-                                       nearNode = nearNode->right();
-                                       continue;
-                               }
-                               // Update otherwise.
-                               farNode = nearNode->left();
-                               nearNode = nearNode->right();
-                       }
-                       
-                       // Update location on the traversal stack.
-                       tmp = exitPos;
-                       
-                       // ??? Increment to an unused node ???
-                       if (++exitPos == entryPos) ++exitPos;
-                       
-                       // Specify a new exit node.
-                       travStack[exitPos].node = farNode;
-                       travStack[exitPos].t = (split - origin[axis])* 
e.inverseDirection[axis];
-                       
-                       travStack[exitPos].prev = tmp;
-               }
-               
-               // Check to see if we found a leaf node.
-               if (nearNode) {
-               
-                       bool first_leaf = (ray_alpha == 0.0);
-                       
-                       // Intersect the ray with a list of triangles.
-                       if (intersectTrianglesTransparent(ray, e, 
-                                                                             
                                                                              
    nearNode->listBegin(), nearNode->listSize(), 
-                                                                             
                                                                              
    travStack[exitPos].t, &isectData, context, first_leaf) && 
-                                       (isectData.rayHitTriIndex >= 0)) {
-       
-                               // If this is the first leaf, record the hit 
and normal.                        
-                               if (first_leaf) {
-                                       // record hit if picking
-                                       if (isPickingEnabled()) {
-                                               pickedTri = 
isectData.rayHitTriIndex;
-                                               // cerr << "picked " << 
pickedTri << "\n";
-                                               pickedBeginIndex = 
pickedEndIndex = pickedTri;
-                                               while (pickedBeginIndex > 0 &&
-                                                       
triToGroupMap->get(pickedBeginIndex-1)
-                                                               == 
triToGroupMap->get(pickedBeginIndex))
-                                                       pickedBeginIndex --;
-                                               while (pickedEndIndex < 
tris->getLen()-1 &&
-                                                       
triToGroupMap->get(pickedEndIndex+1)
-                                                               == 
triToGroupMap->get(pickedEndIndex))
-                                                       pickedEndIndex ++;
-                                               // cerr << "picked begin " << 
pickedBeginIndex << "end " << pickedEndIndex << "\n";
-                                               // cerr << "picked flag: " << 
(int)pickedFlag << std::endl;
-                                               for (int i=pickedBeginIndex; 
i<=pickedEndIndex; i++)
-                                                       triFlags->set(i, 
pickedFlag);
-                                       }
-
-                                       // Process the hit.
-                                       e.hitInfo.hit(isectData.rayHit.t, 
getMaterial(), this, 0 );
-                                       
-                                       // Copy the normal into the scratch 
pad.
-                                       // Used for shootOneRay type queries.
-                                       
e.hitInfo.scratchpad<TransparentKDTree::ScratchPadInfo>().normal = 
-            normals[isectData.rayHitTriIndex][0];
-                                       
-                                       first_leaf = false;
-                               }
-                               
-                               // Check to see if the ray is fully 
attenuated.
-                               if 
(e.hitInfo.scratchpad<ScratchPadInfo>().alpha > 0.9) {
-                                       break;
-                               }
-                       }
-               }
-               
-               // Move to the next 
-               entryPos = exitPos;
-               exitPos = travStack[exitPos].prev;
-               nearNode = travStack[entryPos].node;
-       }
-       
-       // Blend with the background.
-       ray_color += (Color(RGB(0.8,0.8,0.8))) * (1.0f - ray_alpha);
+  TravStackEntry travStack[128];
+
+  // Initialize the first two entries on the stack.
+  travStack[entryPos].node = startNode;
+  travStack[entryPos].t = minDist < 0 ? 0 : minDist;
+  travStack[entryPos].prev = 1;
+
+  travStack[exitPos].node = NULL;
+  travStack[exitPos].t = maxDist;
+  travStack[exitPos].prev = 0;
+
+  Pointf  origin    = rays.getOrigin(which);
+  Vectorf direction = rays.getDirection(which);
+  Vectorf invDirection = rays.getInverseDirection(which);
+
+  while (travStack[entryPos].prev) {
+
+    // Traverse down until we find a leaf node.
+    while (nearNode && nearNode->isInternal()) {
+
+      // Determine the axis and the split point.
+      int axis = nearNode->axis();
+      float split = nearNode->split();
+
+      // Find where along the axis the ray enters and exits.
+      float entryPos_coord_on_axis =
+        travStack[entryPos].t*direction[axis] + origin[axis];
+
+      float exitPos_coord_on_axis =
+        travStack[exitPos].t*direction[axis] + origin[axis];
+
+      // Check to see which side of the split the ray enters first.
+      if (entryPos_coord_on_axis <= split) {
+
+        // Check to see if entry and exit are on the
+        // same side of the split.
+        if (exitPos_coord_on_axis <= split) {
+
+          // Same side of the split, so the original interval is ok.
+          nearNode = nearNode->left();
+          continue;
+        }
+
+        // Otherwise update the near and far nodes, and then update
+        // the interval below.
+        farNode = nearNode->right();
+        nearNode = nearNode->left();
+      }
+      else {
+        // Check to see if entry and exit are on the same side.
+        if (exitPos_coord_on_axis >= split) {
+          nearNode = nearNode->right();
+          continue;
+        }
+        // Update otherwise.
+        farNode = nearNode->left();
+        nearNode = nearNode->right();
+      }
+
+      // Update location on the traversal stack.
+      int tmp = exitPos;
+
+      // ??? Increment to an unused node ???
+      if (++exitPos == entryPos) ++exitPos;
+
+      // Specify a new exit node.
+      travStack[exitPos].node = farNode;
+      travStack[exitPos].t = (split - origin[axis])* invDirection[axis];
+      travStack[exitPos].prev = tmp;
+    }
+
+    // Check to see if we found a non-empty leaf node.
+    if (nearNode) {
+
+      bool first_leaf = (ray_alpha == 0);
+
+      // Intersect the ray with a list of triangles.
+      if (intersectTrianglesTransparent(origin, direction, scratch_pad,
+                                        nearNode->listBegin(),
+                                        nearNode->listSize(),
+                                        travStack[exitPos].t, isectData,
+                                        context)
+          && (isectData.rayHitTriIndex >= 0)) {
+
+        // If this is the first leaf, record the hit and normal.
+        if (first_leaf) {
+          // record hit if picking
+          if (isPickingEnabled()) {
+            pickedTri = isectData.rayHitTriIndex;
+            // cerr << "picked " << pickedTri << "\n";
+            pickedBeginIndex = pickedEndIndex = pickedTri;
+            while (pickedBeginIndex > 0 &&
+                   triToGroupMap->get(pickedBeginIndex-1)
+                   == triToGroupMap->get(pickedBeginIndex))
+              pickedBeginIndex --;
+            while (pickedEndIndex < tris->getLen()-1 &&
+                   triToGroupMap->get(pickedEndIndex+1)
+                   == triToGroupMap->get(pickedEndIndex))
+              pickedEndIndex ++;
+            // cerr << "picked begin " << pickedBeginIndex << "end " << 
pickedEndIndex << "\n";
+            // cerr << "picked flag: " << (int)pickedFlag << std::endl;
+            for (int i=pickedBeginIndex; i<=pickedEndIndex; i++)
+              triFlags->set(i, pickedFlag);
+          }
+
+          // Check against the hit record, Note that tex coord mapper is 
null.
+          if (rays.hit(which, isectData.rayHit.t, getMaterial(), this, 0 )) {
+
+            // Copy the normal into the scratch pad.
+            // Used for shootOneRay type queries.
+            scratch_pad.normal = normals[isectData.rayHitTriIndex][0];
+          }
+        }
+
+        // Check to see if the ray is fully attenuated.
+        if (ray_alpha > 0.9) {
+          break;
+        }
+      }
+    }
+
+    // Move to the next
+    entryPos = exitPos;
+    exitPos = travStack[exitPos].prev;
+    nearNode = travStack[entryPos].node;
+  }
+
+  // Blend with the background.
+  ray_color += (Color(RGB(0.8,0.8,0.8))) * (1 - ray_alpha);
 }
 
 
///////////////////////////////////////////////////////////////////////////////

Modified: trunk/Model/Groups/TransparentKDTree.h
==============================================================================
--- trunk/Model/Groups/TransparentKDTree.h      (original)
+++ trunk/Model/Groups/TransparentKDTree.h      Fri Jan 20 15:03:05 2006
@@ -95,12 +95,26 @@
 
     private:           
       Real sample_alpha;
-                       
+
+      // Predeclaration for the benefit of functions that want to use it.
+                       class ScratchPadInfo;
+
       // This method intersects a list of triangles with the ray.
-      int intersectTrianglesTransparent(const Ray* ray, RayPacket::Element 
&e, unsigned int listBegin, int listSize, float maxDist, void *userData, 
const RenderContext &context, bool isFirst=false) const;
-                       
+      int intersectTrianglesTransparent(const Pointf& origin,
+                                        const Vectorf& direction,
+                                        ScratchPadInfo& scratch_pad,
+                                        unsigned int listBegin,
+                                        unsigned int listSize,
+                                        float maxDist,
+                                        RayTriIntersectUserData& userData,
+                                        const RenderContext &context) const;
+
       // This method is called by the above method with a hansong ray.
-      void _intersect(const Ray* ray, RayPacket::Element &e, 
RayTriIntersectUserData &isectData, const RenderContext &context, float 
_minDist=-1, float _maxDist=-1) const;
+      void intersect_node(KDTreeNode *startNode,
+                          RayPacket& rays, int which,
+                          RayTriIntersectUserData &isectData,
+                          const RenderContext &context,
+                          float minDist, float maxDist) const;
                
       // This structure is used to order the triangle hits along the ray
       // before blending.

Modified: trunk/Model/Instances/Instance.cc
==============================================================================
--- trunk/Model/Instances/Instance.cc   (original)
+++ trunk/Model/Instances/Instance.cc   Fri Jan 20 15:03:05 2006
@@ -1,14 +1,18 @@
 
 #include <Model/Instances/Instance.h>
+#include <Model/Instances/MPT.h>
 #include <Interface/RayPacket.h>
 #include <Core/Exceptions/BadPrimitive.h>
 #include <Core/Geometry/BBox.h>
 #include <Core/Math/MiscMath.h>
 #include <sstream>
 using namespace std;
-
 using namespace Manta;
 
+// TODO:
+// 1. Only transform hit position instead of ray origin/direction 
(computeNormal and texCoords)
+// 2. Avoid redundant transformation in texCooords
+
 Instance::Instance(Object* instance, const AffineTransform& transform)
   : instance(instance), transform(transform)
 {
@@ -42,59 +46,48 @@
 void Instance::intersect(const RenderContext& context, RayPacket& rays) const
 {
   RayPacketData raydata;
-  RayPacket instance_rays(raydata, rays.getSize(), rays.getDepth(),
+  RayPacket instance_rays(raydata, rays.begin(), rays.end(), rays.getDepth(),
                          rays.getAllFlags());
   Real scales[RayPacket::MaxSize];
   Real inv_scales[RayPacket::MaxSize];
 
   if(rays.getFlag(RayPacket::ConstantOrigin)){
-    RayPacket::Element& e0 = rays.get(0);
-
-        Point o = transform_inv * e0.ray.origin();
+    Point o = transform_inv * rays.getOrigin(rays.begin());
         
-    for(int i = 0;i<rays.getSize();i++){
-      RayPacket::Element& e = rays.get(i);
-      RayPacket::Element& te = instance_rays.get(i);
-
-               Vector dir = transform_inv * e.ray.direction();
+    for(int i = rays.begin();i<rays.end();i++){
+      Vector dir = transform_inv * rays.getDirection(i);
                
       Real length = dir.length();
       inv_scales[i] = length;
       Real ilength = 1/length;
       scales[i] = ilength;
-      te.ray.set(o, dir*ilength);
-      te.hitInfo.reset(e.hitInfo.minT()*length);
+      instance_rays.setRay(i, o, dir*ilength);
+      instance_rays.resetHit(i, rays.getMinT(i)*length);
     }
   } else {
-    for(int i = 0;i<rays.getSize();i++){
-      RayPacket::Element& e = rays.get(i);
-      RayPacket::Element& te = instance_rays.get(i);
-
-      Point o = transform_inv * e.ray.origin();
-      Vector dir = transform_inv * e.ray.direction();
+    for(int i = rays.begin();i<rays.end();i++){
+      Point o = transform_inv * rays.getOrigin(i);
+      Vector dir = transform_inv * rays.getDirection(i);
 
       Real length = dir.length();
       inv_scales[i] = length;
       Real ilength = 1/length;
       scales[i] = ilength;
-      te.ray.set(o, dir*ilength);
-      te.hitInfo.reset(e.hitInfo.minT()*length);
+      instance_rays.setRay(i, o, dir*ilength);
+      instance_rays.resetHit(i, rays.getMinT(i)*length);
     }
   }
   instance->intersect(context, instance_rays);
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    RayPacket::Element& te = instance_rays.get(i);
-    if(te.hitInfo.wasHit()){
+  for(int i=rays.begin();i<rays.end();i++){
+    if(instance_rays.wasHit(i)){
       // Instance was hit
       Real s = scales[i];
-      if(e.hitInfo.hit(te.hitInfo.minT()*s, material, this, tex)){
+      if(rays.hit(i, instance_rays.getMinT(i)*s, material, this, tex)){
         // Instance is now the closest
-        Real is = inv_scales[i];
-        e.hitInfo.scratchpad<MPTscale>() = MPTscale(te.hitInfo.hitMaterial(),
-                                                    
te.hitInfo.hitPrimitive(),
-                                                    
te.hitInfo.hitTexCoordMapper(),
-                                                    s, is);
+        rays.scratchpad<MPTscale>(i) = 
MPTscale(instance_rays.getHitMaterial(i),
+                                                
instance_rays.getHitPrimitive(i),
+                                                
instance_rays.getHitTexCoordMapper(i),
+                                                s, inv_scales[i]);
       }
     }
   }
@@ -106,39 +99,38 @@
   Ray old_rays[RayPacket::MaxSize];
 
   // Save the original rays
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    old_rays[i] = e.ray;
-    Point o    = transform_inv * e.ray.origin();        
-    Vector dir = transform_inv * e.ray.direction();
-
-    Real scale = rays.get(i).hitInfo.scratchpad<MPTscale>().scale;
-    e.ray.set(o, dir*scale);
-    old_minT[i] = e.hitInfo.minT();
-    Real inv_scale = rays.get(i).hitInfo.scratchpad<MPTscale>().inv_scale;
-    e.hitInfo.scaleT(inv_scale);
+  for(int i=rays.begin();i<rays.end();i++){
+    old_rays[i] = rays.getRay(i);
+
+    Point o = transform_inv * old_rays[i].origin();
+    Vector dir = transform_inv * old_rays[i].direction();
+
+    Real scale = rays.scratchpad<MPTscale>(i).scale;
+    rays.setRay(i, o, dir*scale);
+    old_minT[i] = rays.getMinT(i);
+    Real inv_scale = rays.scratchpad<MPTscale>(i).inv_scale;
+    rays.scaleMinT(i, inv_scale);
   }
   rays.resetFlag(RayPacket::HaveHitPositions);
 
-  for(int i=0;i<rays.getSize();){
-    RayPacket::Element& e = rays.get(i);
-    const Primitive* prim = e.hitInfo.scratchpad<MPT>().primitive;
+  // Try to create a ray packet that all use the same child primitive
+  // to compute normals.
+  for(int i=rays.begin();i<rays.end();){
+    const Primitive* prim = rays.scratchpad<MPT>(i).primitive;
     int end = i+1;
-    while(end < rays.getSize() && 
rays.get(end).hitInfo.scratchpad<MPT>().primitive == prim)
+    while(end < rays.end() && rays.scratchpad<MPT>(end).primitive == prim)
       end++;
     RayPacket subPacket(rays, i, end);
     prim->computeNormal(context, subPacket);
     i = end;
   }
-  
-  // Put the origins and minT back, scale normal
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    e.ray = old_rays[i];
-    e.hitInfo.overrideT(old_minT[i]);
 
-        e.normal = transpose_mult(transform_inv,e.normal);
-        e.normal.normalize();
+  // Put the rays and minT back, scale normal
+  for(int i=rays.begin();i<rays.end();i++){
+    rays.setRay(i, old_rays[i]);
+    rays.overrideMinT(i, old_minT[i]);
+
+    rays.setNormal(i, transpose_mult(transform_inv,rays.getNormal(i)));
   }
   rays.resetFlag(RayPacket::HaveHitPositions);
 }
@@ -150,12 +142,13 @@
 
 void Instance::shade(const RenderContext& context, RayPacket& rays) const
 {
-  for(int i=0;i<rays.getSize();){
-    RayPacket::Element& e = rays.get(i);
-    const Material* matl = e.hitInfo.scratchpad<MPT>().material;
+  for(int i=rays.begin();i<rays.end();){
+    const Material* matl = rays.scratchpad<MPT>(i).material;
     int end = i+1;
-    while(end < rays.getSize() && 
rays.get(end).hitInfo.scratchpad<MPT>().material == matl)
+
+    while(end < rays.end() && rays.scratchpad<MPT>(end).material == matl)
       end++;
+
     RayPacket subPacket(rays, i, end);
     matl->shade(context, subPacket);
     i = end;
@@ -169,37 +162,34 @@
   Ray old_rays[RayPacket::MaxSize];
 
   // Save the original rays
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    old_rays[i] = e.ray;
-
-    Point o    = transform_inv * e.ray.origin();
-    Vector dir = transform_inv * e.ray.direction();
-
-    Real scale = rays.get(i).hitInfo.scratchpad<MPTscale>().scale;
-    e.ray.set(o, dir*scale);
-    old_minT[i] = e.hitInfo.minT();
-    Real inv_scale = rays.get(i).hitInfo.scratchpad<MPTscale>().inv_scale;
-    e.hitInfo.scaleT(inv_scale);
+  for(int i=rays.begin();i<rays.end();i++){
+    old_rays[i] = rays.getRay(i);
+
+    Point o = transform_inv * old_rays[i].origin();
+    Vector dir = transform_inv * old_rays[i].direction();
+
+    Real scale = rays.scratchpad<MPTscale>(i).scale;
+    rays.setRay(i, o, dir*scale);
+    old_minT[i] = rays.getMinT(i);
+    Real inv_scale = rays.scratchpad<MPTscale>(i).inv_scale;
+    rays.scaleMinT(i, inv_scale);
   }
   rays.resetFlag(RayPacket::HaveHitPositions);
 
-  for(int i=0;i<rays.getSize();){
-    RayPacket::Element& e = rays.get(i);
-    const TexCoordMapper* tex = e.hitInfo.scratchpad<MPT>().tex;
+  for(int i=rays.begin();i<rays.end();){
+    const TexCoordMapper* tex = rays.scratchpad<MPT>(i).tex;
     int end = i+1;
-    while(end < rays.getSize() && 
rays.get(end).hitInfo.scratchpad<MPT>().tex == tex)
+    while(end < rays.end() && rays.scratchpad<MPT>(end).tex == tex)
       end++;
     RayPacket subPacket(rays, i, end);
     tex->computeTexCoords2(context, subPacket);
     i = end;
   }
 
-  // Put the origins and minT back
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    e.ray = old_rays[i];
-    e.hitInfo.overrideT(old_minT[i]);
+  // Put the rays and minT back
+  for(int i=rays.begin();i<rays.end();i++){
+    rays.setRay(i, old_rays[i]);
+    rays.overrideMinT(i, old_minT[i]);
   }
   rays.resetFlag(RayPacket::HaveHitPositions);
 }
@@ -211,37 +201,34 @@
   Ray old_rays[RayPacket::MaxSize];
 
   // Save the original rays
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    old_rays[i] = e.ray;
-
-    Point o    = transform_inv * e.ray.origin();
-    Vector dir = transform_inv * e.ray.direction();
-
-    Real scale = rays.get(i).hitInfo.scratchpad<MPTscale>().scale;
-    e.ray.set(o, dir*scale);
-    old_minT[i] = e.hitInfo.minT();
-    Real inv_scale = rays.get(i).hitInfo.scratchpad<MPTscale>().inv_scale;
-    e.hitInfo.scaleT(inv_scale);
+  for(int i=rays.begin();i<rays.end();i++){
+    old_rays[i] = rays.getRay(i);
+
+    Point o = transform_inv * old_rays[i].origin();
+    Vector dir = transform_inv * old_rays[i].direction();
+
+    Real scale = rays.scratchpad<MPTscale>(i).scale;
+    rays.setRay(i, o, dir*scale);
+    old_minT[i] = rays.getMinT(i);
+    Real inv_scale = rays.scratchpad<MPTscale>(i).inv_scale;
+    rays.scaleMinT(i, inv_scale);
   }
   rays.resetFlag(RayPacket::HaveHitPositions);
 
-  for(int i=0;i<rays.getSize();){
-    RayPacket::Element& e = rays.get(i);
-    const TexCoordMapper* tex = e.hitInfo.scratchpad<MPT>().tex;
+  for(int i=rays.begin();i<rays.end();){
+    const TexCoordMapper* tex = rays.scratchpad<MPT>(i).tex;
     int end = i+1;
-    while(end < rays.getSize() && 
rays.get(end).hitInfo.scratchpad<MPT>().tex == tex)
+    while(end < rays.end() && rays.scratchpad<MPT>(end).tex == tex)
       end++;
     RayPacket subPacket(rays, i, end);
-    tex->computeTexCoords2(context, subPacket);
+    tex->computeTexCoords3(context, subPacket);
     i = end;
   }
 
-  // Put the origins and minT back, scale normal
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    e.ray = old_rays[i];
-    e.hitInfo.overrideT(old_minT[i]);
+  // Put the rays and minT back, scale normal
+  for(int i=rays.begin();i<rays.end();i++){
+    rays.setRay(i, old_rays[i]);
+    rays.overrideMinT(i, old_minT[i]);
   }
   rays.resetFlag(RayPacket::HaveHitPositions);
 }

Modified: trunk/Model/Instances/InstanceRST.cc
==============================================================================
--- trunk/Model/Instances/InstanceRST.cc        (original)
+++ trunk/Model/Instances/InstanceRST.cc        Fri Jan 20 15:03:05 2006
@@ -4,6 +4,7 @@
 #include <Core/Exceptions/BadPrimitive.h>
 #include <Core/Geometry/BBox.h>
 #include <Core/Math/MiscMath.h>
+#include <Model/Instances/MPT.h>
 #include <sstream>
 using namespace std;
 
@@ -59,46 +60,36 @@
 void InstanceRST::intersect(const RenderContext& context, RayPacket& rays) 
const
 {
   RayPacketData raydata;
-  RayPacket instance_rays(raydata, rays.getSize(), rays.getDepth(),
+  RayPacket instance_rays(raydata, rays.begin(), rays.end(), rays.getDepth(),
                          rays.getAllFlags());
 
   if(rays.getFlag(RayPacket::ConstantOrigin)){
-    RayPacket::Element& e0 = rays.get(0);
+    Point o = transform_inv * rays.getOrigin(rays.begin());
 
-    Point o = transform_inv * e0.ray.origin();
+    for(int i = rays.begin();i<rays.end();i++){
+      Vector dir = transform_inv * rays.getDirection(i);
 
-    for(int i = 0;i<rays.getSize();i++){
-      RayPacket::Element& e = rays.get(i);
-      RayPacket::Element& te = instance_rays.get(i);
-
-      Vector dir = transform_inv * e.ray.direction();
-
-      te.ray.set(o, dir*scale);
-      te.hitInfo.reset(e.hitInfo.minT()*inv_scale);
+      instance_rays.setRay(i, o, dir*scale);
+      instance_rays.resetHit(i, rays.getMinT(i)*inv_scale);
     }
   } else {
-    for(int i = 0;i<rays.getSize();i++){
-      RayPacket::Element& e = rays.get(i);
-      RayPacket::Element& te = instance_rays.get(i);
-
-      Point o = transform_inv * e.ray.origin();
-      Vector dir = transform_inv * e.ray.direction();
+    for(int i = rays.begin();i<rays.end();i++){
+      Point o = transform_inv * rays.getOrigin(i);
+      Vector dir = transform_inv * rays.getDirection(i);
 
-      te.ray.set(o, dir*scale);
-      te.hitInfo.reset(e.hitInfo.minT()*inv_scale);
+      instance_rays.setRay(i, o, dir*scale);
+      instance_rays.resetHit(i, rays.getMinT(i)*inv_scale);
     }
   }
   instance->intersect(context, instance_rays);
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    RayPacket::Element& te = instance_rays.get(i);
-    if(te.hitInfo.wasHit()){
+  for(int i=rays.begin();i<rays.end();i++){
+    if(instance_rays.wasHit(i)){
       // Instance was hit
-      if(e.hitInfo.hit(te.hitInfo.minT()*scale, material, this, tex)){
-                 // Instance is now the closest
-                 e.hitInfo.scratchpad<MPT>() = MPT(te.hitInfo.hitMaterial(),
-                                                                             
                                  te.hitInfo.hitPrimitive(),
-                                                                             
                                  te.hitInfo.hitTexCoordMapper());
+      if(rays.hit(i, instance_rays.getMinT(i)*scale, material, this, tex)){
+        // Instance is now the closest
+        rays.scratchpad<MPT>(i) = MPT(instance_rays.getHitMaterial(i),
+                                      instance_rays.getHitPrimitive(i),
+                                      instance_rays.getHitTexCoordMapper(i));
       }
     }
   }
@@ -110,38 +101,42 @@
   Ray old_rays[RayPacket::MaxSize];
 
   // Save the original rays
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    old_rays[i] = e.ray;
-
-    Point o = transform_inv * e.ray.origin();
-    Vector dir = transform_inv * e.ray.direction();
-
-    e.ray.set(o, dir*scale);
-    old_minT[i] = e.hitInfo.minT();
-    e.hitInfo.scaleT(inv_scale);
+  for(int i=rays.begin();i<rays.end();i++){
+    old_rays[i] = rays.getRay(i);
+
+    Point o = transform_inv * old_rays[i].origin();
+    Vector dir = transform_inv * old_rays[i].direction();
+
+    rays.setRay(i, o, dir*scale);
+    old_minT[i] = rays.getMinT(i);
+    rays.scaleMinT(i, inv_scale);
   }
   rays.resetFlag(RayPacket::HaveHitPositions);
 
-  for(int i=0;i<rays.getSize();){
-    RayPacket::Element& e = rays.get(i);
-    const Primitive* prim = e.hitInfo.scratchpad<MPT>().primitive;
+  // Try to create a ray packet that all use the same child primitive
+  // to compute normals.
+  int allUnitNormals = RayPacket::HaveUnitNormals;
+  for(int i=rays.begin();i<rays.end();){
+    const Primitive* prim = rays.scratchpad<MPT>(i).primitive;
     int end = i+1;
-    while(end < rays.getSize() && 
rays.get(end).hitInfo.scratchpad<MPT>().primitive == prim)
+    while(end < rays.end() && rays.scratchpad<MPT>(end).primitive == prim)
       end++;
     RayPacket subPacket(rays, i, end);
     prim->computeNormal(context, subPacket);
+    // If we ever encounter a case where the normals aren't normalized
+    // turn the flag off.
+    allUnitNormals &= subPacket.getAllFlags();
     i = end;
   }
-  
-  // Put the origins and minT back, scale normal
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    e.ray = old_rays[i];
-    e.hitInfo.overrideT(old_minT[i]);
+  // If all the normals were unit length set the parent RayPacket's flag.
+  rays.setFlag(allUnitNormals);
 
-        e.normal = transpose_mult(transform_inv,e.normal);
-    e.normal *= scale;
+  // Put the rays and minT back, scale normal
+  for(int i=rays.begin();i<rays.end();i++){
+    rays.setRay(i, old_rays[i]);
+    rays.overrideMinT(i, old_minT[i]);
+
+    rays.setNormal(i, transpose_mult(transform_inv,rays.getNormal(i)) * 
scale);
   }
   rays.resetFlag(RayPacket::HaveHitPositions);
 }
@@ -153,12 +148,11 @@
 
 void InstanceRST::shade(const RenderContext& context, RayPacket& rays) const
 {
-  for(int i=0;i<rays.getSize();){
-    RayPacket::Element& e = rays.get(i);
-    const Material* matl = e.hitInfo.scratchpad<MPT>().material;
+  for(int i=rays.begin();i<rays.end();){
+    const Material* matl = rays.scratchpad<MPT>(i).material;
     int end = i+1;
 
-    while(end < rays.getSize() && 
rays.get(end).hitInfo.scratchpad<MPT>().material == matl)
+    while(end < rays.end() && rays.scratchpad<MPT>(end).material == matl)
       end++;
 
     RayPacket subPacket(rays, i, end);
@@ -174,35 +168,32 @@
   Ray old_rays[RayPacket::MaxSize];
 
   // Save the original rays
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    old_rays[i] = e.ray;
-
-    Point o    = transform_inv * e.ray.origin();
-    Vector dir = transform_inv * e.ray.direction();
-
-    e.ray.set(o, dir*scale);
-    old_minT[i] = e.hitInfo.minT();
-    e.hitInfo.scaleT(inv_scale);
+  for(int i=rays.begin();i<rays.end();i++){
+    old_rays[i] = rays.getRay(i);
+
+    Point o = transform_inv * old_rays[i].origin();
+    Vector dir = transform_inv * old_rays[i].direction();
+
+    rays.setRay(i, o, dir*scale);
+    old_minT[i] = rays.getMinT(i);
+    rays.scaleMinT(i, inv_scale);
   }
   rays.resetFlag(RayPacket::HaveHitPositions);
 
-  for(int i=0;i<rays.getSize();){
-    RayPacket::Element& e = rays.get(i);
-    const TexCoordMapper* tex = e.hitInfo.scratchpad<MPT>().tex;
+  for(int i=rays.begin();i<rays.end();){
+    const TexCoordMapper* tex = rays.scratchpad<MPT>(i).tex;
     int end = i+1;
-    while(end < rays.getSize() && 
rays.get(end).hitInfo.scratchpad<MPT>().tex == tex)
+    while(end < rays.end() && rays.scratchpad<MPT>(end).tex == tex)
       end++;
     RayPacket subPacket(rays, i, end);
     tex->computeTexCoords2(context, subPacket);
     i = end;
   }
 
-  // Put the origins and minT back
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    e.ray = old_rays[i];
-    e.hitInfo.overrideT(old_minT[i]);
+  // Put the rays and minT back
+  for(int i=rays.begin();i<rays.end();i++){
+    rays.setRay(i, old_rays[i]);
+    rays.overrideMinT(i, old_minT[i]);
   }
   rays.resetFlag(RayPacket::HaveHitPositions);
 }
@@ -214,35 +205,32 @@
   Ray old_rays[RayPacket::MaxSize];
 
   // Save the original rays
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    old_rays[i] = e.ray;
-
-    Point o = transform_inv * e.ray.origin();
-    Vector dir = transform_inv * e.ray.direction();
-
-    e.ray.set(o, dir*scale);
-    old_minT[i] = e.hitInfo.minT();
-    e.hitInfo.scaleT(inv_scale);
+  for(int i=rays.begin();i<rays.end();i++){
+    old_rays[i] = rays.getRay(i);
+
+    Point o = transform_inv * old_rays[i].origin();
+    Vector dir = transform_inv * old_rays[i].direction();
+
+    rays.setRay(i, o, dir*scale);
+    old_minT[i] = rays.getMinT(i);
+    rays.scaleMinT(i, inv_scale);
   }
   rays.resetFlag(RayPacket::HaveHitPositions);
 
-  for(int i=0;i<rays.getSize();){
-    RayPacket::Element& e = rays.get(i);
-    const TexCoordMapper* tex = e.hitInfo.scratchpad<MPT>().tex;
+  for(int i=rays.begin();i<rays.end();){
+    const TexCoordMapper* tex = rays.scratchpad<MPT>(i).tex;
     int end = i+1;
-    while(end < rays.getSize() && 
rays.get(end).hitInfo.scratchpad<MPT>().tex == tex)
+    while(end < rays.end() && rays.scratchpad<MPT>(end).tex == tex)
       end++;
     RayPacket subPacket(rays, i, end);
-    tex->computeTexCoords2(context, subPacket);
+    tex->computeTexCoords3(context, subPacket);
     i = end;
   }
 
-  // Put the origins and minT back, scale normal
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    e.ray = old_rays[i];
-    e.hitInfo.overrideT(old_minT[i]);
+  // Put the rays and minT back
+  for(int i=rays.begin();i<rays.end();i++){
+    rays.setRay(i, old_rays[i]);
+    rays.overrideMinT(i, old_minT[i]);
   }
   rays.resetFlag(RayPacket::HaveHitPositions);
 }

Modified: trunk/Model/Instances/InstanceRT.cc
==============================================================================
--- trunk/Model/Instances/InstanceRT.cc (original)
+++ trunk/Model/Instances/InstanceRT.cc Fri Jan 20 15:03:05 2006
@@ -1,5 +1,6 @@
 
 #include <Model/Instances/InstanceRT.h>
+#include <Model/Instances/MPT.h>
 #include <Interface/RayPacket.h>
 #include <Core/Exceptions/BadPrimitive.h>
 #include <Core/Geometry/BBox.h>
@@ -57,46 +58,36 @@
 void InstanceRT::intersect(const RenderContext& context, RayPacket& rays) 
const
 {
   RayPacketData raydata;
-  RayPacket instance_rays(raydata, rays.getSize(), rays.getDepth(),
+  RayPacket instance_rays(raydata, rays.begin(), rays.end(), rays.getDepth(),
                          rays.getAllFlags());
 
   if(rays.getFlag(RayPacket::ConstantOrigin)){
-    RayPacket::Element& e0 = rays.get(0);
+    Point o = transform_inv * rays.getOrigin(rays.begin());
 
-    Point o = transform_inv * e0.ray.origin();
+    for(int i = rays.begin();i<rays.end();i++){
+      Vector dir = transform_inv * rays.getDirection(i);
 
-    for(int i = 0;i<rays.getSize();i++){
-      RayPacket::Element& e = rays.get(i);
-      RayPacket::Element& te = instance_rays.get(i);
-
-      Vector dir = transform_inv * e.ray.direction();
-
-      te.ray.set(o, dir);
-      te.hitInfo.reset(e.hitInfo.minT());
+      instance_rays.setRay(i, o, dir);
+      instance_rays.resetHit(i, rays.getMinT(i));
     }
   } else {
-    for(int i = 0;i<rays.getSize();i++){
-      RayPacket::Element& e = rays.get(i);
-      RayPacket::Element& te = instance_rays.get(i);
-
-      Point o = transform_inv * e.ray.origin();
-      Vector dir = transform_inv * e.ray.direction();
+    for(int i = rays.begin();i<rays.end();i++){
+      Point o = transform_inv * rays.getOrigin(i);
+      Vector dir = transform_inv * rays.getDirection(i);
 
-      te.ray.set(o, dir);
-      te.hitInfo.reset(e.hitInfo.minT());
+      instance_rays.setRay(i, o, dir);
+      instance_rays.resetHit(i, rays.getMinT(i));
     }
   }
   instance->intersect(context, instance_rays);
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    RayPacket::Element& te = instance_rays.get(i);
-    if(te.hitInfo.wasHit()){
+  for(int i=rays.begin();i<rays.end();i++){
+    if(instance_rays.wasHit(i)){
       // Instance was hit
-      if(e.hitInfo.hit(te.hitInfo.minT(), material, this, tex)){
-       // Instance is now the closest
-       e.hitInfo.scratchpad<MPT>() = MPT(te.hitInfo.hitMaterial(),
-                                         te.hitInfo.hitPrimitive(),
-                                         te.hitInfo.hitTexCoordMapper());
+      if(rays.hit(i, instance_rays.getMinT(i), material, this, tex)){
+        // Instance is now the closest
+        rays.scratchpad<MPT>(i) = MPT(instance_rays.getHitMaterial(i),
+                                      instance_rays.getHitPrimitive(i),
+                                      instance_rays.getHitTexCoordMapper(i));
       }
     }
   }
@@ -107,32 +98,36 @@
   Ray old_rays[RayPacket::MaxSize];
 
   // Save the original rays
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    old_rays[i] = e.ray;
+  for(int i=rays.begin();i<rays.end();i++){
+    old_rays[i] = rays.getRay(i);
 
-    Point o = transform_inv * e.ray.origin();
-    Vector dir = transform_inv * e.ray.direction();
+    Point o = transform_inv * old_rays[i].origin();
+    Vector dir = transform_inv * old_rays[i].direction();
 
-    e.ray.set(o, dir);
+    rays.setRay(i, o, dir);
   }
   rays.resetFlag(RayPacket::HaveHitPositions);
-  for(int i=0;i<rays.getSize();){
-    RayPacket::Element& e = rays.get(i);
-    const Primitive* prim = e.hitInfo.scratchpad<MPT>().primitive;
+
+  int allUnitNormals = RayPacket::HaveUnitNormals;
+  for(int i=rays.begin();i<rays.end();){
+    const Primitive* prim = rays.scratchpad<MPT>(i).primitive;
     int end = i+1;
-    while(end < rays.getSize() && 
rays.get(end).hitInfo.scratchpad<MPT>().primitive == prim)
+    while(end < rays.end() && rays.scratchpad<MPT>(end).primitive == prim)
       end++;
     RayPacket subPacket(rays, i, end);
     prim->computeNormal(context, subPacket);
+    // If we ever encounter a case where the normals aren't normalized
+    // turn the flag off.
+    allUnitNormals &= subPacket.getAllFlags();
     i = end;
   }
+  // If all the normals were unit length set the parent RayPacket's flag.
+  rays.setFlag(allUnitNormals);
 
   // Put the rays back and fix the normals
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    e.ray = old_rays[i];
-        e.normal = transpose_mult(transform_inv,e.normal);
+  for(int i=rays.begin();i<rays.end();i++){
+    rays.setRay(i, old_rays[i]);
+    rays.setNormal(i, transpose_mult(transform_inv,rays.getNormal(i)));
   }
   rays.resetFlag(RayPacket::HaveHitPositions);
 }
@@ -144,11 +139,10 @@
 
 void InstanceRT::shade(const RenderContext& context, RayPacket& rays) const
 {
-  for(int i=0;i<rays.getSize();){
-    RayPacket::Element& e = rays.get(i);
-    const Material* matl = e.hitInfo.scratchpad<MPT>().material;
+  for(int i=rays.begin();i<rays.end();){
+    const Material* matl = rays.scratchpad<MPT>(i).material;
     int end = i+1;
-    while(end < rays.getSize() && 
rays.get(end).hitInfo.scratchpad<MPT>().material == matl)
+    while(end < rays.end() && rays.scratchpad<MPT>(end).material == matl)
       end++;
     RayPacket subPacket(rays, i, end);
     matl->shade(context, subPacket);
@@ -163,21 +157,20 @@
   Ray old_rays[RayPacket::MaxSize];
 
   // Save the original rays
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    old_rays[i] = e.ray;
+  for(int i=rays.begin();i<rays.end();i++){
+    old_rays[i] = rays.getRay(i);
 
-    Point o = transform_inv * e.ray.origin();
-    Vector dir = transform_inv * e.ray.direction();
+    Point o = transform_inv * old_rays[i].origin();
+    Vector dir = transform_inv * old_rays[i].direction();
 
-    e.ray.set(o, dir);
+    rays.setRay(i, o, dir);
   }
   rays.resetFlag(RayPacket::HaveHitPositions);
-  for(int i=0;i<rays.getSize();){
-    RayPacket::Element& e = rays.get(i);
-    const TexCoordMapper* tex = e.hitInfo.scratchpad<MPT>().tex;
+
+  for(int i=rays.begin();i<rays.end();){
+    const TexCoordMapper* tex = rays.scratchpad<MPT>(i).tex;
     int end = i+1;
-    while(end < rays.getSize() && 
rays.get(end).hitInfo.scratchpad<MPT>().tex == tex)
+    while(end < rays.end() && rays.scratchpad<MPT>(end).tex == tex)
       end++;
     RayPacket subPacket(rays, i, end);
     tex->computeTexCoords2(context, subPacket);
@@ -185,10 +178,8 @@
   }
 
   // Put the rays back and fix the normals
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    e.ray = old_rays[i];
-        e.normal = transform_inv * e.normal;
+  for(int i=rays.begin();i<rays.end();i++){
+    rays.setRay(i, old_rays[i]);
   }
   rays.resetFlag(RayPacket::HaveHitPositions);
 }
@@ -199,21 +190,20 @@
   Ray old_rays[RayPacket::MaxSize];
 
   // Save the original rays
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    old_rays[i] = e.ray;
+  for(int i=rays.begin();i<rays.end();i++){
+    old_rays[i] = rays.getRay(i);
 
-    Point o = transform * e.ray.origin();
-    Vector dir = transform * e.ray.direction();
+    Point o = transform_inv * old_rays[i].origin();
+    Vector dir = transform_inv * old_rays[i].direction();
 
-    e.ray.set(o, dir);
+    rays.setRay(i, o, dir);
   }
   rays.resetFlag(RayPacket::HaveHitPositions);
-  for(int i=0;i<rays.getSize();){
-    RayPacket::Element& e = rays.get(i);
-    const TexCoordMapper* tex = e.hitInfo.scratchpad<MPT>().tex;
+
+  for(int i=rays.begin();i<rays.end();){
+    const TexCoordMapper* tex = rays.scratchpad<MPT>(i).tex;
     int end = i+1;
-    while(end < rays.getSize() && 
rays.get(end).hitInfo.scratchpad<MPT>().tex == tex)
+    while(end < rays.end() && rays.scratchpad<MPT>(end).tex == tex)
       end++;
     RayPacket subPacket(rays, i, end);
     tex->computeTexCoords3(context, subPacket);
@@ -221,10 +211,8 @@
   }
 
   // Put the rays back and fix the normals
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    e.ray = old_rays[i];
-    e.normal = transform_inv * e.normal;
+  for(int i=rays.begin();i<rays.end();i++){
+    rays.setRay(i, old_rays[i]);
   }
   rays.resetFlag(RayPacket::HaveHitPositions);
 }

Modified: trunk/Model/Instances/InstanceST.cc
==============================================================================
--- trunk/Model/Instances/InstanceST.cc (original)
+++ trunk/Model/Instances/InstanceST.cc Fri Jan 20 15:03:05 2006
@@ -1,12 +1,13 @@
 
 #include <Model/Instances/InstanceST.h>
+#include <Model/Instances/MPT.h>
 #include <Interface/RayPacket.h>
 #include <Core/Geometry/BBox.h>
 
 using namespace Manta;
 
 InstanceST::InstanceST(Object* instance, const Vector& scale,
-                    const Vector& translation)
+                       const Vector& translation)
   : instance(instance), scale(scale), translation(translation)
 {
   // By default, use the texture coordinates and material of the child object
@@ -39,152 +40,141 @@
 void InstanceST::intersect(const RenderContext& context, RayPacket& rays) 
const
 {
   RayPacketData raydata;
-  RayPacket instance_rays(raydata, rays.getSize(), rays.getDepth(), 
rays.getAllFlags());
+  RayPacket instance_rays(raydata, rays.begin(), rays.end(), 
rays.getDepth(), rays.getAllFlags());
 
   Real scales[RayPacket::MaxSize];
   Real inv_scales[RayPacket::MaxSize];
   if(uniform_scale){
     Real iscale = inv_scale.x();
     if(rays.getFlag(RayPacket::ConstantOrigin)){
-      RayPacket::Element& e = rays.get(0);
-      Point o( Vector(e.ray.origin()-translation)*iscale );
-      for(int i = 0;i<rays.getSize();i++){
-                 RayPacket::Element& e = rays.get(i);
-                 RayPacket::Element& te = instance_rays.get(i);
-                 te.ray.set(o, e.ray.direction());
-                 te.hitInfo.reset(e.hitInfo.minT()*iscale);
+      Point o( Vector(rays.getOrigin(rays.begin())-translation)*iscale );
+
+      for(int i = rays.begin();i<rays.end();i++){
+        instance_rays.setRay(i, o, rays.getDirection(i));
+        instance_rays.resetHit(i, rays.getMinT(i)*iscale);
       }
     } else {
-      for(int i = 0;i<rays.getSize();i++){
-                 RayPacket::Element& e = rays.get(i);
-                 RayPacket::Element& te = instance_rays.get(i);
-                 
te.ray.set(Point(Vector(e.ray.origin()-translation)*iscale), 
e.ray.direction());
-                 te.hitInfo.reset(e.hitInfo.minT()*iscale);
+      for(int i = rays.begin();i<rays.end();i++){
+        Point o( Vector(rays.getOrigin(i)-translation)*iscale );
+        instance_rays.setRay(i, o, rays.getDirection(i));
+        instance_rays.resetHit(i, rays.getMinT(i)*iscale);
       }
     }
   } else {
     if(rays.getFlag(RayPacket::ConstantOrigin)){
-      RayPacket::Element& e = rays.get(0);
-      Point o(Vector(e.ray.origin()-translation)*inv_scale);
-      for(int i = 0;i<rays.getSize();i++){
-                 RayPacket::Element& e = rays.get(i);
-                 RayPacket::Element& te = instance_rays.get(i);
-                 Vector dir(e.ray.direction()*inv_scale);
-                 Real length = dir.length();
-                 inv_scales[i] = length;
-                 Real ilength = 1/length;
-                 scales[i] = ilength;
-                 te.ray.set(o, dir*ilength);
-                 te.hitInfo.reset(e.hitInfo.minT()*length);
+      Point o( Vector(rays.getOrigin(rays.begin())-translation)*inv_scale );
+      for(int i = rays.begin();i<rays.end();i++){
+        Vector dir(rays.getDirection(i)*inv_scale);
+        Real length = dir.length();
+        inv_scales[i] = length;
+        Real ilength = 1/length;
+        scales[i] = ilength;
+        instance_rays.setRay(i, o, dir*ilength);
+        instance_rays.resetHit(i, rays.getMinT(i)*length);
       }
     } else {
-      for(int i = 0;i<rays.getSize();i++){
-                 RayPacket::Element& e = rays.get(i);
-                 RayPacket::Element& te = instance_rays.get(i);
-                 Vector dir(e.ray.direction()*inv_scale);
-                 Real length = dir.length();
-                 scales[i] = length;
-                 Real ilength = 1/length;
-                 inv_scales[i] = ilength;
-                 
te.ray.set(Point((Vector(e.ray.origin())-translation)*inv_scale),
-                                                dir*ilength);
-                 te.hitInfo.reset(e.hitInfo.minT()*length);
+      for(int i = rays.begin();i<rays.end();i++){
+        Point o( Vector(rays.getOrigin(i)-translation)*inv_scale );
+        Vector dir(rays.getDirection(i)*inv_scale);
+        Real length = dir.length();
+        scales[i] = length;
+        Real ilength = 1/length;
+        inv_scales[i] = ilength;
+        instance_rays.setRay(i, o, dir*ilength);
+        instance_rays.resetHit(i, rays.getMinT(i)*length);
       }
     }
   }
   instance->intersect(context, instance_rays);
   if(uniform_scale){
     Real s = scale.x();
-    for(int i=0;i<rays.getSize();i++){
-      RayPacket::Element& e = rays.get(i);
-      RayPacket::Element& te = instance_rays.get(i);
-      if(te.hitInfo.wasHit()){
-       // Instance was hit
-       if(e.hitInfo.hit(te.hitInfo.minT()*s, material, this, tex)){
-         // Instance is now the closest
-         e.hitInfo.scratchpad<MPT>() = MPT(te.hitInfo.hitMaterial(),
-                                           te.hitInfo.hitPrimitive(),
-                                           te.hitInfo.hitTexCoordMapper());
-       }
+    for(int i=rays.begin();i<rays.end();i++){
+      if(instance_rays.wasHit(i)){
+        // Instance was hit
+        if(rays.hit(i, instance_rays.getMinT(i)*s, material, this, tex)){
+          // Instance is now the closest
+          rays.scratchpad<MPT>(i) = MPT(instance_rays.getHitMaterial(i),
+                                        instance_rays.getHitPrimitive(i),
+                                        
instance_rays.getHitTexCoordMapper(i));
+        }
       }
     }
   } else {
-    for(int i=0;i<rays.getSize();i++){
-      RayPacket::Element& e = rays.get(i);
-      RayPacket::Element& te = instance_rays.get(i);
-      if(te.hitInfo.wasHit()){
+    for(int i=rays.begin();i<rays.end();i++){
+      if(instance_rays.wasHit(i)){
         // Instance was hit
         Real s = scales[i];
-        if(e.hitInfo.hit(te.hitInfo.minT()*s, material, this, tex)){
+        if(rays.hit(i, instance_rays.getMinT(i)*s, material, this, tex)){
           // Instance is now the closest
-          Real is = inv_scales[i];
-          e.hitInfo.scratchpad<MPTscale>() =
-            MPTscale(te.hitInfo.hitMaterial(),
-                     te.hitInfo.hitPrimitive(),
-                     te.hitInfo.hitTexCoordMapper(),
-                     s, is);
+          rays.scratchpad<MPTscale>(i) =
+            MPTscale(instance_rays.getHitMaterial(i),
+                     instance_rays.getHitPrimitive(i),
+                     instance_rays.getHitTexCoordMapper(i),
+                     s, inv_scales[i]);
         }
       }
     }
   }
 }
 
-void InstanceST::computeNormal(const RenderContext& context, RayPacket& 
rays) const
+void
+InstanceST::computeNormal(const RenderContext& context, RayPacket& rays) 
const
 {
   Real old_minT[RayPacket::MaxSize];
   Point old_origins[RayPacket::MaxSize];
   Ray old_rays[RayPacket::MaxSize];
+
   if(uniform_scale){
     // Save the original origins and minT
     Real is = inv_scale.x();
-    for(int i=0;i<rays.getSize();i++){
-      RayPacket::Element& e = rays.get(i);
-      old_origins[i] = e.ray.origin();
-      e.ray.setOrigin(Point(Vector(old_origins[i]-translation)*is));
-      old_minT[i] = e.hitInfo.minT();
-      e.hitInfo.scaleT(is);
+    for(int i=rays.begin();i<rays.end();i++){
+      old_origins[i] = rays.getOrigin(i);
+      rays.setOrigin(i, Point(Vector(old_origins[i]-translation)*is));
+      old_minT[i] = rays.getMinT(i);
+      rays.scaleMinT(i, is);
     }
   } else {
     // Save the original rays and minT
-    for(int i=0;i<rays.getSize();i++){
-      RayPacket::Element& e = rays.get(i);
-      old_rays[i] = e.ray;
-      Vector dir(e.ray.direction()*inv_scale);
-      Real ilength = rays.get(i).hitInfo.scratchpad<MPTscale>().scale;
-      e.ray.set(Point((Vector(e.ray.origin())-translation)*inv_scale),
-               dir*ilength);
-      old_minT[i] = e.hitInfo.minT();
-      Real length = rays.get(i).hitInfo.scratchpad<MPTscale>().inv_scale;
-      e.hitInfo.scaleT(length);
+    for(int i=rays.begin();i<rays.end();i++){
+      old_rays[i] = rays.getRay(i);
+      Vector dir(old_rays[i].direction()*inv_scale);
+      Real ilength = rays.scratchpad<MPTscale>(i).scale;
+      Point o( (old_rays[i].origin()-translation).multipliedBy(inv_scale) );
+      rays.setRay(i, o, dir*ilength);
+      old_minT[i] = rays.getMinT(i);
+      Real length = rays.scratchpad<MPTscale>(i).inv_scale;
+      rays.scaleMinT(i, length);
     }
   }
   rays.resetFlag(RayPacket::HaveHitPositions);
-  for(int i=0;i<rays.getSize();){
-    RayPacket::Element& e = rays.get(i);
-    const Primitive* prim = e.hitInfo.scratchpad<MPT>().primitive;
+
+  int allUnitNormals = RayPacket::HaveUnitNormals;
+  for(int i=rays.begin();i<rays.end();){
+    const Primitive* prim = rays.scratchpad<MPT>(i).primitive;
     int end = i+1;
-    while(end < rays.getSize() && 
rays.get(end).hitInfo.scratchpad<MPT>().primitive == prim)
+    while(end < rays.end() && rays.scratchpad<MPT>(end).primitive == prim)
       end++;
     RayPacket subPacket(rays, i, end);
     prim->computeNormal(context, subPacket);
+    // If we ever encounter a case where the normals aren't normalized
+    // turn the flag off.
+    allUnitNormals &= subPacket.getAllFlags();
     i = end;
-  }
-  
+  }  
   if(uniform_scale){
     // Put the origins and minT back
-    for(int i=0;i<rays.getSize();i++){
-      RayPacket::Element& e = rays.get(i);
-      e.ray.setOrigin(old_origins[i]);
-      e.hitInfo.overrideT(old_minT[i]);
+    for(int i=rays.begin();i<rays.end();i++){
+      rays.setOrigin(i, old_origins[i]);
+      rays.overrideMinT(i, old_minT[i]);
     }
+    // If all the normals were unit length set the parent RayPacket's flag.
+    rays.setFlag(allUnitNormals);
   } else {
     // Put the origins and minT back, scale normal
-    for(int i=0;i<rays.getSize();i++){
-      RayPacket::Element& e = rays.get(i);
-      e.ray = old_rays[i];
-      e.hitInfo.overrideT(old_minT[i]);
-      e.normal *= inv_scale;
-      e.normal.normalize();
+    for(int i=rays.begin();i<rays.end();i++){
+      rays.setRay(i, old_rays[i]);
+      rays.overrideMinT(i, old_minT[i]);
+      rays.setNormal(i, rays.getNormal(i) * scale);
     }
   }
   rays.resetFlag(RayPacket::HaveHitPositions);
@@ -197,11 +187,10 @@
 
 void InstanceST::shade(const RenderContext& context, RayPacket& rays) const
 {
-  for(int i=0;i<rays.getSize();){
-    RayPacket::Element& e = rays.get(i);
-    const Material* matl = e.hitInfo.scratchpad<MPT>().material;
+  for(int i=rays.begin();i<rays.end();){
+    const Material* matl = rays.scratchpad<MPT>(i).material;
     int end = i+1;
-    while(end < rays.getSize() && 
rays.get(end).hitInfo.scratchpad<MPT>().material == matl)
+    while(end < rays.end() && rays.scratchpad<MPT>(end).material == matl)
       end++;
     RayPacket subPacket(rays, i, end);
     matl->shade(context, subPacket);
@@ -210,41 +199,40 @@
 }
 
 void InstanceST::computeTexCoords2(const RenderContext& context,
-                              RayPacket& rays) const
+                                   RayPacket& rays) const
 {
   Real old_minT[RayPacket::MaxSize];
   Point old_origins[RayPacket::MaxSize];
   Ray old_rays[RayPacket::MaxSize];
+
   if(uniform_scale){
     // Save the original origins and minT
     Real is = inv_scale.x();
-    for(int i=0;i<rays.getSize();i++){
-      RayPacket::Element& e = rays.get(i);
-      old_origins[i] = e.ray.origin();
-      e.ray.setOrigin(Point(Vector(old_origins[i]-translation)*is));
-      old_minT[i] = e.hitInfo.minT();
-      e.hitInfo.scaleT(is);
+    for(int i=rays.begin();i<rays.end();i++){
+      old_origins[i] = rays.getOrigin(i);
+      rays.setOrigin(i, Point(Vector(old_origins[i]-translation)*is));
+      old_minT[i] = rays.getMinT(i);
+      rays.scaleMinT(i, is);
     }
   } else {
     // Save the original rays and minT
-    for(int i=0;i<rays.getSize();i++){
-      RayPacket::Element& e = rays.get(i);
-      old_rays[i] = e.ray;
-      Vector dir(e.ray.direction()*inv_scale);
-      Real ilength = rays.get(i).hitInfo.scratchpad<MPTscale>().scale;
-      e.ray.set(Point((Vector(e.ray.origin())-translation)*inv_scale),
-               dir*ilength);
-      old_minT[i] = e.hitInfo.minT();
-      Real length = rays.get(i).hitInfo.scratchpad<MPTscale>().inv_scale;
-      e.hitInfo.scaleT(length);
+    for(int i=rays.begin();i<rays.end();i++){
+      old_rays[i] = rays.getRay(i);
+      Vector dir(old_rays[i].direction()*inv_scale);
+      Real ilength = rays.scratchpad<MPTscale>(i).scale;
+      Point o( (old_rays[i].origin()-translation).multipliedBy(inv_scale) );
+      rays.setRay(i, o, dir*ilength);
+      old_minT[i] = rays.getMinT(i);
+      Real length = rays.scratchpad<MPTscale>(i).inv_scale;
+      rays.scaleMinT(i, length);
     }
   }
   rays.resetFlag(RayPacket::HaveHitPositions);
-  for(int i=0;i<rays.getSize();){
-    RayPacket::Element& e = rays.get(i);
-    const TexCoordMapper* tex = e.hitInfo.scratchpad<MPT>().tex;
+
+  for(int i=rays.begin();i<rays.end();){
+    const TexCoordMapper* tex = rays.scratchpad<MPT>(i).tex;
     int end = i+1;
-    while(end < rays.getSize() && 
rays.get(end).hitInfo.scratchpad<MPT>().tex == tex)
+    while(end < rays.end() && rays.scratchpad<MPT>(end).tex == tex)
       end++;
     RayPacket subPacket(rays, i, end);
     tex->computeTexCoords2(context, subPacket);
@@ -253,57 +241,55 @@
 
   if(uniform_scale){
     // Put the origins and minT back
-    for(int i=0;i<rays.getSize();i++){
-      RayPacket::Element& e = rays.get(i);
-      e.ray.setOrigin(old_origins[i]);
-      e.hitInfo.overrideT(old_minT[i]);
+    for(int i=rays.begin();i<rays.end();i++){
+      rays.setOrigin(i, old_origins[i]);
+      rays.overrideMinT(i, old_minT[i]);
     }
   } else {
-    // Put the origins and minT back
-    for(int i=0;i<rays.getSize();i++){
-      RayPacket::Element& e = rays.get(i);
-      e.ray = old_rays[i];
-      e.hitInfo.overrideT(old_minT[i]);
+    // Put the origins and minT back, scale normal
+    for(int i=rays.begin();i<rays.end();i++){
+      rays.setRay(i, old_rays[i]);
+      rays.overrideMinT(i, old_minT[i]);
     }
   }
+  rays.resetFlag(RayPacket::HaveHitPositions);
 }
 
 void InstanceST::computeTexCoords3(const RenderContext& context,
-                              RayPacket& rays) const
+                                   RayPacket& rays) const
 {
   Real old_minT[RayPacket::MaxSize];
   Point old_origins[RayPacket::MaxSize];
   Ray old_rays[RayPacket::MaxSize];
+
   if(uniform_scale){
     // Save the original origins and minT
     Real is = inv_scale.x();
-    for(int i=0;i<rays.getSize();i++){
-      RayPacket::Element& e = rays.get(i);
-      old_origins[i] = e.ray.origin();
-      e.ray.setOrigin(Point(Vector(old_origins[i]-translation)*is));
-      old_minT[i] = e.hitInfo.minT();
-      e.hitInfo.scaleT(is);
+    for(int i=rays.begin();i<rays.end();i++){
+      old_origins[i] = rays.getOrigin(i);
+      rays.setOrigin(i, Point(Vector(old_origins[i]-translation)*is));
+      old_minT[i] = rays.getMinT(i);
+      rays.scaleMinT(i, is);
     }
   } else {
     // Save the original rays and minT
-    for(int i=0;i<rays.getSize();i++){
-      RayPacket::Element& e = rays.get(i);
-      old_rays[i] = e.ray;
-      Vector dir(e.ray.direction()*inv_scale);
-      Real ilength = rays.get(i).hitInfo.scratchpad<MPTscale>().scale;
-      e.ray.set(Point((Vector(e.ray.origin())-translation)*inv_scale),
-               dir*ilength);
-      old_minT[i] = e.hitInfo.minT();
-      Real length = rays.get(i).hitInfo.scratchpad<MPTscale>().inv_scale;
-      e.hitInfo.scaleT(length);
+    for(int i=rays.begin();i<rays.end();i++){
+      old_rays[i] = rays.getRay(i);
+      Vector dir(old_rays[i].direction()*inv_scale);
+      Real ilength = rays.scratchpad<MPTscale>(i).scale;
+      Point o( (old_rays[i].origin()-translation).multipliedBy(inv_scale) );
+      rays.setRay(i, o, dir*ilength);
+      old_minT[i] = rays.getMinT(i);
+      Real length = rays.scratchpad<MPTscale>(i).inv_scale;
+      rays.scaleMinT(i, length);
     }
   }
   rays.resetFlag(RayPacket::HaveHitPositions);
-  for(int i=0;i<rays.getSize();){
-    RayPacket::Element& e = rays.get(i);
-    const TexCoordMapper* tex = e.hitInfo.scratchpad<MPT>().tex;
+
+  for(int i=rays.begin();i<rays.end();){
+    const TexCoordMapper* tex = rays.scratchpad<MPT>(i).tex;
     int end = i+1;
-    while(end < rays.getSize() && 
rays.get(end).hitInfo.scratchpad<MPT>().tex == tex)
+    while(end < rays.end() && rays.scratchpad<MPT>(end).tex == tex)
       end++;
     RayPacket subPacket(rays, i, end);
     tex->computeTexCoords3(context, subPacket);
@@ -312,20 +298,20 @@
 
   if(uniform_scale){
     // Put the origins and minT back
-    for(int i=0;i<rays.getSize();i++){
-      RayPacket::Element& e = rays.get(i);
-      e.ray.setOrigin(old_origins[i]);
-      e.hitInfo.overrideT(old_minT[i]);
+    for(int i=rays.begin();i<rays.end();i++){
+      rays.setOrigin(i, old_origins[i]);
+      rays.overrideMinT(i, old_minT[i]);
     }
   } else {
-    // Put the origins and minT back
-    for(int i=0;i<rays.getSize();i++){
-      RayPacket::Element& e = rays.get(i);
-      e.ray = old_rays[i];
-      e.hitInfo.overrideT(old_minT[i]);
+    // Put the origins and minT back, scale normal
+    for(int i=rays.begin();i<rays.end();i++){
+      rays.setRay(i, old_rays[i]);
+      rays.overrideMinT(i, old_minT[i]);
     }
   }
+  rays.resetFlag(RayPacket::HaveHitPositions);
 }
+
 
 void InstanceST::overrideMaterial(Material* in_material)
 {

Modified: trunk/Model/Instances/InstanceT.cc
==============================================================================
--- trunk/Model/Instances/InstanceT.cc  (original)
+++ trunk/Model/Instances/InstanceT.cc  Fri Jan 20 15:03:05 2006
@@ -1,5 +1,6 @@
 
 #include <Model/Instances/InstanceT.h>
+#include <Model/Instances/MPT.h>
 #include <Interface/RayPacket.h>
 #include <Core/Geometry/BBox.h>
 
@@ -33,37 +34,31 @@
 void InstanceT::intersect(const RenderContext& context, RayPacket& rays) 
const
 {
   RayPacketData raydata;
-  RayPacket instance_rays(raydata, rays.getSize(), rays.getDepth(),
-                         rays.getAllFlags());
+  RayPacket instance_rays(raydata, rays.begin(), rays.end(), rays.getDepth(),
+                          rays.getAllFlags());
 
   if(rays.getFlag(RayPacket::ConstantOrigin)){
-    RayPacket::Element& e = rays.get(0);
-    Point O(e.ray.origin()-translation);
-    for(int i = 0;i<rays.getSize();i++){
-      RayPacket::Element& e = rays.get(i);
-      RayPacket::Element& te = instance_rays.get(i);
-      te.ray.set(O, e.ray.direction());
-      te.hitInfo.reset(e.hitInfo.minT());
+    Point o(rays.getOrigin(rays.begin())-translation);
+    for(int i = rays.begin();i<rays.end();i++){
+      instance_rays.setRay(i, o, rays.getDirection(i));
+      instance_rays.resetHit(i, rays.getMinT(i));
     }
   } else {
-    for(int i = 0;i<rays.getSize();i++){
-      RayPacket::Element& e = rays.get(i);
-      RayPacket::Element& te = instance_rays.get(i);
-      te.ray.set(e.ray.origin()-translation, e.ray.direction());
-      te.hitInfo.reset(e.hitInfo.minT());
+    for(int i = rays.begin();i<rays.end();i++){
+      Point o(rays.getOrigin(i)-translation);
+      instance_rays.setRay(i, o, rays.getDirection(i));
+      instance_rays.resetHit(i, rays.getMinT(i));
     }
   }
   instance->intersect(context, instance_rays);
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    RayPacket::Element& te = instance_rays.get(i);
-    if(te.hitInfo.wasHit()){
+  for(int i=rays.begin();i<rays.end();i++){
+    if(instance_rays.wasHit(i)){
       // Instance was hit
-      if(e.hitInfo.hit(te.hitInfo.minT(), material, this, tex)){
-       // Instance is now the closest
-       e.hitInfo.scratchpad<MPT>() = MPT(te.hitInfo.hitMaterial(),
-                                         te.hitInfo.hitPrimitive(),
-                                         te.hitInfo.hitTexCoordMapper());
+      if(rays.hit(i, instance_rays.getMinT(i), material, this, tex)){
+        // Instance is now the closest
+        rays.scratchpad<MPT>(i) = MPT(instance_rays.getHitMaterial(i),
+                                      instance_rays.getHitPrimitive(i),
+                                      instance_rays.getHitTexCoordMapper(i));
       }
     }
   }
@@ -74,27 +69,31 @@
   Point old_origins[RayPacket::MaxSize];
 
   // Save the original origins
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    old_origins[i] = e.ray.origin();
-    e.ray.setOrigin(old_origins[i]-translation);
+  for(int i=rays.begin();i<rays.end();i++){
+    old_origins[i] = rays.getOrigin(i);
+    rays.setOrigin(i, old_origins[i]-translation);
   }
   rays.resetFlag(RayPacket::HaveHitPositions);
-  for(int i=0;i<rays.getSize();){
-    RayPacket::Element& e = rays.get(i);
-    const Primitive* prim = e.hitInfo.scratchpad<MPT>().primitive;
+
+  int allUnitNormals = RayPacket::HaveUnitNormals;
+  for(int i=rays.begin();i<rays.end();){
+    const Primitive* prim = rays.scratchpad<MPT>(i).primitive;
     int end = i+1;
-    while(end < rays.getSize() && 
rays.get(end).hitInfo.scratchpad<MPT>().primitive == prim)
+    while(end < rays.end() && rays.scratchpad<MPT>(end).primitive == prim)
       end++;
     RayPacket subPacket(rays, i, end);
     prim->computeNormal(context, subPacket);
+    // If we ever encounter a case where the normals aren't normalized
+    // turn the flag off.
+    allUnitNormals &= subPacket.getAllFlags();
     i = end;
   }
+  // If all the normals were unit length set the parent RayPacket's flag.
+  rays.setFlag(allUnitNormals);
 
   // Put the origins back
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    e.ray.setOrigin(old_origins[i]);
+  for(int i=rays.begin();i<rays.end();i++){
+    rays.setOrigin(i, old_origins[i]);
   }
   rays.resetFlag(RayPacket::HaveHitPositions);
 }
@@ -106,11 +105,10 @@
 
 void InstanceT::shade(const RenderContext& context, RayPacket& rays) const
 {
-  for(int i=0;i<rays.getSize();){
-    RayPacket::Element& e = rays.get(i);
-    const Material* matl = e.hitInfo.scratchpad<MPT>().material;
+  for(int i=rays.begin();i<rays.end();){
+    const Material* matl = rays.scratchpad<MPT>(i).material;
     int end = i+1;
-    while(end < rays.getSize() && 
rays.get(end).hitInfo.scratchpad<MPT>().material == matl)
+    while(end < rays.end() && rays.scratchpad<MPT>(end).material == matl)
       end++;
     RayPacket subPacket(rays, i, end);
     matl->shade(context, subPacket);
@@ -120,22 +118,21 @@
 
 
 void InstanceT::computeTexCoords2(const RenderContext& context,
-                              RayPacket& rays) const
+                                  RayPacket& rays) const
 {
   Point old_origins[RayPacket::MaxSize];
 
   // Save the original origins
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    old_origins[i] = e.ray.origin();
-    e.ray.setOrigin(old_origins[i]-translation);
+  for(int i=rays.begin();i<rays.end();i++){
+    old_origins[i] = rays.getOrigin(i);
+    rays.setOrigin(i, old_origins[i]-translation);
   }
   rays.resetFlag(RayPacket::HaveHitPositions);
-  for(int i=0;i<rays.getSize();){
-    RayPacket::Element& e = rays.get(i);
-    const TexCoordMapper* tex = e.hitInfo.scratchpad<MPT>().tex;
+
+  for(int i=rays.begin();i<rays.end();){
+    const TexCoordMapper* tex = rays.scratchpad<MPT>(i).tex;
     int end = i+1;
-    while(end < rays.getSize() && 
rays.get(end).hitInfo.scratchpad<MPT>().tex == tex)
+    while(end < rays.end() && rays.scratchpad<MPT>(end).tex == tex)
       end++;
     RayPacket subPacket(rays, i, end);
     tex->computeTexCoords2(context, subPacket);
@@ -143,29 +140,27 @@
   }
 
   // Put the origins back
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    e.ray.setOrigin(old_origins[i]);
+  for(int i=rays.begin();i<rays.end();i++){
+    rays.setOrigin(i, old_origins[i]);
   }
 }
 
 void InstanceT::computeTexCoords3(const RenderContext& context,
-                              RayPacket& rays) const
+                                  RayPacket& rays) const
 {
   Point old_origins[RayPacket::MaxSize];
 
   // Save the original origins
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    old_origins[i] = e.ray.origin();
-    e.ray.setOrigin(old_origins[i]-translation);
+  for(int i=rays.begin();i<rays.end();i++){
+    old_origins[i] = rays.getOrigin(i);
+    rays.setOrigin(i, old_origins[i]-translation);
   }
   rays.resetFlag(RayPacket::HaveHitPositions);
-  for(int i=0;i<rays.getSize();){
-    RayPacket::Element& e = rays.get(i);
-    const TexCoordMapper* tex = e.hitInfo.scratchpad<MPT>().tex;
+
+  for(int i=rays.begin();i<rays.end();){
+    const TexCoordMapper* tex = rays.scratchpad<MPT>(i).tex;
     int end = i+1;
-    while(end < rays.getSize() && 
rays.get(end).hitInfo.scratchpad<MPT>().tex == tex)
+    while(end < rays.end() && rays.scratchpad<MPT>(end).tex == tex)
       end++;
     RayPacket subPacket(rays, i, end);
     tex->computeTexCoords3(context, subPacket);
@@ -173,9 +168,8 @@
   }
 
   // Put the origins back
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    e.ray.setOrigin(old_origins[i]);
+  for(int i=rays.begin();i<rays.end();i++){
+    rays.setOrigin(i, old_origins[i]);
   }
 }
 

Modified: trunk/Model/Intersections/AxisAlignedBox.h
==============================================================================
--- trunk/Model/Intersections/AxisAlignedBox.h  (original)
+++ trunk/Model/Intersections/AxisAlignedBox.h  Fri Jan 20 15:03:05 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: trunk/Model/Lights/CMakeLists.txt
==============================================================================
--- trunk/Model/Lights/CMakeLists.txt   (original)
+++ trunk/Model/Lights/CMakeLists.txt   Fri Jan 20 15:03:05 2006
@@ -1,6 +1,7 @@
 
 SET (Manta_Lights_SRCS
+     Lights/HeadLight.h
+     Lights/HeadLight.cc
      Lights/PointLight.h
      Lights/PointLight.cc
-     Lights/HeadLight.h
-     Lights/HeadLight.cc)
+    )

Modified: trunk/Model/Lights/HeadLight.cc
==============================================================================
--- trunk/Model/Lights/HeadLight.cc     (original)
+++ trunk/Model/Lights/HeadLight.cc     Fri Jan 20 15:03:05 2006
@@ -3,13 +3,16 @@
 #include <Model/Lights/HeadLight.h>
 #include <Interface/Context.h>
 #include <Interface/Camera.h>
+#include <Interface/RayPacket.h>
+#include <Core/Geometry/PointVector.h>
 
 using namespace Manta;
 
-void HeadLight::computeLight( Color &resultColor, Vector &lightDirection,
+void HeadLight::computeLight( Color  resultColor[RayPacket::MaxSize],
+                              Vector lightDirection[RayPacket::MaxSize],
                               const RenderContext &context,
-                              RayPacket::Element &e ) const {
-
+                              RayPacket &rays) const
+{
   // Determine the camera position.
   Point camera = context.camera->getPosition();
   Vector up    = context.camera->getUp();
@@ -17,8 +20,9 @@
   // Determine light position.
   Point position = camera + (up * offset);
 
-  // Finally compute light direction.
-  lightDirection = position - e.hitPosition;
-
-  resultColor = color;
+  rays.computeHitPositions();
+  for(int i = rays.begin(); i < rays.end(); i++){
+    resultColor[i] = color;
+    lightDirection[i] = position - rays.getHitPosition(i);
+  }
 }

Modified: trunk/Model/Lights/HeadLight.h
==============================================================================
--- trunk/Model/Lights/HeadLight.h      (original)
+++ trunk/Model/Lights/HeadLight.h      Fri Jan 20 15:03:05 2006
@@ -8,18 +8,20 @@
 
 namespace Manta {
   class HeadLight : public Light {
-public:
+  public:
     HeadLight(const Real offset_, const Color &color_) : offset( offset_ ), 
color( color_ ) {  };
-               
+
     virtual void preprocess(const PreprocessContext&) { /* Does Nothing. */ 
};
-               virtual void computeLight( Color &resultColor, Vector 
&lightDirection,
-                                          const RenderContext &context, 
RayPacket::Element &e ) const;
-               
-               void setOffset( Real offset_ ) { offset = offset_; };
-               Real getOffset() { return offset; };
-               
-private:
-               Real  offset;
+    virtual void computeLight( Color  resultColor[RayPacket::MaxSize],
+                               Vector lightDirection[RayPacket::MaxSize],
+                               const RenderContext &context,
+                               RayPacket &rays) const;
+
+    void setOffset( Real offset_ ) { offset = offset_; };
+    Real getOffset() { return offset; };
+
+  private:
+    Real  offset;
     Color color;
   };
 }

Modified: trunk/Model/Lights/PointLight.cc
==============================================================================
--- trunk/Model/Lights/PointLight.cc    (original)
+++ trunk/Model/Lights/PointLight.cc    Fri Jan 20 15:03:05 2006
@@ -16,15 +16,14 @@
 {
 }
 
-void PointLight::computeLight( Color &resultColor, Vector &lightDirection,
-                               const RenderContext &/*context*/,
-                               RayPacket::Element &e ) const {
-
-       // Specify the color.
-       resultColor = color;
-       
-       // Compute the light direction.
-       lightDirection = (position - e.hitPosition);
-       
+void PointLight::computeLight( Color  resultColor[RayPacket::MaxSize],
+                               Vector lightDirection[RayPacket::MaxSize],
+                               const RenderContext &context,
+                               RayPacket &rays) const
+{
+  rays.computeHitPositions();
+  for(int i = rays.begin(); i < rays.end(); i++){
+    resultColor[i] = color;
+    lightDirection[i] = position - rays.getHitPosition(i);
+  }
 }
-

Modified: trunk/Model/Lights/PointLight.h
==============================================================================
--- trunk/Model/Lights/PointLight.h     (original)
+++ trunk/Model/Lights/PointLight.h     Fri Jan 20 15:03:05 2006
@@ -13,10 +13,11 @@
     virtual ~PointLight();
 
     virtual void preprocess(const PreprocessContext&);
-    
-               virtual void computeLight( Color &resultColor, Vector 
&lightDirection,
-                                          const RenderContext &context, 
RayPacket::Element &e ) const;
-               
+
+    virtual void computeLight( Color  resultColor[RayPacket::MaxSize],
+                               Vector lightDirection[RayPacket::MaxSize],
+                               const RenderContext &context,
+                               RayPacket &rays) const;
   private:
     Point position;
     Color color;

Modified: trunk/Model/Materials/AmbientOcclusion.cc
==============================================================================
--- trunk/Model/Materials/AmbientOcclusion.cc   (original)
+++ trunk/Model/Materials/AmbientOcclusion.cc   Fri Jan 20 15:03:05 2006
@@ -9,136 +9,149 @@
 #include <SCIRun/Core/Math/Trig.h>
 
 using namespace Manta;
+using SCIRun::Sqrt;
 
 // TODO: sort the rays generated in generateDirections to make them more
 // coherent for ray packets.
+// TODO: Try to pack as many occlusion rays into a single ray packet.
 
-AmbientOcclusion::AmbientOcclusion(const Color& color, float cutoff_dist, 
int num_dirs)
+AmbientOcclusion::AmbientOcclusion(const Color& color, float cutoff_dist,
+                                   int num_dirs)
 {
-    colortex = new Constant<Color>(color);
-    cutoff = cutoff_dist;
-    num_directions = num_dirs;
-    inv_num_directions = 1.f/float(num_directions);
-    generateDirections();
+  colortex = new Constant<Color>(color);
+  cutoff = cutoff_dist;
+  inv_num_directions = 1.0/num_dirs;
+  generateDirections(num_dirs);
 }
 
-AmbientOcclusion::AmbientOcclusion(const Texture<Color>* color, float 
cutoff_dist, int num_dirs) : colortex(color), cutoff(cutoff_dist), 
num_directions(num_dirs)
+AmbientOcclusion::AmbientOcclusion(const Texture<Color>* color,
+                                   float cutoff_dist, int num_dirs)
+  : colortex(color), cutoff(cutoff_dist)
 {
-    inv_num_directions = 1.f/float(num_directions);
-    generateDirections();
+  inv_num_directions = 1.0/num_dirs;
+  generateDirections(num_dirs);
 }
 
 AmbientOcclusion::~AmbientOcclusion()
 {
-    if (directions) delete[] directions;
 }
 
-void AmbientOcclusion::generateDirections()
-
+void AmbientOcclusion::generateDirections(int num_directions)
 {
-    directions = new Vector[num_directions];
-    MT_RNG rng;
-    // generate cosine weighted directions
-    for ( int i = 0; i < num_directions; i++ )
-    {
-        double r1 = rng.genRealRand<double>();
-        double r2 = rng.genRealRand<double>();
-
-        double phi = 2.0 * Pi * r1;
-        double r   = sqrt(r2);
-        double x   = r * Cos(phi);
-        double y   = r * Sin(phi);
-        double z   = 1.0 - x*x - y*y;
-        z = (z > 0.0) ? sqrt(z) : 0.0;
+  directions.resize(num_directions);
+  MT_RNG rng;
+  // generate cosine weighted directions
+  for ( int i = 0; i < num_directions; i++ )
+  {
+    double r1 = rng.genRealRand<double>();
+    double r2 = rng.genRealRand<double>();
+
+    double phi = 2.0 * Pi * r1;
+    double r   = sqrt(r2);
+    double x   = r * Cos(phi);
+    double y   = r * Sin(phi);
+    double z   = 1.0 - x*x - y*y;
+    z = (z > 0.0) ? Sqrt(z) : 0.0;
 
-        directions[i] = Vector(x, y, z);
-    }
+    directions[i] = Vector(x, y, z);
+  }
 }
 
-void AmbientOcclusion::shade(const RenderContext& context, RayPacket& rays) 
const
+void AmbientOcclusion::shade(const RenderContext& context,
+                             RayPacket& rays) const
 {
-    // Compute normals
-    rays.computeNormals(context);
-    rays.computeHitPositions();
-
-    // Compute colors
-    Color colors[RayPacket::MaxSize];
-    colortex->mapValues(context, rays, colors);
-
-    RayPacketData data;
-    int start = 0;
-    do
-    {
-        RayPacket shadowRays(data, 0, rays.getDepth(), 0);
-        int end = context.shadowAlgorithm->computeShadows(context, 
activeLights,
-                                                          rays, start, 
shadowRays);
-        shadowRays.normalizeDirections();
-        for(int i=start;i<end;i++)
-        {
-            RayPacket::Element& e = rays.get(i);
-
-            // for each position, compute a local coordinate frame
-            // and build a set of rays to push into a ray packet
-            Vector W(e.normal); // surface ONB
-            W.normalize();
-            Vector U(Cross(W, Vector(1,0,0)));
-            double squared_length = U.length2();
-            if ( squared_length < 1e-6 )
-            {
-                U = Cross(W, Vector(0,1,0));
-                U.normalize();
-            }
-            else
-                U *= 1./sqrt(squared_length);
-            Vector V(Cross(W, U));
-
-            // Send out the ambient occlusion tests
-            int num_sent = 0;
-            float num_miss = 0.f;
-            while ( num_sent < num_directions )
-            {
-                int start = num_sent;
-                int end   = start + RayPacket::MaxSize;
-                if (end > num_directions) end = num_directions;
-
-                RayPacketData occlusion_data;
-                RayPacket occlusion_rays(occlusion_data, end-start, 
rays.getDepth(), RayPacket::NormalizedDirections | RayPacket::ConstantOrigin);
-
-                for ( int r = start; r < end; r++ )
-                {
-                    RayPacket::Element& element = 
occlusion_rays.get(r-start);
-                    Vector trans_dir = directions[r][0]*U + 
directions[r][1]*V + directions[r][2]*W;
-                    element.ray.set(e.hitPosition, trans_dir);
-                    // set max distance
-                    element.hitInfo.reset(cutoff);
-                }
-                // packet is ready, test it for occlusion
-                context.scene->getObject()->intersect(context, 
occlusion_rays);
-                // count the number of occluded ones
-                for (int r = start; r < end; r++ )
-                {
-                    RayPacket::Element& element = 
occlusion_rays.get(r-start);
-                    if(!element.hitInfo.wasHit())
-                        num_miss+=1.0f;
-                }
-                num_sent = end;
-            }
-
-            // Test for shadows and diffuse lighting from regular light 
sources
-            Color totalLight(RGB(0,0,0));
-            for(int j=e.shadowBegin;j<e.shadowEnd;j++)
-            {
-                RayPacket::Element& s = shadowRays.get(j);
-                if(!s.hitInfo.wasHit())
-                {
-                    double cos_theta = Dot(s.ray.direction(), e.normal);
-                    totalLight += s.light*cos_theta;
-                }
-            }
-
-            rays.setResult(i, 
colors[i]*totalLight*0.6+colors[i]*(num_miss*inv_num_directions*0.4));
-        }
-        start = end;
-    } while(start < rays.getSize());
+  // Compute normals
+  rays.computeNormals(context);
+  rays.computeHitPositions();
+
+  // We are going to first compute the ambient values.
+  ColorArray total;
+  for(int i = rays.begin(); i < rays.end(); ++i) {
+    // for each position, compute a local coordinate frame
+    // and build a set of rays to push into a ray packet
+    Vector W(rays.getNormal(i)); // surface ONB
+    Vector U(Cross(W, Vector(1,0,0)));
+    Real squared_length = U.length2();
+    if ( squared_length < (Real)1e-6 )
+        U = Cross(W, Vector(0,1,0));
+    Vector V(Cross(W, U));
+
+    // Send out the ambient occlusion tests
+    int num_sent = 0;
+    int num_miss = 0;
+    int num_directions = static_cast<int>(directions.size());
+    while ( num_sent < num_directions ) {
+      int start = num_sent;
+      int end   = start + RayPacket::MaxSize;
+      if (end > num_directions) end = num_directions;
+
+      RayPacketData occlusion_data;
+      // Should the normalized flag be set?  The normals coming in
+      // should already be normalized.
+      int flag = RayPacket::NormalizedDirections | RayPacket::ConstantOrigin;
+      RayPacket occlusion_rays(occlusion_data, start, end, rays.getDepth(),
+                               flag);
+
+      for ( int r = start; r < end; r++ ) {
+        Vector trans_dir = (directions[r][0]*U +
+                            directions[r][1]*V +
+                            directions[r][2]*W);
+        occlusion_rays.setRay(r, rays.getHitPosition(i), trans_dir);
+        // set max distance
+        occlusion_rays.resetHit(r, cutoff);
+      }
+
+      // packet is ready, test it for occlusion
+      context.scene->getObject()->intersect(context, occlusion_rays);
+
+      // count the number of occluded ones
+      for (int r = start; r < end; r++ ) {
+        if(!occlusion_rays.wasHit(r))
+          num_miss++;
+      }
+      num_sent = end;
+    }
+    for(int j=0;j<Color::NumComponents;j++)
+      total[j][i] = num_miss * (inv_num_directions * (ColorComponent)0.4);
+  }
+
+  // Compute the diffuse shading
+  RayPacketData data;
+  ShadowAlgorithm::StateBuffer stateBuffer;
+  bool firstTime = true;
+  bool done;
+  do {
+    int map[RayPacket::MaxSize];
+    RayPacket shadowRays(data, 0, 0, rays.getDepth(), 0);
+    done = context.shadowAlgorithm->computeShadows(context, activeLights,
+                                                   rays, map, shadowRays,
+                                                   firstTime, stateBuffer);
+    shadowRays.normalizeDirections();
+    for(int j=shadowRays.begin(); j < shadowRays.end(); j++){
+      if(!shadowRays.wasHit(j)){
+        // Not in shadow, so compute the direct and specular contributions.
+        int to = map[j];
+        Vector normal = rays.getNormal(to);
+        Vector shadowdir = shadowRays.getDirection(j);
+        ColorComponent cos_theta = Dot(shadowdir, normal);
+        Color light = shadowRays.getColor(j);
+        for(int k = 0; k < Color::NumComponents;k++)
+          total[k][to] += light[k]*cos_theta*(ColorComponent)0.6;
+      }
+    }
+
+    firstTime = false;
+  } while(!done);
 
+  // Compute diffuse colors
+  Color diffuse[RayPacket::MaxSize];
+  colortex->mapValues(context, rays, diffuse);
+
+  // Sum up diffuse/specular contributions
+  for(int i = rays.begin(); i < rays.end(); i++){
+    Color result;
+    for(int j=0;j<Color::NumComponents;j++)
+      result[j] = diffuse[i][j] * total[j][i];
+    rays.setColor(i, result);
+  }
 }

Modified: trunk/Model/Materials/AmbientOcclusion.h
==============================================================================
--- trunk/Model/Materials/AmbientOcclusion.h    (original)
+++ trunk/Model/Materials/AmbientOcclusion.h    Fri Jan 20 15:03:05 2006
@@ -5,29 +5,33 @@
 #include <Core/Color/Color.h>
 #include <Interface/Texture.h>
 
+#include <sgi_stl_warnings_off.h>
+#include <vector>
+#include <sgi_stl_warnings_on.h>
+
 namespace Manta
 {
-    class LightSet;
-
-    class AmbientOcclusion : public LitMaterial
-    {
-    public:
-        AmbientOcclusion(const Color& color, float cutoff_dist, int 
num_dirs);
-        AmbientOcclusion(const Texture<Color>* color, float cutoff_dist, int 
num_dirs);
-        AmbientOcclusion() {  }
-        ~AmbientOcclusion();
+  class LightSet;
 
-        void generateDirections();
+  class AmbientOcclusion : public LitMaterial
+  {
+  public:
+    AmbientOcclusion(const Color& color, float cutoff_dist, int num_dirs);
+    AmbientOcclusion(const Texture<Color>* color, float cutoff_dist,
+                     int num_dirs);
+    AmbientOcclusion() {  }
+    ~AmbientOcclusion();
 
-        // generate the directions
-        void shade(const RenderContext& context, RayPacket& rays) const;
+    void generateDirections(int num_directions);
+    
+    // generate the directions
+    void shade(const RenderContext& context, RayPacket& rays) const;
     private:
-        const Texture<Color>* colortex;
-        float cutoff;
-        Vector* directions;
-        int num_directions;
-        float inv_num_directions;
-    };
+    const Texture<Color>* colortex;
+    float cutoff;
+    std::vector<Vector> directions;
+    ColorComponent inv_num_directions;
+  };
 }
 
 #endif

Modified: trunk/Model/Materials/Checker.cc
==============================================================================
--- trunk/Model/Materials/Checker.cc    (original)
+++ trunk/Model/Materials/Checker.cc    Fri Jan 20 15:03:05 2006
@@ -30,9 +30,8 @@
     rays.computeTextureCoordinates3(context);
   else
     rays.computeTextureCoordinates2(context);
-  RayPacket::Element& e0 = rays.get(0);
-  Real vv1 = Dot(e0.texCoords, v1);
-  Real vv2 = Dot(e0.texCoords, v2);
+  Real vv1 = Dot(rays.getTexCoords(0), v1);
+  Real vv2 = Dot(rays.getTexCoords(0), v2);
   if(vv1<0)
     vv1=-vv1+1;
   if(vv2<0)
@@ -40,17 +39,15 @@
   int i1 = (int)vv1;
   int i2 = (int)vv2;
   int which0 = (i1+i2)%2;
-  int start = 0;
-  while(start < rays.getSize()){
+  for(int start = rays.begin(); start < rays.end();){
     int stop = start+1;
     // I'm not sure what the default value for "which" should be, but
     // this will not change the value of "which0" if "which" is never
     // changed.  - James Bigler
     int which = which0;
-    while(stop < rays.getSize()){
-      RayPacket::Element& e = rays.get(stop);
-      Real vv1 = Dot(e.texCoords, v1);
-      Real vv2 = Dot(e.texCoords, v2);
+    while(stop < rays.end()){
+      Real vv1 = Dot(rays.getTexCoords(stop), v1);
+      Real vv2 = Dot(rays.getTexCoords(stop), v2);
       if(vv1<0)
         vv1=-vv1+1;
       if(vv2<0)

Modified: trunk/Model/Materials/Dielectric.cc
==============================================================================
--- trunk/Model/Materials/Dielectric.cc (original)
+++ trunk/Model/Materials/Dielectric.cc Fri Jan 20 15:03:05 2006
@@ -37,9 +37,10 @@
 #include <Interface/Renderer.h>
 #include <Interface/Scene.h>
 #include <Interface/ShadowAlgorithm.h>
-#include <Core/Math/Trig.h>
+#include <Core/Math/Expon.h>
 
 using namespace Manta;
+using namespace SCIRun;
 
 Dielectric::Dielectric(const Texture<Real>* n, const Texture<Real>* nt,
                        const Texture<Color>* sigma_a, 
@@ -55,19 +56,15 @@
 
 void Dielectric::shade(const RenderContext& context, RayPacket& rays) const
 {
-  if(rays.getDepth() >= context.scene->getRenderParameters().maxDepth)
-  {
-    for(int i=0;i<rays.getSize();i++)
-    {
-      rays.setResult(i, Color::black());
-    }
+  if(rays.getDepth() >= context.scene->getRenderParameters().maxDepth) {
+    for(int i=rays.begin();i<rays.end();i++)
+      rays.setColor(i, Color::black());
     return;
   }
 
   rays.computeHitPositions();
   rays.normalizeDirections();
   rays.computeNormals(context);
-  rays.normalizeNormals();
 
   Real n_values[RayPacket::MaxSize];
   Real nt_values[RayPacket::MaxSize];
@@ -80,9 +77,10 @@
   RayPacketData reflected_data;
   RayPacketData refracted_data;
 
-  RayPacket reflected_rays(reflected_data, 0, rays.getDepth()+1, 
RayPacket::NormalizedDirections);
-  RayPacket refracted_rays(refracted_data, 0, rays.getDepth()+1, 
RayPacket::NormalizedDirections);
+  RayPacket reflected_rays(reflected_data, 0, 0, rays.getDepth()+1, 
RayPacket::NormalizedDirections);
+  RayPacket refracted_rays(refracted_data, 0, 0, rays.getDepth()+1, 
RayPacket::NormalizedDirections);
 
+  Color results[RayPacket::MaxSize];
   Color refl_attenuation[RayPacket::MaxSize];
   Color refr_attenuation[RayPacket::MaxSize];
 
@@ -94,44 +92,40 @@
   Real cutoff = localCutoffScale * 
context.scene->getRenderParameters().importanceCutoff;
 
   // Compute coefficients and set up raypackets
-  for(int i=0;i<rays.getSize();i++)
-  {
-    RayPacket::Element& e = rays.get(i);
-    e.color = Color::black();
+  for(int i=rays.begin();i<rays.end();i++) {
+    results[i] = Color::black();
 
-    Real n_dot_v = Dot(e.normal, e.ray.direction());
+    Vector rayD = rays.getDirection(i);
+    Vector normal = rays.getNormal(i);
+    Real n_dot_v = Dot(normal, rayD);
     Real eta_tmp_inv;
     bool was_incoming = ( n_dot_v < 0 );
     Color beers_color;
-    if ( was_incoming )
-    {
+    if ( was_incoming ) {
       eta_tmp_inv = nt_values[i]/n_values[i];
       n_dot_v = -n_dot_v;
       beers_color = Color::white();
-    }
-    else
-    {
-      e.normal = -e.normal;
+    } else {
+      normal = -normal;
       eta_tmp_inv = n_values[i]/nt_values[i];
-      beers_color = sigma_a_values[i].Pow(e.hitInfo.minT());
+      beers_color = sigma_a_values[i].Pow(rays.getMinT(i));
     }
 
     Real cosine_sq = 1 + (n_dot_v*n_dot_v - 1) * (eta_tmp_inv*eta_tmp_inv);
-    if ( cosine_sq <= 0 )
-    {
+    Color in_importance = rays.getImportance(i);
+    Point hitpos = rays.getHitPosition(i);
+    if ( cosine_sq <= 0 ) {
       // total internal reflection - no attenuation
-      RayPacket::Element& r = reflected_rays.get(num_refl);
-      r.importance = e.importance * beers_color;
-      if(r.importance.luminance() > cutoff){
-        Vector refl_dir = e.ray.direction() + 2*n_dot_v*e.normal;
-        r.ray.set(e.hitPosition, refl_dir);
+      Color refl_importance = in_importance * beers_color;
+      if(refl_importance.luminance() > cutoff){
+        rays.setImportance(num_refl, refl_importance);
+        Vector refl_dir = rayD + 2*n_dot_v*normal;
+        reflected_rays.setRay(num_refl, hitpos, refl_dir);
         refl_source[num_refl] = i;
         refl_attenuation[num_refl] = beers_color;
         num_refl++;
       }
-    }
-    else
-    {
+    } else {
       Real cosine = Sqrt(cosine_sq);
       Real k = 1 - cosine;
       k*=(k*k)*(k*k);
@@ -142,23 +136,23 @@
 
       // Possibly create refraction ray
       refr_attenuation[num_refr] = beers_color * (1-R);
-      RayPacket::Element& refr = refracted_rays.get(num_refr);
-      refr.importance = e.importance * refr_attenuation[num_refr];
-      if(refr.importance.luminance() > cutoff){
-        Vector refr_dir = (e.ray.direction()*eta_tmp_inv +
-                           (n_dot_v*eta_tmp_inv - cosine) * e.normal);
-        refr.ray.set(e.hitPosition, refr_dir);
+      Color refr_importance = in_importance * refr_attenuation[num_refr];
+      if(refr_importance.luminance() > cutoff){
+        refracted_rays.setImportance(num_refr, refr_importance);
+        Vector refr_dir = rayD*eta_tmp_inv +
+                          (n_dot_v*eta_tmp_inv - cosine) * normal;
+        refracted_rays.setRay(num_refr, hitpos, refr_dir);
         refr_source[num_refr] = i;
         num_refr++;
       }
 
       // Possibly create reflection ray
       refl_attenuation[num_refl] = beers_color * R;
-      RayPacket::Element& refl = reflected_rays.get(num_refl);
-      refl.importance = e.importance * refl_attenuation[num_refl];
-      if(refl.importance.luminance() > cutoff){
-        Vector refl_dir = e.ray.direction() + (2*n_dot_v)*e.normal;
-        refl.ray.set(e.hitPosition, refl_dir);
+      Color refl_importance = in_importance * refl_attenuation[num_refl];
+      if(refl_importance.luminance() > cutoff){
+        reflected_rays.setImportance(num_refl, refl_importance);
+        Vector refl_dir = rayD + (2*n_dot_v)*normal;
+        reflected_rays.setRay(num_refl, hitpos, refl_dir);
         refl_source[num_refl] = i;
         num_refl++;
       }
@@ -177,15 +171,9 @@
 
   // compute their results
   for (int i = 0; i < num_refl; i++)
-  {
-    RayPacket::Element& r = reflected_rays.get(i);
-    RayPacket::Element& e = rays.get(refl_source[i]);
-    e.color += refl_attenuation[i] * r.color;
-  }
+    results[refl_source[i]] += refl_attenuation[i] * 
reflected_rays.getColor(i);
   for (int i = 0; i < num_refr; i++)
-  {
-    RayPacket::Element& r = refracted_rays.get(i);
-    RayPacket::Element& e = rays.get(refr_source[i]);
-    e.color += refr_attenuation[i] * r.color;
-  }
+    results[refr_source[i]] += refr_attenuation[i] * 
refracted_rays.getColor(i);
+  for(int i = rays.begin(); i < rays.end(); i++)
+    rays.setColor(i, results[i]);
 }

Modified: trunk/Model/Materials/Flat.cc
==============================================================================
--- trunk/Model/Materials/Flat.cc       (original)
+++ trunk/Model/Materials/Flat.cc       Fri Jan 20 15:03:05 2006
@@ -63,8 +63,6 @@
   colortex->mapValues(context, rays, colors);
 
   // Copy the colors into the ray packet.
-  for(int i=0;i<rays.getSize();i++) {
-    
-    rays.setResult( i, colors[i] );
-  }
+  for(int i=rays.begin();i<rays.end();i++)
+    rays.setColor( i, colors[i] );
 }

Modified: trunk/Model/Materials/Lambertian.cc
==============================================================================
--- trunk/Model/Materials/Lambertian.cc (original)
+++ trunk/Model/Materials/Lambertian.cc Fri Jan 20 15:03:05 2006
@@ -34,37 +34,58 @@
   rays.computeNormals(context);
 
   // Compute colors
-  Color colors[RayPacket::MaxSize];
-  colortex->mapValues(context, rays, colors);
+  Color diffuse[RayPacket::MaxSize];
+  colortex->mapValues(context, rays, diffuse);
 
   // Compute ambient contributions for all rays
-  activeLights->getAmbientLight()->computeAmbient(context, rays);
+  ColorArray totalLight;
+  activeLights->getAmbientLight()->computeAmbient(context, rays, totalLight);
 
   // We normalized directions for proper dot product computation.
   rays.normalizeDirections();
 
-  RayPacketData data;
-  int start = 0;
-
+  ShadowAlgorithm::StateBuffer stateBuffer;
+  bool firstTime = true;
+  bool done;
+  int count = 0;
   do {
-    RayPacket shadowRays(data, 0, rays.getDepth(), 0);
-    int end = context.shadowAlgorithm->computeShadows(context, activeLights,
-                                                     rays, start, 
shadowRays);
-    // We normalized directions for proper dot product computation.
+    int map[RayPacket::MaxSize];
+    RayPacketData shadowData;
+    RayPacket shadowRays(shadowData, 0, 0, rays.getDepth(), 0);
+
+    // Call the shadowalgorithm(sa) to generate shadow rays.  We may not be
+    // able to compute all of them, so we pass along a buffer for the sa
+    // object to store it's state.  The firstTime flag tells the sa to fill
+    // in the state rather than using anything in the state buffer.  Most
+    // sas will only need to store an int or two in the statebuffer.
+    done = context.shadowAlgorithm->computeShadows(context, activeLights,
+                                                   rays, map, shadowRays,
+                                                   firstTime, stateBuffer);
+
+    // We need normalized directions for proper dot product computation.
     shadowRays.normalizeDirections();
 
-      for(int i=start;i<end;i++){
-        RayPacket::Element& e = rays.get(i);
-        Color totalLight(e.ambientLight);
-        for(int j=e.shadowBegin;j<e.shadowEnd;j++){
-          RayPacket::Element& s = shadowRays.get(j);
-          if(!s.hitInfo.wasHit()){
-            ColorComponent cos_theta = Dot(s.ray.direction(), e.normal);
-            totalLight += s.light*cos_theta;
-          }
-        }
-        rays.setResult(i, colors[i]*totalLight);
+    for(int j=shadowRays.begin(); j < shadowRays.end(); j++){
+      if(!shadowRays.wasHit(j)){
+        // Not in shadow, so compute the direct and specular contributions.
+        int to = map[j];
+        Vector normal = rays.getNormal(to);
+        Vector shadowdir = shadowRays.getDirection(j);
+        ColorComponent cos_theta = Dot(shadowdir, normal);
+        Color light = shadowRays.getColor(j);
+        for(int k = 0; k < Color::NumComponents;k++)
+          totalLight[k][to] += light[k]*cos_theta;
       }
-    start = end;
-  } while(start < rays.getSize());
+    }
+    firstTime = false;
+  } while(!done);
+
+  // Sum up diffuse/specular contributions
+  for(int i = rays.begin(); i < rays.end(); i++){
+    Color result;
+    for(int j=0;j<Color::NumComponents;j++)
+      result[j] = totalLight[j][i] * diffuse[i][j];
+    rays.setColor(i, result);
+  }
+
 }

Modified: trunk/Model/Materials/MetalMaterial.cc
==============================================================================
--- trunk/Model/Materials/MetalMaterial.cc      (original)
+++ trunk/Model/Materials/MetalMaterial.cc      Fri Jan 20 15:03:05 2006
@@ -40,25 +40,21 @@
   
     rays.computeHitPositions();
     RayPacketData rdata;
-    RayPacket refl_rays(rdata, rays.getSize(), rays.getDepth()+1,
+    RayPacket refl_rays(rdata, rays.begin(), rays.end(), rays.getDepth()+1,
                         RayPacket::NormalizedDirections);
-    for(int i=0;i<rays.getSize();i++)
-      {  
-        RayPacket::Element& e = rays.get(i);
-        Vector refl_dir = e.ray.direction() - e.normal*(2*Dot(e.normal, 
e.ray.direction()));
-        RayPacket::Element& r = refl_rays.get(i);
-        r.ray.set(e.hitPosition,  refl_dir);
-        r.importance = e.importance;
-      }
+    for(int i=rays.begin();i<rays.end();i++) {  
+      Vector rayD = rays.getDirection(i);
+      Vector normal = rays.getNormal(i);
+      Vector refl_dir = rayD - normal*(2*Dot(normal, rayD));
+      refl_rays.setRay(i, rays.getHitPosition(i),  refl_dir);
+      refl_rays.setImportance(i, rays.getImportance(i));
+    }
     
-    refl_rays.resetHit();
+    refl_rays.resetHits();
     context.renderer->traceRays(context, refl_rays);
-    for(int i=0;i<rays.getSize();i++) {
-      RayPacket::Element& e = rays.get(i);
-      RayPacket::Element& r = refl_rays.get(i);
-
+    for(int i=rays.begin();i<rays.end();i++) {
       // compute Schlick Fresnel approximation
-      Real cosine = -Dot(e.normal, e.ray.direction());
+      Real cosine = -Dot(rays.getNormal(i), rays.getDirection(i));
       if(cosine < 0) cosine =-cosine;
       Real k = 1 - cosine;
       k*=k*k*k*k;
@@ -69,12 +65,11 @@
       ColorComponent kc = (ColorComponent)k;
       Color R = specular[i] * (1-kc) + Color::white()*kc;
 
-      e.color = R * r.color;
+      rays.setColor(i, R * refl_rays.getColor(i));
     }
   } else {
     // Stuff black in it.
-    for(int i=0;i<rays.getSize();i++) {
-      rays.setResult(i, Color::black());
-    }
+    for(int i=rays.begin();i<rays.end();i++) 
+      rays.setColor(i, Color::black());
   }
 }

Modified: trunk/Model/Materials/NormalMaterial.cc
==============================================================================
--- trunk/Model/Materials/NormalMaterial.cc     (original)
+++ trunk/Model/Materials/NormalMaterial.cc     Fri Jan 20 15:03:05 2006
@@ -8,15 +8,15 @@
 
 void NormalMaterial::shade( const RenderContext &context, RayPacket &rays) 
const {
        
-       // Compute the normal for each ray.
-       rays.computeNormals( context );
+  // Compute the normal for each ray.
+  rays.computeNormals( context );
        
-       // Iterate over the packet and set the colors.
-       for (int i=0;i<rays.getSize();++i) {
+  // Iterate over the packet and set the colors.
+  for (int i=rays.begin();i<rays.end();++i) {
 
     // Copy the normal out.
-    Vector normal = rays.get(i).normal;
-    rays.setResult( i, Color( RGB( normal[0],normal[1], normal[2] )) );
+    Vector normal = rays.getNormal(i);
+    rays.setColor( i, Color( RGB( normal[0],normal[1], normal[2] )) );
                
 #if 0
     // Add a wireframe.

Modified: trunk/Model/Materials/Phong.cc
==============================================================================
--- trunk/Model/Materials/Phong.cc      (original)
+++ trunk/Model/Materials/Phong.cc      Fri Jan 20 15:03:05 2006
@@ -11,6 +11,8 @@
 #include <Interface/Scene.h>
 #include <Interface/ShadowAlgorithm.h>
 #include <Model/Textures/Constant.h>
+#include <Core/Util/NotFinished.h>
+#include <Core/Color/ColorSpace_fancy.h>
 
 using namespace Manta;
 
@@ -62,45 +64,70 @@
   rays.computeNormals(context);
 
   // Compute ambient contributions for all rays
-  activeLights->getAmbientLight()->computeAmbient(context, rays);
+  ColorArray ambientAndDiffuseLight;
+  activeLights->getAmbientLight()->computeAmbient(context, rays, 
ambientAndDiffuseLight);
 
-  // We normalized directions for proper dot product computation.
-  rays.normalizeDirections();
+  // Initialize specular to zero
+  ColorArray specularLight;
+  for(int i = rays.begin(); i < rays.end(); i++)
+    for(int j=0;j<Color::NumComponents;j++)
+      specularLight[j][i] = 0;
 
-  RayPacketData data;
-  int start = 0;
+  // We need normalized directions for proper dot product computation.
+  rays.normalizeDirections();
 
+  ShadowAlgorithm::StateBuffer stateBuffer;
+  bool firstTime = true;
+  bool done;
+  int count = 0;
   do {
-    RayPacket shadowRays(data, 0, rays.getDepth(), 0);
-    int end = context.shadowAlgorithm->computeShadows(context, activeLights,
-                                                     rays, start, 
shadowRays);
+    int map[RayPacket::MaxSize];
+    RayPacketData shadowData;
+    RayPacket shadowRays(shadowData, 0, 0, rays.getDepth(), 0);
+
+    // Call the shadowalgorithm(sa) to generate shadow rays.  We may not be
+    // able to compute all of them, so we pass along a buffer for the sa
+    // object to store it's state.  The firstTime flag tells the sa to fill
+    // in the state rather than using anything in the state buffer.  Most
+    // sas will only need to store an int or two in the statebuffer.
+    done = context.shadowAlgorithm->computeShadows(context, activeLights,
+                                                   rays, map, shadowRays,
+                                                   firstTime, stateBuffer);
 
-    // We normalized directions for proper dot product computation.
+    // We need normalized directions for proper dot product computation.
     shadowRays.normalizeDirections();
 
-    for(int i=start;i<end;i++){
-      RayPacket::Element& e = rays.get(i);
-      // Initialize with the ambient contribution.
-      Color totalDiffuse(e.ambientLight);
-      Color totalSpecular = Color::black();
-      for(int j=e.shadowBegin;j<e.shadowEnd;j++){
-        RayPacket::Element& s = shadowRays.get(j);
-        if(!s.hitInfo.wasHit()){
-          // Not in shadow, so compute the direct and specular contributions.
-          ColorComponent cos_theta = Dot(s.ray.direction(), e.normal);
-          totalDiffuse += s.light*cos_theta;
-          Vector H = s.ray.direction()-e.ray.direction();
-          ColorComponent cos_alpha = Dot(H, e.normal);
-          if(cos_alpha > 0){
-            ColorComponent length = H.length();
-            totalSpecular += s.light * ipow(cos_alpha/length, specpow);
-          }
+    for(int j=shadowRays.begin(); j < shadowRays.end(); j++){
+      if(!shadowRays.wasHit(j)){
+        // Not in shadow, so compute the direct and specular contributions.
+        int to = map[j];
+        Vector normal = rays.getNormal(to);
+        Vector shadowdir = shadowRays.getDirection(j);
+        ColorComponent cos_theta = Dot(shadowdir, normal);
+        Color light = shadowRays.getColor(j);
+        for(int k = 0; k < Color::NumComponents;k++)
+          ambientAndDiffuseLight[k][to] += light[k]*cos_theta;
+        Vector dir = rays.getDirection(to);
+        Vector H = shadowdir-dir;
+        ColorComponent cos_alpha = Dot(H, normal);
+        if(cos_alpha > 0){
+          Color::ComponentType length = H.length();
+          Color::ComponentType scale = ipow(cos_alpha/length, specpow);
+          for(int k=0;k<Color::NumComponents;k++)
+            specularLight[k][to] += light[k] * scale;
         }
       }
-      rays.setResult(i, diffuse[i]*totalDiffuse+specular[i]*totalSpecular);
     }
-    start = end;
-  } while(start < rays.getSize());
+    firstTime = false;
+  } while(!done);
+
+  // Sum up diffuse/specular contributions
+  for(int i = rays.begin(); i < rays.end(); i++){
+    Color result;
+    for(int j=0;j<Color::NumComponents;j++)
+      result[j] = specularLight[j][i] * specular[i][j] + 
ambientAndDiffuseLight[j][i] * diffuse[i][j];
+    rays.setColor(i, result);
+  }
 
   // Compute reflections
   if(do_refl && rays.getDepth() < 
context.scene->getRenderParameters().maxDepth){
@@ -109,22 +136,17 @@
 
     rays.computeHitPositions();
     RayPacketData rdata;
-    RayPacket refl_rays(rdata, rays.getSize(), rays.getDepth()+1,
+    RayPacket refl_rays(rdata, rays.begin(), rays.end(), rays.getDepth()+1,
                         RayPacket::NormalizedDirections);
-    for(int i=0;i<rays.getSize();i++){
-      RayPacket::Element& e = rays.get(i);
-      Vector refl_dir = (e.ray.direction() -
-                         e.normal*(2*Dot(e.normal, e.ray.direction() )));
-      RayPacket::Element& r = refl_rays.get(i);
-      r.ray.set(e.hitPosition,  refl_dir);
-      r.importance = e.importance * refl[i];
+    for(int i=rays.begin();i<rays.end();i++){
+      Vector refl_dir = (rays.getDirection(i) -
+                         rays.getNormal(i)*(2*Dot(rays.getNormal(i), 
rays.getDirection(i) )));
+      refl_rays.setRay(i, rays.getHitPosition(i), refl_dir);
+      refl_rays.setImportance(i, rays.getImportance(i) * refl[i]);
     }
-    refl_rays.resetHit();
+    refl_rays.resetHits();
     context.renderer->traceRays(context, refl_rays);
-    for(int i=0;i<rays.getSize();i++){
-      RayPacket::Element& e = rays.get(i);
-      RayPacket::Element& r = refl_rays.get(i);
-      e.color += r.color * refl[i];
-    }
+    for(int i=rays.begin();i<rays.end();i++)
+      rays.setColor(i, rays.getColor(i) + refl_rays.getColor(i) * refl[i]);
   }
 }

Modified: trunk/Model/MiscObjects/CMakeLists.txt
==============================================================================
--- trunk/Model/MiscObjects/CMakeLists.txt      (original)
+++ trunk/Model/MiscObjects/CMakeLists.txt      Fri Jan 20 15:03:05 2006
@@ -1,8 +1,8 @@
 SET (Manta_MiscObjects_SRCS
+  MiscObjects/CuttingPlane.h
+  MiscObjects/CuttingPlane.cc
   MiscObjects/Difference.h
   MiscObjects/Difference.cc
   MiscObjects/Intersection.h
   MiscObjects/Intersection.cc
-  MiscObjects/CuttingPlane.h
-  MiscObjects/CuttingPlane.cc
-)
\ No newline at end of file
+)

Modified: trunk/Model/MiscObjects/CuttingPlane.cc
==============================================================================
--- trunk/Model/MiscObjects/CuttingPlane.cc     (original)
+++ trunk/Model/MiscObjects/CuttingPlane.cc     Fri Jan 20 15:03:05 2006
@@ -7,142 +7,141 @@
 
 using namespace Manta;
 
-void CuttingPlane::movePlaneAlongNormal( Real distance ) { 
-
-       plane_point = initial_point + (plane_normal * distance * 100.0);
+void CuttingPlane::movePlaneAlongNormal( Real distance )
+{
+  plane_point = initial_point + (plane_normal * distance * 100.0);
 }
 
 // Preprocess the internal object and compute its bounds.
-void CuttingPlane::preprocess( const PreprocessContext &context ) {
-       
-       // Call preprocess on the object.
-       internal_object->preprocess( context );
-       
-       // Compute its bounds.
-       internal_object->computeBounds( context, bounds );
-
-       // Determine how far away the edges of the bounding box are from the 
-       // initial point.
-       movement_scale = bounds.diagonal().length() * (Real)0.5;
+void CuttingPlane::preprocess( const PreprocessContext &context )
+{
+  // Call preprocess on the object.
+  internal_object->preprocess( context );
+       
+  // Compute its bounds.
+  internal_object->computeBounds( context, bounds );
+
+  // Determine how far away the edges of the bounding box are from the 
+  // initial point.
+  movement_scale = bounds.diagonal().length() * (Real)0.5;
 }
 
 void CuttingPlane::intersect(const RenderContext& context, RayPacket& rays) 
const {
 
-       // Send a new ray packet with new ray origins.
-       RayPacketData new_data;
-       RayPacket     new_rays( new_data, rays.getSize(), rays.getDepth(), 
rays.getAllFlags());
-       
-       rays.normalizeDirections();
-       rays.computeInverseDirections();
-        rays.computeSigns();
+  // Send a new ray packet with new ray origins.
+  RayPacketData new_data;
+  RayPacket     new_rays( new_data, rays.begin(), rays.end(), 
rays.getDepth(),
+                          rays.getAllFlags());
+  
+  rays.normalizeDirections();
+  rays.computeInverseDirections();
+  rays.computeSigns();
        
-       // Map between rays in original packet and new packet in case some 
rays are skipped.
-       int packet_map[RayPacket::MaxSize];
+  // Map between rays in original packet and new packet in case some rays 
are skipped.
+  int packet_map[RayPacket::MaxSize];
        
-       // Keep track of which new rays intersect the front face of the plane.
-       bool front_facing[RayPacket::MaxSize];
+  // Keep track of which new rays intersect the front face of the plane.
+  bool front_facing[RayPacket::MaxSize];
        
-       // Keep track of the plane_t offset for each ray.
-       Real plane_t[RayPacket::MaxSize];
+  // Keep track of the plane_t offset for each ray.
+  Real plane_t[RayPacket::MaxSize];
         
-       
/////////////////////////////////////////////////////////////////////////////
-       // Create the new rays.
-       int new_i = 0, i;
-       for (i=0;i<rays.getSize();++i) {
-               RayPacket::Element &e = rays.get( i );
-               
-               Real box_min, box_max;
-               
-               // Check to see if the ray intersects the bounding box.
-               if (Intersection::intersectAaBox( bounds, box_min, box_max,
-                                                                             
                                                                          
e.ray, e.sign, e.inverseDirection )) {
-                       
-                       // Intersect the ray with the plane.
-                       Intersection::intersectPlane( plane_point, 
plane_normal, plane_t[new_i], e.ray );
-                       
-                       RayPacket::Element &n = new_rays.get( new_i );
-                       
-                       // Record which original ray this new ray maps to.
-                       packet_map[new_i] = i;
-               
-                       // Check to see if the ray origin is on the front or 
back facing side of
-                       // the cutting plane (the front facing side is cut 
away).
-                       if (front_facing[new_i] = (Dot(plane_normal, 
(e.ray.origin()-plane_point)) > 0.0)) {
-                                       
-                                       // If plane_t is negative, the ray 
can't possibly hit the cut model.
-                                       // because the ray is pointing away 
from the plane.
-                                       if (plane_t[new_i] > 0.0) {
-                                               
-                                               // If front facing, move the 
new ray to the cutting plane.
-                                               
n.ray.set(e.ray.origin()+(e.ray.direction()*plane_t[new_i]),e.ray.direction());
-                                               
new_rays.resetFlag(RayPacket::ConstantOrigin);
-
-                                               
-                                               // Subtract the distance from 
the hit t.
-                                               n.hitInfo.reset( 
e.hitInfo.minT() - plane_t[new_i] );
-                                               
-                                               ++new_i;
-                                       }
-                       }
-                       else {
-                               
-                               // Otherwise if back facing, move the hit t 
in the hit record to the plane
-                               // (it will need to be moved back afterwards)
-                               n.ray = e.ray;
-                               //n.hitInfo.reset( plane_t[new_i] );
-                               n.hitInfo.reset( e.hitInfo.minT() );
-                       
-                               ++new_i;        
-                       }
-                       
-               
-               }
-       }
-       
-       // Check to see if all of the rays miss the bounds.
-       if (new_i == 0) {
-               return;
-       }
-       
-       // Specify the number of new rays.
-       new_rays.resize( new_i );
-       
-       
/////////////////////////////////////////////////////////////////////////////
-       // Intersect the new ray packet with the internal object.
-       internal_object->intersect( context, new_rays );
-       
-       
/////////////////////////////////////////////////////////////////////////////
-       // Map the results back to the old rays.
-       for (new_i=0; new_i<new_rays.getSize(); ++new_i) {
-       
-               RayPacket::Element &n = new_rays.get(new_i);
-               
-               // Check to see if the new ray hit something.
-               if (n.hitInfo.wasHit()) {
-
-                       // Determine which old ray this maps to.
-                       RayPacket::Element &e = rays.get( packet_map[new_i] );
-                       
-                       // Check to see if the old ray is front or back 
facing.
-                       if (front_facing[new_i]) {
-                               // If so, then translate the hit t back into 
the old hit record.
-                               if (e.hitInfo.hit( 
n.hitInfo.minT()+plane_t[new_i], 
-                                                                             
           n.hitInfo.hitMaterial(),
-                                                                             
           n.hitInfo.hitPrimitive(),
-                                                                             
           n.hitInfo.hitTexCoordMapper() ))
-                                       e.hitInfo.copyScratchpad( n.hitInfo );
-                       }
-                       else {
-                               // Otherwise, if the original ray is back 
facing check to see if the hit
-                               // is closer then the cutting plane.
-                               if ((plane_t[new_i] < 0.0) || 
(n.hitInfo.minT() < plane_t[new_i])) {
-                                       if (e.hitInfo.hit( n.hitInfo.minT(), 
-                                                                             
                   n.hitInfo.hitMaterial(),
-                                                                             
                   n.hitInfo.hitPrimitive(),
-                                                                             
                   n.hitInfo.hitTexCoordMapper() ))
-                                               e.hitInfo.copyScratchpad( 
n.hitInfo );
-                               }
-                       }
-               }
-       }
+  
/////////////////////////////////////////////////////////////////////////////
+  // Create the new rays.
+  int new_i = 0;
+  for (int i=rays.begin();i<rays.end();++i) {
+    Real box_min, box_max;
+
+    Ray ray = rays.getRay(i);
+    // Check to see if the ray intersects the bounding box.
+    if (Intersection::intersectAaBox( bounds, box_min, box_max,
+                                      ray, rays.getSigns(i),
+                                      rays.getInverseDirection(i) )) {
+      
+      // Intersect the ray with the plane.
+      Intersection::intersectPlane( plane_point, plane_normal, 
plane_t[new_i],
+                                    ray );
+      
+      // Record which original ray this new ray maps to.
+      packet_map[new_i] = i;
+      
+      // Check to see if the ray origin is on the front or back facing side 
of
+      // the cutting plane (the front facing side is cut away).
+      front_facing[new_i] = Dot(plane_normal, (ray.origin()-plane_point)) > 
0;
+      if (front_facing[new_i]) {
+       
+        // If plane_t is negative, the ray can't possibly hit the cut model.
+        // because the ray is pointing away from the plane.
+        if (plane_t[new_i] > 0) {
+          
+          // If front facing, move the new ray to the cutting plane.
+          new_rays.setRay(new_i, 
ray.origin()+(ray.direction()*plane_t[new_i]),
+                          ray.direction());
+          new_rays.resetFlag(RayPacket::ConstantOrigin);
+          
+          
+          // Subtract the distance from the hit t.
+          new_rays.resetHit( new_i, rays.getMinT(i) - plane_t[new_i] );
+          
+          ++new_i;
+        }
+      }
+      else {
+       
+        // Otherwise if back facing, move the hit t in the hit record
+        // to the plane (it will need to be moved back afterwards)
+        new_rays.setRay(new_i, ray);
+        new_rays.resetHit( new_i, rays.getMinT(i) );
+       
+        ++new_i;       
+      }
+      
+      
+    }
+  }
+  
+  // Check to see if all of the rays miss the bounds.
+  if (new_i == 0) {
+    return;
+  }
+  
+  // Specify the number of new rays.
+  new_rays.resize( new_i );
+  
+  
/////////////////////////////////////////////////////////////////////////////
+  // Intersect the new ray packet with the internal object.
+  internal_object->intersect( context, new_rays );
+  
+  
/////////////////////////////////////////////////////////////////////////////
+  // Map the results back to the old rays.
+  for (new_i=new_rays.begin(); new_i<new_rays.end(); ++new_i) {
+    
+    // Check to see if the new ray hit something.
+    if (new_rays.wasHit(new_i)) {
+      
+      // Determine which old ray this maps to.
+      int old_i = packet_map[new_i];
+      
+      // Check to see if the old ray is front or back facing.
+      if (front_facing[new_i]) {
+        // If so, then translate the hit t back into the old hit record.
+        if (rays.hit( old_i, new_rays.getMinT(new_i)+plane_t[new_i], 
+                      new_rays.getHitMaterial(new_i),
+                      new_rays.getHitPrimitive(new_i),
+                      new_rays.getHitTexCoordMapper(new_i) ))
+          rays.copyScratchpad( old_i, new_rays, new_i );
+      }
+      else {
+        // Otherwise, if the original ray is back facing check to see
+        // if the hit is closer then the cutting plane.
+        if ((plane_t[new_i]<0) || (new_rays.getMinT(new_i) < 
plane_t[new_i])) {
+          if (rays.hit( old_i, new_rays.getMinT(new_i),
+                        new_rays.getHitMaterial(new_i),
+                        new_rays.getHitPrimitive(new_i),
+                        new_rays.getHitTexCoordMapper(new_i) ))
+            rays.copyScratchpad( old_i, new_rays, new_i );
+        }
+      }
+    }
+  }
 }

Modified: trunk/Model/MiscObjects/Difference.cc
==============================================================================
--- trunk/Model/MiscObjects/Difference.cc       (original)
+++ trunk/Model/MiscObjects/Difference.cc       Fri Jan 20 15:03:05 2006
@@ -30,20 +30,17 @@
 void Difference::intersect(const RenderContext& context, RayPacket& rays) 
const
 {
   RayPacketData raydata1;
-  RayPacket object1_rays(raydata1, rays.getSize(), rays.getDepth(),
+  RayPacket object1_rays(raydata1, rays.begin(), rays.end(), rays.getDepth(),
                          rays.getAllFlags());
   RayPacketData raydata2;
-  RayPacket object2_rays(raydata2, rays.getSize(), rays.getDepth(),
+  RayPacket object2_rays(raydata2, rays.begin(), rays.end(), rays.getDepth(),
                          rays.getAllFlags());
 
-  for(int i = 0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    RayPacket::Element& e1 = object1_rays.get(i);
-    RayPacket::Element& e2 = object2_rays.get(i);
-    e1.ray = e.ray;
-    e2.ray = e.ray;
-    e1.hitInfo.reset(e.hitInfo.minT());
-    e2.hitInfo.reset(e.hitInfo.minT());
+  for(int i = rays.begin();i<rays.end();i++){
+    object1_rays.setRay(i, rays.getRay(i));
+    object2_rays.setRay(i, rays.getRay(i));
+    object1_rays.resetHit(i, rays.getMinT(i));
+    object2_rays.resetHit(i, rays.getMinT(i));
   }
   object1->intersect(context, object1_rays);
   object2->intersect(context, object2_rays);

Modified: trunk/Model/MiscObjects/Intersection.cc
==============================================================================
--- trunk/Model/MiscObjects/Intersection.cc     (original)
+++ trunk/Model/MiscObjects/Intersection.cc     Fri Jan 20 15:03:05 2006
@@ -33,33 +33,31 @@
 void Intersection::intersect(const RenderContext& context, RayPacket& rays) 
const
 {
   RayPacketData raydata1;
-  RayPacket object1_rays(raydata1, rays.getSize(), rays.getDepth(),
+  RayPacket object1_rays(raydata1, rays.begin(), rays.end(), rays.getDepth(),
                          rays.getAllFlags());
   RayPacketData raydata2;
-  RayPacket object2_rays(raydata2, rays.getSize(), rays.getDepth(),
+  RayPacket object2_rays(raydata2, rays.begin(), rays.end(), rays.getDepth(),
                          rays.getAllFlags());
 
-  for(int i = 0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    RayPacket::Element& e1 = object1_rays.get(i);
-    RayPacket::Element& e2 = object2_rays.get(i);
-    e1.ray = e.ray;
-    e2.ray = e.ray;
-    e1.hitInfo.reset(e.hitInfo.minT());
-    e2.hitInfo.reset(e.hitInfo.minT());
+  for(int i = rays.begin();i<rays.end();i++){
+    object1_rays.setRay(i, rays.getRay(i));
+    object2_rays.setRay(i, rays.getRay(i));
+    object1_rays.resetHit(i, rays.getMinT(i));
+    object2_rays.resetHit(i, rays.getMinT(i));
   }
   object1->intersect(context, object1_rays);
   object2->intersect(context, object2_rays);
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    RayPacket::Element& e1 = object1_rays.get(i);
-    RayPacket::Element& e2 = object2_rays.get(i);
-    if(e1.hitInfo.minT() > e2.hitInfo.minT()){
-      e.hitInfo.hit(e1.hitInfo.minT(), e1.hitInfo.hitMaterial(),
-                   e1.hitInfo.hitPrimitive(), 
e1.hitInfo.hitTexCoordMapper());
+  for(int i=rays.begin();i<rays.end();i++){
+    if(object1_rays.getMinT(i) > object2_rays.getMinT(i)){
+      rays.hit(i, object1_rays.getMinT(i),
+               object1_rays.getHitMaterial(i),
+               object1_rays.getHitPrimitive(i),
+               object1_rays.getHitTexCoordMapper(i));
     } else {
-      e.hitInfo.hit(e2.hitInfo.minT(), e2.hitInfo.hitMaterial(),
-                   e2.hitInfo.hitPrimitive(), 
e2.hitInfo.hitTexCoordMapper());
+      rays.hit(i, object2_rays.getMinT(i),
+               object2_rays.getHitMaterial(i),
+               object2_rays.getHitPrimitive(i),
+               object2_rays.getHitTexCoordMapper(i));
     }
   }
 }

Modified: trunk/Model/Primitives/BvhTriangleMesh.cc
==============================================================================
--- trunk/Model/Primitives/BvhTriangleMesh.cc   (original)
+++ trunk/Model/Primitives/BvhTriangleMesh.cc   Fri Jan 20 15:03:05 2006
@@ -49,107 +49,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;
+  }
 }
 
 
///////////////////////////////////////////////////////////////////////////////
@@ -159,72 +151,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;
 }
 
 
///////////////////////////////////////////////////////////////////////////////
@@ -235,82 +228,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: trunk/Model/Primitives/Cone.cc
==============================================================================
--- trunk/Model/Primitives/Cone.cc      (original)
+++ trunk/Model/Primitives/Cone.cc      Fri Jan 20 15:03:05 2006
@@ -3,9 +3,10 @@
 #include <Interface/RayPacket.h>
 #include <Core/Geometry/BBox.h>
 #include <Core/Util/NotFinished.h>
-#include <Core/Math/Trig.h>
+#include <Core/Math/Expon.h>
 
 using namespace Manta;
+using namespace SCIRun;
 using namespace std;
 
 Cone::Cone(Material* mat, const Point& bottom, const Point& top, Real Rb, 
Real Rt)
@@ -28,7 +29,6 @@
 void Cone::intersect(const RenderContext&, RayPacket& rays) const
 {
   if(rays.getFlag(RayPacket::ConstantOrigin)) {
-    RayPacket::Element& e0 = rays.get(0);
     Point Pa = bottom + Rb * (top - bottom) / (Rb-Rt);
     Real btx = (top.x()-bottom.x())*(top.x()-bottom.x());
     Real bty = (top.y()-bottom.y())*(top.y()-bottom.y());
@@ -43,11 +43,10 @@
     Real sinA = lbt/hyp;
     Real cosA2 = cosA*cosA;
     Real sinA2 = sinA*sinA;
-    Point P(xform * e0.ray.origin());
+    Point P(xform * rays.getOrigin(rays.begin()));
     Vector dP(P - Pa);
-    for(int i=0; i<rays.getSize(); i++) {
-      RayPacket::Element& e = rays.get(i);
-      Vector V(xform * e.ray.direction());
+    for(int i=rays.begin(); i<rays.end(); i++) {
+      Vector V(xform * rays.getDirection(i));
       Vector tv = V;
       Real dist_scale = tv.normalize();
       Real a = ((cosA2*Dot(V-Dot(V,Va)*Va, V-Dot(V,Va)*Va))-
@@ -73,10 +72,10 @@
         Real z1 = P.z()+t1*V.z();
         Real z2 = P.z()+t2*V.z();
         if(t1>0 && z1 > 0 && z1 < 1) {
-          e.hitInfo.hit(t1/dist_scale, getMaterial(), this, 
getTexCoordMapper());
+          rays.hit(i, t1/dist_scale, getMaterial(), this, 
getTexCoordMapper());
         }
         if(t2>0 && z2 > 0 && z2 < 1) {
-          e.hitInfo.hit(t2/dist_scale, getMaterial(), this, 
getTexCoordMapper());
+          rays.hit(i, t2/dist_scale, getMaterial(), this, 
getTexCoordMapper());
         }
       }
     }
@@ -96,11 +95,10 @@
     Real sinA = lbt/hyp;
     Real cosA2 = cosA*cosA;
     Real sinA2 = sinA*sinA;
-    for(int i=0; i<rays.getSize(); i++) {
-      RayPacket::Element& e = rays.get(i);
-      Point P(xform * e.ray.origin());
+    for(int i=rays.begin(); i<rays.end(); i++) {
+      Point P(xform * rays.getOrigin(i));
       Vector dP(P - Pa);
-      Vector V(xform * e.ray.direction());
+      Vector V(xform * rays.getDirection(i));
       Vector tv = V;
       Real dist_scale = tv.normalize();
       Real a = ((cosA2*Dot(V-Dot(V,Va)*Va, V-Dot(V,Va)*Va))-
@@ -125,10 +123,10 @@
         Real z1 = P.z()+t1*V.z();
         Real z2 = P.z()+t2*V.z();
         if(t1>0 && z1 > 0 && z1 < 1) {
-          e.hitInfo.hit(t1/dist_scale, getMaterial(), this, 
getTexCoordMapper());
+          rays.hit(i, t1/dist_scale, getMaterial(), this, 
getTexCoordMapper());
         }
         if(t2>0 && z2 > 0 && z2 < 1) {
-          e.hitInfo.hit(t2/dist_scale, getMaterial(), this, 
getTexCoordMapper());
+          rays.hit(i, t2/dist_scale, getMaterial(), this, 
getTexCoordMapper());
         }
       }
     }
@@ -139,8 +137,7 @@
 void Cone::computeNormal(const RenderContext&, RayPacket& rays) const
 {
   rays.computeHitPositions();
-  for(int i=0; i<rays.getSize(); i++) {
-    RayPacket::Element& e = rays.get(i);
+  for(int i=rays.begin(); i<rays.end(); i++) {
 #if 0
     Vector xn(xform.project(e.hitPosition).asVector());
     xn.z(0);
@@ -156,19 +153,15 @@
 void Cone::computeTexCoords2(const RenderContext&,
                             RayPacket& rays) const
 {
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    e.texCoords = e.hitInfo.scratchpad<Point>();
-  }
+  for(int i=rays.begin();i<rays.end();i++)
+    rays.setTexCoords(i, rays.scratchpad<Point>(i));
   rays.setFlag(RayPacket::HaveTexture2|RayPacket::HaveTexture3);
 }
 
 void Cone::computeTexCoords3(const RenderContext&,
                                      RayPacket& rays) const
 {
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    e.texCoords = e.hitInfo.scratchpad<Point>();
-  }
+  for(int i=rays.begin();i<rays.end();i++)
+    rays.setTexCoords(i, rays.scratchpad<Point>(i));
   rays.setFlag(RayPacket::HaveTexture2|RayPacket::HaveTexture3);
 }

Modified: trunk/Model/Primitives/Cone.h
==============================================================================
--- trunk/Model/Primitives/Cone.h       (original)
+++ trunk/Model/Primitives/Cone.h       Fri Jan 20 15:03:05 2006
@@ -9,7 +9,6 @@
 
 namespace Manta
 {
-
   class Cone : public PrimitiveCommon, public TexCoordMapper {
   public:
     Cone(Material* mat, const Point& bottom, const Point& top, Real Rb, Real 
Rt);

Modified: trunk/Model/Primitives/Cube.cc
==============================================================================
--- trunk/Model/Primitives/Cube.cc      (original)
+++ trunk/Model/Primitives/Cube.cc      Fri Jan 20 15:03:05 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,155 +37,48 @@
   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
 }
 
 
 void Cube::computeNormal(const RenderContext&, RayPacket& rays) const
 {
   rays.computeHitPositions();
-  for(int i=0; i<rays.getSize(); i++) {
-    
-    RayPacket::Element& e = rays.get(i);
-    
-    if (Abs(e.hitPosition.x() - bbox[0][0]) < 0.0001)
-      e.normal =  Vector(-1, 0, 0 );
-    
-    else if (Abs(e.hitPosition.x() - bbox[1][0]) < 0.0001)
-      e.normal =  Vector( 1, 0, 0 );
+  for(int i=rays.begin(); i<rays.end(); i++) {
+    Point hp = rays.getHitPosition(i);
+    if (Abs(hp.x() - bbox[0][0]) < 0.0001)
+      rays.setNormal(i, Vector(-1, 0, 0 ));
+    
+    else if (Abs(hp.x() - bbox[1][0]) < 0.0001)
+      rays.setNormal(i, Vector( 1, 0, 0 ));
     
-    else if (Abs(e.hitPosition.y() - bbox[0][1]) < 0.0001)
-      e.normal =  Vector( 0,-1, 0 );
+    else if (Abs(hp.y() - bbox[0][1]) < 0.0001)
+      rays.setNormal(i, Vector( 0,-1, 0 ));
     
-    else if (Abs(e.hitPosition.y() - bbox[1][1]) < 0.0001)
-      e.normal =  Vector( 0, 1, 0 );
+    else if (Abs(hp.y() - bbox[1][1]) < 0.0001)
+      rays.setNormal(i, Vector( 0, 1, 0 ));
     
-    else if (Abs(e.hitPosition.z() - bbox[0][2]) < 0.0001)
-      e.normal =  Vector( 0, 0,-1 );
+    else if (Abs(hp.z() - bbox[0][2]) < 0.0001)
+      rays.setNormal(i, Vector( 0, 0,-1 ));
     
     else 
-      e.normal =  Vector( 0, 0, 1 );
+      rays.setNormal(i, Vector( 0, 0, 1 ));
   }
 }

Modified: trunk/Model/Primitives/Cube.h
==============================================================================
--- trunk/Model/Primitives/Cube.h       (original)
+++ trunk/Model/Primitives/Cube.h       Fri Jan 20 15:03:05 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: trunk/Model/Primitives/Disk.cc
==============================================================================
--- trunk/Model/Primitives/Disk.cc      (original)
+++ trunk/Model/Primitives/Disk.cc      Fri Jan 20 15:03:05 2006
@@ -1,23 +1,34 @@
+
 #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;
 
-Disk::Disk(Material* mat, const Point& center, const Vector& n, Real radius, 
const Vector& axis) : PrimitiveCommon(mat, this), _c(center), _n(n), 
_r(radius), _partial(false), _minTheta(0.0), _maxTheta(2.0 * M_PI) {
+Disk::Disk(Material* mat, const Point& center, const Vector& n,
+           Real radius, const Vector& axis) 
+  : PrimitiveCommon(mat, this), _c(center), _n(n), _r(radius),
+    _partial(false), _minTheta(0.0), _maxTheta(2.0 * M_PI)
+{
   _n.normalize();
   _d = -Dot(_n, _c);
   setupAxes(axis);
 }
 
-Disk::Disk(Material* mat, const Point& center, const Vector& n, Real radius, 
const Vector& axis, Real minTheta, Real maxTheta) : PrimitiveCommon(mat, 
this), _c(center), _n(n), _r(radius), _partial(true), _minTheta(minTheta), 
_maxTheta(maxTheta) {
+Disk::Disk(Material* mat, const Point& center, const Vector& n,
+           Real radius, const Vector& axis, Real minTheta, Real maxTheta) 
+  : PrimitiveCommon(mat, this), _c(center), _n(n), _r(radius),
+    _partial(true), _minTheta(minTheta), _maxTheta(maxTheta)
+{
   _n.normalize();
   _d = -Dot(_n, _c);
   setupAxes(axis);
 }
 
-Disk::~Disk() {
+Disk::~Disk()
+{
 }
 
 void Disk::computeBounds(const PreprocessContext& /*context*/,
@@ -26,40 +37,33 @@
   bbox.extendByDisc(_c, _n, _r);
 }
 
-void Disk::intersect(const RenderContext& /*context*/, RayPacket& rays) 
const {
-  int i, numRays(rays.getSize());
-  static const Real EPSILON(1.0e-6);
-  Point rayO;
-  Vector rayD;
-  Real denom, t;
-
+void Disk::intersect(const RenderContext& /*context*/, RayPacket& rays) const
+{
   if (rays.getFlag(RayPacket::ConstantOrigin)) {
-    rayO = rays.get(0).ray.origin();
+    Point rayO = rays.getOrigin(rays.begin());
     Real nDotO(Dot(_n, rayO));
 
-    for (i = 0; i < numRays; i++) {
-      RayPacket::Element& e(rays.get(i));
-      rayD = e.ray.direction();
-      denom = Dot(_n, rayD);
+    for (int i = rays.begin(); i < rays.end(); i++) {
+      Vector rayD = rays.getDirection(i);
+      Real denom = Dot(_n, rayD);
 
-      if ((denom < -EPSILON) || (denom > EPSILON)) {
-        t = -(_d + nDotO) / denom;
+      if (denom < -DENOM_EPSILON || denom > DENOM_EPSILON) {
+        Real t = -(_d + nDotO) / denom;
         if (checkBounds(rayO + t * rayD)) {
-          e.hitInfo.hit(t, getMaterial(), this, getTexCoordMapper());
+          rays.hit(i, t, getMaterial(), this, getTexCoordMapper());
         }
       }
     }
   } else {
-    for (i = 0; i < numRays; i++) {
-      RayPacket::Element& e(rays.get(i));
-      rayD = e.ray.direction();
-      rayO = e.ray.origin();
-      denom = Dot(_n, rayD);
+    for (int i = rays.begin(); i < rays.end(); i++) {
+      Point rayO = rays.getOrigin(i);
+      Vector rayD = rays.getDirection(i);
+      Real denom = Dot(_n, rayD);
 
-      if ((denom < -EPSILON) || (denom > EPSILON)) {
-        t = -(_d + Dot(_n, rayO)) / denom;
+      if (denom < -DENOM_EPSILON || denom > DENOM_EPSILON) {
+        Real t = -(_d + Dot(_n, rayO)) / denom;
         if (checkBounds(rayO + t * rayD)) {
-          e.hitInfo.hit(t, getMaterial(), this, getTexCoordMapper());
+          rays.hit(i, t, getMaterial(), this, getTexCoordMapper());
         }
       }
     }
@@ -68,56 +72,56 @@
 
 
 void Disk::computeNormal(const RenderContext& /*context*/,
-                         RayPacket& rays) const {
-  int i, numRays(rays.getSize());
-  
-  for (i = 0; i < numRays; i++) {
-    RayPacket::Element& e(rays.get(i));
-    e.normal = _n;
-  }
+                         RayPacket& rays) const
+{
+  for (int i = rays.begin(); i < rays.end(); i++)
+    rays.setNormal(i, _n);
 
   // set flags to indicate packet now has unit normals
   rays.setFlag(RayPacket::HaveNormals & RayPacket::HaveUnitNormals);
 }
 
 void Disk::computeTexCoords2(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();
+  rays.computeHitPositions();
 
   // set 2-d texture coordinates as returned by getTexCoords()
-  for (i = 0; i < numRays; i++) {
-    RayPacket::Element& e(rays.get(i));
-    p = e.hitPosition;
-    getTexCoords(p);
-    e.texCoords = p;
+  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 += (Real)M_PI;
+    rays.setTexCoords(i, Point(dist/_r, (theta - _minTheta) / (_maxTheta - 
_minTheta), 0));
   }
 
   // set flag to show texcoords have been computed
-  rays.setFlag(RayPacket::HaveTexture2);
+  rays.setFlag(RayPacket::HaveTexture2 | RayPacket::HaveTexture3);
 }
 
 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++) {
-    RayPacket::Element& e(rays.get(i));
-    e.texCoords = e.hitPosition;
+  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 += (Real)M_PI;
+    rays.setTexCoords(i, Point(dist/_r, (theta - _minTheta) / (_maxTheta - 
_minTheta), 0));
   }
 
   // set flag to show texcoords have been computed
-  rays.setFlag(RayPacket::HaveTexture3);
+  rays.setFlag(RayPacket::HaveTexture3 | RayPacket::HaveTexture3);
 }
 
 /**
@@ -155,7 +159,8 @@
  * close to the direction of the normal, then the z-axis is used instead of 
the
  * given vector.
  **/
-void Disk::setupAxes(const Vector& axis) {
+void Disk::setupAxes(const Vector& axis)
+{
   static const Real EPSILON(1.0e-6);
 
   _u = axis;
@@ -172,22 +177,3 @@
   _v.normalize();
   _u = Cross(_v, _n);
 }
-
-/**
- * getTexCoords(p)
- *
- * Assumes the point p lies within the disk.  Returns the 2-D texture
- * coordinates in the disk in p.
- **/
-void Disk::getTexCoords(Point& p) const {
-  Vector dir(p - _c);
-  Real dist(dir.normalize()), theta;
-
-  theta = atan2(Dot(_v, dir), Dot(_u, dir));
-  if (theta < 0.0)
-    theta = 2 * (Real)M_PI + theta;
-  
-  p = Point(dist / _r, (theta - _minTheta) / (_maxTheta - _minTheta), 0);
-}
-
-

Modified: trunk/Model/Primitives/Disk.h
==============================================================================
--- trunk/Model/Primitives/Disk.h       (original)
+++ trunk/Model/Primitives/Disk.h       Fri Jan 20 15:03:05 2006
@@ -9,8 +9,10 @@
 namespace Manta {
   class Disk : public PrimitiveCommon, public TexCoordMapper {
   public:
-    Disk(Material* mat, const Point& center, const Vector& n, Real radius, 
const Vector& axis);
-    Disk(Material* mat, const Point& center, const Vector& n, Real radius, 
const Vector& axis, Real minTheta, Real maxTheta);
+    Disk(Material* mat, const Point& center, const Vector& n,
+         Real radius, const Vector& axis);
+    Disk(Material* mat, const Point& center, const Vector& n,
+         Real radius, const Vector& axis, Real minTheta, Real maxTheta);
     virtual ~Disk();
     
     virtual void computeBounds(const PreprocessContext& context, BBox& bbox) 
const;

Modified: trunk/Model/Primitives/HeavyTriangle.cc
==============================================================================
--- trunk/Model/Primitives/HeavyTriangle.cc     (original)
+++ trunk/Model/Primitives/HeavyTriangle.cc     Fri Jan 20 15:03:05 2006
@@ -48,14 +48,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 = getTexCoordMapper();
@@ -68,33 +68,21 @@
 {
   rays.computeHitPositions();
 
-  if (rays.getFlag(RayPacket::HaveNormals)) {
-    if (rays.getFlag(RayPacket::HaveUnitNormals))
-       return;
-  }
-  else {
-
-    for(int i=0; i<rays.getSize(); 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 - th.a - th.b);
+    Real a = th.a;
+    Real b = th.b;
+    Real c = (1.0 - th.a - th.b);
     
-      e.normal = (n[1]*a) + (n[2]*b) + (n[0]*c);
-      e.normal.normalize();
-    }
-
-    rays.setFlag(RayPacket::HaveUnitNormals);
+    Vector normal = (n[1]*a) + (n[2]*b) + (n[0]*c);
+    normal.normalize();
+    rays.setNormal(i, normal);
   }
-  
 }
 
-void HeavyTriangle::computeBounds(const PreprocessContext& context, BBox& 
bbox) const {
-
+void HeavyTriangle::computeBounds(const PreprocessContext& context, BBox& 
bbox) const
+{
   bbox.extendByPoint( point );
   bbox.extendByPoint( point+edge[0] );
   bbox.extendByPoint( point+edge[1] );

Modified: trunk/Model/Primitives/Heightfield.cc
==============================================================================
--- trunk/Model/Primitives/Heightfield.cc       (original)
+++ trunk/Model/Primitives/Heightfield.cc       Fri Jan 20 15:03:05 2006
@@ -2,6 +2,7 @@
 #include <Model/Primitives/Heightfield.h>
 #include <Interface/RayPacket.h>
 #include <Core/Geometry/BBox.h>
+#include <Core/Math/Expon.h>
 #include <Core/Math/MiscMath.h>
 #include <Core/Math/MinMax.h>
 #include <Core/Geometry/PointVector.h>
@@ -10,7 +11,7 @@
 
 using namespace Manta;
 using namespace std;
-
+using SCIRun::Sqrt;
 
 #define ALLOCATE2DARRAY(array, nx, ny, type)  \
 {                                             \
@@ -82,22 +83,18 @@
   Real tnear, tfar, zenter, texit, zexit;
   bool validtcells[2];
 
-  if (!(rays.getFlag(RayPacket::NormalizedDirections)))
-  {
-    rays.normalizeDirections();
-    rays.setFlag(RayPacket::NormalizedDirections);
-  }
+  rays.normalizeDirections();
+  rays.computeInverseDirections();
 
-  for(int i=0; i<rays.getSize(); i++)
+  for(int i=rays.begin(); i<rays.end(); i++)
   {
-    RayPacket::Element & e = rays.get(i);
-    Ray & ray = e.ray;
+    Ray ray = rays.getRay(i);
 
     using Manta::Min;
     using Manta::Max;
-    rays.computeInverseDirections();
-    Vector t1 = (m_Box.getMin() - ray.origin()) * e.inverseDirection;
-    Vector t2 = (m_Box.getMax() - ray.origin()) * e.inverseDirection;
+    Vector id = rays.getInverseDirection(i);
+    Vector t1 = (m_Box.getMin() - ray.origin()) * id;
+    Vector t2 = (m_Box.getMax() - ray.origin()) * id;
     Vector tn = Min(t1, t2);
     Vector tf = Max(t1, t2);
     tnear = tn.maxComponent();
@@ -108,8 +105,12 @@
     using SCIRun::Min;
     using SCIRun::Max;
 
-    if (m_Box.getMin().x() < ray.origin().x() && m_Box.getMin().y() < 
ray.origin().y() && m_Box.getMin().z() < ray.origin().z() && 
-        m_Box.getMax().x() > ray.origin().x() && m_Box.getMax().y() > 
ray.origin().y() && m_Box.getMax().z() < ray.origin().z() )
+    if (m_Box.getMin().x() < ray.origin().x() 
+        && m_Box.getMin().y() < ray.origin().y() 
+        && m_Box.getMin().z() < ray.origin().z() 
+        && m_Box.getMax().x() > ray.origin().x() 
+        && m_Box.getMax().y() > ray.origin().y() 
+        && m_Box.getMax().z() < ray.origin().z() )
       tnear = 0.0;
 
     diagonal = m_Box.diagonal();
@@ -189,8 +190,8 @@
 
           if (tcell > T_EPSILON && tcell < texit && u > 0.0 && u < 1.0 && v 
> 0.0 && v < 1.0)
           {
-            if (e.hitInfo.hit(tnear + tcell, getMaterial(), this, 
getTexCoordMapper()))
-              e.hitInfo.scratchpad<Vector>() = Vector(- (z[1] + v*z[3]) / 
cellSize[0], - (z[2] + u*z[3]) / cellSize[1], 1.0);
+            if (rays.hit(i, tnear + tcell, getMaterial(), this, 
getTexCoordMapper()))
+              rays.scratchpad<Vector>(i) = Vector(- (z[1] + v*z[3]) / 
cellSize[0], - (z[2] + u*z[3]) / cellSize[1], 1.0);
             break;
           }
         }
@@ -201,7 +202,7 @@
           {
             Real tcells[2], a2, u, v, tcell;
 
-            delta = sqrt(delta);
+            delta = Sqrt(delta);
             a2 = 2 * a;
 
             tcells[0] = (-b - delta) / a2;
@@ -221,8 +222,8 @@
               v = sy + tcell * dy;
               if (u > 0.0 && u < 1.0 && v > 0.0 && v < 1.0)
               {
-                if (e.hitInfo.hit(tnear + tcell, getMaterial(), this, 
getTexCoordMapper()))
-                  e.hitInfo.scratchpad<Vector>() = Vector( - (z[1] + v*z[3]) 
/ cellSize[0], - (z[2] + u*z[3]) / cellSize[1], 1.0);
+                if (rays.hit(i, tnear + tcell, getMaterial(), this, 
getTexCoordMapper()))
+                  rays.scratchpad<Vector>(i) = Vector( - (z[1] + v*z[3]) / 
cellSize[0], - (z[2] + u*z[3]) / cellSize[1], 1.0);
                 break;
               }
             }
@@ -248,17 +249,9 @@
 void Heightfield::computeNormal(const RenderContext& /*context*/,
                                 RayPacket& rays) const
 {
-  int i, numRays(rays.getSize());
-  
-  for (i=0; i<numRays; i++)
-  {
-    RayPacket::Element & e(rays.get(i));
-    e.normal = e.hitInfo.scratchpad<Vector>();
-    e.normal.normalize();
-  }
-
-  // set flags to indicate packet now has unit normals
-  rays.setFlag(RayPacket::HaveNormals | RayPacket::HaveUnitNormals);
+  for (int i=rays.begin(); i<rays.end(); i++)
+    rays.setNormal(i, rays.scratchpad<Vector>(i));
+  rays.setFlag(RayPacket::HaveNormals);
 }
 
 

Modified: trunk/Model/Primitives/Heightfield.h
==============================================================================
--- trunk/Model/Primitives/Heightfield.h        (original)
+++ trunk/Model/Primitives/Heightfield.h        Fri Jan 20 15:03:05 2006
@@ -8,7 +8,6 @@
 
 namespace Manta {
 
-  //  using namespace SCIRun;
   class Heightfield : public PrimitiveCommon
   {
 

Modified: trunk/Model/Primitives/Hemisphere.cc
==============================================================================
--- trunk/Model/Primitives/Hemisphere.cc        (original)
+++ trunk/Model/Primitives/Hemisphere.cc        Fri Jan 20 15:03:05 2006
@@ -2,137 +2,142 @@
 #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
 
 using namespace Manta;
+using namespace SCIRun;
 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 {
-  int i, numRays(rays.getSize()),
-    rpFlags(rays.getAllFlags() & (RayPacket::ConstantOrigin | 
RayPacket::NormalizedDirections));
-  Real a, b, c, disc, r, t;
-  Point rayO;
-  Vector rayD, tRayO;
-
-  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());
+            }
+          }
        }
       }
     }
@@ -140,53 +145,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);
 }
 
 /**
@@ -195,16 +190,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: trunk/Model/Primitives/Hemisphere.h
==============================================================================
--- trunk/Model/Primitives/Hemisphere.h (original)
+++ trunk/Model/Primitives/Hemisphere.h Fri Jan 20 15:03:05 2006
@@ -21,6 +21,7 @@
   private:
     Point _c;
     Real _r;
+    Real _inv_r;
     Vector _n, _u, _v;
 
     bool checkBounds(const Point& p) const;

Modified: trunk/Model/Primitives/Parallelogram.cc
==============================================================================
--- trunk/Model/Primitives/Parallelogram.cc     (original)
+++ trunk/Model/Primitives/Parallelogram.cc     Fri Jan 20 15:03:05 2006
@@ -36,8 +36,10 @@
 
 void Parallelogram::computeNormal(const RenderContext&, RayPacket& rays) 
const
 {
-  for(int i=0;i<rays.getSize();i++)
-    rays.get(i).normal = normal;
+  for(int i=rays.begin();i<rays.end();i++)
+    rays.setNormal(i, normal);
+  // We know the normal is unit length, so let the RayPacket know too.
+  rays.setFlag(RayPacket::HaveUnitNormals);
 }
 
 void Parallelogram::intersect(const RenderContext&, RayPacket& rays) const
@@ -47,21 +49,20 @@
   // affect this value.  You should be doing this dot product against
   // normalized vectors anyway.
   rays.normalizeDirections();
-  if(rays.getAllFlags() & RayPacket::ConstantOrigin && rays.getSize()>1){
-    RayPacket::Element& e0 = rays.get(0);
-    Real num = d-Dot(normal, e0.ray.origin());
-    Point a(e0.ray.origin()-anchor);
+  if(rays.getFlag(RayPacket::ConstantOrigin) && rays.end()-rays.begin() > 1){
+    Real num = d-Dot(normal, rays.getOrigin(0));
+    Point a(rays.getOrigin(0)-anchor);
     Real o1 = Dot(a, v1);
     Real o2 = Dot(a, v2);
-    for(int i=0;i<rays.getSize();i++){
-      RayPacket::Element& e = rays.get(i);
-      Real dt=Dot(e.ray.direction(), normal);
+    int i = rays.begin();
+    do {
+      Real dt=Dot(rays.getDirection(i), normal);
       if(Abs(dt) < (Real)1.e-6)
         continue;
       Real t=num/dt;
-      if(t>e.hitInfo.minT())
+      if(t>rays.getMinT(i))
         continue;
-      Vector vi(e.ray.direction()*t);
+      Vector vi(rays.getDirection(i)*t);
       Real a1 = Dot(v1, vi)+o1;
       if (a1 < 0 || a1 > 1)
         continue;
@@ -69,19 +70,21 @@
       if (a2 < 0 || a2 > 1)
         continue;
 
-      if(e.hitInfo.hit(t, getMaterial(), this, getTexCoordMapper()))
-        e.hitInfo.scratchpad<Point>() = Point(a1, a2, 0);
-    }
+      if(rays.hit(i, t, getMaterial(), this, getTexCoordMapper()))
+        rays.scratchpad<Point>(i) = Point(a1, a2, 0);
+    } while(++i < rays.end());
   } else {
-    for(int i=0;i<rays.getSize();i++){
-      RayPacket::Element& e = rays.get(i);
-      Real dt=Dot(e.ray.direction(), normal);
+    int i = rays.begin();
+    do {
+      Vector dir = rays.getDirection(i);
+      Real dt=Dot(dir, normal);
       if(Abs(dt) < (Real)1.e-6)
         continue;
-      Real t=(d-Dot(normal, e.ray.origin()))/dt;
-      if(t>e.hitInfo.minT())
+      Point origin = rays.getOrigin(i);
+      Real t=(d-Dot(normal, origin))/dt;
+      if(t>rays.getMinT(i))
         continue;
-      Point p(e.ray.origin()+e.ray.direction()*t);
+      Point p(origin+dir*t);
       Vector vi(p-anchor);
       Real a1 = Dot(v1, vi);
       if (a1 < 0 || a1 > 1)
@@ -90,18 +93,17 @@
       if (a2 < 0 || a2 > 1)
         continue;
 
-      if(e.hitInfo.hit(t, getMaterial(), this, getTexCoordMapper()))
-        e.hitInfo.scratchpad<Point>() = Point(a1, a2, 0);
-    }
+      if(rays.hit(i, t, getMaterial(), this, getTexCoordMapper()))
+        rays.scratchpad<Point>(i) = Point(a1, a2, 0);
+    } while(++i < rays.end());
   }
 }
 
 void Parallelogram::computeTexCoords2(const RenderContext&,
                                      RayPacket& rays) const
 {
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    e.texCoords = e.hitInfo.scratchpad<Point>();
+  for(int i=rays.begin();i<rays.end();i++){
+    rays.setTexCoords(i, rays.scratchpad<Point>(i));
   }
   rays.setFlag(RayPacket::HaveTexture2|RayPacket::HaveTexture3);
 }
@@ -109,9 +111,8 @@
 void Parallelogram::computeTexCoords3(const RenderContext&,
                                      RayPacket& rays) const
 {
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    e.texCoords = e.hitInfo.scratchpad<Point>();
+  for(int i=rays.begin();i<rays.end();i++){
+    rays.setTexCoords(i, rays.scratchpad<Point>(i));
   }
   rays.setFlag(RayPacket::HaveTexture2|RayPacket::HaveTexture3);
 }

Modified: trunk/Model/Primitives/ParticleBVH.cc
==============================================================================
--- trunk/Model/Primitives/ParticleBVH.cc       (original)
+++ trunk/Model/Primitives/ParticleBVH.cc       Fri Jan 20 15:03:05 2006
@@ -114,16 +114,18 @@
   bound[ 0 ] = box.getMin().x(); bound[ 1 ] = box.getMax().x();
   bound[ 2 ] = box.getMin().y(); bound[ 3 ] = box.getMax().y();
   bound[ 4 ] = box.getMin().z(); bound[ 5 ] = box.getMax().z();
-  for ( int ray = 0; ray < rays.getSize(); ++ray ) {
-    RayPacket::Element &element( rays.get( ray ) );
+  for ( int ray = rays.begin(); ray < rays.end(); ++ray ) {
     double maximum_minimum = T_EPSILON;
-    double minimum_maximum = element.hitInfo.minT();
-    double x_minimum = ( bound[     element.sign[ 0 ] ] - 
element.ray.origin().x() ) * element.inverseDirection.x();
-    double x_maximum = ( bound[ 1 - element.sign[ 0 ] ] - 
element.ray.origin().x() ) * element.inverseDirection.x();
-    double y_minimum = ( bound[ 2 + element.sign[ 1 ] ] - 
element.ray.origin().y() ) * element.inverseDirection.y();
-    double y_maximum = ( bound[ 3 - element.sign[ 1 ] ] - 
element.ray.origin().y() ) * element.inverseDirection.y();
-    double z_minimum = ( bound[ 4 + element.sign[ 2 ] ] - 
element.ray.origin().z() ) * element.inverseDirection.z();
-    double z_maximum = ( bound[ 5 - element.sign[ 2 ] ] - 
element.ray.origin().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;
@@ -153,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;
         }
       }
     }
@@ -185,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;
       }
     }
@@ -208,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 );
 }
@@ -231,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: trunk/Model/Primitives/Plane.cc
==============================================================================
--- trunk/Model/Primitives/Plane.cc     (original)
+++ trunk/Model/Primitives/Plane.cc     Fri Jan 20 15:03:05 2006
@@ -62,14 +62,13 @@
   // This is a simple first pass.  We should do different
   // optimizations in the future.
   rays.normalizeDirections();
-  for(int i = 0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    Real dn = Dot( e.ray.direction(), normal );
+  for(int i = rays.begin();i<rays.end();i++){
+    Real dn = Dot( rays.getDirection(i), normal );
     if (dn != 0) {
       // Ray isn't parallel to the plane.
-      Real ao = Dot( (center-e.ray.origin()), normal );
+      Real ao = Dot( (center-rays.getOrigin(i)), normal );
       Real t = ao/dn;
-      e.hitInfo.hit(t, getMaterial(), this, getTexCoordMapper());
+      rays.hit(i, t, getMaterial(), this, getTexCoordMapper());
     }
   }
 }
@@ -79,9 +78,8 @@
 {
   // We don't need to do anything except stuff the normal in the the
   // RayPacket.
-  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);
   }
   rays.setFlag(RayPacket::HaveUnitNormals);
 }

Modified: trunk/Model/Primitives/PrimitiveCommon.h
==============================================================================
--- trunk/Model/Primitives/PrimitiveCommon.h    (original)
+++ trunk/Model/Primitives/PrimitiveCommon.h    Fri Jan 20 15:03:05 2006
@@ -9,11 +9,12 @@
   class PrimitiveCommon : public Primitive {
   public:
     PrimitiveCommon(Material* material, const TexCoordMapper* tex = 0);
-               PrimitiveCommon() {  }; // Empty default constructor (used 
for an array of some primitive)
+    // Empty default constructor (used for an array of some primitive)
+    PrimitiveCommon() {  };
     virtual ~PrimitiveCommon();
 
-               // Note that this preprocess method sets up the activeLights 
for the associated
-               // material (not sure what happens for shared materials)
+    // Note that this preprocess method sets up the activeLights for the 
associated
+    // material (not sure what happens for shared materials)
     virtual void preprocess(const PreprocessContext&);
 
     // Accessors.
@@ -22,7 +23,6 @@
 
     void setMaterial( Material *material_ ) { material = material; }
     Material *getMaterial() const { return material; }
-    
 
   private:
     Material* material;

Modified: trunk/Model/Primitives/Ring.cc
==============================================================================
--- trunk/Model/Primitives/Ring.cc      (original)
+++ trunk/Model/Primitives/Ring.cc      Fri Jan 20 15:03:05 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: trunk/Model/Primitives/Sphere.cc
==============================================================================
--- trunk/Model/Primitives/Sphere.cc    (original)
+++ trunk/Model/Primitives/Sphere.cc    Fri Jan 20 15:03:05 2006
@@ -4,10 +4,11 @@
 #include <Core/Geometry/BBox.h>
 #include <Core/Math/MiscMath.h>
 #include <Core/Math/Trig.h>
+#include <Core/Math/Expon.h>
 
 using namespace Manta;
+using namespace SCIRun;
 using namespace std;
-using SCIRun::Clamp;
 
 Sphere::Sphere(Material* material, const Point& center, Real radius)
 : PrimitiveCommon(material, this), center(center), radius(radius)
@@ -44,14 +45,14 @@
       if(tca < 0){
         // Behind ray, no intersections...
       } else {
-                         Real t2hc=rad2-l2oc+tca*tca;
-                               if(t2hc <= 0){
-                                       // Ray misses, no intersections
-                               } else {
-                                       Real thc=Sqrt(t2hc);
-                                       e.hitInfo.hit(tca-thc, getMaterial(), 
this, getTexCoordMapper());
-                                       e.hitInfo.hit(tca+thc, getMaterial(), 
this, getTexCoordMapper());
-                               }
+        Real t2hc=rad2-l2oc+tca*tca;
+        if(t2hc <= 0){
+          // Ray misses, no intersections
+        } else {
+          Real thc=Sqrt(t2hc);
+          e.hitInfo.hit(tca-thc, getMaterial(), this, getTexCoordMapper());
+          e.hitInfo.hit(tca+thc, getMaterial(), this, getTexCoordMapper());
+        }
       }
     }
   }
@@ -60,22 +61,20 @@
   case RayPacket::ConstantOrigin|RayPacket::NormalizedDirections:
     {
       // Rays of constant origin and normalized directions
-      RayPacket::Element& e0 = rays.get(0);
-      Vector O(e0.ray.origin()-center);
+      Vector O(rays.getOrigin(0)-center);
       Real C = Dot(O, O) - radius*radius;
-      for(int i = 0;i<rays.getSize();i++){
-        RayPacket::Element& e = rays.get(i);
-        const Vector& D(e.ray.direction());
+      for(int i = rays.begin();i<rays.end();i++){
+        Vector D(rays.getDirection(i));
         Real B = Dot(O, D);
         Real disc = B*B-C;
         if(disc >= 0){
           Real r = Sqrt(disc);
           Real t0 = -(r+B);
           if(t0 > T_EPSILON){
-            e.hitInfo.hit(t0, getMaterial(), this, getTexCoordMapper());
+            rays.hit(i, t0, getMaterial(), this, getTexCoordMapper());
           } else {
             Real t1 = r-B;
-            e.hitInfo.hit(t1, getMaterial(), this, getTexCoordMapper());
+            rays.hit(i, t1, getMaterial(), this, getTexCoordMapper());
           }
         }
       }
@@ -84,12 +83,10 @@
   case RayPacket::ConstantOrigin:
     {
       // Rays of constant origin for not normalized directions
-      RayPacket::Element& e0 = rays.get(0);
-      Vector O(e0.ray.origin()-center);
+      Vector O(rays.getOrigin(0)-center);
       Real C = Dot(O, O) - radius*radius;
-      for(int i = 0;i<rays.getSize();i++){
-        RayPacket::Element& e = rays.get(i);
-        const Vector& D(e.ray.direction());
+      for(int i = rays.begin();i<rays.end();i++){
+        Vector D(rays.getDirection(i));
         Real A = Dot(D, D);
         Real B = Dot(O, D);
         Real disc = B*B-A*C;
@@ -97,10 +94,10 @@
           Real r = Sqrt(disc);
           Real t0 = -(r+B)/A;
           if(t0 > T_EPSILON){
-            e.hitInfo.hit(t0, getMaterial(), this, getTexCoordMapper());
+            rays.hit(i, t0, getMaterial(), this, getTexCoordMapper());
           } else {
             Real t1 = (r-B)/A;
-            e.hitInfo.hit(t1, getMaterial(), this, getTexCoordMapper());
+            rays.hit(i, t1, getMaterial(), this, getTexCoordMapper());
           }
         }
       }
@@ -109,10 +106,9 @@
   case RayPacket::NormalizedDirections:
     {
       // Rays of non-constant origin and normalized directions
-      for(int i = 0;i<rays.getSize();i++){
-        RayPacket::Element& e = rays.get(i);
-        Vector O(e.ray.origin()-center);
-        const Vector& D(e.ray.direction());
+      for(int i = rays.begin();i<rays.end();i++){
+        Vector O(rays.getOrigin(i)-center);
+        Vector D(rays.getDirection(i));
         Real B = Dot(O, D);
         Real C = Dot(O, O) - radius*radius;
         Real disc = B*B-C;
@@ -120,10 +116,10 @@
           Real r = Sqrt(disc);
           Real t0 = -(r+B);
           if(t0 > T_EPSILON){
-            e.hitInfo.hit(t0, getMaterial(), this, getTexCoordMapper());
+            rays.hit(i, t0, getMaterial(), this, getTexCoordMapper());
           } else {
             Real t1 = r-B;
-            e.hitInfo.hit(t1, getMaterial(), this, getTexCoordMapper());
+            rays.hit(i, t1, getMaterial(), this, getTexCoordMapper());
           }
         }
       }
@@ -132,10 +128,9 @@
   case 0:
     {
       // Rays of non-constant origin and non-normalized directions
-      for(int i = 0;i<rays.getSize();i++){
-        RayPacket::Element& e = rays.get(i);
-        Vector O(e.ray.origin()-center);
-        const Vector& D(e.ray.direction());
+      for(int i = rays.begin();i<rays.end();i++){
+        Vector O(rays.getOrigin(i)-center);
+        Vector D(rays.getDirection(i));
         Real A = Dot(D, D);
         Real B = Dot(O, D);
         Real C = Dot(O, O) - radius*radius;
@@ -144,10 +139,10 @@
           Real r = Sqrt(disc);
           Real t0 = -(r+B)/A;
           if(t0 > T_EPSILON){
-            e.hitInfo.hit(t0, getMaterial(), this, getTexCoordMapper());
+            rays.hit(i, t0, getMaterial(), this, getTexCoordMapper());
           } else {
             Real t1 = (r-B)/A;
-            e.hitInfo.hit(t1, getMaterial(), this, getTexCoordMapper());
+            rays.hit(i, t1, getMaterial(), this, getTexCoordMapper());
           }
         }
       }
@@ -160,10 +155,10 @@
 void Sphere::computeNormal(const RenderContext&, RayPacket& rays) const
 {
   rays.computeHitPositions();
-  for(int i = 0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    e.normal = e.hitPosition-center;
-    e.normal*=inv_radius;
+  for(int i = rays.begin();i<rays.end();i++){
+    Vector n = rays.getHitPosition(i) - center;
+    n *= inv_radius;
+    rays.setNormal(i, n);
   }
   rays.setFlag(RayPacket::HaveUnitNormals);
 }
@@ -172,17 +167,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());
     Real x = (phi+(Real)M_PI)*((Real)0.5*(Real)M_1_PI);
     Real y = theta*(Real)M_1_PI;
-    e.texCoords = Point(x,
-                        y,
-                        0);
+    rays.setTexCoords(i, Point(x, y, 0));
   }
   rays.setFlag(RayPacket::HaveTexture2|RayPacket::HaveTexture3);
 }
@@ -191,15 +183,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*(Real)M_1_PI),
-                        theta*(Real)M_1_PI,
-                        0);
+    rays.setTexCoords(i, Point((phi+(Real)M_PI)*((Real)0.5*(Real)M_1_PI),
+                               theta*(Real)M_1_PI,
+                               0));
   }
   rays.setFlag(RayPacket::HaveTexture2|RayPacket::HaveTexture3);
 }

Modified: trunk/Model/Primitives/SuperEllipsoid.cc
==============================================================================
--- trunk/Model/Primitives/SuperEllipsoid.cc    (original)
+++ trunk/Model/Primitives/SuperEllipsoid.cc    Fri Jan 20 15:03:05 2006
@@ -84,19 +84,16 @@
 {
 
   rays.computeInverseDirections();
-  for( int i = 0; i < rays.getSize(); ++i ) {
-    RayPacket::Element& e( rays.get(i) );
-
-    Vector offset_center( e.ray.origin() - center );
-    //float radius = 1.01;
-    //float inv_radius = 1.0;
+  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;
@@ -104,8 +101,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;
@@ -115,29 +112,28 @@
     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;
-    Real near_deriv = Dot( functionGradient(
-                                 ( offset_center + tnear * e.ray.direction() 
) * inv_radius,
-                                 near_value ),
-                             e.ray.direction() );
-    Real far_deriv = Dot( functionGradient(
-                                ( offset_center + tfar * e.ray.direction() ) 
* inv_radius,
-                                far_value ),
-                            e.ray.direction() );
+    Vector rayD = rays.getDirection(i);
+    Real near_deriv = Dot( functionGradient( ( offset_center + tnear * rayD )
+                                             * inv_radius, near_value ),
+                           rayD );
+    Real far_deriv = Dot( functionGradient( ( offset_center + tfar * rayD )
+                                            * inv_radius, far_value ),
+                          rayD );
     if ( ( near_value < (Real)T_EPSILON && far_value < (Real)T_EPSILON ) ||
          ( near_value * far_value > 0 && near_deriv * far_deriv > 0 ) )
       continue;
@@ -148,24 +144,26 @@
       Real a_bracket = tnear;
       Real b_bracket = tfar;
       Real left = golden_mean * a_bracket + ( 1 - golden_mean ) * b_bracket;
-      Real left_value = functionValue(
-        ( offset_center + left * e.ray.direction() ) * inv_radius );
+      Real left_value = functionValue( ( offset_center + left * rayD )
+                                       * inv_radius );
       Real right = ( 1 - golden_mean ) * a_bracket + golden_mean * b_bracket;
-      Real right_value = functionValue(
-        ( offset_center + right * e.ray.direction() ) * inv_radius );
+      Real right_value = functionValue( ( offset_center + right * rayD )
+                                        * inv_radius );
       while( SCIRun::Abs( b_bracket - a_bracket ) > bracket_width ) {
         if ( left_value < right_value ) {
           b_bracket = right;
           right = left;
           right_value = left_value;
           left = golden_mean * a_bracket + ( 1 - golden_mean ) * b_bracket;
-          left_value = functionValue( ( offset_center + left * 
e.ray.direction() ) * inv_radius );
+          left_value = functionValue( ( offset_center + left * rayD )
+                                      * inv_radius );
         } else {
           a_bracket = left;
           left = right;
           left_value = right_value;
           right = ( 1 - golden_mean ) * a_bracket + golden_mean * b_bracket;
-          right_value = functionValue( ( offset_center + right * 
e.ray.direction() ) * inv_radius );
+          right_value = functionValue( ( offset_center + right * rayD )
+                                       * inv_radius );
         }
       }
 
@@ -193,10 +191,10 @@
       continue;
     Real troot = ( tnear + tfar ) * (Real)0.5;
     Real root_value;
-    Real root_deriv = Dot( logarithmFunctionGradient(
-                                 ( offset_center + troot * e.ray.direction() 
) * inv_radius,
-                                 root_value ),
-                             e.ray.direction() );
+    Real root_deriv =
+      Dot( logarithmFunctionGradient( ( offset_center + troot * rayD )
+                                      * inv_radius, root_value ),
+           rayD );
     int iterations = 0;
     while ( SCIRun::Abs( tfar - tnear ) >= (Real)T_EPSILON &&
             SCIRun::Abs( root_value ) >= (Real)T_EPSILON &&
@@ -211,14 +209,14 @@
       troot -= root_value / root_deriv;
       if ( troot <= tnear || troot >= tfar )
         troot = ( tnear + tfar ) * (Real)0.5;
-      root_deriv = Dot( logarithmFunctionGradient(
-                            ( offset_center + troot * e.ray.direction() ) * 
inv_radius,
-                            root_value ),
-                        e.ray.direction() );
+      root_deriv =
+        Dot( logarithmFunctionGradient( ( offset_center + troot * rayD )
+                                        * inv_radius, root_value ),
+             rayD );
     }
 
     // Finally, set the hit location
-    e.hitInfo.hit( troot, getMaterial(), this, getTexCoordMapper() );
+    rays.hit( i, troot, getMaterial(), this, getTexCoordMapper() );
 
   }
 
@@ -230,12 +228,10 @@
 {
   Real ignored;
   rays.computeHitPositions();
-  for( int i = 0; i < rays.getSize(); i++ ) {
-    RayPacket::Element &e( rays.get( i ) );
-    e.normal = functionGradient( Vector( 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( Vector(rays.getHitPosition(i)),
+                                        ignored ));
+  rays.setFlag(RayPacket::HaveNormals);
 }
 
 void SuperEllipsoid::computeTexCoords2(
@@ -243,15 +239,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 );
 }
@@ -261,15 +256,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: trunk/Model/Primitives/TexTriangle.cc
==============================================================================
--- trunk/Model/Primitives/TexTriangle.cc       (original)
+++ trunk/Model/Primitives/TexTriangle.cc       Fri Jan 20 15:03:05 2006
@@ -11,18 +11,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 );
 }
@@ -32,14 +29,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: trunk/Model/Primitives/Triangle.cc
==============================================================================
--- trunk/Model/Primitives/Triangle.cc  (original)
+++ trunk/Model/Primitives/Triangle.cc  Fri Jan 20 15:03:05 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)));
 }
 
 

Modified: trunk/Model/TexCoordMappers/LinearMapper.cc
==============================================================================
--- trunk/Model/TexCoordMappers/LinearMapper.cc (original)
+++ trunk/Model/TexCoordMappers/LinearMapper.cc Fri Jan 20 15:03:05 2006
@@ -26,12 +26,9 @@
                                      RayPacket& rays) const
 {
   rays.computeHitPositions();
-  for(int i = 0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-
+  for(int i = rays.begin();i<rays.end();i++)
     // Unproject a hit point by multiplying by inverse.
-    e.texCoords = transform * e.hitPosition;
-  }
+    rays.setTexCoords(i, transform * rays.getHitPosition(i));
   rays.setFlag(RayPacket::HaveTexture2|RayPacket::HaveTexture3);
 }
 
@@ -39,11 +36,8 @@
                                      RayPacket& rays) const
 {
   rays.computeHitPositions();
-  for(int i = 0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-
-        // Unproject a hit point by multiplying by inverse.
-    e.texCoords = transform * e.hitPosition;
-  }
+  for(int i = rays.begin();i<rays.end();i++)
+    // Unproject a hit point by multiplying by inverse.
+    rays.setTexCoords(i, transform * rays.getHitPosition(i));
   rays.setFlag(RayPacket::HaveTexture2|RayPacket::HaveTexture3);
 }

Modified: trunk/Model/TexCoordMappers/SphericalMapper.cc
==============================================================================
--- trunk/Model/TexCoordMappers/SphericalMapper.cc      (original)
+++ trunk/Model/TexCoordMappers/SphericalMapper.cc      Fri Jan 20 15:03:05 
2006
@@ -21,16 +21,15 @@
                                      RayPacket& rays) const
 {
   rays.computeHitPositions();
-  for(int i = 0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    Vector n = e.hitPosition-center;
+  for(int i = rays.begin();i<rays.end();i++){
+    Vector n = rays.getHitPosition(i)-center;
     Real w = n.normalize() * 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,
-                        w);
+    rays.setTexCoords(i, Point((phi+(Real)M_PI)*(Real)(0.5*M_1_PI),
+                               theta*(Real)M_1_PI,
+                               w));
   }
   rays.setFlag(RayPacket::HaveTexture2|RayPacket::HaveTexture3);
 }
@@ -39,16 +38,15 @@
                                      RayPacket& rays) const
 {
   rays.computeHitPositions();
-  for(int i = 0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    Vector n = e.hitPosition-center;
+  for(int i = rays.begin();i<rays.end();i++){
+    Vector n = rays.getHitPosition(i)-center;
     Real w = n.normalize() * 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,
-                        w);
+    rays.setTexCoords(i, Point((phi+(Real)M_PI)*(Real)(0.5*M_1_PI),
+                               theta*(Real)M_1_PI,
+                               w));
   }
   rays.setFlag(RayPacket::HaveTexture2|RayPacket::HaveTexture3);
 }

Modified: trunk/Model/TexCoordMappers/UniformMapper.cc
==============================================================================
--- trunk/Model/TexCoordMappers/UniformMapper.cc        (original)
+++ trunk/Model/TexCoordMappers/UniformMapper.cc        Fri Jan 20 15:03:05 
2006
@@ -16,9 +16,8 @@
                                      RayPacket& rays) const
 {
   rays.computeHitPositions();
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    e.texCoords = e.hitPosition;
+  for(int i=rays.begin();i<rays.end();i++){
+    rays.setTexCoords(i, rays.getHitPosition(i));
   }
   rays.setFlag(RayPacket::HaveTexture2|RayPacket::HaveTexture3);
 }
@@ -27,9 +26,8 @@
                                      RayPacket& rays) const
 {
   rays.computeHitPositions();
-  for(int i=0;i<rays.getSize();i++){
-    RayPacket::Element& e = rays.get(i);
-    e.texCoords = e.hitPosition;
+  for(int i=rays.begin();i<rays.end();i++){
+    rays.setTexCoords(i, rays.getHitPosition(i));
   }
   rays.setFlag(RayPacket::HaveTexture2|RayPacket::HaveTexture3);
 }

Modified: trunk/Model/Textures/CheckerTexture.h
==============================================================================
--- trunk/Model/Textures/CheckerTexture.h       (original)
+++ trunk/Model/Textures/CheckerTexture.h       Fri Jan 20 15:03:05 2006
@@ -58,10 +58,9 @@
       rays.computeTextureCoordinates3(context);
     else
       rays.computeTextureCoordinates2(context);
-    for(int i=0;i<rays.getSize();i++){
-      RayPacket::Element& e = rays.get(i);
-      Real vv1 = Dot(e.texCoords, v1);
-      Real vv2 = Dot(e.texCoords, v2);
+    for(int i=rays.begin();i<rays.end();i++){
+      Real vv1 = Dot(rays.getTexCoords(i), v1);
+      Real vv2 = Dot(rays.getTexCoords(i), v2);
       if(vv1<0)
         vv1=-vv1+1;
       if(vv2<0)

Modified: trunk/Model/Textures/Constant.h
==============================================================================
--- trunk/Model/Textures/Constant.h     (original)
+++ trunk/Model/Textures/Constant.h     Fri Jan 20 15:03:05 2006
@@ -43,7 +43,7 @@
                                      RayPacket& rays,
                                      ValueType results[]) const
   {
-    for(int i=0;i<rays.getSize();i++)
+    for(int i=rays.begin();i<rays.end();i++)
       results[i] = value;
   }
 }

Modified: trunk/Model/Textures/ImageTexture.h
==============================================================================
--- trunk/Model/Textures/ImageTexture.h (original)
+++ trunk/Model/Textures/ImageTexture.h Fri Jan 20 15:03:05 2006
@@ -114,7 +114,7 @@
     void setInterpolationMethod(int new_method);
 
   private:
-    typedef typename ValueType::ScalarType ScalarType;
+    typedef typename ValueType::ComponentType ScalarType;
 
     inline void BL_edge_behavior(ScalarType val, int behavior, int size,
                                  int& low, int& high,
@@ -234,9 +234,8 @@
     PointT<ScalarType, 2> tex_coords[RayPacket::MaxSize];
 
     // Grab the texture coordinates
-    for( int i = 0; i < rays.getSize(); ++i ) {
-      RayPacket::Element &e = rays.get( i );
-      tex_coords[i] = PointT<ScalarType, 2>(e.texCoords.x(), 
e.texCoords.y());
+    for( int i = rays.begin(); i < rays.end(); ++i ) {
+      tex_coords[i] = rays.getTexCoords2(i);
       tex_coords[i].multiplyBy(scale);
     }
 
@@ -247,7 +246,7 @@
     switch (interpolation_method) {
     case Bilinear:
       {
-        for( int i = 0; i < rays.getSize(); ++i) {
+        for( int i = rays.begin(); i < rays.end(); ++i) {
           ScalarType x = tex_coords[i].x();
           ScalarType y = tex_coords[i].y();
           int x_low, y_low, x_high, y_high;
@@ -268,7 +267,7 @@
       break;
     case NearestNeighbor:
       {
-        for( int i = 0; i < rays.getSize(); ++i) {
+        for( int i = rays.begin(); i < rays.end(); ++i) {
           int tx = NN_edge_behavior(static_cast<int>(tex_coords[i].x()*xres),
                                     u_edge, texture.dim1());
           int ty = NN_edge_behavior(static_cast<int>(tex_coords[i].y()*yres),

Modified: trunk/Model/Textures/MarbleTexture.h
==============================================================================
--- trunk/Model/Textures/MarbleTexture.h        (original)
+++ trunk/Model/Textures/MarbleTexture.h        Fri Jan 20 15:03:05 2006
@@ -79,11 +79,10 @@
     ValueType results[] ) const
   {
     rays.computeTextureCoordinates3( context );
-    for( int i = 0; i < rays.getSize(); i++ ) {
-      RayPacket::Element &e = rays.get( i );
-      Point T = e.texCoords.multipliedBy(scale * fscale);
+    for( int i = rays.begin(); i < rays.end(); i++ ) {
+      Point T = rays.getTexCoords(i).multipliedBy(scale * fscale);
       ColorComponent value = (Real)0.25 *
-        Cos( e.texCoords.x() * scale + tscale *
+        Cos( rays.getTexCoords(i).x() * scale + tscale *
              (Real)Turbulence( T, octaves, lacunarity, gain ) );
       results[ i ] = SCIRun::Interpolate( value1, value2, value );
     }

Modified: trunk/Model/Textures/OakTexture.h
==============================================================================
--- trunk/Model/Textures/OakTexture.h   (original)
+++ trunk/Model/Textures/OakTexture.h   Fri Jan 20 15:03:05 2006
@@ -97,32 +97,29 @@
     RayPacket &rays,
     ValueType results[] ) const
   {
-    using SCIRun::Clamp;
-    using SCIRun::Interpolate;
     using SCIRun::SmoothStep;
     rays.computeTextureCoordinates3( context );
-    for( int i = 0; i < rays.getSize(); i++ ) {
-      RayPacket::Element &e = rays.get( i );
-
-      Vector offset = VectorFBM( e.texCoords.multipliedBy(ringnoisefreq), 2, 
4.0, 0.5 );
-      Point Pring = e.texCoords + ringnoise * offset;
-      Vector vsnoise = VectorNoise( Point( 0.5, 0.5, e.texCoords.z() * 
trunkwobblefreq ) );
+    for( int i = rays.begin(); i < rays.end(); i++ ) {
+      Point tc = rays.getTexCoords(i);
+      Vector offset = VectorFBM( tc.multipliedBy(ringnoisefreq), 2, 4.0, 0.5 
);
+      Point Pring = tc + ringnoise * offset;
+      Vector vsnoise = VectorNoise( Point( 0.5, 0.5, tc.z() * 
trunkwobblefreq ) );
       Pring += Vector( trunkwobble * vsnoise.x(), trunkwobble * vsnoise.y(), 
0.0 );
-      double r = sqrt( Pring.x() * Pring.x() + Pring.y() * Pring.y() ) * 
ringfreq;
+      double r = SCIRun::Sqrt( Pring.x() * Pring.x() + Pring.y() * Pring.y() 
) * ringfreq;
       r += angularwobble * SmoothStep( r, 0, 5 ) * ScalarNoise( Point( 
angularwobble * Pring.x(),
                                                                        
angularwobble * Pring.y(),
                                                                        
angularwobble * Pring.z() * 0.1 ) );
       r += 0.5 * ScalarNoise( Point( 0.5, 0.5, r ) );
       double rfrac = r - floor( r );
       double inring = SmoothStep( rfrac, 0.1, 0.55 ) - SmoothStep( rfrac, 
0.7, 0.95 );
-      Point Pgrain( e.texCoords.multipliedBy(Vector(grainfreq, grainfreq, 
grainfreq*0.05)));
+      Point Pgrain( tc.multipliedBy(Vector(grainfreq, grainfreq, 
grainfreq*0.05)));
       double grain = 0.0;
       double amp = 1.0;
       for ( int it = 0; it < 2; ++it )
       {
           double g = 0.8 * ScalarNoise( Pgrain );
           g *= ( 0.3 + 0.7 * inring );
-          g = Clamp( 0.8 - g, 0.0, 1.0 );
+          g = SCIRun::Clamp( 0.8 - g, 0.0, 1.0 );
           g = grainy * SmoothStep( g * g, 0.5, 1.0 );
           if ( it == 0 )
               inring *= 0.7;
@@ -130,8 +127,8 @@
           Pgrain.multiplyBy(2.0);
           amp *= 0.5;
       }
-      double value = Interpolate( 1.0, grain, inring * ringy );
-      results[ i ] = Interpolate( value2, value1, value );
+      double value = SCIRun::Interpolate( 1.0, grain, inring * ringy );
+      results[ i ] = SCIRun::Interpolate( value2, value1, value );
     }
   }
 }

Modified: trunk/Model/Textures/TexCoordTexture.cc
==============================================================================
--- trunk/Model/Textures/TexCoordTexture.cc     (original)
+++ trunk/Model/Textures/TexCoordTexture.cc     Fri Jan 20 15:03:05 2006
@@ -46,20 +46,13 @@
   // Compute the texture coordinates.
   rays.computeTextureCoordinates3( context );
     
-  for( int i = 0; i < rays.getSize(); ++i ) {
-    RayPacket::Element &e = rays.get( i );
-
+  for( int i = rays.begin(); i < rays.end(); ++i ) {
+    Point texCoords = rays.getTexCoords(i);
     // Convert the coordinates to a color.
-    results[i] = Color( RGB( (ColorComponent)e.texCoords[0],
-                             (ColorComponent)e.texCoords[1],
+    results[i] = Color( RGB( (ColorComponent)texCoords[0],
+                             (ColorComponent)texCoords[1],
                              (ColorComponent)0 ) );
-
-    
-    // results[i] = Color( RGB( (ColorComponent)1.0,
-    //                         (ColorComponent)1.0,
-    //                         (ColorComponent)0.0 ) );
   }
-
 
 } // end mapValues
   

Modified: trunk/Model/Textures/TriVerTexture.cc
==============================================================================
--- trunk/Model/Textures/TriVerTexture.cc       (original)
+++ trunk/Model/Textures/TriVerTexture.cc       Fri Jan 20 15:03:05 2006
@@ -17,12 +17,11 @@
   {
     rays.computeTextureCoordinates3( context );
     
-    for( int i = 0; i < rays.getSize(); i++ ) {
-      RayPacket::Element &e = rays.get( i );
-      Point T = e.texCoords;
-      Triangle::TriangleHit& th = 
e.hitInfo.scratchpad<Triangle::TriangleHit>();
+    for( int i = rays.begin(); i < rays.end(); i++ ) {
+      Point T = rays.getTexCoords(i);
+      Triangle::TriangleHit& th = rays.scratchpad<Triangle::TriangleHit>(i);
       const VertexColoredTriangle* vct = 
-         static_cast<const VertexColoredTriangle*>(e.hitInfo.hitPrimitive());
+        static_cast<const VertexColoredTriangle*>(rays.getHitPrimitive(i));
       results[i] = vct->getVertexColor(0)*(1 - th.a - th.b) + 
                    vct->getVertexColor(1)*th.a + vct->getVertexColor(2)*th.b;
     }

Modified: trunk/Model/Textures/WoodTexture.h
==============================================================================
--- trunk/Model/Textures/WoodTexture.h  (original)
+++ trunk/Model/Textures/WoodTexture.h  Fri Jan 20 15:03:05 2006
@@ -82,9 +82,8 @@
     ValueType results[] ) const
   {
     rays.computeTextureCoordinates3( context );
-    for( int i = 0; i < rays.getSize(); i++ ) {
-      RayPacket::Element &e = rays.get( i );
-      Point T = e.texCoords.multipliedBy(scale);
+    for( int i = rays.begin(); i < rays.end(); i++ ) {
+      Point T = rays.getTexCoords(i).multipliedBy(scale);
       double distance = sqrt( T.x() * T.x() + T.y() * T.y() ) * rscale;
       double fbm = tscale * ScalarFBM( T, octaves, lacunarity, gain );
       double value = 0.5 * cos( distance + fbm ) + 0.5;

Modified: trunk/SCIRun/include/sci_defs/error_defs.h
==============================================================================
--- trunk/SCIRun/include/sci_defs/error_defs.h  (original)
+++ trunk/SCIRun/include/sci_defs/error_defs.h  Fri Jan 20 15:03:05 2006
@@ -1,7 +1,7 @@
 #ifndef SCI_ERROR_DEFS_H
 #define SCI_ERROR_DEFS_H
 
-#define SCI_ASSERTION_LEVEL 3
+#define SCI_ASSERTION_LEVEL 0
 #define USE_SCI_THROW 0
 
 #endif

Modified: trunk/StandAlone/CMakeLists.txt
==============================================================================
--- trunk/StandAlone/CMakeLists.txt     (original)
+++ trunk/StandAlone/CMakeLists.txt     Fri Jan 20 15:03:05 2006
@@ -19,16 +19,16 @@
 TARGET_LINK_LIBRARIES(barrier_test SCIRun_Core
                                   ${CMAKE_THREAD_LIBS_INIT})
 
-ADD_EXECUTABLE(frust-test frust-test.cc)
-TARGET_LINK_LIBRARIES(frust-test Manta_Engine
-                                 Manta_UserInterface
-                                 Manta_Model
-                                 Manta_Image
-                                 Manta_Interface
-                                 Manta_Core
-                                 SCIRun_Core
-                                 ${CMAKE_THREAD_LIBS_INIT}
-                                 )
+#ADD_EXECUTABLE(frust-test frust-test.cc)
+#TARGET_LINK_LIBRARIES(frust-test Manta_Engine
+#                                 Manta_UserInterface
+#                                 Manta_Model
+#                                 Manta_Image
+#                                 Manta_Interface
+#                                 Manta_Core
+#                                 SCIRun_Core
+#                                 ${CMAKE_THREAD_LIBS_INIT}
+#                                 )
 
 SET (BUILD_V3C1_TOOLS 0 CACHE BOOL "Include .v3c1 tools")
 IF (BUILD_V3C1_TOOLS) 

Modified: trunk/StandAlone/manta.cc
==============================================================================
--- trunk/StandAlone/manta.cc   (original)
+++ trunk/StandAlone/manta.cc   Fri Jan 20 15:03:05 2006
@@ -246,7 +246,7 @@
           printList(cerr, rtrt->listCameras());
           throw IllegalArgument( s, i, args );
         }
-      } else if(arg == "-bbcamera"){
+      } else if(arg == "-bbcamera" || arg == "-autoview"){
         compute_bb_camera = true;  
         
       } else if(arg == "-res"){
@@ -484,29 +484,11 @@
 Scene* createDefaultScene()
 {
   // Create a default scene.  This scene is used for benchmarks, so
-  // please do not change it.  Please create a new scene instead
+  // please do not change it.  Please create a new scene instead.
+  // Don't even put any #ifdefs in it or code that is commented out.
   Scene* scene = new Scene();
 
-  // Set only one of these #ifs to 1.
-#if 1
   scene->setBackground(new 
ConstantBackground(ColorDB::getNamedColor("SkyBlue3")*0.5));
-#elif 0
-  scene->setBackground(new TextureBackground(new 
Constant<Color>(Color(RGBColor(.2,1,1))), Vector(0,1,0)));
-#elif 0
-  scene->setBackground(new TextureBackground
-                       (new MarbleTexture<Color>(Color(RGB(0.1,0.2,0.5)),
-                                                 Color(RGB(0.7,0.8,1.0)),
-                                                 1.0, 1.0, 15.0,
-                                                 6, 2.0, 0.6 ),
-                        Vector(0,1,0)));
-#elif 0
-  scene->setBackground(new TextureBackground
-                       (new CheckerTexture<Color>(Color(RGBColor(1,0,0)),
-                                                  Color(RGBColor(0,0,1)),
-                                                  Vector(10,0,0),
-                                                  Vector(0,10,0)),
-                        Vector(0,1,0)));
-#endif
 
   Material* red=new Phong(Color(RGBColor(.6,0,0)),
                           Color(RGBColor(.6,.6,.6)), 32, 
(ColorComponent)0.4);
@@ -531,7 +513,6 @@
   UniformMapper* uniformmap = new UniformMapper();
   floor->setTexCoordMapper(uniformmap);
   world->add(floor);
-  //  red = new Flat(Color(RGBColor(1,0.1,0.2)));
   world->add(new Sphere(red, Point(0,0,1.2), 1.0));
   scene->setObject(world);
        

Modified: trunk/SwigInterface/manta.i
==============================================================================
--- trunk/SwigInterface/manta.i (original)
+++ trunk/SwigInterface/manta.i Fri Jan 20 15:03:05 2006
@@ -170,23 +170,21 @@
 
 %{
 #include <Core/Geometry/Ray.h>
-#include <Interface/HitInfo.h>
-#include <Interface/RayPacket.h>
 #include <Interface/Context.h>
 #include <Interface/Object.h>
 #include <Interface/Primitive.h>
 #include <Interface/TexCoordMapper.h>
+#include <Interface/RayPacket.h>
 #include <Interface/Light.h>
 #include <Interface/LightSet.h>
 %}
 
 %include <Core/Geometry/Ray.h>
-%include <Interface/HitInfo.h>
-%include <Interface/RayPacket.h>
 %include <Interface/Context.h>
 %include <Interface/Object.h>
 %include <Interface/Primitive.h>
 %include <Interface/TexCoordMapper.h>
+%include <Interface/RayPacket.h>
 %include <Interface/Light.h>
 %include <Interface/LightSet.h>
 

Modified: trunk/UserInterface/CameraPathAutomator.cc
==============================================================================
--- trunk/UserInterface/CameraPathAutomator.cc  (original)
+++ trunk/UserInterface/CameraPathAutomator.cc  Fri Jan 20 15:03:05 2006
@@ -70,13 +70,15 @@
   interval_start( 1 ),
   interval_last ( total_points-2 )
 {
-  eye    = new Point[total_points];
-  lookat = new Point[total_points];
+  eye    = new Vector[total_points];
+  lookat = new Vector[total_points];
   up     = new Vector[total_points];
 
-  memcpy( eye, eye_, total_points*sizeof(Point) );
-  memcpy( lookat, lookat_, total_points*sizeof(Point) );
-  memcpy( up, up_, total_points*sizeof(Vector) );
+  for(int i = 0; i < total_points; ++i) {
+    eye[i]    = Vector(eye_[i]);
+    lookat[i] = Vector(lookat_[i]);
+    up[i]     = up_[i];
+  }
 }
 
 
@@ -137,8 +139,8 @@
   fseek( file, SEEK_SET, 0 );
 
   // Allocate storage for points.
-  eye    = new Point [total_points];
-  lookat = new Point [total_points];
+  eye    = new Vector[total_points];
+  lookat = new Vector[total_points];
   up     = new Vector[total_points];
 
   
/////////////////////////////////////////////////////////////////////////////
@@ -178,8 +180,7 @@
     
       
/////////////////////////////////////////////////////////////////////////
       // Parse eye, lookat and up from the args.
-      Point  eye_, lookat_;
-      Vector up_;
+      Vector eye_, lookat_, up_;
       
       bool got_eye = false;
       bool got_lookat = false; 
@@ -187,14 +188,14 @@
       
       for (int i=0;i<(int)args.size();++i) {
         if (args[i] == "-eye") {
-          if (!getPointArg(i,args,eye_)) {
+          if (!getVectorArg(i,args,eye_)) {
             sprintf(error_message, "CameraPathAutomator -eye input line: 
%d", line_num );
             throw new IllegalArgument(error_message, i, args);
           }
           got_eye = true;
         }
         else if (args[i] == "-lookat") {
-          if (!getPointArg(i,args,lookat_)) {
+          if (!getVectorArg(i,args,lookat_)) {
             sprintf(error_message, "CameraPathAutomator -lookat input line: 
%d", line_num );
             throw new IllegalArgument(error_message, i, args);
           }
@@ -257,8 +258,8 @@
   int behavior = PATH_STOP;
   int start = 0, last = 0;
   
-  Real delta_t    = 0.0;
-  Real delta_time = 0.0;
+  Real delta_t    = 0;
+  Real delta_time = 0;
 
   for (int i=0; i<args.size(); ++i) {
     if (args[i] == "-file") {
@@ -302,10 +303,10 @@
   automator->set_loop_behavior( behavior );
   
   // Check to see if either delta was specified on the command line.
-  if (delta_t != 0.0) {
+  if (delta_t != 0) {
     automator->set_delta_t( delta_t );
   }
-  if (delta_time != 0.0) {
+  if (delta_time != 0) {
     automator->set_delta_time( delta_time );
   }
 
@@ -326,8 +327,7 @@
 // Implementation of the interpolator.
 void CameraPathAutomator::run_automator() {
 
-  Point current_eye, current_lookat;
-  Vector current_up;
+  Vector current_eye, current_lookat, current_up;
   
   int current_point = 0;
 
@@ -344,38 +344,43 @@
   
   do {
     
-    
/////////////////////////////////////////////////////////////////////////////
+    
//////////////////////////////////////////////////////////////////////////
     // Main Automator loop.
-    for (current_point=first_point;(current_point<last_point) && 
(loop_behavior!=PATH_ABORT);++current_point) {
-    
-      
///////////////////////////////////////////////////////////////////////////
+    for (current_point=first_point;
+         (current_point<last_point) && (loop_behavior!=PATH_ABORT);
+         ++current_point) {
+
+      
////////////////////////////////////////////////////////////////////////
       // Sample by delta_t between the points.
-      for (Real t=0.0; (t<(1.0-delta_t)) && (loop_behavior!=PATH_ABORT); 
t+=delta_t) {
+      for (Real t=0; t<(1-delta_t) && loop_behavior!=PATH_ABORT; t+=delta_t) 
{
 
         // Evaluate the spline.
         // NOTE: operator & is overloaded by Vector to return (Real *)
         // NOTE: none of the necessary operations are defined for Points...
         //       so we cast to vectors for the interpolation.
-      
-        catmull_rom_interpolate( (Vector *)&eye[current_point],    t, 
*((Vector *)&current_eye) );
-        catmull_rom_interpolate( (Vector *)&lookat[current_point], t, 
*((Vector *)&current_lookat) );
-        catmull_rom_interpolate( (Vector *)&up[current_point],     t, 
current_up );
+
+        catmull_rom_interpolate( &eye[current_point],    t, current_eye);
+        catmull_rom_interpolate( &lookat[current_point], t, current_lookat);
+        catmull_rom_interpolate( &up[current_point],     t, current_up );
 
         // Send the transaction to manta.
-        getMantaInterface()->addTransaction("CameraPathAutomator",
-                                            Callback::create(this, 
&CameraPathAutomator::mantaSetCamera,
-                                                             current_eye, 
current_lookat, current_up ));
+        getMantaInterface()->addTransaction
+          ("CameraPathAutomator",
+           Callback::create(this, &CameraPathAutomator::mantaSetCamera,
+                            Point(current_eye), Point(current_lookat),
+                            current_up ));
 
         // Record the time of this transaction before a potential sync
-        double start_time = SCIRun::Time::currentSeconds();      
-      
+        double start_time = SCIRun::Time::currentSeconds();
+
         // Check to see if this is a synchronization point.
         if (sync_frames && ((transaction_number % sync_frames) == 0)) {
 
           // Add a synchronization transaction.
-          getMantaInterface()->addTransaction("CameraPathAutomator-Sync",
-                                              Callback::create(this, 
&CameraPathAutomator::mantaSynchronize,
-                                                               
transaction_number ));
+          getMantaInterface()->addTransaction
+            ("CameraPathAutomator-Sync",
+             Callback::create(this, &CameraPathAutomator::mantaSynchronize,
+                              transaction_number ));
 
           // Wait for the render thread.
           synchronize_barrier.wait( 2 );
@@ -383,7 +388,7 @@
 
         transaction_number++;
 
-        
/////////////////////////////////////////////////////////////////////////
+        
//////////////////////////////////////////////////////////////////////
         // Wait for delta_time seconds.
         while ((SCIRun::Time::currentSeconds()-start_time) < delta_time);
       }
@@ -392,7 +397,7 @@
     // Compute the average fps for this run.
     int total_frames = getMantaInterface()->getCurrentFrame() - start_frame;
     average_fps = 
(Real)total_frames/(SCIRun::Time::currentSeconds()-start_seconds);
-    
+
     std::cerr << "Path complete. "    << total_frames
               << " frames. Avg fps: " << average_fps << std::endl;
   }
@@ -412,8 +417,10 @@
 
///////////////////////////////////////////////////////////////////////////////
 
///////////////////////////////////////////////////////////////////////////////
 
-void CameraPathAutomator::mantaSetCamera( const Point eye_, const Point 
lookat_, const Vector up_ ) {
-  
+void CameraPathAutomator::mantaSetCamera( const Point eye_,
+                                          const Point lookat_,
+                                          const Vector up_ ) {
+
   // Reset the current camera.
   getMantaInterface()->getCamera( channel )->reset( eye_, up_, lookat_ );
 }

Modified: trunk/UserInterface/CameraPathAutomator.h
==============================================================================
--- trunk/UserInterface/CameraPathAutomator.h   (original)
+++ trunk/UserInterface/CameraPathAutomator.h   Fri Jan 20 15:03:05 2006
@@ -44,14 +44,18 @@
   using std::string;
   using std::vector;
   using SCIRun::Barrier;
-  
+
   class CameraPathAutomator : public AutomatorUI {
   private:
 
     
///////////////////////////////////////////////////////////////////////////
     // Control points.
-    Point  *eye;
-    Point  *lookat;
+    //
+    // These are all vectors, because we have to do operators with
+    // them that don't exist for Points.  Points passed in are
+    // converted to Vectors, so the API remains the same.
+    Vector *eye;
+    Vector *lookat;
     Vector *up;
     int total_points;
 
@@ -61,7 +65,7 @@
 
     // Minimum time to wait between camera movements.
     Real delta_time;
-    
+
     // Channel to apply camera changes to.
     int channel;
 
@@ -85,32 +89,38 @@
 
     // fps for the last complete run of this automator.
     Real average_fps;
-    
+
   public:
     // Loop Behaviors
     enum { PATH_STOP, PATH_EXIT, PATH_LOOP, PATH_ABORT };
 
-    CameraPathAutomator( MantaInterface *manta_interface_, int channel_, int 
warmup_, const string &file_name, 
+    CameraPathAutomator( MantaInterface *manta_interface_, int channel_,
+                         int warmup_, const string &file_name,
                          Real delta_t_ = 0.2, Real delta_time_ = 0.2 );
-    
-    CameraPathAutomator( MantaInterface *manta_interface_, int channel_, int 
warmup_,
-                         Point *eye_, Point *lookat_, Vector *up_, int 
total_points_,
+
+    CameraPathAutomator( MantaInterface *manta_interface_, int channel_,
+                         int warmup_, Point *eye_, Point *lookat_,
+                         Vector *up_, int total_points_,
                          Real delta_t_ = 0.2, Real delta_time_ = 0.2 );
     ~CameraPathAutomator();
 
     // Create method called by RTRT_register.
-    static UserInterface *create( const vector<string> &args, MantaInterface 
*manta_interface_ );
+    static UserInterface *create( const vector<string> &args,
+                                  MantaInterface *manta_interface_ );
 
     // Implementation of the interpolator.
     virtual void run_automator();
-    
-    // This method is called by the manta rendering thread to update the 
camera.
-    void mantaSetCamera( const Point eye_, const Point lookat_, const Vector 
up_ );
+
+    // This method is called by the manta rendering thread to update
+    // the camera.
+    void mantaSetCamera( const Point eye_, const Point lookat_,
+                         const Vector up_ );
 
     // This method is called by the manta rendering thread to synchronize.
     void mantaSynchronize( int issue_transaction );
 
-    // This may be called to write the camera path to a specified file in 
the correct format.
+    // This may be called to write the camera path to a specified file
+    // in the correct format.
     void write_path( const string &file_name );
 
     // Accessors.
@@ -118,7 +128,7 @@
 
     inline Real get_delta_t()                { return delta_t; };
     inline void set_delta_t( Real delta_t_ ) { delta_t = delta_t_; };
-    
+
     inline Real get_delta_time()                   { return delta_time; };
     inline void set_delta_time( Real delta_time_ ) { delta_time = 
delta_time_; };
 

Modified: trunk/UserInterface/XWindowUI.cc
==============================================================================
--- trunk/UserInterface/XWindowUI.cc    (original)
+++ trunk/UserInterface/XWindowUI.cc    Fri Jan 20 15:03:05 2006
@@ -11,7 +11,7 @@
 #include <Core/Exceptions/InternalError.h>
 #include <Core/Geometry/AffineTransform.h>
 #include <Core/Math/MiscMath.h>
-#include <Core/Math/Trig.h>
+#include <Core/Math/Expon.h>
 #include <Core/Thread/Runnable.h>
 #include <Core/Thread/Thread.h>
 #include <Core/XUtils/XHelper.h>
@@ -41,11 +41,8 @@
 #define TOKEN_LOCK 2
 
 using namespace Manta;
+using namespace SCIRun;
 using namespace std;
-using SCIRun::Abs;
-using SCIRun::ErrnoException;
-using SCIRun::InternalError;
-using SCIRun::Thread;
 
 UserInterface* XWindowUI::create(const vector<string>& args,
                                  MantaInterface *rtrt_interface)
@@ -402,7 +399,7 @@
   register_key(0, XStringToKeysym("v"),
                "autoview",
                Callback::create(this, &XWindowUI::autoview));
-       register_key(0, XStringToKeysym("c"),
+  register_key(0, XStringToKeysym("c"),
                "output camera",
                Callback::create(this, &XWindowUI::output_camera));           
                                   
   register_key(0, XStringToKeysym("Escape"),

Modified: trunk/fox/FManta/CMakeLists.txt
==============================================================================
--- trunk/fox/FManta/CMakeLists.txt     (original)
+++ trunk/fox/FManta/CMakeLists.txt     Fri Jan 20 15:03:05 2006
@@ -1,14 +1,17 @@
+# Look for library here before you look in Thirdparty path
+SET(FOX_INSTALL_PATH "" CACHE STRING "Default search path for Fox install")
+
 # Determine the version of fox to use. Case sensitive
 SET(FOX_STATIC  FOX-1.5 CACHE STRING "Fox Library version string")
 
 # Search for the actual fox library.
 FIND_LIBRARY( FOUND_FOX_LIB     NAMES ${FOX_STATIC}
-                                PATHS ${THIRD_PARTY_LIBRARY_PATH} 
/usr/local/lib /usr/lib
+                                PATHS ${FOX_INSTALL_PATH}/lib 
${THIRD_PARTY_LIBRARY_PATH} /usr/local/lib /usr/lib
                                 DOC "Fox library path" )
 
 # Seach for the fox include directory.
 STRING(TOLOWER ${FOX_STATIC} FOX_STATIC_LOWERCASE)
-FIND_PATH   ( FOUND_FOX_INCLUDE fx.h 
${THIRD_PARTY_INCLUDE_PATH}/${FOX_STATIC_LOWERCASE}
+FIND_PATH   ( FOUND_FOX_INCLUDE fx.h 
${FOX_INSTALL_PATH}/include/${FOX_STATIC_LOWERCASE} 
${THIRD_PARTY_INCLUDE_PATH}/${FOX_STATIC_LOWERCASE}
               DOC "Fox Include path" )   
 
 

Modified: trunk/fox/FManta/FMantaImageFrame.cc
==============================================================================
--- trunk/fox/FManta/FMantaImageFrame.cc        (original)
+++ trunk/fox/FManta/FMantaImageFrame.cc        Fri Jan 20 15:03:05 2006
@@ -152,18 +152,19 @@
        
        // Create a ray packet.
        RayPacketData data;
-       RayPacket rays( data, 1, 0, 0 );
+       RayPacket rays( data, 0, 1, 0, 0 );
        
        // Shoot the ray.
        Color color;
        rtrt->shootOneRay( color, rays, image_x, image_y, manta_channel );
        
        // Check for a result.
-       if (rays.hitInfo(0).wasHit()) {
+       if (rays.wasHit(0)) {
        
-               // Get the normal.
-               result_position = rays.get(0).hitPosition;
-               result_normal   = rays.get(0).normal;
+               // Get the normal and hit position.  shootOneRay will compute
+               // these for us.
+               result_position = rays.getHitPosition(0);
+               result_normal   = rays.getNormal(0);
        
                return true;
        }

Modified: trunk/fox/FManta/FMantaRecorder.cc
==============================================================================
--- trunk/fox/FManta/FMantaRecorder.cc  (original)
+++ trunk/fox/FManta/FMantaRecorder.cc  Fri Jan 20 15:03:05 2006
@@ -305,7 +305,9 @@
   stop_button->enable();
 
   // Add a fox idle mode chore to record the camera position.
-  getApp()->addTimeout(this, ID_RECORD_CHORE, record_time_interval*1000.0, 0 
);
+  getApp()->addTimeout(this, ID_RECORD_CHORE,
+                       static_cast<unsigned int>(record_time_interval*1000),
+                       0 );
   
   return 1;
 }
@@ -438,7 +440,9 @@
 
   // Send a timeout for the next record event.
   if (record_iter < total_record_points) {
-    getApp()->addTimeout(this, ID_RECORD_CHORE, record_time_interval*1000.0, 
0 );
+    getApp()->addTimeout(this, ID_RECORD_CHORE,
+                         static_cast<unsigned 
int>(record_time_interval*1000),
+                         0 );
   }
   else {
     stop_button->disable();

Modified: trunk/fox/disco_demo/Engine/ImageTraversers/DiscoImageTraverser.cc
==============================================================================
--- trunk/fox/disco_demo/Engine/ImageTraversers/DiscoImageTraverser.cc  
(original)
+++ trunk/fox/disco_demo/Engine/ImageTraversers/DiscoImageTraverser.cc  Fri 
Jan 20 15:03:05 2006
@@ -170,7 +170,7 @@
       int flags = RayPacket::HaveImageCoordinates | RayPacket::ConstantEye;
 
       RayPacketData ray_data;
-      RayPacket     ray_packet( ray_data, 0, 0, flags );
+      RayPacket     ray_packet( ray_data, 0, 0, 0, flags );
       
       // Total number of rays in packet.
       int packet_size = 0;

Modified: trunk/fox/disco_demo/Engine/Renderers/DiscoRayTracer.cc
==============================================================================
--- trunk/fox/disco_demo/Engine/Renderers/DiscoRayTracer.cc     (original)
+++ trunk/fox/disco_demo/Engine/Renderers/DiscoRayTracer.cc     Fri Jan 20 
15:03:05 2006
@@ -88,7 +88,7 @@
 }
 
 void DiscoRayTracer::traceRays(const RenderContext& context, RayPacket& 
rays) {
-  rays.resetHit();
+  rays.resetHits();
   context.scene->getObject()->intersect(context, rays);
 }
 
@@ -114,21 +114,21 @@
 {
   
   // Intersect the ray packet with the scene.
-  ray_packet.resetHit();
+  ray_packet.resetHits();
   context.scene->getObject()->intersect(context, ray_packet);
 
   // Send hit rays to the per sample shader and missed rays to
   // the background shader.
-  for(int i = 0;i<ray_packet.getSize();){
+  for(int i = ray_packet.begin();i<ray_packet.end();){
 
     // Call the per-sample shader.
-    if(ray_packet.hitInfo(i).wasHit()){
+    if(ray_packet.wasHit(i)){
       int end = i+1;
 
       // Set the tile packet hit flag.
       tile_packet.get(i).flags |= TilePacket::WAS_HIT;
 
-      while(end < ray_packet.getSize() && ray_packet.hitInfo(end).wasHit()) {
+      while(end < ray_packet.end() && ray_packet.wasHit(end)) {
         tile_packet.get(end++).flags |= TilePacket::WAS_HIT;
       }
 
@@ -144,7 +144,7 @@
     // Call the background shader.
     else {
       int end = i+1;
-      while(end < ray_packet.getSize() && !ray_packet.hitInfo(end).wasHit())
+      while(end < ray_packet.end() && !ray_packet.wasHit(end))
         end++;
       
       RayPacket subPacket(ray_packet, i, end);
@@ -152,7 +152,7 @@
 
       // Copy the background color over to the tile packet.
       for (int j=i;j<end;++j) {
-        tile_packet.get(j).color = ray_packet.get(j).color;
+        tile_packet.get(j).color = ray_packet.getColor(j);
       }
       
       i=end;

Modified: trunk/fox/disco_demo/Engine/Shaders/AOShader.cc
==============================================================================
--- trunk/fox/disco_demo/Engine/Shaders/AOShader.cc     (original)
+++ trunk/fox/disco_demo/Engine/Shaders/AOShader.cc     Fri Jan 20 15:03:05 
2006
@@ -184,38 +184,32 @@
   int overlap     = (kernel_width-1)/2;
   int task_size   = total_directions / kernel_size;
   
-  for (int i=0;i<ray_packet.getSize();++i) {
+  for (int i=ray_packet.begin();i<ray_packet.end();++i) {
 
-    RayPacket::Element &e = ray_packet.get(i);
+    W[i] = ray_packet.getNormal(i);
 
-    W[i] = e.normal;
-    W[i].normalize();
-
-    // Determine if W can be crossed with 1,0,0
-    Real d = Dot( W[i],Vector(1,0,0));
-    if ((1.0-d) < 1e-6)
+    // Determine if W can be crossed with 1,0,0.  Normally we would do
+    // this by checking the dot product of W and [1,0,0], but since
+    // this is simpley W[0]*1 or W[0] we can simplify the expression.
+    if ((1-W[i][0]) < (Real)1e-6)
       U[i] = Cross( W[i], Vector(0,1,0) );
     else
       U[i] = Cross( W[i], Vector(1,0,0) );
-    U[i].normalize();
-
     V[i] = Cross( W[i], U[i] );
-      
   }
 
   // Create a ray packet for shooting secondary rays.
   RayPacketData secondary_data;
-  RayPacket     secondary_packet( secondary_data, 0, 1, 0 );
+  RayPacket     secondary_packet( secondary_data, 0, 0, 1, 0 );
 
   int secondary_size = 0;
     
   ///////////////////////////////////////////////////////////////////////////
   // Decide which directions to shoot based on TilePacket element task id.
   
-  for (int i=0;i<ray_packet.getSize();++i) {
+  for (int i=ray_packet.begin();i<ray_packet.end();++i) {
     
     TilePacket::Element &p = tile_packet.get( i );
-    RayPacket::Element  &e = ray_packet.get ( i );
 
     int task =
       ((p.tilex+overlap)%kernel_width) +
@@ -239,11 +233,11 @@
       p.color = Color(RGB(dir[0],dir[1],dir[2]));
       
       // Add a ray to the outgoing packet.
-      RayPacket::Element &out = secondary_packet.get( secondary_size++ );
-
       // Initialize the ray.
-      out.ray.set( e.hitPosition, dir );
-      out.hitInfo.reset( ambient_cutoff );
+      secondary_packet.setRay(secondary_size,
+                              ray_packet.getHitPosition(i), dir );
+      secondary_packet.resetHit(secondary_size, ambient_cutoff );
+      ++secondary_size;
       ++total_sent;
 
       // Check to see if the packet is filled.
@@ -255,8 +249,8 @@
         context.scene->getObject()->intersect( context, secondary_packet );
 
         // Count how many hit.
-        for (int j=0;j<secondary_packet.getSize();++j) {
-          if (secondary_packet.get(j).hitInfo.wasHit()) {
+        for (int j=secondary_packet.begin();j<secondary_packet.end();++j) {
+          if (secondary_packet.wasHit(j)) {
             ++total_hit;
           }
         }
@@ -264,6 +258,7 @@
         /////////////////////////////////////////////////////////////////////
         // Reset the secondary packet.
         secondary_packet.setAllFlags( 0 );
+        secondary_packet.resetHits();
         secondary_size = 0;
       }
     }
@@ -274,13 +269,14 @@
     context.scene->getObject()->intersect( context, secondary_packet );
       
     // Count how many hit.
-    for (int j=0;j<secondary_packet.getSize();++j) {
-      if (secondary_packet.get(j).hitInfo.wasHit()) {
+    for (int j=secondary_packet.begin();j<secondary_packet.end();++j) {
+      if (secondary_packet.wasHit(j)) {
         ++total_hit;
       }
     }
 
     secondary_packet.setAllFlags( 0 );
+    secondary_packet.resetHits();
     secondary_size = 0;
 
     ////////////////////////////////////////////////////////////////////////
@@ -289,8 +285,8 @@
 
     // Copy over the material color and normal
     p.color = Color(RGB(1,1,1));
-    p.normal = e.normal;
-  }    
+    p.normal = ray_packet.getNormal(i);
+  }
            
 }
   

Modified: trunk/fox/disco_demo/Interface/PerSampleShader.cc
==============================================================================
--- trunk/fox/disco_demo/Interface/PerSampleShader.cc   (original)
+++ trunk/fox/disco_demo/Interface/PerSampleShader.cc   Fri Jan 20 15:03:05 
2006
@@ -46,16 +46,16 @@
       
   // Go through the ray packet and shade them.  Group rays that hit the
   // same object and material to shade with a single shade call
-  for(int i = 0;i<rays.getSize();){
+  for(int i = rays.begin();i<rays.end();){
     
-    if(rays.hitInfo(i).wasHit()) {
+    if(rays.wasHit(i)) {
       
-      const Material* hit_matl = rays.hitInfo(i).hitMaterial();
+      const Material* hit_matl = rays.getHitMaterial(i);
 
       // Find consecutive rays which hit this material.
       int end = i+1;
-      while(end < rays.getSize() && rays.hitInfo(end).wasHit() &&
-            rays.hitInfo(end).hitMaterial() == hit_matl)
+      while(end < rays.end() && rays.wasHit(end) &&
+            rays.getHitMaterial(end) == hit_matl)
         end++;
 
       // Create a sub packet.
@@ -70,7 +70,7 @@
 
       // Find consecutive ray which don't hit anything.
       int end = i+1;
-      while(end < rays.getSize() && !rays.hitInfo(end).wasHit())
+      while(end < rays.end() && !rays.wasHit(end))
         end++;
 
       RayPacket subPacket(rays, i, end);
@@ -80,5 +80,5 @@
       
       i=end;
     }
-  }      
+  }
 }

Modified: trunk/fox/disco_demo/Interface/TilePacket.h
==============================================================================
--- trunk/fox/disco_demo/Interface/TilePacket.h (original)
+++ trunk/fox/disco_demo/Interface/TilePacket.h Fri Jan 20 15:03:05 2006
@@ -33,7 +33,6 @@
 // Abe Stephens
 
 #include <Interface/RayPacket.h>
-#include <Interface/HitInfo.h>
 
 namespace disco {
 
@@ -46,7 +45,7 @@
   // per sample results
   class TilePacket {
   public:
-    enum { MaxScratchpadSize = (HitInfo::MaxScratchpadSize-16) };
+    enum { MaxScratchpadSize = (RayPacketData::MaxScratchpadSize-16) };
     enum { WAS_HIT = 0x01,
            OVERLAP = 0x02 };
 

Modified: trunk/scenes/acceltest.cc
==============================================================================
--- trunk/scenes/acceltest.cc   (original)
+++ trunk/scenes/acceltest.cc   Fri Jan 20 15:03:05 2006
@@ -39,7 +39,7 @@
       string s;
       if ( !getStringArg( i, args, s ) )
         throw IllegalArgument("scene acceltest -group", i, args);
-      world = context.rtrt_int->makeGroup( s );
+      world = context.manta_interface->makeGroup( s );
       if ( world == 0 )
         throw IllegalArgument( "scene acceltest -group", i, args );
     } else if ( arg == "-model" ) {

Modified: trunk/scenes/objviewer.cc
==============================================================================
--- trunk/scenes/objviewer.cc   (original)
+++ trunk/scenes/objviewer.cc   Fri Jan 20 15:03:05 2006
@@ -47,7 +47,6 @@
 #include <Model/Primitives/TexTriangle.h>
 #include <Model/Primitives/Parallelogram.h>
 #include <Model/Primitives/Cube.h>
-#include <Model/Primitives/BvhTriangleMesh.h>
 #include <Model/Materials/Lambertian.h>
 #include <Model/Materials/Phong.h>
 #include <Model/Materials/Dielectric.h>
@@ -55,6 +54,7 @@
 #include <Model/Materials/Flat.h>
 #include <Model/Groups/Group.h>
 #include <Model/Groups/RealisticBvh.h>
+#include <Model/Groups/BVH.h>
 #include <Model/Lights/HeadLight.h>
 #include <Model/AmbientLights/ConstantAmbient.h>
 #include <Model/Backgrounds/ConstantBackground.h>
@@ -101,6 +101,13 @@
 int  fix_normals_degrees = 90;
 bool flip_faces          = false;
 
+enum {
+  RealisticBvh_Build,
+  BVH_Build
+};
+int  which_BVH           = RealisticBvh_Build;
+vector<string> BVH_args;
+
 ///////////////////////////////////////////////////////////////////////////
 // This function loads a specified .obj file into a runtime acceleration
 // structure for rendering.
@@ -132,6 +139,18 @@
     else if (args[i] == "-flip") {
       flip_faces = true;
     }
+    else if (args[i] == "-BVH") {
+      std::cout << "Doing BVH build\n";
+      which_BVH = BVH_Build;
+    }
+    else if (args[i] == "-bvh-build") {
+      string build;
+                       if (!getStringArg(i, args, build))
+                               throw IllegalArgument("objviewer -bvh_build 
<type:naive,table>",
+                              i, args);
+      BVH_args.push_back("-build");
+      BVH_args.push_back(build);
+    }
        }
 
   
/////////////////////////////////////////////////////////////////////////////
@@ -356,7 +375,8 @@
       Texture<ColorComponent> *reflection = new Constant<ColorComponent>( 
0.0 );
 
       // Phong shader.
-      material_array[index] = new Phong( diffuse_map, specular_map, Ns, 
reflection );      
+      material_array[index] = new Phong( diffuse_map, specular_map,
+                                         static_cast<int>(Ns), reflection );
     }
 
     
///////////////////////////////////////////////////////////////////////////
@@ -379,12 +399,20 @@
 // Create a single bvh to contain the mesh.
 Object *create_single_bvh( GLMmodel *model ) {
 
-       TexTriangle **triangle_array;
+       TexTriangle **triangle_array = 0;
+  BVH* bvh_group = 0;
        
        
/////////////////////////////////////////////////////////////////////////////
        // Allocate storage for primitives and materials.
        int total_triangles = model->numtriangles;
-       triangle_array = new TexTriangle *[ total_triangles ];
+  switch (which_BVH) {
+  case RealisticBvh_Build:
+    triangle_array = new TexTriangle *[ total_triangles ];
+    break;
+  case BVH_Build:
+    bvh_group = new BVH(BVH_args);
+    break;
+  }
        
        create_materials( model );
        
@@ -464,30 +492,49 @@
                                                texcoord[0], texcoord[1], 
texcoord[2]
                                                );
 
-      triangle_array[tri] = triangle;
-      
-      
+      switch (which_BVH) {
+      case RealisticBvh_Build:
+        triangle_array[tri] = triangle;
+        break;
+      case BVH_Build:
+        bvh_group->add(triangle);
+        break;
+      }
       ++tri;
                }
-               
+
                // Move to the next group.
                group = group->next;
                ++mtl;
        }
        
+  std::cerr << "Total triangles added: " << tri << std::endl;
+
+  Object* bvh = 0;
        
/////////////////////////////////////////////////////////////////////////////
-       // Create an acceleration structure.    
-       std::cerr << "Total triangles added: " << tri << std::endl;
-       
-       double time_begin = Time::currentSeconds();
-       
-       // Construct the bvh.
-       RealisticBvh *bvh = new RealisticBvh( (Object **)triangle_array, 
total_triangles );
-       
-       double time_end = Time::currentSeconds();
-       
-       std::cerr << "Bvh creation time: " << (time_end - time_begin) << " 
seconds." << std::endl;
-       
+       // Create an acceleration structure.
+  switch (which_BVH) {
+  case RealisticBvh_Build:
+    {
+
+      double time_begin = Time::currentSeconds();
+
+      // Construct the bvh.
+      bvh = new RealisticBvh( (Object **)triangle_array, total_triangles );
+
+      double time_end = Time::currentSeconds();
+
+      std::cerr << "Bvh creation time: " << (time_end - time_begin) << " 
seconds." << std::endl;
+    }
+    break;
+  case BVH_Build:
+    {
+      bvh = bvh_group;
+      // Preprocesing will be done during the preprocessing phase
+    }
+    break;
+  }
+
        
/////////////////////////////////////////////////////////////////////////////
        // Check the size of bounding boxes.
        PreprocessContext p_context;

Modified: trunk/scenes/primtest.cc
==============================================================================
--- trunk/scenes/primtest.cc    (original)
+++ trunk/scenes/primtest.cc    Fri Jan 20 15:03:05 2006
@@ -111,7 +111,7 @@
   else if(material == "redlambertian")
     matl=new Lambertian(Color(RGB(.6,0,0)));
   else if(material == "metal")
-    matl = new MetalMaterial(Color(RGB(0.7f,0.7f,0.8f)));
+    matl = new MetalMaterial(Color(RGB(0.7,0.7,0.8)));
   else if(material == "checker")
     matl = new Phong(new CheckerTexture<Color>(Color(RGB(.6,.6,.6)),
                                                Color(RGB(.6,0,0)),
@@ -214,9 +214,9 @@
         Point p((numx>1 ? i/static_cast<Real>(numx-1) - (Real)0.5 : 
0)*scale*2,
                 (numy>1 ? j/static_cast<Real>(numy-1) - (Real)0.5 : 
0)*scale*2,
                 0);
-  Primitive* prim = new Cube( matl, p-p2, p2.x()*1.156, p2.y()*1.156, 
p2.z()*1.156 );
-  if ( mapr )
-    prim->setTexCoordMapper( mapr );
+        Primitive* prim = new Cube( matl, p-p2, p+p2);
+        if ( mapr )
+          prim->setTexCoordMapper( mapr );
         group->add( prim );
       }
     }
@@ -227,13 +227,13 @@
     spinprim = prim;
   } else if(primtype == "box"){
     Point p2(scale/max/1.732, scale/max/1.732, scale/max/1.732);
-    Primitive* prim = new Cube(matl, Point(-p2.x(), -p2.y(), -p2.z()), 
p2.x()*2, p2.y()*2, p2.z()*2);
+    Primitive* prim = new Cube(matl, Point(-Vector(p2)), p2);
     if ( mapr )
       prim->setTexCoordMapper( mapr );
     spinprim = prim;
   } else if(primtype == "intersection"){
     Point p2(scale/max/1.414, scale/max/1.414, scale/max/1.414);
-    Primitive* o1 = new Cube(matl, Point(-p2.x(), -p2.y(), -p2.z()), 
p2.x()*2, p2.y()*2, p2.z()*2);
+    Primitive* o1 = new Cube(matl, Point(-Vector(p2)), p2);
     Primitive* o2 = new Sphere(matl, Point(0,0,0), scale/max);
     SphericalMapper* map = new SphericalMapper(Point(0,0,0), scale/max);
     o1->setTexCoordMapper( mapr ? mapr : map );
@@ -241,7 +241,7 @@
     spinprim = new Intersection(o1, o2);
   } else if(primtype == "difference"){
     Point p2(scale/max/1.414, scale/max/1.414, scale/max/1.414);
-    Primitive* o1 = new Cube(matl, Point(-p2.x(), -p2.y(), -p2.z()), 
p2.x()*2, p2.y()*2, p2.z()*2);
+    Primitive* o1 = new Cube(matl, Point(-Vector(p2)), p2);
     Primitive* o2 = new Sphere(matl, Point(0,0,0), scale/max);
     Real s = scale/max/(Real)1.414*2*(Real)(1+1.e-10);
     LinearMapper* map = new LinearMapper(Point(0,0,0),

Modified: trunk/tests/perftest/CMakeLists.txt
==============================================================================
--- trunk/tests/perftest/CMakeLists.txt (original)
+++ trunk/tests/perftest/CMakeLists.txt Fri Jan 20 15:03:05 2006
@@ -1,5 +1,5 @@
 
-ADD_EXECUTABLE(perftest1 perftest1.cc)
-TARGET_LINK_LIBRARIES(perftest1 Manta_Engine Manta_Model)
-
-TARGET_LINK_LIBRARIES(perftest1 ${CMAKE_THREAD_LIBS_INIT})
+#ADD_EXECUTABLE(perftest1 perftest1.cc)
+#TARGET_LINK_LIBRARIES(perftest1 Manta_Engine Manta_Model)
+#
+#TARGET_LINK_LIBRARIES(perftest1 ${CMAKE_THREAD_LIBS_INIT})




  • [MANTA] r857 - in trunk: . Core/Color Core/Geometry Core/Math Core/XUtils Engine/Control Engine/PixelSamplers Engine/Renderers Engine/Shadows Image Interface Model/AmbientLights Model/Backgrounds Model/Cameras Model/Groups Model/Instances Model/Intersections Model/Lights Model/Materials Model/MiscObjects Model/Primitives Model/TexCoordMappers Model/Textures SCIRun/include/sci_defs StandAlone SwigInterface UserInterface fox/FManta fox/disco_demo/Engine/ImageTraversers fox/disco_demo/Engine/Renderers fox/disco_demo/Engine/Shaders fox/disco_demo/Interface scenes tests/perftest, bigler, 01/20/2006

Archive powered by MHonArc 2.6.16.

Top of page