Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r1450 - in trunk/Model: Groups Readers


Chronological Thread 
  • From: thiago@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r1450 - in trunk/Model: Groups Readers
  • Date: Fri, 6 Jul 2007 14:10:57 -0600 (MDT)

Author: thiago
Date: Fri Jul  6 14:10:55 2007
New Revision: 1450

Modified:
   trunk/Model/Groups/Mesh.cc
   trunk/Model/Groups/Mesh.h
   trunk/Model/Groups/ObjGroup.cc
   trunk/Model/Readers/PlyReader.cc
   trunk/Model/Readers/PlyReader.h
Log:
Ply files are now read in as a mesh as well. Primtest will now automatically 
load ply or obj files that are passed to it. for example:

bin/manta -imagetraverser "tiled (-square )" -scene 
"lib/libscene_primtest.dylib(ply -model /Users/thiago/data/models/temp.obj 
-material redlambertian)"

will load the temp.obj scene.



Modified: trunk/Model/Groups/Mesh.cc
==============================================================================
--- trunk/Model/Groups/Mesh.cc  (original)
+++ trunk/Model/Groups/Mesh.cc  Fri Jul  6 14:10:55 2007
@@ -141,6 +141,16 @@
   throw SCIRun::InternalError(string("Illegal call to ") + __func__, 
__FILE__, __LINE__);
 }
 
+void Mesh::addTriangle(Object *tri)
+{
+  //TODO: change this function from taking an Object to taking an
+  //interface of type MeshTriangle.
+  WaldTriangle *waldtri = static_cast<WaldTriangle*>(tri);
+  waldtri->attachMesh(this, objs.size());
+  objs.push_back(waldtri);
+  
+}
+
 void Mesh::computeBounds(const PreprocessContext& context, 
                          int proc, int numProcs) const
 {

Modified: trunk/Model/Groups/Mesh.h
==============================================================================
--- trunk/Model/Groups/Mesh.h   (original)
+++ trunk/Model/Groups/Mesh.h   Fri Jul  6 14:10:55 2007
@@ -56,6 +56,10 @@
     virtual void add(Object* obj);
     virtual void set( int i, Object *obj );
 
+    //this only adds the triangle to the group. You still need to add
+    //the vertices, materials, etc. to the mesh.
+    virtual void addTriangle(Object *tri);
+
     void computeBounds(const PreprocessContext& context, int proc, int 
numProcs) const;
 
     // You can't get access to the actual primitive, because it may not

Modified: trunk/Model/Groups/ObjGroup.cc
==============================================================================
--- trunk/Model/Groups/ObjGroup.cc      (original)
+++ trunk/Model/Groups/ObjGroup.cc      Fri Jul  6 14:10:55 2007
@@ -250,9 +250,7 @@
 //       }
 
       face_material.push_back(material_index);
-   
-      triangles[objs.size()].attachMesh(this, objs.size());
-      objs.push_back(&triangles[objs.size()]);
+      addTriangle(&triangles[objs.size()]);
     }
     
     // Move to the next group.

Modified: trunk/Model/Readers/PlyReader.cc
==============================================================================
--- trunk/Model/Readers/PlyReader.cc    (original)
+++ trunk/Model/Readers/PlyReader.cc    Fri Jul  6 14:10:55 2007
@@ -1,8 +1,8 @@
 
 #include <Model/Readers/PlyReader.h>
 
-#include <Model/Primitives/Triangle.h>
-#include <Model/Primitives/VertexColoredTriangle.h>
+#include <Model/Primitives/WaldTriangle.h>
+// #include <Model/Primitives/VertexColoredTriangle.h>
 #include <Model/Textures/TriVerTexture.h>
 #include <Model/Materials/Lambertian.h>
 #include <Core/Geometry/Vector.h>
@@ -17,12 +17,10 @@
 
 #include <stdlib.h>
 
-//TODO: normals?, acceleration structure.
+//TODO: normals?
 
 using namespace Manta;
 
