Manta Interactive Ray Tracer Development Mailing List

Text archives Help


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


Chronological Thread 
  • From: hansong@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r361 - branches/itanium2/Model/Groups
  • Date: Tue, 31 May 2005 21:36:46 -0600 (MDT)

Author: hansong
Date: Tue May 31 21:36:45 2005
New Revision: 361

Modified:
   branches/itanium2/Model/Groups/kdtree.cc
Log:
Add loader for n1v3/bin format. This format is used with the original Double 
Eagle tanker model. (The sum-up on current formats: .n1v3 for Double Eagle; 
v3c1 for Boeing 777; .tri for misc triangle models)

Modified: branches/itanium2/Model/Groups/kdtree.cc
==============================================================================
--- branches/itanium2/Model/Groups/kdtree.cc    (original)
+++ branches/itanium2/Model/Groups/kdtree.cc    Tue May 31 21:36:45 2005
@@ -149,7 +149,7 @@
        return 1;
 }
 
-int LoadBin_V3C1(const char *filename, VArray<Triangle> **tris, /*Vec3f 
**perVertNormals,*/ Vectorf **perVertNormals, BBox &bounds ) {
+int LoadBin_V3C1(const char *filename, VArray<Triangle> **tris, /*Vectorf 
**perVertNormals,*/ Vectorf **perVertNormals, BBox &bounds ) {
        
        FILE *f;
        if ((f=fopen(filename, "r")) == NULL) {
@@ -205,7 +205,7 @@
                   (*perVertNormals)[3*i] = 
                   (*perVertNormals)[3*i+1] = 
                   (*perVertNormals)[3*i+2] =
-                  Vec3f(_rawData[0], _rawData[1], _rawData[2]);
+                  Vectorf(_rawData[0], _rawData[1], _rawData[2]);
                 */
 
                // Check to see if we are on a big endian system
@@ -282,6 +282,88 @@
        return 1;
 }
 
+int LoadBin_N1V3(const char *filename, VArray<Triangle> **tris, 
+               Vectorf **perVertNormals,
+               BBox &bounds,
+               long long maxtris=-1)
+{
+       FILE *f;
+       int nFloatPerTri = 3+9;
+       int triSize = nFloatPerTri*sizeof(float);
+
+       if ((f=fopen(filename, "r")) == NULL) {
+               fprintf(stderr, "Cannot open file: %s\n", filename);
+               return 0;
+       }
+
+       fseek(f, 0, SEEK_END);
+       long long fileSize = ftell(f);
+       // One normal followed by 3 vertices
+       long long nTris = fileSize / ((3+9)*4);
+
+       if (maxtris>0 && nTris > maxtris)
+               nTris = maxtris;
+
+       long long totalNumFloats = nFloatPerTri * nTris;
+       float *rawData = new float [totalNumFloats];
+       long i;
+#pragma omp parallel for private (i)
+       for (i=0; i<totalNumFloats; i+=1024*4) {
+               rawData[i] = 0;
+       }
+       fseek(f, 0, SEEK_SET);
+       long long nFloats = 
+               fread(rawData, sizeof(float), totalNumFloats, f);
+       if (nFloats != totalNumFloats) {
+               fprintf(stderr, "Error reading file: %s (size in floats: %lld 
read: %lld)\n", filename, totalNumFloats, nFloats);
+       }
+
+       *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] =
+                       Vectorf(_rawData[0], _rawData[1], _rawData[2]);
+               (**tris)[i][0] = Point(_rawData[3], _rawData[4], _rawData[5]);
+               _rawData += 6;
+               (**tris)[i][1] = Point(_rawData[0], _rawData[1], _rawData[2]);
+               _rawData += 3;
+               (**tris)[i][2] = Point(_rawData[0], _rawData[1], _rawData[2]);
+               _rawData += 3;
+               (**tris)[i].payload = 0xFFFFFF;
+               (**tris)[i].edge1 = (**tris)[i][1] - (**tris)[i][0]; 
+               (**tris)[i].edge2 = (**tris)[i][2] - (**tris)[i][0]; 
+
+               //
+               // Update the bounding box of the whole scene
+          for (int j=0; j<3; j++) {
+                  Triangle &tri = (**tris)[i];
+                       bounds.extendByPoint( tri[0] );
+                       bounds.extendByPoint( tri[1] );
+                       bounds.extendByPoint( tri[2] ); 
+          }
+       }
+       /*
+          for (int i=0; i<nTris; i++) {
+          Triangle &tri = (**tris)[i];
+          printf("%f %f %f ", tri.v0[0], tri.v0[1], tri.v0[2]); 
+          printf("%f %f %f ", tri.v1[0], tri.v1[1], tri.v1[2]); 
+          printf("%f %f %f ", tri.v2[0], tri.v2[1], tri.v2[2]); 
+          printf("0xFF0000\n");
+          }
+        */
+       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;
@@ -306,6 +388,8 @@
                LoadTris(fn, &tris, NULL, &normals, bbox );
        } else if (strstr(fn, ".v3c1")) {
                LoadBin_V3C1(fn, &tris, &normals, bbox );
+       } else if (strstr(fn, ".bin") || strstr(fn, "n1v3")) {
+               LoadBin_N1V3(fn, &tris, &normals, bbox );
        } else {
                fprintf(stderr, "Unrecognized file type.\n");
                return 0;




  • [MANTA] r361 - branches/itanium2/Model/Groups, hansong, 05/31/2005

Archive powered by MHonArc 2.6.16.

Top of page