Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r1261 - in trunk: Image Model/Groups Model/Readers/glm scenes


Chronological Thread 
  • From: bigler@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r1261 - in trunk: Image Model/Groups Model/Readers/glm scenes
  • Date: Mon, 18 Dec 2006 16:49:44 -0700 (MST)

Author: bigler
Date: Mon Dec 18 16:49:43 2006
New Revision: 1261

Modified:
   trunk/Image/SimpleImage.h
   trunk/Image/TGAFile.cc
   trunk/Model/Groups/RealisticBvh.cc
   trunk/Model/Readers/glm/glm.cc
   trunk/scenes/objviewer.cc
Log:

Image/SimpleImage.h

  Added get/set methods for single pixels.  This allows us to get
  access to the data without having to convert things to and from
  Fragments.

Image/TGAFile.cc

  Use the SimpleImage<> set methods that will compute the correct
  offset into the data.

  Also check for images with interleaving and throw exceptions for
  now.

Model/Groups/RealisticBvh.cc

  Always compute the bounding boxes even for scenes with one or two
  objects.

Model/Readers/glm/glm.cc

  Fixed a bug with the group name not being copied correctly in the
  second pass.

  Now all vertex, normal, and texture indices are written to
  (initialized to 0 if not present).

scenes/objviewer.cc

  Add useTextureCoords flag that displays the texture coords as the
  texture.

  Add debug flag for printing out additional information.

  Added support for additional types of triangles (with/without
  normals, and with/without texture coordinates).


Modified: trunk/Image/SimpleImage.h
==============================================================================
--- trunk/Image/SimpleImage.h   (original)
+++ trunk/Image/SimpleImage.h   Mon Dec 18 16:49:43 2006
@@ -48,6 +48,8 @@
                          int xres, int yres);
     virtual void set(const Fragment& fragment);
     virtual void get(Fragment& fragment) const;
+    virtual void set(const Pixel& pixel, int x, int y, int eye);
+    virtual Pixel get(int x, int y, int eye) const;
 
     Pixel* getRawPixels(int which_eye) const;
     void* getRawData(int which_eye) const;
@@ -156,6 +158,18 @@
     }
   }
 
