Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r788 - in branches/itanium2: Interface Model/Primitives scenes


Chronological Thread 
  • From: abe@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r788 - in branches/itanium2: Interface Model/Primitives scenes
  • Date: Wed, 14 Dec 2005 14:15:18 -0700 (MST)

Author: abe
Date: Wed Dec 14 14:15:17 2005
New Revision: 788

Modified:
   branches/itanium2/Interface/Primitive.h
   branches/itanium2/Model/Primitives/HeavyTriangle.cc
   branches/itanium2/Model/Primitives/HeavyTriangle.h
   branches/itanium2/Model/Primitives/PrimitiveCommon.h
   branches/itanium2/Model/Primitives/TexTriangle.cc
   branches/itanium2/Model/Primitives/TexTriangle.h
   branches/itanium2/scenes/objviewer.cc
Log:

Final commit to the itanium2 branch. 

I promise. These changes were merged in from the merged trunk for a 
comparison.

M    scenes/objviewer.cc
M    Model/Primitives/HeavyTriangle.h
M    Model/Primitives/TexTriangle.cc
M    Model/Primitives/HeavyTriangle.cc
M    Model/Primitives/PrimitiveCommon.h
M    Model/Primitives/TexTriangle.h
M    Interface/Primitive.h


Modified: branches/itanium2/Interface/Primitive.h
==============================================================================
--- branches/itanium2/Interface/Primitive.h     (original)
+++ branches/itanium2/Interface/Primitive.h     Wed Dec 14 14:15:17 2005
@@ -19,9 +19,8 @@
                               RayPacket& rays) const = 0;
     virtual void setTexCoordMapper(const TexCoordMapper* new_tex) = 0;
   private:
-         // These undefined private methods make it so that primitives 
cannot be copied.
-    // Primitive(const Primitive&);
-    // Primitive& operator=(const Primitive&);
+         Primitive(const Primitive&);
+    Primitive& operator=(const Primitive&);
   };
 }
 

Modified: branches/itanium2/Model/Primitives/HeavyTriangle.cc
==============================================================================
--- branches/itanium2/Model/Primitives/HeavyTriangle.cc (original)
+++ branches/itanium2/Model/Primitives/HeavyTriangle.cc Wed Dec 14 14:15:17 
2005
@@ -58,7 +58,7 @@
       TriangleHit& th = e.hitInfo.scratchpad<TriangleHit>();
       th.a = u;
       th.b = v;
-
+      th.ptr = getTexCoordMapper();
     }
   }
 }

Modified: branches/itanium2/Model/Primitives/HeavyTriangle.h
==============================================================================
--- branches/itanium2/Model/Primitives/HeavyTriangle.h  (original)
+++ branches/itanium2/Model/Primitives/HeavyTriangle.h  Wed Dec 14 14:15:17 
2005
@@ -44,7 +44,7 @@
   // Heavy triangle contains an edge triangle representation in addition to a
   // normal for each vertex.
   class HeavyTriangle : public PrimitiveCommon {
-  private:
+  protected:
     Point  point;
     Vector edge[2];
     Vector n[3];
@@ -52,6 +52,7 @@
   public:
     struct TriangleHit {
       Real a, b;
+      const void *ptr;
     };
 
     HeavyTriangle() : PrimitiveCommon( 0 ) { };

Modified: branches/itanium2/Model/Primitives/PrimitiveCommon.h
==============================================================================
--- branches/itanium2/Model/Primitives/PrimitiveCommon.h        (original)
+++ branches/itanium2/Model/Primitives/PrimitiveCommon.h        Wed Dec 14 
14:15:17 2005
@@ -27,6 +27,9 @@
   private:
     Material* material;
     const TexCoordMapper* tex;
+
+    PrimitiveCommon( const PrimitiveCommon & );
+    PrimitiveCommon &operator = ( const PrimitiveCommon & );
   };
 }
 

Modified: branches/itanium2/Model/Primitives/TexTriangle.cc
==============================================================================
--- branches/itanium2/Model/Primitives/TexTriangle.cc   (original)
+++ branches/itanium2/Model/Primitives/TexTriangle.cc   Wed Dec 14 14:15:17 
2005
@@ -5,6 +5,8 @@
 
 #include <Model/Intersections/TriangleEdge.h>
 