-Material *defaultMaterial = NULL;
-
 double maxColorValue;
 
 bool coloredTriangleMode = false;
@@ -32,17 +30,18 @@
   RGBColor color;
 };
 
-std::vector<VertexData> vertices;
+unsigned int vertices_start = 0;
 VertexData vertexData;
 AffineTransform *t;
 
-static void addVertex() {
+static void addVertex(Mesh *mesh) {
   vertexData.point = t->multiply_point(vertexData.point);
-  vertices.push_back(vertexData);
+  mesh->vertices.push_back(vertexData.point);
 }
 
 static int vertex_cb(p_ply_argument argument) {
-     ply_get_argument_user_data(argument, NULL, NULL);
+     Mesh *mesh;
+     ply_get_argument_user_data(argument, (void**) &mesh, NULL);
      
      const char* name;
      p_ply_property property;
@@ -52,8 +51,8 @@
      long vertexIndex;
      ply_get_argument_element(argument, NULL, &vertexIndex);
      
-     if (vertexIndex == vertices.size()+1) {
-         addVertex();
+     if (vertexIndex + vertices_start == mesh->vertices.size()+1) {
+         addVertex(mesh);
      }
      
      if (strcmp(name, "x") == 0)
@@ -77,8 +76,8 @@
      long length;
      int currVertexIndex;
      
-     Group *group;
-     ply_get_argument_user_data(argument, (void**) &group, NULL);
+     Mesh *mesh;
+     ply_get_argument_user_data(argument, (void**) &mesh, NULL);
      
      long polyIndex, polyVertex;
      ply_get_argument_element(argument, NULL, &polyIndex);
@@ -87,36 +86,39 @@
 
      //do this once only to add last vertex.
      if (polyIndex == 0 && polyVertex == -1) {
-         addVertex();
+         addVertex(mesh);
      }
      
      currVertexIndex = static_cast<int>(ply_get_argument_value(argument));
-
-     Material *mat = defaultMaterial;
+//      cout <<currVertexIndex<<"\t"<<polyIndex <<"\t" << polyVertex<<"\n";
 
      switch (polyVertex) 
      {
      case -1: return 1;
      case 0: firstVertexIndex = currVertexIndex;
-         break;
+       break;
      case 1: prevVertexIndex = currVertexIndex;
-         break;
+       break;
      default: 
-          if (coloredTriangleMode)
-              group->add(new VertexColoredTriangle(mat, 
-                                      vertices[firstVertexIndex].point,
-                                      vertices[prevVertexIndex].point,
-                                      vertices[currVertexIndex].point,
-                                      
Color(vertices[firstVertexIndex].color),
-                                      Color(vertices[prevVertexIndex].color),
-                                      
Color(vertices[currVertexIndex].color)));
-         else
-              group->add(new Triangle(mat, vertices[firstVertexIndex].point,
-                                      vertices[prevVertexIndex].point,
-                                      vertices[currVertexIndex].point));
-         
-         prevVertexIndex = currVertexIndex;
-         break;
+       mesh->vertex_indices.push_back(vertices_start+firstVertexIndex);
+       mesh->vertex_indices.push_back(vertices_start+prevVertexIndex);
+       mesh->vertex_indices.push_back(vertices_start+currVertexIndex);
+       
+       mesh->face_material.push_back(mesh->materials.size()-1);
+       mesh->addTriangle(new WaldTriangle);
+
+         if (coloredTriangleMode) {
+         //TODO: handle colored triangles.
+//            group->add(new VertexColoredTriangle(mat, 
+//                                    vertices[firstVertexIndex].point,
+//                                    vertices[prevVertexIndex].point,
+//                                    vertices[currVertexIndex].point,
+//                                    
Color(vertices[firstVertexIndex].color),
+//                                    Color(vertices[prevVertexIndex].color),
+//                                    
Color(vertices[currVertexIndex].color)));
+       }  
+       prevVertexIndex = currVertexIndex;
+       break;
      }
 
      return 1;
@@ -125,9 +127,11 @@
 
 bool
 Manta::readPlyFile(const string fileName, AffineTransform &_t, 
-                  Group *g, int gridsize, Material *m) {
+                   Mesh *mesh, Material *m) {
      long nVertices;
-     int originalSize = g->getSize();
+     int objs_start = mesh->getSize();
+     unsigned int vertex_indices_start = mesh->vertex_indices.size();
+     vertices_start = mesh->vertices.size();
 
      t = &_t;
      
@@ -143,15 +147,12 @@
      if (!ply_read_header(ply)) return false;
      
      nVertices = ply_set_read_cb(ply, "vertex", "x", vertex_cb, 
-                                NULL, 0);
-
-     vertices.clear();
-     vertices.reserve(nVertices);
+                                mesh, 0);
 
      ply_set_read_cb(ply, "vertex", "y", vertex_cb, 
-                    NULL, 0);
+                    mesh, 0);
      ply_set_read_cb(ply, "vertex", "z", vertex_cb, 
-                    NULL, 0);
+                    mesh, 0);
      
      //get vertex color property
      p_ply_property property;
