Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r681 - in branches/itanium2: Model/Groups Readers/DoubleEagle


Chronological Thread 
  • From: abe@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r681 - in branches/itanium2: Model/Groups Readers/DoubleEagle
  • Date: Sun, 30 Oct 2005 16:39:42 -0700 (MST)

Author: abe
Date: Sun Oct 30 16:39:38 2005
New Revision: 681

Modified:
   branches/itanium2/Model/Groups/KDTreeLoader.cc
   branches/itanium2/Readers/DoubleEagle/vn2v3c1.cc
Log:


Added code to clip fuction that will properly copy out normals from a .nor 
file when the model is clipped.
M    Readers/DoubleEagle/vn2v3c1.cc

Removed debug output statement.
M    Model/Groups/KDTreeLoader.cc


Modified: branches/itanium2/Model/Groups/KDTreeLoader.cc
==============================================================================
--- branches/itanium2/Model/Groups/KDTreeLoader.cc      (original)
+++ branches/itanium2/Model/Groups/KDTreeLoader.cc      Sun Oct 30 16:39:38 
2005
@@ -556,8 +556,8 @@
        int offset = 4; // skip the integer value in the beginning
        while (offset < fileSize) {
                kdtree->groupToNameMap->append(offset);
-               //fprintf(stderr, "offset %d\n", offset);
-               fprintf(stderr, "offset %d = %s\n", offset, 
&(*kdtree->groupNames)[offset]);
+               // fprintf(stderr, "offset %d\n", offset);
+               // fprintf(stderr, "offset %d = %s\n", offset, 
&(*kdtree->groupNames)[offset]);
                while ((*kdtree->groupNames)[offset]) // find next name
                        offset ++;
                offset++;

Modified: branches/itanium2/Readers/DoubleEagle/vn2v3c1.cc
==============================================================================
--- branches/itanium2/Readers/DoubleEagle/vn2v3c1.cc    (original)
+++ branches/itanium2/Readers/DoubleEagle/vn2v3c1.cc    Sun Oct 30 16:39:38 
2005
@@ -5,7 +5,9 @@
 
 #include <string>
 #include <vector>
+#include <list>
 #include <iostream>
+#include <map>
 
 #include <MantaTypes.h>
 #include <Core/Color/ColorDB.h>
@@ -43,7 +45,10 @@
 FILE *out_file = 0;
 int total_faces = 0;
 
-BBox bounds;
+// Output file name.
+char *output_file_name = 0;
+
+
 
 struct nv3_face {
        float normal0[3];
@@ -54,11 +59,27 @@
        float vertex2[3];
 };
 
+struct v3c1_color {
+       float color[3];
+  float &operator[] (int i ) { return color[i]; };
+  const float &operator[] (int i ) const { return color[i]; };
+
+  bool operator == (const v3c1_color &c) const {
+    return
+      (color[0] == c[0]) &&
+      (color[1] == c[1]) &&
+      (color[2] == c[2]);
+  }
+};
+
+
+
 struct v3c1_face {
        float vertex0[3];
        float vertex1[3];
        float vertex2[3];
-       float color[3];
+
+  v3c1_color color;
        
        v3c1_face() {  };
        v3c1_face( const nv3_face &nv_, unsigned char new_color[3] ) {
@@ -69,8 +90,7 @@
 
                color[0] = 0.003921f * (float)new_color[0];
                color[1] = 0.003921f * (float)new_color[1];
-               color[2] = 0.003921f * (float)new_color[2];
-               
+               color[2] = 0.003921f * (float)new_color[2];             
        }
        
        float *vertex( int i ) {
@@ -85,8 +105,50 @@
        }
 };
 
+typedef VectorT<float, 3> Vectorf; 
+struct vertex_normals {
+  Vectorf normal[3];
+};
+
 vector<nv3_face>  in_buffer;
 vector<v3c1_face> out_buffer;
