Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r1133 - in trunk: Core Core/Util Model/MiscObjects Model/Primitives


Chronological Thread 
  • From: knolla@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r1133 - in trunk: Core Core/Util Model/MiscObjects Model/Primitives
  • Date: Sat, 1 Jul 2006 09:13:32 -0600 (MDT)

Author: knolla
Date: Sat Jul  1 09:13:30 2006
New Revision: 1133

Added:
   trunk/Core/Util/LargeFile.cc
   trunk/Core/Util/LargeFile.h
Modified:
   trunk/Core/CMakeLists.txt
   trunk/Model/MiscObjects/BrickArray3.h
   trunk/Model/Primitives/IsosurfaceGridVolume.cc
   trunk/Model/Primitives/OctreeVolume.cc
   trunk/Model/Primitives/OctreeVolume.h
Log:
Fixed BrickArray3 for reading large files; created fread_big in Core/Util

Modified: trunk/Core/CMakeLists.txt
==============================================================================
--- trunk/Core/CMakeLists.txt   (original)
+++ trunk/Core/CMakeLists.txt   Sat Jul  1 09:13:30 2006
@@ -54,6 +54,8 @@
      Util/Args.h
      Util/Args.cc
      Util/Endian.h
+     Util/LargeFile.h
+     Util/LargeFile.cc
      Util/ThreadStorage.h
      Util/ThreadStorage.cc)
 

Added: trunk/Core/Util/LargeFile.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Util/LargeFile.cc        Sat Jul  1 09:13:30 2006
@@ -0,0 +1,26 @@
+
+#include <Core/Util/LargeFile.h>
+#include <fstream>
+
+namespace Manta
+{
+
+size_t fread_big(void *ptr, size_t size, size_t nitems, FILE *stream)
+{
+       unsigned long chunkSize = 0x7fffffff;
+       unsigned long remaining = size*nitems;
+       while (remaining > 0) {
+               unsigned long toRead = 
remaining>chunkSize?chunkSize:remaining;
+               unsigned long result;
+               if ((result = fread(ptr, toRead, 1, stream)) != 1) {
+                       fprintf(stderr, "read error: %ld != %ld",
+                                       toRead, result);
+                       return 0;
+               }
+               remaining -= toRead;
+               ptr = (char*)ptr + toRead;
+       }
+       return nitems;
+}
+
+};

Added: trunk/Core/Util/LargeFile.h
==============================================================================
--- (empty file)
+++ trunk/Core/Util/LargeFile.h Sat Jul  1 09:13:30 2006
@@ -0,0 +1,13 @@
+
+#ifndef Manta_Core_LargeFile_h
+#define Manta_Core_LargeFile_h
+
+#include <stdlib.h>
+#include <fstream>
+
+namespace Manta 
+{
+  size_t fread_big(void *ptr, size_t size, size_t nitems, FILE *stream);
+}
+
+#endif

Modified: trunk/Model/MiscObjects/BrickArray3.h
==============================================================================
--- trunk/Model/MiscObjects/BrickArray3.h       (original)
+++ trunk/Model/MiscObjects/BrickArray3.h       Sat Jul  1 09:13:30 2006
@@ -34,9 +34,9 @@
 
 public:
     //these are index arrays, the data is reorganized so that the memory for 
elem[x,y,z] is close to elem[x+-q,y+-q,z+-q]
-    int* idx1;
-    int* idx2;
-    int* idx3;
+    long* idx1;
+    long* idx2;
+    long* idx3;
 
     int dm1;
     int dm2;
@@ -72,9 +72,9 @@
     inline T* get_dataptr() {return objs;}
 
     //how big is it?
