Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r999 - in trunk: Model/Readers scenes


Chronological Thread 
  • From: bigler@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r999 - in trunk: Model/Readers scenes
  • Date: Mon, 3 Apr 2006 15:45:41 -0600 (MDT)

Author: bigler
Date: Mon Apr  3 15:45:41 2006
New Revision: 999

Added:
   trunk/scenes/iwviewer.cc
Modified:
   trunk/Model/Readers/IW.cc
   trunk/Model/Readers/IW.h
   trunk/scenes/CMakeLists.txt
   trunk/scenes/objviewer.cc
Log:

Model/Readers/IW.cc

  Do some error checking before returning.
  
Model/Readers/IW.h

  Added some convience functions.

scenes/CMakeLists.txt
scenes/iwviewer.cc

  Add iwviewer scene.

scenes/objviewer.cc

  Minimal formatting. ;)


Modified: trunk/Model/Readers/IW.cc
==============================================================================
--- trunk/Model/Readers/IW.cc   (original)
+++ trunk/Model/Readers/IW.cc   Mon Apr  3 15:45:41 2006
@@ -153,7 +153,10 @@
         fprintf(stderr, "Unknown token: (%s)\n", token);
     }
   } // end while loop
-      
+
+  fclose(geomf);
+
+  // Print some stats
   fprintf(stderr, "vertices       :%10llu\n",
           (unsigned long long)iw->vertices.size());
   fprintf(stderr, "vertex normals :%10llu\n",
@@ -163,6 +166,57 @@
   fprintf(stderr, "shaders        :%10llu\n",
           (unsigned long long)iw->shaders.size());
   
-  fclose(geomf);
+  //////////////////////////////////////////
+  // Let's do some error checking:
+
+  // If there are vertex normals then the number must be greater than
+  // or equal to the number of vertices.
+  if (iw->vtxnormals.size() > 0 &&
+      iw->vtxnormals.size() < iw->vertices.size() ) {
+    fprintf(stderr, "Number of vertex normals (%llu) less than number or 
vertices (%llu)\n",
+            (unsigned long long)iw->vtxnormals.size(),
+            (unsigned long long)iw->vertices.size());
+    delete iw;
+    return 0;
+  }
+  
+  // Make sure that the triangle indicies and shader indicies are cool
+  for(size_t i = 0; i < iw->triangles.size(); ++i) {
+    unsigned int a, b, c, group;
+    a = iw->triangles[i][0];
+    b = iw->triangles[i][1];
+    c = iw->triangles[i][2];
+    group = iw->triangles[i][3];
+
+    if (a >= iw->vertices.size()) {
+      fprintf(stderr, "Vertex index (%u) out of range (%llu)\n",
+              a, (unsigned long long)iw->vertices.size());
+      delete iw;
+      return 0;
+    }
+
+    if (b >= iw->vertices.size()) {
+      fprintf(stderr, "Vertex index (%u) out of range (%llu)\n",
+              b, (unsigned long long)iw->vertices.size());
+      delete iw;
+      return 0;
+    }
+
+    if (c >= iw->vertices.size()) {
+      fprintf(stderr, "Vertex index (%u) out of range (%llu)\n",
+              c, (unsigned long long)iw->vertices.size());
+      delete iw;
+      return 0;
+    }
+
+    if (group >= iw->shaders.size()) {
+      fprintf(stderr, "Vertex index (%u) out of range (%llu)\n",
+              group, (unsigned long long)iw->shaders.size());
+      delete iw;
+      return 0;
+    }
+    
+  }
+
   return iw;
 }

Modified: trunk/Model/Readers/IW.h
==============================================================================
--- trunk/Model/Readers/IW.h    (original)
+++ trunk/Model/Readers/IW.h    Mon Apr  3 15:45:41 2006
@@ -63,6 +63,7 @@
 
 #include <Core/Geometry/Vector.h>
 #include <Core/Geometry/VectorT.h>
+#include <Core/Color/ColorSpace.h>
 #include <MantaTypes.h>
 #include <vector>
 
@@ -78,6 +79,15 @@
     // First three indicies are the indicies of verticies/vtxnormals
     // the last index is the shaders index.
     std::vector<VectorT<unsigned int, 4> > triangles;
+
+    Vector va(unsigned int index) { return vertices[triangles[index][0]]; }
+    Vector vb(unsigned int index) { return vertices[triangles[index][1]]; }
+    Vector vc(unsigned int index) { return vertices[triangles[index][2]]; }
+    Color  color(unsigned int index) { return shaders[triangles[index][3]]; }
+
+    Vector vna(unsigned int index) { return vtxnormals[triangles[index][0]]; 
}
+    Vector vnb(unsigned int index) { return vtxnormals[triangles[index][1]]; 
}
+    Vector vnc(unsigned int index) { return vtxnormals[triangles[index][2]]; 
}
   private:
     // Copying could be nasty, so don't allow it.
     IWObject( const Vector& copy ) {}

Modified: trunk/scenes/CMakeLists.txt
==============================================================================
--- trunk/scenes/CMakeLists.txt (original)
+++ trunk/scenes/CMakeLists.txt Mon Apr  3 15:45:41 2006
@@ -72,6 +72,12 @@
    TARGET_LINK_LIBRARIES(scene_objviewer ${MANTA_SCENE_LINK})
 ENDIF(SCENE_OBJVIEWER)
 