+#include <cassert>
+
 using namespace Manta;
 using namespace std;
 
@@ -20,16 +22,31 @@
     Real b = th.b;
     Real c = (1.0 - a - b);
 
-    e.texCoords = Point((tex[1] * a) + (tex[2] * b) +(tex[0] * c));
-    // e.texCoords = Point((t2 * a) + (t0 * b) +(t1 * c));
-    // e.texCoords = Point( tex[0] );
-        
-    // e.texCoords = Point( c, a, b );
+    TexTriangle *t = (TexTriangle *)th.ptr;
+    
+    e.texCoords = Point((t->tex[1] * a) + (t->tex[2] * b) +(t->tex[0] * c));
   }
   rays.setFlag( RayPacket::HaveTexture2|RayPacket::HaveTexture3 );
 }
 
 
-
+void TexTriangle::intersect(const RenderContext&, RayPacket& rays) const
+{
+  rays.normalizeDirections();
+  
+  for(int i=0; i<rays.getSize(); i++) {
+    RayPacket::Element& e = rays.get(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() )) {
+      
+      TriangleHit& th = e.hitInfo.scratchpad<TriangleHit>();
+      th.a = u;
+      th.b = v;
+      th.ptr = this;
+    }
+  }
+}
 
 

Modified: branches/itanium2/Model/Primitives/TexTriangle.h
==============================================================================
--- branches/itanium2/Model/Primitives/TexTriangle.h    (original)
+++ branches/itanium2/Model/Primitives/TexTriangle.h    Wed Dec 14 14:15:17 
2005
@@ -74,9 +74,12 @@
       computeTexCoords2( context, rays );
     }
 
-    
+    virtual void intersect(const RenderContext&, RayPacket& rays) const;    
   protected:
     Vector tex[3];
+
+    TexTriangle( const TexTriangle & );
+    TexTriangle &operator =( const TexTriangle & );
   };
 }
 

Modified: branches/itanium2/scenes/objviewer.cc
==============================================================================
--- branches/itanium2/scenes/objviewer.cc       (original)
+++ branches/itanium2/scenes/objviewer.cc       Wed Dec 14 14:15:17 2005
@@ -71,6 +71,8 @@
 #include <vector>
 #include <string>
 
+#include <cassert>
+
 using namespace std;
 
 using namespace Manta;
@@ -78,7 +80,6 @@
 using namespace Glm;
 
 static Object *create_single_bvh( GLMmodel *model );
-static Object *create_bvh_meshs ( GLMmodel *model );
 static void create_materials( GLMmodel *model );
 
 template< typename ValueType >
@@ -170,11 +171,8 @@
 
   
/////////////////////////////////////////////////////////////////////////////
   // Create the bvh.
-       Object *bvh = 0;        
-       if (use_single_bvh) 
-               bvh = create_single_bvh( model );
-       else 
-               bvh = create_bvh_meshs( model );
+       Object *bvh = create_single_bvh( model );
+
 
        
/////////////////////////////////////////////////////////////////////////////
        // Create the scene.
@@ -250,8 +248,8 @@
   if (file_name.size()) {
     // Load the image texture.
     try {
-      // texture = load_image_texture<Color>( path_name + file_name );
-      texture = new TexCoordTexture;
+      texture = load_image_texture<Color>( path_name + file_name );
+      // texture = new TexCoordTexture;
     }
     catch (SCIRun::Exception &e) {
       std::cerr << "Could not load diffuse map: "
@@ -321,14 +319,10 @@
     // unused default material..
     int index = i-1;
 
-
-
     Texture<Color> *diffuse_map  = check_for_texture( model_path, 
diffuse_map_name, diffuse );
     
     // Lambertian Shader.
-    material_array[index] = new Flat( diffuse_map );
-
-#if 0
+    // material_array[index] = new Flat( diffuse_map );
 
     
///////////////////////////////////////////////////////////////////////////
     // Check for a dielectric.
@@ -349,7 +343,7 @@
 
       Texture<Color> *diffuse_map  = check_for_texture( model_path, 
diffuse_map_name, diffuse );
       Texture<Color> *specular_map = check_for_texture( model_path, 
specular_map_name, specular );
-      Texture<ColorComponent> *reflection = new Constant<ColorComponent>( 
0.2 );
+      Texture<ColorComponent> *reflection = new Constant<ColorComponent>( 
0.0 );
 
       // Phong shader.
       material_array[index] = new Phong( diffuse_map, specular_map, Ns, 
reflection );      
@@ -363,7 +357,7 @@
       // Lambertian Shader.
       material_array[index] = new Lambertian( diffuse_map );
     }
-#endif 
+    
        }
 
 }