-    inline unsigned long get_datasize()
-       {
-               return totaldm1*totaldm2*totaldm3*sizeof(T);
+    inline long get_datasize()
+    {
+        return totaldm1*long(totaldm2*totaldm3*sizeof(T));
     }
 
     //allow more than one BrickArray to share the same data
@@ -118,12 +118,12 @@
        L2=(int)(pow((PAGESIZE*1.0)/(sizeof(T)*L1*L1*L1), 1./3.)+.1);
 
     //pad to make an even number of bricks in each dimension
-       int totalx=(dm1+L2*L1-1)/(L2*L1);
-       int totaly=(dm2+L2*L1-1)/(L2*L1);
-       int totalz=(dm3+L2*L1-1)/(L2*L1);
+       long totalx=(dm1+L2*L1-1)/(L2*L1);
+       long totaly=(dm2+L2*L1-1)/(L2*L1);
+       long totalz=(dm3+L2*L1-1)/(L2*L1);
 
     //create the x address index table
-       idx1=new int[dm1];
+       idx1=new long[dm1];
        for(int x=0;x<dm1;x++){
                int m1x=x%L1;
                int xx=x/L1;
@@ -135,7 +135,7 @@
                                m1x*L1*L1;
        }
     //create the y address index table
-       idx2=new int[dm2];
+       idx2=new long[dm2];
        for(int y=0;y<dm2;y++){
                int m1y=y%L1;
                int yy=y/L1;
@@ -147,7 +147,7 @@
                                m1y*L1;
        }
     //create the z address index table
-       idx3=new int[dm3];
+       idx3=new long[dm3];
        for(int z=0;z<dm3;z++){
                int m1z=z%L1;
                int zz=z/L1;
@@ -163,14 +163,14 @@
        totaldm1=totalx*L2*L1;
        totaldm2=totaly*L2*L1;
        totaldm3=totalz*L2*L1;
-       int totalsize=totaldm1*totaldm2*totaldm3;
+       long totalsize=totaldm1*long(totaldm2*totaldm3);
 
     //create the space to hold the data
     //objs=new T[totalsize];
     //the padding by CACHESIZE+PAGESIZE followed by 
     //the %CACHESIZE aligns start on a double word boundary.
        data=new char[totalsize*sizeof(T)+CACHESIZE+4096]; //original used 
4096, not 16384, why?
-       unsigned long off=(unsigned long)data%CACHESIZE;
+       long off=long(data)%CACHESIZE;
 
        if (off)
                objs=(T*)(data+CACHESIZE-off);
@@ -226,8 +226,8 @@
 template<class T>
                void BrickArray3<T>::initialize(const T& t)
 {
-       int n=dm1*dm2*dm3;
-       for(int i=0;i<n;i++)
+       long n=dm1*long(dm2*dm3);
+       for(long i=0;i<n;i++)
                objs[i]=t;
 }
 

Modified: trunk/Model/Primitives/IsosurfaceGridVolume.cc
==============================================================================
--- trunk/Model/Primitives/IsosurfaceGridVolume.cc      (original)
+++ trunk/Model/Primitives/IsosurfaceGridVolume.cc      Sat Jul  1 09:13:30 
2006
@@ -1,6 +1,7 @@
 
 #include <Model/Primitives/IsosurfaceGridVolume.h>
 #include <Model/Primitives/OctreeVolume.h>
+#include <Core/Util/LargeFile.h>
 #include <Interface/RayPacket.h>
 #include <Model/Intersections/IsosurfaceImplicit.h>
 
@@ -59,7 +60,7 @@
     Array3<ST> indata;
     indata.resize(nx, ny, nz);
     cerr << "Reading " << filename << "...";
-    fread((char*)(&indata.get_dataptr()[0][0][0]), 1, indata.get_datasize(), 
din);
+    fread_big((char*)(&indata.get_dataptr()[0][0][0]), 1, 
indata.get_datasize(), din);
     cerr << "done.\n";
     fclose(din);
 

Modified: trunk/Model/Primitives/OctreeVolume.cc
==============================================================================
--- trunk/Model/Primitives/OctreeVolume.cc      (original)
+++ trunk/Model/Primitives/OctreeVolume.cc      Sat Jul  1 09:13:30 2006
@@ -12,6 +12,7 @@
 */
 
 #include <Model/Primitives/OctreeVolume.h>
+#include <Core/Util/LargeFile.h>
 
 using namespace Manta;
 using namespace SCIRun;
@@ -21,26 +22,6 @@
        val = MIN(rmax, val);\
 \
 
-//use this for reading files over 4G.
-static size_t fread_big(void *ptr, size_t size, size_t nitems, FILE *stream)
-{
-       unsigned long chunkSize = 0x7fffffff;
-       unsigned long remaining = size*nitems;
-       while (remaining > 0) {
-               unsigned long toRead = 
remaining>chunkSize?chunkSize:remaining;
-               unsigned long result;
-               if ((result = fread(ptr, toRead, 1, stream)) != 1) {
-                       fprintf(stderr, "read error: %ld != %ld",
-                                       toRead, result);
-                       return 0;
-               }
-               remaining -= toRead;
-               ptr = (char*)ptr + toRead;
-       }
-       return nitems;
-}
-
-
 OctreeVolume::OctreeVolume()
 {
 }
@@ -159,14 +140,18 @@
                 cerr << "Error opening original data file: " << 
filebase_numbered << '\n';
                 exit(1);
             }
-    
-#ifndef TEST_INDATA
-            Array3<ST> indata;
+
+           cerr << "(size of unsigned long is " << sizeof(unsigned long) << 
")" << endl;
+
+#ifdef TEST_INDATA
+           indata.resize(nx, ny, nz);
+#else
+           cerr << "Creating temporary Array3..." << endl;
+           Array3<ST> indata(nx, ny, nz);
 #endif
-            indata.resize(nx, ny, nz);
-            cerr << "indata(150,150,150)=" << indata(150,150,150) << endl; 
+            cerr << "indata(150,150,150)=" << (int)indata(150,150,150) << 
endl; 
             cerr << "Reading " << filebase_numbered << "...";
-            cerr << "(" << indata.get_datasize() << " read/" << nx * ny * nz 
* sizeof(ST) << " expected)...";
+            cerr << "(" << indata.get_datasize() << " read/" << 
nx*long(ny*nz*sizeof(ST)) << " expected)...";
             fread_big((char*)(&indata.get_dataptr()[0][0][0]), 1, 
indata.get_datasize(), din);
             cerr << "done.\n";
             fclose(din);

Modified: trunk/Model/Primitives/OctreeVolume.h
==============================================================================
--- trunk/Model/Primitives/OctreeVolume.h       (original)
+++ trunk/Model/Primitives/OctreeVolume.h       Sat Jul  1 09:13:30 2006
@@ -66,25 +66,25 @@
         ST values[8];
     };
        
