Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r353 - branches/itanium2/Model/Groups


Chronological Thread 
  • From: hansong@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r353 - branches/itanium2/Model/Groups
  • Date: Thu, 26 May 2005 17:19:39 -0600 (MDT)

Author: hansong
Date: Thu May 26 17:19:38 2005
New Revision: 353

Modified:
   branches/itanium2/Model/Groups/kdtree.cc
Log:
add loader for v3c1 binary triangle data

Modified: branches/itanium2/Model/Groups/kdtree.cc
==============================================================================
--- branches/itanium2/Model/Groups/kdtree.cc    (original)
+++ branches/itanium2/Model/Groups/kdtree.cc    Thu May 26 17:19:38 2005
@@ -136,6 +136,97 @@
        return 1;
 }
 
+int LoadBin_V3C1(const char *filename, VArray<Triangle> **tris, 
+               // Vec3f **perVertNormals,
+               Vectorf **perVertNormals, 
+           BBox &bounds )
+{
+       FILE *f;
+       if ((f=fopen(filename, "r")) == NULL) {
+               fprintf(stderr, "Cannot open file: %s\n", filename);
+               return 0;
+       }
+
+       fseek(f, 0, SEEK_END);
+       long fileSize = ftell(f);
+       // One normal followed by 3 vertices
+       long nTris = fileSize / (12*sizeof(float));
+       int nFloats = fileSize/4;
+       float *rawData = new float [fileSize / 4];
+       //
+       // touch data for good distribution
+       //
+       long i;
+
+#pragma omp parallel for private (i)
+       for (i=0; i<nFloats; i+=1024*4) {
+               rawData[i] = 0;
+       }
+
+       fseek(f, 0, SEEK_SET);
+       long trisRead = fread(rawData, 48, fileSize/48, f);
+       if (trisRead != nTris) {
+               fprintf(stderr, "Error reading file: %s Tris read: %ld; 
expected: %ld\n", filename, trisRead, nTris);
+       }
+
+
+
+
+       *tris = new VArray<Triangle> (nTris);
+       (*tris)->setLen(nTris);
+       *perVertNormals = new Vectorf [nTris*3];
+
+       float *_rawData;
+#pragma omp parallel for private (_rawData, i)
+       for (i=0; i<nTris; i++) {
+               _rawData = rawData + 12 * i;
+               /*
+                  (*perVertNormals)[3*i] = 
+                  (*perVertNormals)[3*i+1] = 
+                  (*perVertNormals)[3*i+2] =
+                  Vec3f(_rawData[0], _rawData[1], _rawData[2]);
+                */
+
+               (**tris)[i][0] = Pointf(_rawData[0], _rawData[1], 
_rawData[2]);
+               _rawData += 3;
+               (**tris)[i][1] = Pointf(_rawData[0], _rawData[1], 
_rawData[2]);
+               _rawData += 3;
+               (**tris)[i][2] = Pointf(_rawData[0], _rawData[1], 
_rawData[2]);
+               _rawData += 3;
+               long r, g, b;
+               r = int(_rawData[0] * 255 + .5f);
+               g = int(_rawData[1] * 255 + .5f);
+               b = int(_rawData[2] * 255 + .5f);
+               _rawData += 3;
+
+               (**tris)[i].edge1 = (**tris)[i][1] - (**tris)[i][0]; 
+               (**tris)[i].edge2 = (**tris)[i][2] - (**tris)[i][0]; 
+               (**tris)[i].payload = ((r<<16)+(g<<8)+b);
+
+               Vectorf v01, v02;
+               v01 = (**tris)[i][1] - (**tris)[i][0];
+               v02 = (**tris)[i][2] - (**tris)[i][0];
+               (*perVertNormals)[3*i] = Cross(v01, v02).normal();
+
+               (*perVertNormals)[3*i+1] =
+                       (*perVertNormals)[3*i+2] = (*perVertNormals)[3*i];
+
+               //
+               // Update the bounding box of the whole scene
+               for (long j=0; j<3; j++) {
+                       Triangle &tri = (**tris)[i];
+                       bounds.extendByPoint( tri[0] );
+                       bounds.extendByPoint( tri[1] );
+                       bounds.extendByPoint( tri[2] ); 
+               }
+
+       }
+
+       fprintf(stderr, "Triangles loaded: %d\n", nTris);
+       delete [] rawData;
+       return 1;
+}
+
 // This structure is only used to read from the kd tree file.
 struct AABox3f {
        Pointf min, max;
@@ -156,7 +247,14 @@
 int KDTree::load( const char *fn) {
        
        // Call a helper function to load the triangles.
-       LoadTris(fn, &tris, NULL, &normals, bbox );
+       if (strstr(fn, ".tri")) {
+               LoadTris(fn, &tris, NULL, &normals, bbox );
+       } else if (strstr(fn, ".v3c1")) {
+               LoadBin_V3C1(fn, &tris, &normals, bbox );
+       } else {
+               fprintf(stderr, "Unrecognized file type.\n");
+               return 0;
+       }
 
        
/////////////////////////////////////////////////////////////////////////////
        // Load the kd tree.




  • [MANTA] r353 - branches/itanium2/Model/Groups, hansong, 05/26/2005

Archive powered by MHonArc 2.6.16.

Top of page