@@ -372,12 +366,12 @@
 // Create a single bvh to contain the mesh.
 Object *create_single_bvh( GLMmodel *model ) {
 
-       TexTriangle *triangle_array;
+       TexTriangle **triangle_array;
        
        
/////////////////////////////////////////////////////////////////////////////
        // Allocate storage for primitives and materials.
        int total_triangles = model->numtriangles;
-       triangle_array = new TexTriangle[ total_triangles ];
+       triangle_array = new TexTriangle *[ total_triangles ];
        
        create_materials( model );
        
@@ -414,9 +408,6 @@
       Vector normal[3];
       Vector texcoord[3];
 
-      // Only use two texture coords.
-      texcoord[2] = Vector( 0, 0, 0 );
-
                        for (int v=0;v<3;++v) {
                                int    index = model->triangles[ 
group->triangles[i] ].vindices[v];
                                float *f     = model->vertices+(index*3);
@@ -436,26 +427,33 @@
 
       }
 
-      for (int v=0; v<2; ++v) {
+      for (int v=0; v<3; ++v) {
         
         int index = model->triangles[ group->triangles[i] ].tindices[v];
-        float *f = model->texcoords+(index*3);
+        float *f = &model->texcoords[index*2];
 
         // Copy out the texcoord
         texcoord[v][0] = f[0];
                                texcoord[v][1] = f[1];
+        texcoord[v][2] = 1.0;
 
                        }
+
+      // for (int v=0;v<3;++v) {
+      //  texcoord[v] = Vector(vertex[v])+Vector(0.5,0.5,0.5);
+      //  texcoord[v][1] = texcoord[v][2];
+      // }
                        
                        // Create a new triangle.
-                       triangle_array[tri] = 
-                               TexTriangle( material,
-                     vertex[0], vertex[1]-vertex[0], vertex[2]-vertex[0],
-                     normal[0], normal[1], normal[2],
-                     texcoord[0], texcoord[1], texcoord[2]
-                     );
-      triangle_array[tri].setTexCoordMapper( &triangle_array[tri] );
+                       TexTriangle *triangle = new TexTriangle( material,
+                                               vertex[0], 
vertex[1]-vertex[0], vertex[2]-vertex[0],
+                                               normal[0], normal[1], 
normal[2],
+                                               texcoord[0], texcoord[1], 
texcoord[2]
+                                               );
 
+      triangle_array[tri] = triangle;
+      
+      
       ++tri;
                }
                
@@ -465,20 +463,13 @@
        }
        
        
/////////////////////////////////////////////////////////////////////////////
-       // Create an acceleration structure.
-       
-       // Make an array of pointers to triangles for input to the bvh.
-       Object **triangle_ptr_array = new Object *[ total_triangles ];
-       for (int i=0;i<total_triangles;++i) {
-               triangle_ptr_array[i] = triangle_array+i;
-       }
-       
+       // Create an acceleration structure.    
        std::cerr << "Total triangles added: " << tri << std::endl;
        
        double time_begin = Time::currentSeconds();
        
        // Construct the bvh.
-       RealisticBvh *bvh = new RealisticBvh( triangle_ptr_array, 
total_triangles );
+       RealisticBvh *bvh = new RealisticBvh( (Object **)triangle_array, 
total_triangles );
        
        double time_end = Time::currentSeconds();
        