+  template<class Pixel>
+  void SimpleImage<Pixel>::set(const Pixel& pixel, int x, int y, int eye)
+  {
+    *(eyeStart[eye][y]+x) = pixel;
+  }
+  
+  template<class Pixel>
+  Pixel SimpleImage<Pixel>::get(int x, int y, int eye) const
+  {
+    return *(eyeStart[eye][y]+x);
+  }
+  
   template<class Pixel>
     Pixel* SimpleImage<Pixel>::getRawPixels(int which_eye) const
   {

Modified: trunk/Image/TGAFile.cc
==============================================================================
--- trunk/Image/TGAFile.cc      (original)
+++ trunk/Image/TGAFile.cc      Mon Dec 18 16:49:43 2006
@@ -265,18 +265,24 @@
     int height = read16bit( in );
     int pixel_depth = in.get();
     int image_descriptor = in.get();
+    // Check image_descriptor
+    if (image_descriptor & (192)) {
+      // Bits 6-7 are for strange interleaving formats.  If they are
+      // set, we should blow up.
+      throw InternalError( "Only non interleaved TGA files currently 
supported", __FILE__, __LINE__  );
+    }
     in.ignore( id_length );
+    bool flip_image = !!(image_descriptor & 32); // bit 5 says flip in y
     if ( pixel_depth == 24 && ( image_descriptor & 15 ) == 0 ) {
       SimpleImage< RGB8Pixel > *si = new SimpleImage< RGB8Pixel >( false, 
width, height );
       RGB8Pixel *buffer = const_cast< RGB8Pixel * >( si->getRawPixels( 0 ) );
       for ( int y = 0; y < height; ++y )
         for ( int x = 0; x < width; ++x ) {
-          RGB8Pixel *offset = ( buffer +
-                                ( image_descriptor & 32 ? height-1 - y : y ) 
* width +
-                                ( image_descriptor & 16 ? width-1 - x : x ) 
);
-          offset->b = static_cast<unsigned char>(in.get());
-          offset->g = static_cast<unsigned char>(in.get());
-          offset->r = static_cast<unsigned char>(in.get());
+          RGB8Pixel pixel;
+          pixel.b = static_cast<unsigned char>(in.get());
+          pixel.g = static_cast<unsigned char>(in.get());
+          pixel.r = static_cast<unsigned char>(in.get());
+          si->set(pixel, x, flip_image ? (height-1-y) : y, 0);
         }
       return si;
     } else if ( pixel_depth == 32 && ( image_descriptor & 15 ) == 8 ) {
@@ -284,13 +290,12 @@
       RGBA8Pixel *buffer = const_cast< RGBA8Pixel * >( si->getRawPixels( 0 ) 
);
       for ( int y = 0; y < height; ++y )
         for ( int x = 0; x < width; ++x ) {
-          RGBA8Pixel *offset = ( buffer +
-                                 ( image_descriptor & 32 ? height-1 - y : y 
) * width +
-                                 ( image_descriptor & 16 ? width-1 - x : x ) 
);
-          offset->b = static_cast<unsigned char>(in.get());
-          offset->g = static_cast<unsigned char>(in.get());
-          offset->r = static_cast<unsigned char>(in.get());
-          offset->a = static_cast<unsigned char>(in.get());
+          RGBA8Pixel pixel;
+          pixel.b = static_cast<unsigned char>(in.get());
+          pixel.g = static_cast<unsigned char>(in.get());
+          pixel.r = static_cast<unsigned char>(in.get());
+          pixel.a = static_cast<unsigned char>(in.get());
+          si->set(pixel, x, flip_image ? (height-1-y) : y, 0);
         }
       return si;
     }

Modified: trunk/Model/Groups/RealisticBvh.cc
==============================================================================
--- trunk/Model/Groups/RealisticBvh.cc  (original)
+++ trunk/Model/Groups/RealisticBvh.cc  Mon Dec 18 16:49:43 2006
@@ -66,6 +66,13 @@
 void
 RealisticBvh::start_build( Object **array, int size ) {
 
+       PreprocessContext context;
+       
+       // Compute the bounds of the array.
+       for (int i=0;i<size;++i) {
+               array[i]->computeBounds( context, bounds );
+       }
+
        // Check to see if there is only one node.
        if (size == 1) {
                child[0] = child[1] = array[0];
@@ -75,13 +82,6 @@
                child[0] = array[0];
                child[1] = array[1];
                return;
-       }
-
-       PreprocessContext context;
-       
-       // Compute the bounds of the array.
-       for (int i=0;i<size;++i) {
-               array[i]->computeBounds( context, bounds );
        }
 
        // Find a pivot point.

Modified: trunk/Model/Readers/glm/glm.cc
==============================================================================
--- trunk/Model/Readers/glm/glm.cc      (original)
+++ trunk/Model/Readers/glm/glm.cc      Mon Dec 18 16:49:43 2006
@@ -181,7 +181,6 @@
   static GLMgroup*
   _glmFindGroup(GLMmodel* model, char* name)
   {
-    fprintf(stderr, "Looking for group named \"%s\"\n", name);
     GLMgroup* group;
 
     assert(model);
@@ -205,7 +204,6 @@
 
     group = _glmFindGroup(model, name);
     if (!group) {
-      fprintf(stderr, "Adding group named \"%s\"\n", name);
       group = (GLMgroup*)malloc(sizeof(GLMgroup));
       group->name = strdup(name);
       group->material = 0;
@@ -216,9 +214,6 @@
       model->groups = group;
       model->numgroups++;
     }
-    else {
-      fprintf(stderr, "Found group named \"%s\"\n", name);
-    }
       
 
     return group;
@@ -797,7 +792,7 @@
         fgets(buf, sizeof(buf), file);
         sscanf(buf, "%s", buf);
         if (grpname) free(grpname);
-        grpname = strdup(grpname);
+        grpname = strdup(buf);
         sprintf(buf, "%s_MAT_%s",
                 grpname, mtlname);
         group = _glmFindGroup(model, buf);
@@ -813,70 +808,82 @@
           sscanf(buf, "%d//%d", &v, &n);
           T(numtriangles).vindices[0] = (v >= 0) ? v : (numvertices + v);
           T(numtriangles).nindices[0] = n;
+          T(numtriangles).tindices[0] = 0;
           fscanf(file, "%d//%d", &v, &n);
           T(numtriangles).vindices[1] = (v >= 0) ? v : (numvertices + v);
           T(numtriangles).nindices[1] = n;
+          T(numtriangles).tindices[1] = 0;
           fscanf(file, "%d//%d", &v, &n);
           T(numtriangles).vindices[2] = (v >= 0) ? v : (numvertices + v);
           T(numtriangles).nindices[2] = n;
+          T(numtriangles).tindices[2] = 0;
           group->triangles[group->numtriangles++] = numtriangles;
           numtriangles++;
           while(fscanf(file, "%d//%d", &v, &n) > 0) {
             T(numtriangles).vindices[0] = T(numtriangles-1).vindices[0];
             T(numtriangles).nindices[0] = T(numtriangles-1).nindices[0];
+            T(numtriangles).tindices[0] = 0;
             T(numtriangles).vindices[1] = T(numtriangles-1).vindices[2];
             T(numtriangles).nindices[1] = T(numtriangles-1).nindices[2];
+            T(numtriangles).tindices[1] = 0;
             T(numtriangles).vindices[2] = (v >= 0) ? v : (numvertices + v);
             T(numtriangles).nindices[2] = n;
+            T(numtriangles).tindices[2] = 0;
             group->triangles[group->numtriangles++] = numtriangles;
             numtriangles++;
           }
         } else if (sscanf(buf, "%d/%d/%d", &v, &t, &n) == 3) {
           /* v/t/n */
           T(numtriangles).vindices[0] = (v >= 0) ? v : (numvertices + v);
-          T(numtriangles).tindices[0] = t;
           T(numtriangles).nindices[0] = n;
+          T(numtriangles).tindices[0] = t;
           fscanf(file, "%d/%d/%d", &v, &t, &n);
           T(numtriangles).vindices[1] = (v >= 0) ? v : (numvertices + v);
-          T(numtriangles).tindices[1] = t;
           T(numtriangles).nindices[1] = n;
+          T(numtriangles).tindices[1] = t;
           fscanf(file, "%d/%d/%d", &v, &t, &n);
           T(numtriangles).vindices[2] = (v >= 0) ? v : (numvertices + v);
-          T(numtriangles).tindices[2] = t;
           T(numtriangles).nindices[2] = n;
+          T(numtriangles).tindices[2] = t;
           group->triangles[group->numtriangles++] = numtriangles;
           numtriangles++;
           while(fscanf(file, "%d/%d/%d", &v, &t, &n) > 0) {
             T(numtriangles).vindices[0] = T(numtriangles-1).vindices[0];
-            T(numtriangles).tindices[0] = T(numtriangles-1).tindices[0];
             T(numtriangles).nindices[0] = T(numtriangles-1).nindices[0];
+            T(numtriangles).tindices[0] = T(numtriangles-1).tindices[0];
             T(numtriangles).vindices[1] = T(numtriangles-1).vindices[2];
-            T(numtriangles).tindices[1] = T(numtriangles-1).tindices[2];
             T(numtriangles).nindices[1] = T(numtriangles-1).nindices[2];
+            T(numtriangles).tindices[1] = T(numtriangles-1).tindices[2];
             T(numtriangles).vindices[2] = (v >= 0) ? v : (numvertices + v);
-            T(numtriangles).tindices[2] = t;
             T(numtriangles).nindices[2] = n;
+            T(numtriangles).tindices[2] = t;
             group->triangles[group->numtriangles++] = numtriangles;
             numtriangles++;
           }
         } else if (sscanf(buf, "%d/%d", &v, &t) == 2) {
           /* v/t */
           T(numtriangles).vindices[0] = (v >= 0) ? v : (numvertices + v);
+          T(numtriangles).nindices[0] = 0;
           T(numtriangles).tindices[0] = t;
           fscanf(file, "%d/%d", &v, &t);
           T(numtriangles).vindices[1] = (v >= 0) ? v : (numvertices + v);
+          T(numtriangles).nindices[1] = 0;
           T(numtriangles).tindices[1] = t;
           fscanf(file, "%d/%d", &v, &t);
           T(numtriangles).vindices[2] = (v >= 0) ? v : (numvertices + v);
+          T(numtriangles).nindices[2] = 0;
           T(numtriangles).tindices[2] = t;
           group->triangles[group->numtriangles++] = numtriangles;
           numtriangles++;
           while(fscanf(file, "%d/%d", &v, &t) > 0) {
             T(numtriangles).vindices[0] = T(numtriangles-1).vindices[0];
+            T(numtriangles).nindices[0] = 0;
             T(numtriangles).tindices[0] = T(numtriangles-1).tindices[0];
             T(numtriangles).vindices[1] = T(numtriangles-1).vindices[2];
+            T(numtriangles).nindices[1] = 0;
             T(numtriangles).tindices[1] = T(numtriangles-1).tindices[2];
             T(numtriangles).vindices[2] = (v >= 0) ? v : (numvertices + v);
+            T(numtriangles).nindices[2] = 0;
             T(numtriangles).tindices[2] = t;
             group->triangles[group->numtriangles++] = numtriangles;
             numtriangles++;
@@ -885,16 +892,28 @@
           /* v */
           sscanf(buf, "%d", &v);
           T(numtriangles).vindices[0] = (v >= 0) ? v : (numvertices + v);
+          T(numtriangles).nindices[0] = 0;
+          T(numtriangles).tindices[0] = 0;
           fscanf(file, "%d", &v);
           T(numtriangles).vindices[1] = (v >= 0) ? v : (numvertices + v);
+          T(numtriangles).nindices[1] = 0;
+          T(numtriangles).tindices[1] = 0;
           fscanf(file, "%d", &v);
           T(numtriangles).vindices[2] = (v >= 0) ? v : (numvertices + v);
+          T(numtriangles).nindices[2] = 0;
+          T(numtriangles).tindices[2] = 0;
           group->triangles[group->numtriangles++] = numtriangles;
           numtriangles++;
           while(fscanf(file, "%d", &v) > 0) {
             T(numtriangles).vindices[0] = T(numtriangles-1).vindices[0];
+            T(numtriangles).nindices[0] = 0;
+            T(numtriangles).tindices[0] = 0;
             T(numtriangles).vindices[1] = T(numtriangles-1).vindices[2];
+            T(numtriangles).nindices[1] = 0;
+            T(numtriangles).tindices[1] = 0;
             T(numtriangles).vindices[2] = (v >= 0) ? v : (numvertices + v);
+            T(numtriangles).nindices[2] = 0;
+            T(numtriangles).tindices[2] = 0;
             group->triangles[group->numtriangles++] = numtriangles;
             numtriangles++;
           }

Modified: trunk/scenes/objviewer.cc
==============================================================================
--- trunk/scenes/objviewer.cc   (original)
+++ trunk/scenes/objviewer.cc   Mon Dec 18 16:49:43 2006
@@ -106,6 +106,8 @@
 // Do blender specific things
 bool blender             = false;
 bool bilinear_textures   = false;
+bool useTextureCoords    = false;
+bool debug               = false;
 
 enum {
     RealisticBvh_Build,
@@ -181,6 +183,12 @@
         else if (args[i] == "-bilinear") {
             bilinear_textures = true;
         }
+        else if (args[i] == "-textureCoords") {
+            useTextureCoords = true;
+        }
+        else if (args[i] == "-debug") {
+            debug = true;
+        }
     }
 
     
///////////////////////////////////////////////////////////////////////////
@@ -297,6 +305,11 @@
 
     Texture<Color> *texture = 0;
 
+    if (useTextureCoords) {
+      texture = new TexCoordTexture;
+      return texture;
+    }
+
     if (file_name.size()) {
         // Load the image texture.
         try {
@@ -443,7 +456,7 @@
 // Create a single bvh to contain the mesh.
 Object *create_single_bvh( GLMmodel *model ) {
 
-    TexTriangle **triangle_array = 0;
+    Object **triangle_array = 0;
     Group* bvh_group = 0;
 
     
//////////////////////////////////////////////////////////////////////////
@@ -451,7 +464,7 @@
     int total_triangles = model->numtriangles;
     switch (which_BVH) {
     case RealisticBvh_Build:
-        triangle_array = new TexTriangle *[ total_triangles ];
+        triangle_array = new Object *[ total_triangles ];
         break;
     case DynBVH_Build:
         bvh_group = new DynBVH();
@@ -508,6 +521,9 @@
             Vector normal[3];
             Vector texcoord[3];
 
+            bool have_normals = true;
+            bool have_textures = true;
+
             for (int v=0;v<3;++v) {
                 int    index = model->triangles[ group->triangles[i] 
].vindices[v];
                 float *f     = model->vertices+(index*3);
@@ -518,39 +534,80 @@
                 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];
-
-            }
-
-            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][2] = 1.0;
+                if (index > 0) {
+                  f = model->normals+(index*3);
+                  
+                  // Copy out the normal.
+                  normal[v][0] = f[0];
+                  normal[v][1] = f[1];
+                  normal[v][2] = f[2];
+                }
+                else {
+                  // If one of the vertices doesn't have texture
+                  // coordinates, then all don't.
+                  have_normals = false;
+                }
+
+                index = model->triangles[ group->triangles[i] ].tindices[v];
+                if (index > 0) {
+                  f = model->texcoords+(index*2);
+
+                  // Copy out the texcoord
+                  texcoord[v][0] = f[0];
+                  texcoord[v][1] = f[1];
+                  texcoord[v][2] = 1.0;
+                }
+                else {
+                  have_textures = false;
+                }
 
             }
 
-            // 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,
-                                                     vertex[0], 
vertex[1]-vertex[0], vertex[2]-vertex[0],
-                                                     normal[0], normal[1], 
normal[2],
-                                                     texcoord[0], 
texcoord[1], texcoord[2]
-                );
-
+            Object *triangle = 0;
+            if (have_textures) {
+              if (have_normals) {
+                if (debug) {
+                  cerr << "Creating TexTriangle( "<<material_index<<",\n"
+                       << "                     "<<vertex[0]<<", 
"<<vertex[1]-vertex[0]<<", "<<vertex[2]-vertex[0]<<",\n"
+                       << "                     "<<normal[0]<<", 
"<<normal[1]<<", "<<normal[2]<<",\n"
+                       << "                     "<<texcoord[0]<<", 
"<<texcoord[1]<<", "<<texcoord[2]<<");\n";
+                }
+                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]);
+              } else {
+                if (debug) {
+                  cerr << "Creating TexTriangle( "<<material_index<<",\n"
+                       << "                     "<<vertex[0]<<", 
"<<vertex[1]<<", "<<vertex[2]<<",\n"
+                       << "                     "<<texcoord[0]<<", 
"<<texcoord[1]<<", "<<texcoord[2]<<");\n";
+                }
+                triangle = new TexTriangle( material,
+                                            vertex[0], vertex[1], vertex[2],
+                                            texcoord[0], texcoord[1], 
texcoord[2]);
+              }
+            } else {
+              // No texture coordinates
+              if (have_normals) {
+                if (debug) {
+                  cerr << "Creating HeavyTriangle( "<<material_index<<",\n"
+                       << "                       "<<vertex[0]<<", 
"<<vertex[1]-vertex[0]<<", "<<vertex[2]-vertex[0]<<",\n"
+                       << "                       "<<normal[0]<<", 
"<<normal[1]<<", "<<normal[2]<<")\n";
+                }
+                triangle = new HeavyTriangle( material,
+                                              vertex[0], 
vertex[1]-vertex[0], vertex[2]-vertex[0],
+                                              normal[0], normal[1], 
normal[2]);
+              } else {
+                if (debug) {
+                  cerr << "Creating HeavyTriangle( "<<material_index<<",\n"
+                       << "                       "<<vertex[0]<<", 
"<<vertex[1]<<", "<<vertex[2]<<");\n";
+                }
+                triangle = new HeavyTriangle( material,
+                                              vertex[0], vertex[1], 
vertex[2]);
+              }
+            }
+            
             switch (which_BVH) {
             case RealisticBvh_Build:
                 triangle_array[tri] = triangle;
@@ -583,7 +640,7 @@
         double time_begin = Time::currentSeconds();
 
         // Construct the bvh.
-        bvh = new RealisticBvh( (Object **)triangle_array, total_triangles );
+        bvh = new RealisticBvh( triangle_array, total_triangles );
 
         double time_end = Time::currentSeconds();
 




  • [MANTA] r1261 - in trunk: Image Model/Groups Model/Readers/glm scenes, bigler, 12/18/2006

Archive powered by MHonArc 2.6.16.

Top of page