Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r551 - in branches/itanium2: Model/Groups StandAlone


Chronological Thread 
  • From: bigler@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r551 - in branches/itanium2: Model/Groups StandAlone
  • Date: Wed, 14 Sep 2005 17:07:45 -0600 (MDT)

Author: bigler
Date: Wed Sep 14 17:07:44 2005
New Revision: 551

Modified:
   branches/itanium2/Model/Groups/FrustumKDTree.cc
   branches/itanium2/Model/Groups/FrustumKDTree.h
   branches/itanium2/StandAlone/frust-test.cc
Log:


Model/Groups/FrustumKDTree.cc
Model/Groups/FrustumKDTree.h

  Removed PacketFrustum constructor that took a RayPacket.  Moved
  constructor that took the bounds of the frustum to the .cc file.
  Added debug_level members to PacketFrustum and FrustumKDTree
  classes.  Other debugging code optionally printed out.

StandAlone/frust-test.cc

  Updates to match the new API for PacketFrustum and FrustumKDTree.
  Turn debugging on.


Modified: branches/itanium2/Model/Groups/FrustumKDTree.cc
==============================================================================
--- branches/itanium2/Model/Groups/FrustumKDTree.cc     (original)
+++ branches/itanium2/Model/Groups/FrustumKDTree.cc     Wed Sep 14 17:07:44 
2005
@@ -32,8 +32,13 @@
 #include <float.h>
 #include <Model/Intersections/Plane.h>
 
+#include <sgi_stl_warnings_off.h>
+#include <iostream>
+#include <sgi_stl_warnings_on.h>
+
 using namespace Manta;
 using namespace Kdtree;
+using namespace std;
 
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
@@ -41,94 +46,31 @@
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
 
