Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r957 - trunk/scenes


Chronological Thread 
  • From: boulos@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r957 - trunk/scenes
  • Date: Fri, 24 Feb 2006 00:05:00 -0700 (MST)

Author: boulos
Date: Fri Feb 24 00:05:00 2006
New Revision: 957

Modified:
   trunk/scenes/objviewer.cc
Log:
Changing objviewer to also support DynBVH.


Modified: trunk/scenes/objviewer.cc
==============================================================================
--- trunk/scenes/objviewer.cc   (original)
+++ trunk/scenes/objviewer.cc   Fri Feb 24 00:05:00 2006
@@ -54,6 +54,7 @@
 #include <Model/Groups/Group.h>
 #include <Model/Groups/RealisticBvh.h>
 #include <Model/Groups/BVH.h>
+#include <Model/Groups/DynBVH.h>
 #include <Model/Lights/HeadLight.h>
 #include <Model/AmbientLights/ConstantAmbient.h>
 #include <Model/Backgrounds/ConstantBackground.h>
@@ -104,6 +105,7 @@
 
 enum {
   RealisticBvh_Build,
+  DynBVH_Build,
   BVH_Build
 };
 int  which_BVH           = RealisticBvh_Build;
@@ -112,20 +114,20 @@
 ///////////////////////////////////////////////////////////////////////////
 // This function loads a specified .obj file into a runtime acceleration
 // structure for rendering.
-extern "C" 
+extern "C"
 Scene* make_scene(const ReadContext& context, const vector<string>& args) {
 
-       // Check the arguments.
-       for (int i=0;i<args.size();++i) {
-       
-               if (args[i] == "-file") {
-                       // Read in the file name.
-                       if (!getStringArg(i, args, file_name))
-                               throw IllegalArgument("objviewer -file 
<filename>", i, args);
-               }
-               else if (args[i] == "-single") {
-                       use_single_bvh = true;
-               }
+        // Check the arguments.
+        for (int i=0;i<args.size();++i) {
+
+                if (args[i] == "-file") {
+                        // Read in the file name.
+                        if (!getStringArg(i, args, file_name))
+                                throw IllegalArgument("objviewer -file 
<filename>", i, args);
+                }
+                else if (args[i] == "-single") {
+                        use_single_bvh = true;
+                }
     else if (args[i] == "-bounds") {
       display_bounds = true;
     }
@@ -134,7 +136,7 @@
     }
     else if (args[i] == "-fixnormals") {
       fix_normals = true;
-      
+
       getIntArg( i, args, fix_normals_degrees );
     }
     else if (args[i] == "-flip") {
@@ -146,8 +148,8 @@
     }
     else if (args[i] == "-bvh-build") {
       string build;
-                       if (!getStringArg(i, args, build))
-                               throw IllegalArgument("objviewer -bvh_build 
<type:naive,table>",
+                        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);
@@ -155,17 +157,17 @@
     else if (args[i] == "-nocentering") {
       center_object = false;
     }
-       }
+        }
 
   
/////////////////////////////////////////////////////////////////////////////
-       // Load in the file using glm.
-       GLMmodel *model = glmReadOBJ( file_name.c_str() );
-       if (model == 0) {
-               std::cout << "Error cannot read model from file." << 
std::endl;
-               return 0;
-       }
+        // Load in the file using glm.
+        GLMmodel *model = glmReadOBJ( file_name.c_str() );
+        if (model == 0) {
+                std::cout << "Error cannot read model from file." << 
std::endl;
+                return 0;
+        }
 
-       // Flip the face winding.
+        // Flip the face winding.
   if (flip_faces) {
     glmReverseWinding( model );
   }
@@ -186,8 +188,8 @@
     Vector translate = ((Vector(bmax) + Vector(bmin)) * 0.5);
 
     std::cerr << "Min: " << bmin << " Max: " << bmax << " translate: " << 
translate << std::endl;
-  
-    Vectorf *vertex;  
+
+    Vectorf *vertex;
     for (int i=0;i<model->numvertices;++i) {
       vertex = (Vectorf *)&model->vertices[i*3];
 
@@ -197,27 +199,27 @@
 
   
/////////////////////////////////////////////////////////////////////////////
   // Create the bvh.
-       Object *bvh = create_single_bvh( model );
+        Object *bvh = create_single_bvh( model );
+
 
+        
/////////////////////////////////////////////////////////////////////////////
+        // Create the scene.
+        Scene *scene = new Scene();
+
+        // Add a head light.
+        LightSet *lights = new LightSet();
+        lights->add( new HeadLight( 0.0, Color(RGB(1.0,1.0,1.0)) ));
+        lights->setAmbientLight( new ConstantAmbient( Color(RGB(0.4,0.4,0.4) 
) ));
+        scene->setLights( lights );
 
-       
/////////////////////////////////////////////////////////////////////////////
-       // Create the scene.
-       Scene *scene = new Scene();
-       
-       // Add a head light.
-       LightSet *lights = new LightSet();
-       lights->add( new HeadLight( 0.0, Color(RGB(1.0,1.0,1.0)) ));
-       lights->setAmbientLight( new ConstantAmbient( Color(RGB(0.4,0.4,0.4) 
) ));
-       scene->setLights( lights );
-       
   Material* red=new Lambertian(Color(RGBColor(.6,0,0)));
-       Material* yellow=new Lambertian(Color(RGBColor(.6,.6,0)));
+        Material* yellow=new Lambertian(Color(RGBColor(.6,.6,0)));
 
   // Add a floor.
   Parallelogram* floor = new Parallelogram(yellow, 
Vector(-20,-20,bounds[0][2]),
-                                                                             
                                                                           
Vector(40,0,0), Vector(0,40,0));
-       Group *manta_group = new Group();
-       // manta_group->add( floor );
+                                                                             
                                                                            
Vector(40,0,0), Vector(0,40,0));
+        Group *manta_group = new Group();
+        // manta_group->add( floor );
 
   if (display_bounds) {
     manta_group->add( new Cube( red, bounds[0], bounds[1] ) );
@@ -225,14 +227,14 @@
   else {
     manta_group->add( bvh );
   }
-       
-       // Add the bvh to the scene.
-       scene->setObject( manta_group );
-       
-       // Background.
-       scene->setBackground( new ConstantBackground( Color(RGB(0.8, 0.8, 
0.8)) ) );
 
-       return scene;
+        // Add the bvh to the scene.
+        scene->setObject( manta_group );
+
+        // Background.
+        scene->setBackground( new ConstantBackground( Color(RGB(0.8, 0.8, 
0.8)) ) );
+
+        return scene;
 }
 
 
///////////////////////////////////////////////////////////////////////////////
@@ -256,7 +258,7 @@
     // Try reading the image using teem.
     image = readNRRD( file_name );
   }
-    
+
   // Create the texture.
   ImageTexture<Color> *texture = new ImageTexture<Color>( image );
 
@@ -283,7 +285,7 @@
                 << ": " << e.message() << std::endl;
     }
   }