+SET(SCENE_IWVIEWER 0 CACHE BOOL "IW file viewer.")
+IF(SCENE_IWVIEWER)
+   ADD_LIBRARY(scene_iwviewer iwviewer.cc)
+   TARGET_LINK_LIBRARIES(scene_iwviewer ${MANTA_SCENE_LINK})
+ENDIF(SCENE_IWVIEWER)
+
 SET(SCENE_PERF 0 CACHE BOOL "Perf Test Scene.")
 IF(SCENE_PERF)
    ADD_LIBRARY(scene_perf perf.cc)

Added: trunk/scenes/iwviewer.cc
==============================================================================
--- (empty file)
+++ trunk/scenes/iwviewer.cc    Mon Apr  3 15:45:41 2006
@@ -0,0 +1,134 @@
+/*
+  For more information, please see: http://software.sci.utah.edu
+
+  The MIT License
+
+  Copyright (c) 2005
+  Scientific Computing and Imaging Institute, University of Utah
+
+  License for the specific language governing rights and limitations under
+  Permission is hereby granted, free of charge, to any person obtaining a
+  copy of this software and associated documentation files (the "Software"),
+  to deal in the Software without restriction, including without limitation
+  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+  and/or sell copies of the Software, and to permit persons to whom the
+  Software is furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included
+  in all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+  DEALINGS IN THE SOFTWARE.
+*/
+
+#include <Model/Readers/IW.h>
+
+#include <Interface/LightSet.h>
+#include <Interface/Scene.h>
+#include <Core/Util/Args.h>
+#include <Core/Exceptions/IllegalArgument.h>
+
+#include <Model/Lights/HeadLight.h>
+#include <Model/AmbientLights/ConstantAmbient.h>
+#include <Model/Backgrounds/ConstantBackground.h>
+#include <Model/Primitives/Triangle.h>
+#include <Model/Primitives/WaldTriangle.h>
+#include <Model/Materials/Lambertian.h>
+#include <Model/Groups/DynBVH.h>
+
+#include <iostream>
+#include <vector>
+
+using namespace Manta;
+using namespace std;
+
+enum {
+  WaldTri,
+  Tri
+};
+
+static string file_name;
+static int tri_type = WaldTri;
+static bool use_default_color = false;
+static BBox bounds;
+
+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" || args[i] == "-iwfile") {
+      // Read in the file name.
+      if (!getStringArg(i, args, file_name))
+        throw IllegalArgument("iwviewer -file <filename>", i, args);
+    } else if (args[i] == "-tri" ) {
+      tri_type = Tri;
+    }
+  }
+
+  IWObject* iw = IWObjectRead(file_name.c_str());
+  if (!iw) {
+    cerr << "Error reading file : "<<file_name<<".\n";
+    return 0;
+  }
+
+  // Make the materials
+  vector<Material*> materials;
+  for(size_t i = 0; i < iw->shaders.size(); ++i) {
+    materials.push_back(new Lambertian(iw->shaders[i]));
+  }
+  Material* default_material = new Lambertian(Color(RGBColor(0.5,0.6,0.5)));
+  
+  Group* bvh_group = 0;
+
+  bvh_group = new DynBVH();
+
+  // Iterate over all the triangles and make them
+  switch (tri_type) {
+  case WaldTri:
+    for(size_t i = 0; i < iw->triangles.size(); ++i) {
+      Material* matl = 0;
+      if (use_default_color)
+        matl = default_material;
+      else
+        matl = materials[iw->triangles[i][3]];
+      bvh_group->add(new WaldTriangle(matl, iw->va(i), iw->vb(i), 
iw->vc(i)));
+    }
+    break;
+  case Tri:
+    for(size_t i = 0; i < iw->triangles.size(); ++i) {
+      Material* matl = 0;
+      if (use_default_color)
+        matl = default_material;
+      else
+        matl = materials[iw->triangles[i][3]];
+      bvh_group->add(new Triangle(matl, iw->va(i), iw->vb(i), iw->vc(i)));
+    }
+    break;
+  }
+
+  ///////////////////////////////////////////////////////////////////////////
+  // 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 );
+
+  // Add the bvh to the scene.
+  scene->setObject( bvh_group );
+
+  // Background.
+  scene->setBackground( new ConstantBackground( Color(RGB(0.8, 0.8, 1) ) ) );
+
+  return scene;
+  
+}

Modified: trunk/scenes/objviewer.cc
==============================================================================
--- trunk/scenes/objviewer.cc   (original)
+++ trunk/scenes/objviewer.cc   Mon Apr  3 15:45:41 2006
@@ -163,7 +163,7 @@
         }
     }
 
-    
/////////////////////////////////////////////////////////////////////////////
+    
///////////////////////////////////////////////////////////////////////////
     // Load in the file using glm.
     GLMmodel *model = glmReadOBJ( file_name.c_str() );
     if (model == 0) {
@@ -186,7 +186,7 @@
     Vectorf bmax, bmin;
     glmBoundingBox( model, (float *)&bmin, (float *)&bmax );
 
-    
/////////////////////////////////////////////////////////////////////////////
+    
///////////////////////////////////////////////////////////////////////////
     // Center the model
     if (center_object) {
         Vector translate = ((Vector(bmax) + Vector(bmin)) * 0.5);
@@ -201,12 +201,12 @@
         }
     }
 
-    
/////////////////////////////////////////////////////////////////////////////
+    
///////////////////////////////////////////////////////////////////////////
     // Create the bvh.
     Object *bvh = create_single_bvh( model );
 
 
-    
/////////////////////////////////////////////////////////////////////////////
+    
///////////////////////////////////////////////////////////////////////////
     // Create the scene.
     Scene *scene = new Scene();
 




  • [MANTA] r999 - in trunk: Model/Readers scenes, bigler, 04/03/2006

Archive powered by MHonArc 2.6.16.

Top of page