-// Create a frustum around the specified ray packet. Assumes all rays
-// have common origin and all rays have a common direction.
-PacketFrustum::PacketFrustum( const RayPacket &rays ) {
-
-  // Assume that all rays have a common origin.
-  frustum_origin = rays.get(0).ray.origin();
-
-  
/////////////////////////////////////////////////////////////////////////////
-  // Choose a plane to intersect all of the rays with based on the direction
-  // of the rays.
-  Point  plane_point;
-  Vector plane_normal;
-
-#if 0 // This seems to be handled by a parent somewhere, so I'll leave
-      // this commented out for now.
-
-  // If we don't have constant directions for our ray packet, we can't
-  // make one of these.
-  ASSERT(rays.getFlags & RayPacket::ConstantDirections);
-#endif
-
-  for (int i=0;i<3;++i) {
-    int signMask = rays.get(0).signMask[i];
-    frustum_direction[i] = signMask;
-
-    // Compute the plane point and normal.
-    plane_point [i] = (2.0 * signMask) - 1.0;    // signMask[i] now in {-1,1}
-    plane_normal[i] = plane_point[i] * 0.577350;
-  }
-
-  
/////////////////////////////////////////////////////////////////////////////
-  // Compute the axes of a coordinate system on the plane.
-  Vector plane_u, plane_v;
-
-  // Project x and y axis to the plane (plane normal is never either x or y).
-  plane_u = (Vector(1,0,0) -
-             (plane_normal * Dot( Vector(1,0,0), plane_normal ) ) );
-  plane_u.normalize();
-
-  plane_v = (Vector(0,1,0) -
-             (plane_normal * Dot( Vector(0,1,0), plane_normal ) ) );
-  plane_v.normalize();
-
-  
/////////////////////////////////////////////////////////////////////////////
-  // Find min and max corners of bounding frustum intersected with all rays 
in
-  // packet.
-  typedef VectorT<Real, 2> Vector2;
-  typedef PointT <Real, 2> Point2;
-
-  Vector2 min(  FLT_MAX,  FLT_MAX );
-  Vector2 max( -FLT_MAX, -FLT_MAX );
-
-  for (int i=0;i<rays.getSize();++i) {
-    const RayPacket::Element &e = rays.get(i);
-
-    // Intersect the ray with the plane.
-    Real t;
-    Intersection::intersectPlane( plane_point, plane_normal, t, e.ray );
-
-    // Compute intersection point in world coords.
-    Vector  i_vec( e.ray.origin() + (e.ray.direction() * t) );
-    i_vec = i_vec - (Vector)plane_point;
-
-    // Determine the intersection point in plane coordinates.
-    Point2 p;
-    p[0] = Dot( i_vec, plane_u );
-    p[1] = Dot( i_vec, plane_v );
-
-    // Check p against the bounds.
-    for (int j=0;j<2;++j) {
-      if (p[j] < min[j])      min[j] = p[j];
-      else if (p[j] > max[j]) max[j] = p[j];
+PacketFrustum::PacketFrustum( const Point &origin_,
+                              const Vector &bound0_, const Vector &bound1_,
+                              const Vector &bound2_, const Vector &bound3_,
+                              int debug_level) :
+  frustum_origin( origin_ ), debug_level(debug_level)
+{
+  frustum_bound[0] = bound0_;
+  frustum_bound[1] = bound1_;
+  frustum_bound[2] = bound2_;
+  frustum_bound[3] = bound3_;
+
+  // Compute frustum_direction from the bounds
+
+  if (debug_level > 0) {
+    cerr << "frustum_origin = "<<frustum_origin<<"\n";
+    for(int i = 0; i < 4; ++i) {
+      cerr << "frustum_bound["<<i<<"] = "<<frustum_bound[i]<<"\n";
+    }
+    for (int i=0;i<3;++i) {
+      frustum_direction[i] = 0;
+      cerr << "frustum_direction["<<i<<"] = "<<frustum_direction[i]<<"\n";
     }
   }
-
-  
/////////////////////////////////////////////////////////////////////////////
-  // Transform bounding corners into world vectors.
-  frustum_bound[0] = ((plane_point + (plane_u * min[0]) + (plane_v * 
min[1])) -
-                      frustum_origin);
-  frustum_bound[1] = ((plane_point + (plane_u * max[0]) + (plane_v * 
min[1])) -
-                      frustum_origin);
-  frustum_bound[2] = ((plane_point + (plane_u * max[0]) + (plane_v * 
max[1])) -
-                      frustum_origin);
-  frustum_bound[3] = ((plane_point + (plane_u * min[0]) + (plane_v * 
max[1])) -
-                      frustum_origin);
 }
 
-
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
 // FRUSTUM KD TREE  FRUSTUM KD TREE  FRUSTUM KD TREE  FRUSTUM KD TREE  FR
@@ -153,7 +95,7 @@
   }
 
   // Create a packet bounding frustum and intersect it with the tree.
-  PacketFrustum frustum( rays );
+  //  PacketFrustum frustum( rays );
 
   ///////////////////////////////////////////////////////////////////////
   // Intersect the frustum down the kdtree.
@@ -240,8 +182,12 @@
   // as a candidate starting point.
 
   if ( ((n[0] > min_edge[0]) && !above[0]) ||
-       ((n[1] > min_edge[1]) && !above[1]) )
+       ((n[1] > min_edge[1]) && !above[1]) ) {
+    if (debug_level > 0) cerr << "Overlap test tripped\n";
     return INTERSECT_BOTH;
+  }
+
+  if (debug_level > 0) cerr << "No overlap detected\n";
 
   // Determine A and B child -- A is closer to the frustum origin.
 #if 0

Modified: branches/itanium2/Model/Groups/FrustumKDTree.h
==============================================================================
--- branches/itanium2/Model/Groups/FrustumKDTree.h      (original)
+++ branches/itanium2/Model/Groups/FrustumKDTree.h      Wed Sep 14 17:07:44 
2005
@@ -53,22 +53,11 @@
                                          // have the same direction.
 
     public:
-      // Create a frustum around the specified ray packet. Assumes all
-      // rays have common origin and all rays are in the same
-      // hemisphere.
-      PacketFrustum( const RayPacket &rays );
-
       // Create a frustum given a common origin and four bounding vectors.
       PacketFrustum( const Point &origin_,
                      const Vector &bound0_, const Vector &bound1_,
-                     const Vector &bound2_, const Vector &bound3_ ) :
-        frustum_origin( origin_ )
-      {
-        frustum_bound[0] = bound0_;
-        frustum_bound[1] = bound1_;
-        frustum_bound[2] = bound2_;
-        frustum_bound[3] = bound3_;
-      }
+                     const Vector &bound2_, const Vector &bound3_,
+                     int debug_level = 0);
 
       // Accessors.
       const Point  &origin()       const { return frustum_origin;    };