-  
+
   if (texture == 0) {
 
     // Otherwise use a constant color.
@@ -308,15 +310,15 @@
   if (pos != string::npos) {
     model_path = model_path.substr( 0, pos+1 );
   }
-  
-       material_array = new Material *[ model->nummaterials ];
 
-       // Read in the materials.
-       for (int i=0;i<model->nummaterials;++i) {
+        material_array = new Material *[ model->nummaterials ];
+
+        // Read in the materials.
+        for (int i=0;i<model->nummaterials;++i) {
 
     
///////////////////////////////////////////////////////////////////////////
     // Copy out material attributes.
-               string mtl_name = model->materials[i].name;
+                string mtl_name = model->materials[i].name;
 
     // Color ambient (RGB( model->materials[i].ambient[0],
     //                     model->materials[i].ambient[1],
@@ -340,14 +342,14 @@
     string diffuse_map_name  = (model->materials[i].diffuse_map[0]  != '\0') 
?
       model->materials[i].diffuse_map : "";
     string specular_map_name = (model->materials[i].specular_map[0] != '\0') 
?
-      model->materials[i].specular_map : "";    
-    
+      model->materials[i].specular_map : "";
+
     // Note that the first material added by blender is always an
     // 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 );
 
@@ -356,18 +358,18 @@
     if (Tr != 0) {
 
       std::cerr << "Material " << index << " dielectric" << std::endl;
-      
+
       // Constant textures for refraction parameters.
       Texture<Real> *n  = new Constant<Real>( 1.6 );
       Texture<Real> *nt = new Constant<Real>( 1.0 );
 
       Texture<Color> *diffuse_map = check_for_texture( model_path, 
diffuse_map_name, diffuse );
       // Texture<Color> *diffuse_map = new Constant<Color>( Color(RGB(.9, 
.8, .8)) );
-      
+
       // Create a dielectric shader.
       // material_array[index] = new Dielectric( n, nt, diffuse_map );
       material_array[index] = new Dielectric(1.6, 1.0, Color(RGB(.9, .8, 
.8)));
-            
+
     }
 
     
