Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[Manta] r1997 - trunk/Model/Primitives


Chronological Thread 
  • From: roni@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [Manta] r1997 - trunk/Model/Primitives
  • Date: Fri, 18 Jan 2008 17:58:59 -0700 (MST)

Author: roni
Date: Fri Jan 18 17:58:58 2008
New Revision: 1997

Added:
   trunk/Model/Primitives/QuadFacedHexahedron.cc
   trunk/Model/Primitives/QuadFacedHexahedron.h
Modified:
   trunk/Model/Primitives/CMakeLists.txt
   trunk/Model/Primitives/ConvexQuad.cc
   trunk/Model/Primitives/ConvexQuad.h
Log:
Adding "quadrilateral faced hexahedron" primitive, which is just a
topological generalization of the cube.  Instantiate by supplying a
material pointer and eight vertices.  The first four vertices specify
the "bottom" face in counter-clockwise order, and the last four
specify the vertices connected to the bottom four vertices, making up
the "top" face.

Model/Primitives/ConvexQuad.cc
Model/Primitives/ConvexQuad.h

  Changing around some header inclusions and eliminating unneeded
dependencies.

Model/Primitives/CMakeLists.txt
Model/Primitives/QuadFacedHexahedron.cc
Model/Primitives/QuadFacedHexahedron.h

  Adding the QFHex and plugged it in.


Modified: trunk/Model/Primitives/CMakeLists.txt
==============================================================================
--- trunk/Model/Primitives/CMakeLists.txt       (original)
+++ trunk/Model/Primitives/CMakeLists.txt       Fri Jan 18 17:58:58 2008
@@ -34,6 +34,8 @@
      Primitives/Plane.h
      Primitives/PrimitiveCommon.cc
      Primitives/PrimitiveCommon.h
+     Primitives/QuadFacedHexahedron.cc
+     Primitives/QuadFacedHexahedron.h
      Primitives/Ring.cc
      Primitives/Ring.h
      Primitives/Sphere.cc

Modified: trunk/Model/Primitives/ConvexQuad.cc
==============================================================================
--- trunk/Model/Primitives/ConvexQuad.cc        (original)
+++ trunk/Model/Primitives/ConvexQuad.cc        Fri Jan 18 17:58:58 2008
@@ -1,7 +1,7 @@
 #include <Model/Primitives/ConvexQuad.h>
 #include <Core/Exceptions/BadPrimitive.h>
+#include <Core/Geometry/BBox.h>
 #include <Core/Geometry/Vector.h>
-#include <Core/Math/MiscMath.h>
 #include <Interface/Context.h>
 #include <Interface/RayPacket.h>
 #include <Model/Primitives/Plane.h>
@@ -46,7 +46,6 @@
     if(Dot(Cross(v[j]-v[i], v[k]-v[j]), normal) < 0){
       std::stringstream s;
       s << "ConvexQuad vertices (" << v[0] << ", " << v[1] << ", " << v[2] 
<< ", " << v[3] << ") do not specify a convex region";
-      //throw BadPrimitive("ConvexQuad vertices do not specify a convex 
region");
       throw BadPrimitive(s.str().c_str());
     }
   }

Modified: trunk/Model/Primitives/ConvexQuad.h
==============================================================================
--- trunk/Model/Primitives/ConvexQuad.h (original)
+++ trunk/Model/Primitives/ConvexQuad.h Fri Jan 18 17:58:58 2008
@@ -1,12 +1,10 @@
 #ifndef Model_Primitives_ConvexQuad_h
 #define Model_Primitives_ConvexQuad_h
 