@@ -76,6 +65,8 @@
 
       // Direction, sign mask of all bounding rays assumed to be the same.
       unsigned int direction( int i ) const { return frustum_direction[i]; };
+
+      int debug_level;
     };
 
     
///////////////////////////////////////////////////////////////////////////
@@ -89,7 +80,6 @@
     // individual rays are intersected with the tree.
 
     class FrustumKDTree : public KDTree {
-      // protected:
     public:
       
/////////////////////////////////////////////////////////////////////////
       // Create a frustum from a ray packet, and intersect with the kdtree.
@@ -117,11 +107,15 @@
     public:
       
/////////////////////////////////////////////////////////////////////////
       // Create a FrustumKDTree which data may be loaded into.
-      FrustumKDTree( Material *material_ ) : KDTree( material_ ) {  };
+      FrustumKDTree( Material *material_ ) :
+        KDTree( material_ ),
+        debug_level(0)
+      {  };
 
       // Use data owned by another kdtree.
       FrustumKDTree( KDTree *kdtree_, Material *material_ ) :
-        KDTree( kdtree_, material_ )
+        KDTree( kdtree_, material_ ),
+        debug_level(0)
       {  }
 
       virtual ~FrustumKDTree() {}
@@ -129,6 +123,9 @@
       // Intersection method -- Intersect frustum with kdtree then call
       // KDTree::intersect.
       //virtual void intersect(const RenderContext& context, RayPacket& 
rays) const;
+
+      // Data members
+      int debug_level;
     };
 
   }; // end namespace Kdtree

Modified: branches/itanium2/StandAlone/frust-test.cc
==============================================================================
--- branches/itanium2/StandAlone/frust-test.cc  (original)
+++ branches/itanium2/StandAlone/frust-test.cc  Wed Sep 14 17:07:44 2005
@@ -57,19 +57,20 @@
                                NULL, NULL,
                                NULL,NULL );
   // Ah, the ray packet
-  RayPacketData rp_data;
-  int rp_flags = RayPacket::ConstantOrigin | RayPacket::ConstantDirections;
-  RayPacket rays(rp_data, 2, 1, rp_flags);
-  Point ray_origin(20, 1, 20);
-  Point Pn(20,1,2), Pf(2,1,2);
-  rays.get(0).ray = Ray(ray_origin, Pn-ray_origin);
-  rays.get(1).ray = Ray(ray_origin, Pf-ray_origin);
+  Point ray_origin(20, 0, 20);
+  Point Pn(19,1,2), Pf(2,1,2);
+  cout << "Pn-ray_origin = "<<Pn-ray_origin<<"\n";
+  cout << "Pf-ray_origin = "<<Pf-ray_origin<<"\n";
 
   // Now for the PacketFrustum
-  PacketFrustum pfrustum(rays);
+  PacketFrustum pfrustum(ray_origin,
+                         Pn-ray_origin, Pn-ray_origin,
+                         Pf-ray_origin, Pf-ray_origin,
+                         1);
 
   // Now to try a test
   FrustumKDTree kdtree(NULL);
+  kdtree.debug_level = 1;
 
   FrustumKDTree::IntersectCase result =
     kdtree.frustum_node_intersect(render_context, &node, pfrustum, bbox);




  • [MANTA] r551 - in branches/itanium2: Model/Groups StandAlone, bigler, 09/14/2005

Archive powered by MHonArc 2.6.16.

Top of page