///////////////////////////////////////////////////////////////////////////
@@ -375,7 +377,7 @@
     else if (Ns != 0) {
 
       std::cerr << "Material " << index << " Specular" << std::endl;
-      
+
       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.0 );
@@ -390,14 +392,14 @@
     else {
 
       std::cerr << "Material " << index << " Lambertian" << std::endl;
-      
+
       Texture<Color> *diffuse_map  = check_for_texture( model_path, 
diffuse_map_name, diffuse );
 
       // Lambertian Shader.
       material_array[index] = new Lambertian( diffuse_map );
     }
-    
-       }
+
+        }
 
 }
 
@@ -405,25 +407,28 @@
 // Create a single bvh to contain the mesh.
 Object *create_single_bvh( GLMmodel *model ) {
 
-       TexTriangle **triangle_array = 0;
-  BVH* bvh_group = 0;
-       
-       
/////////////////////////////////////////////////////////////////////////////
-       // Allocate storage for primitives and materials.
-       int total_triangles = model->numtriangles;
+        TexTriangle **triangle_array = 0;
+  Group* bvh_group = 0;
+
+        
/////////////////////////////////////////////////////////////////////////////
+        // Allocate storage for primitives and materials.
+        int total_triangles = model->numtriangles;
   switch (which_BVH) {
   case RealisticBvh_Build:
     triangle_array = new TexTriangle *[ total_triangles ];
     break;
+  case DynBVH_Build:
+      bvh_group = new DynBVH();
+      break;
   case BVH_Build:
     bvh_group = new BVH(BVH_args);
     break;
   }
-       
-       create_materials( model );
-       
-       int tri = 0;
-       int mtl = 0;
+
+        create_materials( model );
+
+        int tri = 0;
+        int mtl = 0;
 
   Material *default_material = 0;
   if (use_lambertian) {
@@ -433,66 +438,66 @@
     default_material = new Flat( new NormalTexture() );
   }
 
-  
-       // 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) {
-                       
-                       Vector vertex[3];
+
+        // 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) {
+
+                        Vector vertex[3];
       Vector normal[3];
       Vector texcoord[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];
+                        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];
 
         index = model->triangles[ group->triangles[i] ].nindices[v];
         f = model->normals+(index*3);
 
         // Copy out the normal.
         normal[v][0] = f[0];
-                               normal[v][1] = f[1];
-                               normal[v][2] = f[2];
+                                normal[v][1] = f[1];
+                                normal[v][2] = f[2];
 
       }
 
       for (int v=0; v<3; ++v) {
-        
+
         int index = model->triangles[ group->triangles[i] ].tindices[v];
         float *f = &model->texcoords[index*2];
 
         // Copy out the texcoord
         texcoord[v][0] = f[0];
-                               texcoord[v][1] = f[1];
+                                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.
-                       TexTriangle *triangle = new TexTriangle( material,
+
+                        // Create a new triangle.
+                        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]
@@ -502,23 +507,25 @@
       case RealisticBvh_Build:
         triangle_array[tri] = triangle;
         break;
+      case DynBVH_Build:
       case BVH_Build:
+          // both cases just add
         bvh_group->add(triangle);
         break;
       }
       ++tri;
-               }
+                }
+
+                // Move to the next group.
+                group = group->next;
+                ++mtl;
+        }
 
-               // Move to the next group.
-               group = group->next;
-               ++mtl;
-       }
-       
   std::cerr << "Total triangles added: " << tri << std::endl;
 
   Object* bvh = 0;
-       
/////////////////////////////////////////////////////////////////////////////
-       // Create an acceleration structure.
+        
/////////////////////////////////////////////////////////////////////////////
+        // Create an acceleration structure.
   switch (which_BVH) {
   case RealisticBvh_Build:
     {
@@ -533,22 +540,21 @@
       std::cerr << "Bvh creation time: " << (time_end - time_begin) << " 
seconds." << std::endl;
     }
     break;
+  case DynBVH_Build:
   case BVH_Build:
-    {
       bvh = bvh_group;
       // Preprocesing will be done during the preprocessing phase
-    }
     break;
   }
 
-       
/////////////////////////////////////////////////////////////////////////////
-       // 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;      
+        
/////////////////////////////////////////////////////////////////////////////
+        // 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;
+        return bvh;
 }
 
 




  • [MANTA] r957 - trunk/scenes, boulos, 02/24/2006

Archive powered by MHonArc 2.6.16.

Top of page