-#include <Core/Geometry/BBox.h>
 #include <Model/Primitives/PrimitiveCommon.h>
 
 namespace Manta{
   class Material;
-  class Plane;
 
   class ConvexQuad : public PrimitiveCommon {
   public:

Added: trunk/Model/Primitives/QuadFacedHexahedron.cc
==============================================================================
--- (empty file)
+++ trunk/Model/Primitives/QuadFacedHexahedron.cc       Fri Jan 18 17:58:58 
2008
@@ -0,0 +1,94 @@
+#include <Model/Primitives/QuadFacedHexahedron.h>
+#include <Core/Geometry/BBox.h>
+#include <Core/Geometry/Vector.h>
+#include <Interface/Context.h>
+#include <Interface/RayPacket.h>
+
+using namespace Manta;
+
+const unsigned QuadFacedHexahedron::faceIndex[6][4] = { {0, 3, 2, 1},   
//bottom
+                                                        {0, 4, 7, 3},   
//left
+                                                        {2, 3, 7, 6},   
//back
+                                                        {1, 2, 6, 5},   
//right
+                                                        {0, 1, 5, 4},   
//front
+                                                        {4, 5, 6, 7} }; //top
+
+QuadFacedHexahedron::QuadFacedHexahedron(Material *matl,
+                                         const Vector& v0, const Vector& v1, 
const Vector& v2, const Vector& v3,
+                                         const Vector& v4, const Vector& v5, 
const Vector& v6, const Vector& v7)
+  : PrimitiveCommon(matl)
+{
+  // Save the vertices.
+  v[0] = v0;
+  v[1] = v1;
+  v[2] = v2;
+  v[3] = v3;
+  v[4] = v4;
+  v[5] = v5;
+  v[6] = v6;
+  v[7] = v7;
+}
+
+void QuadFacedHexahedron::computeBounds(const PreprocessContext& context,
+                                        BBox& bbox) const {
+  for(unsigned i=0; i<8; i++)
+    bbox.extendByPoint(v[i]);
+}
+
+void QuadFacedHexahedron::intersect(const RenderContext& context,
+                                    RayPacket& rays) const {
+  // Each face is a quad, so compute the intersection with each one
+  // and pick the smallest positive t value.
+  for(int i=rays.begin(); i<rays.end(); i++){
+    //Real smallest_t = std::numeric_limits<Real>::max();
+    Real smallest_t = rays.getMinT(i);
+    int hitface = -1;
+
+    for(unsigned j=0; j<6; j++){
+      const Vector *vv[] = {v + faceIndex[j][0],
+                            v + faceIndex[j][1],
+                            v + faceIndex[j][2],
+                            v + faceIndex[j][3]};
+
+      // Ray plane intersection, with the plane containing v0->v3,
+      const Vector normal = Cross(*(vv[1])-*(vv[0]), *(vv[3])-*(vv[0]));
+
+      // Check if ray is parallel to plane.
+      Real dn = Dot(rays.getDirection(i), normal);
+      if(dn == 0)
+        continue;
+
+      Real ao = Dot(*(vv[0])-rays.getOrigin(i), normal);
+      Real t = ao/dn;
+
+      const Vector p = rays.getOrigin(i) + t*rays.getDirection(i);
+
+      // See if the hit position falls inside the quad.
+      bool inside = true;
+      for(int k=0; k<4; k++){
+        const Real d = Dot(Cross(*(vv[(k+1)%4]) - *(vv[k]), p - *(vv[k])), 
normal);
+        if(d < 0.0){
+          inside = false;
+          break;
+        }
+      }
+
+      if(inside && (t < smallest_t) ){
+        hitface = j;
+        smallest_t = t;
+      }
+    }
+
+    if(hitface >= 0){
+      rays.hit(i, smallest_t, getMaterial(), this, getTexCoordMapper());
+      rays.getScratchpad<int>(0)[i] = hitface;
+    }
+  }
+}
+
+void QuadFacedHexahedron::computeNormal(const RenderContext& context,
+                                        RayPacket& rays) const {
+  for(int i=rays.begin(); i<rays.end(); i++)
+    rays.setNormal(i, Cross(v[faceIndex[rays.getScratchpad<int>(0)[i]][1]] - 
v[faceIndex[rays.getScratchpad<int>(0)[i]][0]],
+                            v[faceIndex[rays.getScratchpad<int>(0)[i]][3]] - 
v[faceIndex[rays.getScratchpad<int>(0)[i]][0]]));
+}

Added: trunk/Model/Primitives/QuadFacedHexahedron.h
==============================================================================
--- (empty file)
+++ trunk/Model/Primitives/QuadFacedHexahedron.h        Fri Jan 18 17:58:58 
2008
@@ -0,0 +1,31 @@
+#ifndef Manta_Model_QuadFacedHexahedron_h
+#define Manta_Model_QuadFacedHexahedron_h
+
+#include <Model/Primitives/PrimitiveCommon.h>
+
+namespace Manta{
+  class Material;
+
+  class QuadFacedHexahedron : public PrimitiveCommon {
+  public:
+    QuadFacedHexahedron(Material *matl,
+                        const Vector& v0, const Vector& v1, const Vector& 
v2, const Vector& v3,
+                        const Vector& v4, const Vector& v5, const Vector& 
v6, const Vector& v7);
+
+    void computeBounds(const PreprocessContext& context,
+                      BBox& bbox_) const;
+
+    void intersect(const RenderContext& context,
+                  RayPacket& rays) const;
+
+    void computeNormal(const RenderContext& context,
+                      RayPacket& rays) const;
+
+  private:
+    static const unsigned faceIndex[6][4];
+
+    Vector v[8];
+  };
+}
+
+#endif




  • [Manta] r1997 - trunk/Model/Primitives, roni, 01/18/2008

Archive powered by MHonArc 2.6.16.

Top of page