@@ -160,17 +161,19 @@
      property = ply_find_property(ply_find_element(ply, "vertex"), 
"diffuse_red");
      
      ply_set_read_cb(ply, "vertex", "diffuse_red", vertex_cb, 
-                    NULL, 0);
+                    mesh, 0);
      ply_set_read_cb(ply, "vertex", "diffuse_blue", vertex_cb, 
-                    NULL, 0);
+                    mesh, 0);
      ply_set_read_cb(ply, "vertex", "diffuse_green", vertex_cb, 
-                    NULL, 0);
+                    mesh, 0);
 
 
      /*if we add other color types, need to try getting their property
       *if current property is still NULL.
       */
 
+     Material *defaultMaterial = NULL;
+
      if (property) 
      {
          //TODO: we might not want to overwrite the matl passed in to us...
@@ -197,7 +200,7 @@
          }
      }
 
-     ply_set_read_cb(ply, "face", "vertex_indices", face_cb, g, 0);
+     ply_set_read_cb(ply, "face", "vertex_indices", face_cb, mesh, 0);
 
      if (defaultMaterial)
      { } //do nothing
@@ -206,9 +209,13 @@
      else
          defaultMaterial = new Lambertian(Color(RGBColor(1,1,1)));
 
+     mesh->materials.push_back(defaultMaterial);
+
      if (!ply_read(ply)) {
          //need to clean up group.
-         g->shrinkTo(originalSize, true);
+         mesh->shrinkTo(objs_start, true);
+         mesh->vertices.resize(vertices_start);
+         mesh->vertex_indices.resize(vertex_indices_start);
          if (!m && defaultMaterial)
              delete defaultMaterial;
          

Modified: trunk/Model/Readers/PlyReader.h
==============================================================================
--- trunk/Model/Readers/PlyReader.h     (original)
+++ trunk/Model/Readers/PlyReader.h     Fri Jul  6 14:10:55 2007
@@ -3,7 +3,7 @@
 #define Manta_Model_PlyReader_h
 
 #include <Core/Geometry/AffineTransform.h>
-#include <Model/Groups/Group.h>
+#include <Model/Groups/Mesh.h>
 
 #include <sgi_stl_warnings_off.h>
 #include <string>
@@ -17,7 +17,7 @@
   class Group;
   
   extern "C" bool readPlyFile(const string fileName, AffineTransform &t, 
-                              Group *g, int gridsize=0, Material *m=0);
+                              Mesh *mesh, Material *m=0);
 }
 
 #endif




  • [MANTA] r1450 - in trunk/Model: Groups Readers, thiago, 07/06/2007

Archive powered by MHonArc 2.6.16.

Top of page