-       struct OctNode
-       {
-               char offsets[8];        //-1 if leaf; 0-7 if child exists
-               ST mins[8];
-               ST maxs[8];
-               unsigned int children_start;
-               ST values[8];
-       };
+    struct OctNode
+    {
+        char offsets[8];       //-1 if leaf; 0-7 if child exists
+       ST mins[8];
+       ST maxs[8];
+       unsigned int children_start;
+       ST values[8];
+    };
 
     //node used in build
     struct BuildNode
     {
         char offsets[8];
-               ST values[8];
-               unsigned int myStart;
+       ST values[8];
+       unsigned int myStart;
         unsigned int children_start;
-               ST expected_value;
-               ST min, max;
-               unsigned char myIndex;
+       ST expected_value;
+       ST min, max;
+       unsigned char myIndex;
         bool keepMe;
         bool isLeaf;
     };
@@ -102,8 +102,8 @@
         //the maximum depth of the octree, finest resolution
         int max_depth;
                
-               //the depth of caps; always == max_depth-2
-               int cap_depth;
+       //the depth of caps; always == max_depth-2
+       int cap_depth;
         
         //the width of the kernel that is allegedly reading the octree data.
         //  This determines the ghosting overlap, if any, of the min/max 
values
@@ -146,9 +146,9 @@
         bool use_adaptive_res;         
         /* END VARS SHOULD BE IN OCTISOVOLUME */
                
-               #ifdef TEST_INDATA   
+#ifdef TEST_INDATA   
         SCIRun::Array3<ST> indata;
-               #endif    
+#endif    
         
         inline float getMaxTime() const
         {
@@ -221,23 +221,21 @@
         {
             return inv_child_bit_depth[d];
         }
-
         
         inline int get_max_depth() const
         {
             return max_depth;
         }
                
-               inline int get_cap_depth() const
-               {
-                       return cap_depth;
-               }
-
+       inline int get_cap_depth() const
+               {
+                   return cap_depth;
+               }
                
-               inline int get_pre_cap_depth() const
-               {
-                       return pre_cap_depth;
-               }
+       inline int get_pre_cap_depth() const
+               {
+                   return pre_cap_depth;
+       }
 
         OctreeVolume();
 




  • [MANTA] r1133 - in trunk: Core Core/Util Model/MiscObjects Model/Primitives, knolla, 07/01/2006

Archive powered by MHonArc 2.6.16.

Top of page