+vector<vertex_normals>   normal_buffer;
+
+// Objects containing global results
+BBox bounds;
+
+class FaceColorMap {
+private:
+  typedef pair<v3c1_color,int> PairType;
+  typedef list< PairType > ListType;
+  ListType color_list;
+public:
+  typedef ListType::iterator iterator;
+
+  int size() const { return color_list.size(); };
+  int &operator[] ( const v3c1_color &c ) {
+
+    // Seach for the color in the list.
+    ListType::iterator color = color_list.begin();
+    while (color != color_list.end()) {
+      if (color->first == c) {
+        break;
+      }
+      ++color;
+    }
+
+    // Check to see if the color wasn't found.
+    if (color == color_list.end()) {
+      color_list.push_front( PairType( c, 0 ) );
+      color = color_list.begin();
+    }
+
+    // Return the number.
+    return color->second;    
+  }
+  iterator begin() { return color_list.begin(); };
+  iterator end() { return color_list.end(); };
+};
 
 struct m_vertex {
   float v[3];
@@ -101,9 +163,6 @@
        int file_list_begin = 0;
        int file_list_end = 0;
        
-       // Output file name.
-       char *output_file_name = 0;
-
        // Cutting plane.
        Point  plane_point;
        Vector plane_normal;
@@ -595,10 +654,14 @@
        
        // Compute the bounds of this file.
        BBox file_bounds;
-       
-       // Copy the faces into the output buffer.
+  FaceColorMap file_color_map;
+  
+       // Examine each face.
        for (int i=0;i<file_faces;++i) {
-               
+
+    // Add this face color to the face color map.
+    file_color_map[ out_buffer[i].color ]++;
+    
                // Compute the bounds of the face.
                file_bounds.extendByPoint( Point( out_buffer[i].vertex0[0], 
out_buffer[i].vertex0[1], out_buffer[i].vertex0[2] ) );
                file_bounds.extendByPoint( Point( out_buffer[i].vertex1[0], 
out_buffer[i].vertex1[1], out_buffer[i].vertex1[2] ) );
@@ -609,7 +672,16 @@
        std::cout << " " << file_bounds[0][0] << " " << file_bounds[0][1] <<" 
" << file_bounds[0][2]
                        << " " << file_bounds[1][0] << " " << 
file_bounds[1][1] <<" " << file_bounds[1][2] 
                        << std::endl;
-       
+
+  // Output the colors.
+  std::cout << "Total colors: " << file_color_map.size() << std::endl;
+  FaceColorMap::iterator iter = file_color_map.begin();
+  while (iter != file_color_map.end()) {
+    std::cout << "\t Color " << iter->first[0] << " " << iter->first[1] << " 
" << iter->first[2] << ": "
+              << iter->second << std::endl;
+    ++iter;
+  }
+
        // Add this file's bounds to the bounds of all the files.
        bounds.extendByBox( file_bounds );
        
@@ -641,13 +713,61 @@
        else {
                printf( "%s faces: %d\n", file_name, (int)file_faces );
        }
-       
+
+  // Determine normal file name.
+  char normal_file_name[64];
+  sprintf( normal_file_name, "%s.nor", file_name );
+  printf( "Checking for normal file: %s\n", normal_file_name );
+  
+  // Check to see if normal data is available.
+  FILE *normal_file = 0;
+  bool use_normals = true;
+  if ((normal_file = fopen( normal_file_name, "r" )) == 0) {
+    perror( "Could not find normal file.");
+    use_normals = false;
+  }
+
+  // Check to make sure there are the correct number of normals.
+  int file_normals = 0;
+  if (use_normals) {
+    fseek( normal_file, 0, SEEK_END );
+    file_size = ftell( normal_file );
+    fseek( normal_file, 0, SEEK_SET );
+
+    // Check for incomplete data.
+    if ((file_size % (sizeof(Vectorf)*3)) != 0) {
+      printf( "%s size %d is not a multiple of 3*sizeof(Vectorf) (%d)\n",
+              normal_file_name, (int)file_size, (int)(3*sizeof(Vectorf)) );
+    }
+
+    // Check for matching number of normals.
+    file_normals = file_size / sizeof(Vectorf);
+    if ((file_faces*3) != file_normals) {
+      printf( "%s contains %d normals which does not match %d faces *3\n",
+              normal_file_name, file_normals, (int)file_faces );
+    }
+  }
+
        // Read in the data.
        out_buffer.resize( file_faces );
-       fread( &out_buffer[0], sizeof(v3c1_face), file_faces, in_file );
-       
+       fread( &out_buffer[0], sizeof(v3c1_face), file_faces, in_file );      
  
        fclose( in_file );
-       
+
+  FILE *out_normal_file;
+  if (use_normals) {
+    // Read in the normals.
+    normal_buffer.resize( file_faces );
+    fread( &normal_buffer[0], sizeof(vertex_normals), file_faces, 
normal_file );
+    fclose( normal_file );
+
+    sprintf( normal_file_name, "%s.nor", output_file_name );
+    
+    // Open normal output file.
+    if ((out_normal_file = fopen( normal_file_name, "w" )) == 0) {
+      perror( "Could not open normal output file for writing\n" );
+    }
+  }
+
        // Copy the faces into the output buffer.
        for (int i=0;i<file_faces;++i) {
 
@@ -679,9 +799,16 @@
                                
                                        bounds.extendByPoint( vertex );
                        }
-                       
+
+      // Output the face.
                        ++total_faces;
                        fwrite( &out_buffer[i], sizeof( v3c1_face ), 1, 
out_file );
+
+      if (use_normals) {
+        // Output the normals.
+        fwrite( &normal_buffer[i], sizeof(vertex_normals), 1, 
out_normal_file );
+      }
                }
        }
 }
+




  • [MANTA] r681 - in branches/itanium2: Model/Groups Readers/DoubleEagle, abe, 10/30/2005

Archive powered by MHonArc 2.6.16.

Top of page