@@ -494,230 +485,7 @@
        return bvh;
 }
 
-static Object *create_many_bvh( GLMmodel *model ) {
-       
-       Triangle *triangle_array;
-       
-       
/////////////////////////////////////////////////////////////////////////////
-       // Allocate storage for primitives and materials.
-       int total_triangles = model->numtriangles;
-       triangle_array = new Triangle[ total_triangles ];
-       
-       create_materials( model );
-       
-       int tri = 0;
-       int mtl = 0;
-       
-       // Lambertian *default_material = new Lambertian( Color(RGB( 1.0, 
0.0, 0.0 ) )  );
-       Material *default_material = new NormalMaterial();
-       
-       // Read in the groups.
-       GLMgroup *group = model->groups;
-       while (group != 0) {
-               
-               // Determine the material for this group.
-               Material *material;
-               if ((group->material-1) < model->nummaterials) {
-                       material = material_array[group->material-1];
-               }
-               else {
-                       material = default_material;
-               }
-               
-               // Copy out triangles.
-               int total_faces = group->numtriangles;
-               for (int i=0;i<total_faces;++i) {
-                       
-                       Point vertex[3];
-                       for (int v=0;v<3;++v) {
-                               int    index = model->triangles[ 
group->triangles[i] ].vindices[v];
-                               float *f     = model->vertices+(index*3);
-                               
-                               // Copy out the vertex.
-                               vertex[v][0] = f[0];
-                               vertex[v][1] = f[1];
-                               vertex[v][2] = f[2];
-                       }
-                       
-                       // Create a new triangle.
-                       triangle_array[tri++] = Triangle( material, 
vertex[0], vertex[1], vertex[2] );
-               }
-               
-               // Move to the next group.
-               group = group->next;
-               ++mtl;
-       }
-       
-       
/////////////////////////////////////////////////////////////////////////////
-       // Create an acceleration structure.
-       
-       // Make an array of pointers to triangles for input to the bvh.
-       Object **triangle_ptr_array = new Object *[ total_triangles ];
-       for (int i=0;i<total_triangles;++i) {
-               triangle_ptr_array[i] = triangle_array+i;
-       }
-       
-       std::cerr << "Total triangles added: " << tri << std::endl;
-       
-       double time_begin = Time::currentSeconds();
-       
-       // Construct the bvh.
-       RealisticBvh *bvh = new RealisticBvh( triangle_ptr_array, 
total_triangles );
-       
-       double time_end = Time::currentSeconds();
-       
-       std::cerr << "Bvh creation time: " << (time_end - time_begin) << " 
seconds." << std::endl;
-       
-       
/////////////////////////////////////////////////////////////////////////////
-       // Check the size of bounding boxes.
-       PreprocessContext p_context;
-       bvh->computeBounds( p_context, bounds );                        
-       
-       std::cerr << "Bvh: Bounding box " << bounds[0] << " : " << bounds[1] 
<< std::endl;      
-       
-       return bvh;
-}
-
-Object *create_bvh_meshs( GLMmodel *model ) {
-       
-       Point *vertex_array;
-       Vector *edge_array;
-       Vector *normal_array;
-       
-       typedef BvhTriangleMesh::IndexedTriangle IndexedTriangle;
-       IndexedTriangle *triangle_array;
-       
-       create_materials( model );
-
-       
/////////////////////////////////////////////////////////////////////////////
-       // Determine the total number of faces and normals.
-       int total_triangles = model->numtriangles;
-       int total_vnormals  = model->numnormals;
-       
-       // Allocate storage for vertex and edges.
-       vertex_array = new Point[ total_triangles ];
-       edge_array   = new Vector[ total_triangles*2 ];
-       
-       // Allocate storage for normals.
-       normal_array = new Vector[ total_vnormals ];
-
-       // Allocate storage for triangles.
-       triangle_array = new IndexedTriangle[ total_triangles ];
 
-       
/////////////////////////////////////////////////////////////////////////////
-       
-       // Keep track of iterators over the arrays.
-       int vertex = 0;
-       int edge   = 0;
-       int normal = 0;
-       int triangle = 0;
-       
-       // Copy all of the vertex normals out.
-       for (normal=0;normal<total_vnormals;++normal) {
-               normal_array[normal] = Vector( model->normals[1+(normal*3)],
-                                              model->normals[1+(normal*3)+1],
-                                                                             
                                                           
model->normals[1+(normal*3)+2] );
-       }
-       
-       // Copy all of the triangles out.
-       for (triangle=0;triangle<total_triangles;++triangle) {
-               
-               // Determine the three vertices of the triangle.
-               Point p[3];
-               for (int v=0;v<3;++v) {
-                       int    index = model->triangles[ triangle 
].vindices[v];
-                       float *f     = model->vertices+(index*3);
-                       
-                       p[v][0] = f[0];
-                       p[v][1] = f[1];
-                       p[v][2] = f[2];
-               }
-               
-               // Copy the v0 vertex.
-               triangle_array[triangle].v0 = vertex;
-               vertex_array[vertex++] = p[0];
-               
-               // Compute the edges of the triangle.
-               triangle_array[triangle].e0 = edge;
-               edge_array[edge++] = (p[1] - p[0]);
-               
-               triangle_array[triangle].e1 = edge;
-               edge_array[edge++] = (p[2] - p[0]);
-               
-               // Copy the vertex normal indices.
-               triangle_array[triangle].n0 = model->triangles[ triangle 
].nindices[0]-1;
-               triangle_array[triangle].n1 = model->triangles[ triangle 
].nindices[1]-1;
-               triangle_array[triangle].n2 = model->triangles[ triangle 
].nindices[2]-1;
-       }
-       
-       
/////////////////////////////////////////////////////////////////////////////
-       
-       // Allocate input array for the top level bvh.
-       Object **object_array = new Object *[ model->numgroups ];
-       int object = 0;
-       
-       Material *default_material = new NormalMaterial();
-       PreprocessContext context;
-       
-       // Create a bvh for each group.
-       GLMgroup *group = model->groups;
-       while (group != 0) {
-               
-               if (group->numtriangles > 0) {
-                       
-                       // Determine the material for this group.
-                       Material *material;
-                       if ((group->material-1) < model->nummaterials) {
-                               material = material_array[group->material-1];
-                       }
-                       else {
-                               material = default_material;
-                       }
-                       
-                       // Create an input array for the mesh.
-                       int *input_array = new int[ group->numtriangles ];
-                       
-                       for (int i=0;i<group->numtriangles;++i) {
-                               input_array[i] = group->triangles[i];
-                       }
-                       
-                       // Construct a bvh.
-                       object_array[object] = new BvhTriangleMesh( 
vertex_array,
-                                                                             
                                                                              
                                            edge_array,
-                                                                             
                                                                              
                                            normal_array,
-                                                                             
                                                                              
                                            triangle_array,
-                                                                             
                                                                              
                                            
-                                                                             
                                                                              
                                            input_array, 
(int)group->numtriangles,
-                                                                             
                                                                              
                                            material );
-                       
-                       delete [] input_array;
-                       
-                       // Mesh bounds.
-                       BBox mesh_bounds;
-                       object_array[object]->computeBounds( context, 
mesh_bounds );
-                       
-                       std::cerr << "Added mesh: bounds: " << mesh_bounds[0] 
<< " " << mesh_bounds[1] << std::endl;
-               
-                       ++object;
-               }
-               // Move to the next group.
-               group = group->next;
-
-       }
-       
-       
/////////////////////////////////////////////////////////////////////////////
-       // Construct a bvh over the sub meshes.
-       Object *obj;
-       if (object > 1) 
-               obj = new RealisticBvh( object_array, object );
-       else 
-               obj = object_array[0];
-
-       // Determine the bounds of the scene.
-       obj->computeBounds( context, bounds );
-       
-       return obj;
-}
 
 
 




  • [MANTA] r788 - in branches/itanium2: Interface Model/Primitives scenes, abe, 12/14/2005

Archive powered by MHonArc 2.6.16.

Top of page