Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r1077 - in trunk: Model/Primitives scenes


Chronological Thread 
  • From: knolla@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r1077 - in trunk: Model/Primitives scenes
  • Date: Sat, 20 May 2006 22:55:51 -0600 (MDT)

Author: knolla
Date: Sat May 20 22:55:42 2006
New Revision: 1077

Modified:
   trunk/Model/Primitives/IsosurfaceOctreeVolume.cc
   trunk/Model/Primitives/IsosurfaceOctreeVolume.h
   trunk/Model/Primitives/OctreeVolume.cc
   trunk/Model/Primitives/OctreeVolume.h
   trunk/scenes/octisovol.cc
Log:
improvements to octree volumes: everything except shading now works.

Modified: trunk/Model/Primitives/IsosurfaceOctreeVolume.cc
==============================================================================
--- trunk/Model/Primitives/IsosurfaceOctreeVolume.cc    (original)
+++ trunk/Model/Primitives/IsosurfaceOctreeVolume.cc    Sat May 20 22:55:42 
2006
@@ -43,136 +43,90 @@
     return octdata->get_bounds();
 }
 
-bool IsosurfaceOctreeVolume::bbox_intersects(const BBox& box, const 
RayPacket& rays) const
-{
-    for (int ray = rays.begin(); ray < rays.end(); ray++ )
-    {
-        float maximum_minimum = 1e-5;
-        float minimum_maximum = rays.getMinT(ray);
-
-        float x_minimum = (box[rays.getSign(ray,0)][0]   - 
rays.getOrigin(ray,0)) * rays.getInverseDirection(ray,0);
-        float x_maximum = (box[1-rays.getSign(ray,0)][0] - 
rays.getOrigin(ray,0)) * rays.getInverseDirection(ray,0);
-
-        float y_minimum = (box[rays.getSign(ray,1)][1]   - 
rays.getOrigin(ray,1)) * rays.getInverseDirection(ray,1);
-        float y_maximum = (box[1-rays.getSign(ray,1)][1] - 
rays.getOrigin(ray,1)) * rays.getInverseDirection(ray,1);
-
-        float z_minimum = (box[rays.getSign(ray,2)][2]   - 
rays.getOrigin(ray,2)) * rays.getInverseDirection(ray,2);
-        float z_maximum = (box[1-rays.getSign(ray,2)][2] - 
rays.getOrigin(ray,2)) * rays.getInverseDirection(ray,2);
-
-        if ( minimum_maximum < x_minimum ||
-             maximum_minimum > x_maximum )
-            continue;
-        if ( minimum_maximum > x_maximum )
-            minimum_maximum = x_maximum;
-        if ( maximum_minimum < x_minimum )
-            maximum_minimum = x_minimum;
-        if ( minimum_maximum < y_minimum ||
-             maximum_minimum > y_maximum )
-            continue;
-        if ( minimum_maximum > y_maximum )
-                minimum_maximum = y_maximum;
-        if ( maximum_minimum < y_minimum )
-            maximum_minimum = y_minimum;
-
-        if ( minimum_maximum >= z_minimum &&
-             maximum_minimum <= z_maximum )
-            return true; // found a hit
-    }
-    return false;
-}
-
 void IsosurfaceOctreeVolume::intersect(RenderContext const &context, 
RayPacket &packet) const
 {
-    if(bbox_intersects(octdata->get_bounds(), packet))
-    {
-        for ( int i = packet.rayBegin; i < packet.rayEnd; i++ )
-            single_intersect(packet, i);
-    }
+    for ( int i = packet.rayBegin; i < packet.rayEnd; i++ )
+        single_intersect(packet, i);
 }
 
 void IsosurfaceOctreeVolume::single_intersect(RayPacket& rays, int 
which_one) const
 {
-    //find tenter, texit, penter using ray-AABB intersection
-    Vector ws_dir = rays.getDirection(which_one);
-    Vector ws_inv_dir = rays.getInverseDirection(which_one);
-    Vector ws_orig = rays.getOrigin(which_one);
-    Vector min = octdata->get_bounds().getMin();
-    Vector max = octdata->get_bounds().getMax();
-    
-    //first, transform ray from world space to octree space on [0, 1 << 
octdata->get_max_depth()]^3
-    Vector orig = 
octdata->get_inv_node_width(octdata->get_max_depth()-1-octdata->get_multires_level())
 * (ws_orig - min);
-    Vector dir = 
octdata->get_inv_node_width(octdata->get_max_depth()-1-octdata->get_multires_level())
 * ws_dir;
-    Vector inv_dir = 
octdata->get_node_width(octdata->get_max_depth()-1-octdata->get_multires_level())
 * ws_inv_dir;
-
-    //XXX - implement improved ray/AABB for this? (precompute signs?)
-    float tenter, texit;
-    float max_width = (float)(octdata->get_child_bit_depth(0)<<1);
-    if(dir.x() > 0)
-    {
-        tenter = inv_dir.x() * (-orig.x());
-        texit = inv_dir.x() * (max_width-orig.x());
-    } 
-    else 
+    Vector t0;
+    Vector t1;
+    Vector t1p;
+    
+    Vector orig = rays.getOrigin(which_one);
+    Vector dir = rays.getDirection(which_one);
+    //Vector inv_dir = rays.getInverseDirection(which_one);
+    Vector inv_dir = dir.inverse();
+    
+#pragma unroll(3)
+    for(int axis=0; axis<3; axis++)
     {
-        tenter = inv_dir.x() * (max_width-orig.x());
-        texit = inv_dir.x() * (-orig.x());
+        t0.data[axis] = -orig.data[axis] * inv_dir.data[axis];
+        t1.data[axis] = (octdata->dims[axis] - orig.data[axis]) * 
inv_dir.data[axis];
+        t1p.data[axis] = (octdata->padded_dims[axis] - orig.data[axis]) * 
inv_dir.data[axis];
     }
-
-    float y0, y1;
-    if(dir.y() > 0)
+    float tenter, texit, tenter_padded, texit_padded;
+    if (rays.getSign(which_one,0))
     {
-        y0 = inv_dir.y() * (-orig.y());
-        y1 = inv_dir.y() * (max_width-orig.y());
-    } 
-    else 
-    {
-        y0 = inv_dir.y() * (max_width-orig.y());
-        y1 = inv_dir.y() * (-orig.y());
+        tenter = t1.data[0];
+        tenter_padded = t1p.data[0];
+        texit = texit_padded = t0.data[0];
     }
-    tenter = MAX(tenter, y0);
-    texit = MIN(texit, y1);
-    if (tenter > texit)
-        return;
-
-    float z0, z1;
-    if(dir.z() > 0)
+    else
     {
-        z0 = inv_dir.z() * (-orig.z());
-        z1 = inv_dir.z() * (max_width-orig.z());
-    } 
-    else 
+        tenter = tenter_padded = t0.data[0];
+        texit = t1.data[0];
+        texit_padded = t1p.data[0];
+    }
+#pragma unroll(2)
+    for(int axis=1; axis<3; axis++)
     {
-        z0 = inv_dir.z() * (max_width-orig.z());
-        z1 = inv_dir.z() * (-orig.z());
+        if (rays.getSign(which_one,axis))
+        {
+            tenter = MAX(tenter, t0.data[axis]);
+            tenter_padded = MAX(tenter_padded, t0.data[axis]);
+            texit = MIN(texit, t1.data[axis]);
+            texit_padded = MIN(texit_padded, t1p.data[axis]);
+        }
+        else
+        {
+            tenter = MAX(tenter, t1.data[axis]);
+            tenter_padded = MAX(tenter_padded, t1p.data[axis]);
+            texit = MIN(texit, t0.data[axis]);
+            texit_padded = MIN(texit_padded, t0.data[axis]);
+        }
+        if (tenter > texit)
+            return;
     }
-    tenter = MAX(tenter, z0);
-    texit = MIN(texit, z1);
-    if (tenter > texit)
-        return;
-
-    if (texit < 0.)
+        
+    if (texit < 0.f)
         return;
-
-    tenter = MAX(0., tenter);
+        
+    //tenter = MAX(0.f, tenter);
 
     unsigned int index_trace[octdata->get_max_depth()+1];
 
     Vec3i cell(0,0,0);
     
-    single_traverse_node(rays, which_one, orig, dir, inv_dir, 
octdata->get_multires_level(), 0, 0, index_trace, cell, tenter, texit);  
+    single_traverse_node(rays, which_one, orig, dir, inv_dir, 
octdata->get_multires_level(), 
+                        0, 0, index_trace, cell, tenter, texit_padded);      
  
 }      
        
 bool IsosurfaceOctreeVolume::single_traverse_node(RayPacket& rays, int 
which_one,
-                          const Vector& orig, const Vector& dir, const 
Vector& inv_dir, int res,
-                          int depth, int node_index, unsigned int 
index_trace[], Vec3i& cell, const float tenter, 
-                          const float texit) const
+                        const Vector& orig, const Vector& dir, const Vector& 
inv_dir, 
+                        int res, int depth, unsigned int node_index, 
+                        unsigned int index_trace[], Vec3i& cell, const float 
tenter, 
+                        const float texit) const
 {
     OctNode& node = octdata->get_node(depth, node_index);
-        
+                      
     index_trace[depth] = node_index;
     
-    int child_bit = octdata->get_child_bit_depth(depth+res);
-    Vector center(static_cast<float>(cell.data[0] | child_bit), 
static_cast<float>(cell.data[1] | child_bit), static_cast<float>(cell.data[2] 
| child_bit));
+    int child_bit = octdata->get_child_bit_depth(depth);
+    Vector center(static_cast<float>(cell.data[0] | child_bit), 
+                static_cast<float>(cell.data[1] | child_bit), 
static_cast<float>(cell.data[2] | child_bit));
     Vector tcenter = inv_dir * (center - orig);
     
     Vector penter = orig + dir*tenter;
@@ -247,6 +201,7 @@
         {
             if (node.scalar_leaf & (1 << target_child))
             {
+                return false;
                 if (single_traverse_leaf(rays, which_one, orig, dir, 
inv_dir, res, 
                     next_depth, depth, node.children[target_child].scalar, 
                     child_cell, index_trace, child_cell, child_tenter, 
child_texit))
@@ -254,18 +209,16 @@
             }
             else
             {
-                int child_idx = node.children_start + 
node.children[target_child].offset;
-                if (next_depth+1 == octdata->get_max_depth()-res)      //cap
+                unsigned int child_idx = node.children_start + 
node.children[target_child].offset;
+                if (next_depth+1 == octdata->get_max_depth())  //cap
                 {                      
-                    if (single_traverse_cap(rays, which_one, orig, dir, 
inv_dir, 
-                        res, next_depth, child_idx,
+                    if (single_traverse_cap(rays, which_one, orig, dir, 
inv_dir, res, next_depth, child_idx,
                         index_trace, child_cell, child_tenter, child_texit))
                         return true;
                 }
                 else
                 {
-                    if (single_traverse_node(rays, which_one, orig, dir, 
inv_dir, 
-                        res, next_depth, child_idx,
+                    if (single_traverse_node(rays, which_one, orig, dir, 
inv_dir, res, next_depth, child_idx,
                         index_trace, child_cell, child_tenter, child_texit))
                         return true;
                 }
@@ -378,9 +331,8 @@
             if (depth == octdata->get_max_depth()-1-res)
             {
                 //try isosurface intersection
-                Vector child_cell_float(child_cell.data[0], 
child_cell.data[1], child_cell.data[2]);
-                Vector cmin = (child_cell_float * 
octdata->get_node_width(depth)) + octdata->get_bounds().getMin();
-                Vector cmax = cmin + octdata->get_node_width(depth);
+                Vector cmin(child_cell.data[0], child_cell.data[1], 
child_cell.data[2]);
+                Vector cmax = cmin + Vector(1.f,1.f,1.f);
                 
 #ifdef USE_OCTREE_DATA
                 //use octree data
@@ -497,7 +449,7 @@
                     if (IsosurfaceImplicit::single_intersect(rays, 
which_one, cmin, cmax, rho, 
                         octdata->get_isovalue(), child_tenter, child_texit, 
hit_t))
                     {
-                        if (rays.hit(which_one, hit_t, 
PrimitiveCommon::getMaterial(), 0, 0)) 
+                        if (rays.hit(which_one, hit_t, 
PrimitiveCommon::getMaterial(), this, 0)) 
                         {
                             Vector normal;
                             Vector phit = rays.getOrigin(which_one) + 
rays.getDirection(which_one)*hit_t;
@@ -512,7 +464,8 @@
             else //not at cap-level depth
             {
                 if (single_traverse_leaf(rays, which_one, orig, dir, 
inv_dir, res, 
-                    next_depth, leaf_depth, scalar, leaf_base_cell, 
index_trace, child_cell, child_tenter, child_texit))
+                    next_depth, leaf_depth, scalar, leaf_base_cell, 
+                    index_trace, child_cell, child_tenter, child_texit))
                     return true;
             }
         }
@@ -538,9 +491,9 @@
 }
 
 bool IsosurfaceOctreeVolume::single_traverse_cap(RayPacket& rays, int 
which_one,
-                          const Vector& orig, const Vector& dir, const 
Vector& inv_dir, int res,
-                          int depth, int cap_index, unsigned int 
index_trace[], Vec3i& cell, 
-                          const float tenter, const float texit) const
+                        const Vector& orig, const Vector& dir, const Vector& 
inv_dir, int res, 
+                        int depth, unsigned int cap_index, unsigned int 
index_trace[], Vec3i& cell, 
+                        const float tenter, const float texit) const
 {      
     OctCap& cap = octdata->get_cap(cap_index);        
     index_trace[depth] = cap_index;
@@ -614,9 +567,8 @@
         }
 
         //try isosurface intersection in this node
-        Vector child_cell_float(child_cell.data[0], child_cell.data[1], 
child_cell.data[2]);
-        Vector cmin = (child_cell_float * octdata->get_node_width(depth)) + 
octdata->get_bounds().getMin();
-        Vector cmax = cmin + octdata->get_node_width(depth);
+        Vector cmin(child_cell.data[0], child_cell.data[1], 
child_cell.data[2]);
+        Vector cmax = cmin + Vector(1.f,1.f,1.f);
         
 #ifdef USE_OCTREE_DATA
         //use octree data
@@ -720,7 +672,7 @@
             if (IsosurfaceImplicit::single_intersect(rays, which_one, cmin, 
cmax, rho, 
                 octdata->get_isovalue(), child_tenter, child_texit, hit_t))
             {
-                if (rays.hit(which_one, hit_t, 
PrimitiveCommon::getMaterial(), 0, 0)) 
+                if (rays.hit(which_one, hit_t, 
PrimitiveCommon::getMaterial(), this, 0)) 
                 {
                     Vector normal;
                     Vector phit = rays.getOrigin(which_one) + 
rays.getDirection(which_one)*hit_t;

Modified: trunk/Model/Primitives/IsosurfaceOctreeVolume.h
==============================================================================
--- trunk/Model/Primitives/IsosurfaceOctreeVolume.h     (original)
+++ trunk/Model/Primitives/IsosurfaceOctreeVolume.h     Sat May 20 22:55:42 
2006
@@ -27,14 +27,12 @@
             BBox getBounds() const;
             
         private:    
-        
-            bool bbox_intersects(const BBox& box, const RayPacket& rays) 
const;
             
             void single_intersect(RayPacket& rays, int which_one) const;
             
             bool single_traverse_node(RayPacket& rays, int which_one,
                           const Vector& orig, const Vector& dir, const 
Vector& inv_dir, int res,
-                          int depth, int node_index, unsigned int 
index_trace[], Vec3i& cell, 
+                          int depth, unsigned int node_index, unsigned int 
index_trace[], Vec3i& cell, 
                           const float tenter, const float texit) const;
                           
             bool single_traverse_leaf(RayPacket& rays, int which_one,
@@ -43,8 +41,8 @@
                         unsigned int index_trace[], Vec3i& cell, const float 
tenter, const float texit) const;
                         
             bool single_traverse_cap(RayPacket& rays, int which_one,
-                          const Vector& orig, const Vector& dir, const 
Vector& inv_dir, int res,
-                          int depth, int cap_index, unsigned int 
index_trace[], Vec3i& cell, const float tenter, 
+                          const Vector& orig, const Vector& dir, const 
Vector& inv_dir, int res, 
+                          int depth, unsigned int cap_index, unsigned int 
index_trace[], Vec3i& cell, const float tenter, 
                           const float texit) const;
                           
                             //lookup returning 0 if out of bounds. Only 
works for scalar datatypes.

Modified: trunk/Model/Primitives/OctreeVolume.cc
==============================================================================
--- trunk/Model/Primitives/OctreeVolume.cc      (original)
+++ trunk/Model/Primitives/OctreeVolume.cc      Sat May 20 22:55:42 2006
@@ -21,7 +21,36 @@
        val = MIN(rmax, val);\
 \
 
-OctreeVolume::OctreeVolume(std::string filebase,
+//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()
+{
+}
+
+OctreeVolume::OctreeVolume(char* filebase)
+{
+    read_file(filebase);
+}
+
+OctreeVolume::OctreeVolume(char* filebase,
             int startTimestep, 
             int endTimestep,
             double variance_threshold, 
@@ -39,16 +68,6 @@
     current_timestep = 0;
     
     isoval = 22;
-
-#pragma unroll(3)
-    for(int i=0; i<3; i++)
-    {
-        pmin.data[i] = bounds[0].data[i];
-        pmax.data[i] = bounds[1].data[i];
-        diag.data[i] = bounds[1].data[i] - bounds[0].data[i];
-    }
-
-    cout << "diag = " << diag.data[0] << "," << diag.data[1] << "," << 
diag.data[2] << endl;
     
     //read in the octree data from .oth, .otd files
     {
@@ -58,8 +77,9 @@
         num_timesteps = endTimestep - startTimestep + 1;
         steps = new Timestep[num_timesteps];
         
-        std::string buf = filebase + ".hdr";
-        ifstream in(buf.c_str());
+        char buf[1024];
+        sprintf(buf, "%s.hdr", filebase);
+        ifstream in(buf);
     
         cerr<< "Reading original data: " << buf << endl;
         int nx, ny, nz;
@@ -70,7 +90,7 @@
             exit(1);
         }
             
-        in >> actual_dims.data[0] >> actual_dims.data[1] >> 
actual_dims.data[2];
+        in >> nx >> ny >> nz;    
         double x,y,z;
         in >> x >> y >> z;
         in >> x >> y >> z;
@@ -83,16 +103,28 @@
         datamin = isomin;
         datamax = isomax;
         use_adaptive_res = false;
-    
+        
+        int_dims.data[0] = nx;
+        int_dims.data[1] = ny;
+        int_dims.data[2] = nz;
+        dims.data[0] = (float)(int_dims.data[0]); 
+        dims.data[1] = (float)(int_dims.data[1]); 
+        dims.data[2] = (float)(int_dims.data[2]); 
+        
+        bounds[0] = Vector(0.f, 0.f, 0.f);
+        bounds[1] = dims;
+
         //determine the max_depth
         kernel_width = kernelWidth;    
-        cerr << "(Original data has dimensions " << actual_dims.data[0] << 
", " << actual_dims.data[1] << ", " << actual_dims.data[2] << ")\n";
+        cerr << "(Original data has dimensions " << int_dims.data[0] << ", " 
<< int_dims.data[1] << ", " << int_dims.data[2] << ")\n";
         double ddepth_1 = log((double)nx) / log(2.0);
         double ddepth_2 = log((double)ny) / log(2.0);
         double ddepth_3 = log((double)nz) / log(2.0);
         double ddepth = MAX(MAX(ddepth_1, ddepth_2), ddepth_3);
         max_depth = (int)(ceil(ddepth));
         
+        padded_dims.data[0] = padded_dims.data[1] = padded_dims.data[2] = 
(float)max_depth_bit;
+        
         //make the child_bit_depth arrays
         child_bit_depth = new int[max_depth+1];
         inv_child_bit_depth = new float[max_depth+1];
@@ -110,55 +142,43 @@
             exit(1);
         }
             
-        diag = pmax - pmin;
-    
         //read in the single-resolution data
-        char filebase_numbered[4000];
+        char filebase_numbered[4096];
         for(int fts = startTimestep, ts = 0; fts <= endTimestep; fts++, ts++)
         {
-            sprintf(filebase_numbered,"%s_%04i.raw",filebase,fts);
+            if (num_timesteps > 1)
+                sprintf(filebase_numbered,"%s_%04i.raw",filebase,fts);
+            else
+                sprintf(filebase_numbered,"%s.raw",filebase);
             
-            int din = open(filebase_numbered, O_RDONLY);
-            if (din == -1) 
+            FILE* din = fopen(filebase_numbered, "rb");
+            if (!din) 
             {
                 cerr << "Error opening original data file: " << 
filebase_numbered << '\n';
                 exit(1);
             }
     
-            Array3<ST> indata;
-            indata.resize(nx, ny, nz);
+            Array3<ST> indata(nx, ny, nz);
+            cerr << "indata(150,150,150)=" << indata(150,150,150) << endl; 
             cerr << "Reading " << filebase_numbered << "...";
-            cerr << "(" << indata.get_datasize() << " read/" << nx * ny * nz 
* sizeof(ST) << "expected)...";
-            read(din, indata.get_dataptr(), indata.get_datasize());
+            cerr << "(" << indata.get_datasize() << " read/" << nx * ny * nz 
* sizeof(ST) << " expected)...";
+            fread_big((char*)(&indata.get_dataptr()[0][0][0]), 1, 
indata.get_datasize(), din);
             cerr << "done.\n";
-            close(din);
+            fclose(din);
+            
+            cerr << "indata(150,150,150)=" << indata(150,150,150) << endl; 
                 
             //build the octree data from the single-res data.
             cerr << "Building multi-resolution octree data. (var thresh = 
"<< variance_threshold << ", kernel width = " << kernelWidth << ", mres 
levels = " << mresLevels << ")...";
             make_from_single_res_data(indata, ts, variance_threshold, 
kernelWidth, mresLevels, isomin, isomax);
         
-            cerr << "\nDone making from single res data\n";             
+            cerr << "\nDone making from single res data" << endl;            
   
         }
         
         write_file(filebase);
         
         multires_level = 0;
         current_timestep = 0;
-        
-        pad_scale_factor.data[0] = (float)max_depth_bit / 
(float)actual_dims.data[0];
-        pad_scale_factor.data[1] = (float)max_depth_bit / 
(float)actual_dims.data[1];
-        pad_scale_factor.data[2] = (float)max_depth_bit / 
(float)actual_dims.data[2];
-        
-        padded_diag = diag * pad_scale_factor;
-        padded_pmax = pmin + padded_diag;
-    
-        node_width = new Vector[max_depth];
-        inv_node_width = new Vector[max_depth];
-        for(int d=0; d<max_depth; d++)
-        {      
-            node_width[d] = padded_diag * (1.0f / (float)(1 << (d+1)));
-            inv_node_width[d] = node_width[d].inverse();
-        }
     }
 
     cout << "\nDone creating OctISOVolume!" << endl;
@@ -186,9 +206,6 @@
     
     delete[] child_bit_depth;
     delete[] inv_child_bit_depth;
-    
-    delete[] node_width;
-    delete[] inv_node_width;
 }
 
 
@@ -556,17 +573,19 @@
     delete[] buildnodes;
 }
 
-bool OctreeVolume::read_file(std::string filebase)
+bool OctreeVolume::read_file(char* filebase)
 {
-    cout << "\nReading octree volume data from \"" << filebase << "\".oth, 
.otd...";
+    cerr << "\nReading octree volume data from \"" << filebase << "\".oth, 
.otd...";
+    
+    char filename[1024];
+    sprintf(filename, "%s.oth", filebase);
     
-    string filename = filebase + ".oth";
-    ifstream in(filename.c_str());
+    ifstream in(filename);
     if (!in)
         return false;
-       
+        
     in >> max_depth;
-    in >> actual_dims.data[0] >> actual_dims.data[1] >> actual_dims.data[2];
+    in >> int_dims.data[0] >> int_dims.data[1] >> int_dims.data[2];
     in >> kernel_width;
     in >> datamin;
     in >> datamax;
@@ -583,21 +602,14 @@
        max_depth_bit = 1 << max_depth;
        inv_max_depth_bit = 1.0f / static_cast<float>(max_depth_bit);
     
-    pad_scale_factor.data[0] = (float)max_depth_bit / 
(float)actual_dims.data[0];
-    pad_scale_factor.data[1] = (float)max_depth_bit / 
(float)actual_dims.data[1];
-    pad_scale_factor.data[2] = (float)max_depth_bit / 
(float)actual_dims.data[2];
-    
-       padded_diag = diag * pad_scale_factor;
-       padded_pmax = pmin + padded_diag;
-    
-       node_width = new Vector[max_depth];
-       inv_node_width = new Vector[max_depth];
-       for(int d=0; d<max_depth; d++)
-       {       
-               node_width[d] = padded_diag * (1.0f / (float)(1 << (d+1)));
-               inv_node_width[d] = node_width[d].inverse();
-       }
-    
+    dims.data[0] = (float)(int_dims.data[0]);
+    dims.data[1] = (float)(int_dims.data[1]);
+    dims.data[2] = (float)(int_dims.data[2]);
+    padded_dims.data[0] = padded_dims.data[1] = padded_dims.data[2] = 
(float)max_depth_bit;
+            
+    bounds[0] = Vector(0.f, 0.f, 0.f);
+    bounds[1] = dims;       
+            
        current_timestep = 0;
        multires_level = 0;
     
@@ -612,18 +624,22 @@
         {
             steps[ts].num_nodes[r] = new unsigned int[max_depth-1];
             for(int d=0; d<max_depth-1-r; d++)
+            {
                 in >> steps[ts].num_nodes[r][d];
+            }
             in >> steps[ts].num_caps[r];
         }
     }
     
     in.close();
     
-    filename = filebase + ".otd";
-    
-    FILE *in2 = fopen(filename.c_str(),"rb");
+    sprintf(filename, "%s.otd", filebase);
+    FILE *in2 = fopen(filename,"rb");
     if (!in2)
+    {
+        cerr << "OctreeVolume: error reading octree data:" << filename << 
endl;
         return false;
+    }
     
     for(int ts = 0; ts < num_timesteps; ts++)
        {
@@ -635,6 +651,7 @@
             {
                 steps[ts].nodes[r][d] = new 
OctNode[steps[ts].num_nodes[r][d]];
                 int num_read = fread((char*)steps[ts].nodes[r][d], 
sizeof(OctNode), steps[ts].num_nodes[r][d],in2);
+                cerr << "Read " << num_read << " nodes" << " at depth " << d 
<< endl;
                 if (num_read != steps[ts].num_nodes[r][d])
                 {
                     cerr << "OctreeVolume: error reading octnodes" << endl;
@@ -643,8 +660,8 @@
             }
                        //read in the caps
                        steps[ts].caps[r] = new OctCap[steps[ts].num_caps[r]];
-                       //        read(in2, 
reinterpret_cast<char*>(steps[ts].caps[r]), steps[ts].num_caps[r] * 
sizeof(OctCap));
                        int num_read = 
fread((char*)steps[ts].caps[r],sizeof(OctCap),steps[ts].num_caps[r],in2);
+            cerr << "Read " << num_read << " caps" << endl;
                        if (num_read != steps[ts].num_caps[r])
             {
                 cerr << "OctreeVolume: error reading octcaps" << endl;
@@ -653,22 +670,24 @@
                }
        }
     fclose(in2);
-    cout << "done!\n";
+
+    cerr << "done!" << endl;
     
     return true;
 }
 
-bool OctreeVolume::write_file(std::string filebase)
+bool OctreeVolume::write_file(char* filebase)
 {
     cout << "\nWriting octree volume data to \"" << filebase << "\".oth, 
.otd...";
     
-    string filename = filebase + ".oth";
-    ofstream out(filename.c_str());
+    char filename[1024];
+    sprintf(filename, "%s.oth", filebase);
+    ofstream out(filename);
     if (!out)
         return false;
     
     out << max_depth << endl;
-    out << actual_dims.data[0] << " " << actual_dims.data[1] << " " << 
actual_dims.data[2] << endl;
+    out << int_dims.data[0] << " " << int_dims.data[1] << " " << 
int_dims.data[2] << endl;
     out << kernel_width << endl;
     out << datamin << " " << datamax << endl;
     out << num_timesteps << endl;
@@ -685,8 +704,8 @@
        }
     out.close();
        
-    filename = filebase + ".otd";
-    FILE* out2 = fopen(filename.c_str(), "wb");
+    sprintf(filename, "%s.otd", filebase);
+    FILE* out2 = fopen(filename, "wb");
     if (!out2)
         return false;
     

Modified: trunk/Model/Primitives/OctreeVolume.h
==============================================================================
--- trunk/Model/Primitives/OctreeVolume.h       (original)
+++ trunk/Model/Primitives/OctreeVolume.h       Sat May 20 22:55:42 2006
@@ -118,24 +118,13 @@
         };
         
         Timestep* steps;
-
-        int* refcnt;
         
-        /* THESE VARS SHOULD BE IN OCTISOVOLUME */
-        BBox bounds;
-        Vector pmin;
-        Vector pmax;
-        Vector padded_pmax;            //when actual dims are not exact 
powers of 2
-        
-        Vector diag;
-        Vector padded_diag;
-        Vector pad_scale_factor;
-        Vec3i actual_dims;             //the actual dims, padded to the 
lowest power of 2 that contains the largest one.
-
-        //tells us the width of each node (or voxel) in world space
-        Vector* node_width;
-        Vector* inv_node_width;
+        BBox bounds;                //=={pmin,pmax}
+        Vector dims;                // = the volume dimensions in float 
(same as diag)
+        Vector padded_dims;         //the rounded-up highest power of 2 of 
any dimension
+        Vec3i int_dims;             //the actual dims, padded to the lowest 
power of 2 that contains the largest one.
         
+        /* THESE VARS SHOULD BE IN OCTISOVOLUME */
         int multires_level;
         int current_timestep;
         ST isoval;
@@ -203,17 +192,7 @@
         {
             return bounds;
         }
-        
-        inline Vector& get_node_width(int d) const
-        {
-            return node_width[d];
-        }
-        
-        inline Vector& get_inv_node_width(int d) const
-        {
-            return inv_node_width[d];
-        }
-        
+                
         inline int get_child_bit_depth(int d) const
         {
             return child_bit_depth[d];
@@ -224,18 +203,14 @@
             return max_depth;
         }
 
-        
-        OctreeVolume(){}
+        OctreeVolume();
 
-        OctreeVolume(std::string filebase)
-        {
-            read_file(filebase);
-        }
+        OctreeVolume(char* filebase);
         
         /*!
             Multiple timestep constructor
          */
-        OctreeVolume(std::string filebase, 
+        OctreeVolume(char* filebase, 
                     int startTimestep, 
                     int endTimestep,
                     double variance_threshold, 
@@ -422,10 +397,11 @@
         }      
         
         /*!
-            The octree data building routine. AARONBAD - this is highly 
unoptimized. While the resulting data is fine, 
-            the build process could be made faster (and maybe parallel?) by 
just unrolling loops.
+            The octree data building routine. 
+            AARONBAD - this is highly unoptimized. While the resulting data 
is fine, 
+            the build process could be made faster by just unrolling loops. 
Parallelizing it would also be
+            desirable.
         */
-
         void make_from_single_res_data(SCIRun::Array3<ST>& originalData, 
                                         int ts, 
                                         double variance_threshold, 
@@ -434,8 +410,8 @@
                                         ST isomin = 0, 
                                         ST isomax = 0);
 
-        bool read_file(std::string filebase);
-        bool write_file(std::string filebase);
+        bool read_file(char* filebase);
+        bool write_file(char* filebase);
         
     private:
         inline ST lookup_safe(SCIRun::Array3<ST>& originalData, int d1, int 
d2, int d3) const

Modified: trunk/scenes/octisovol.cc
==============================================================================
--- trunk/scenes/octisovol.cc   (original)
+++ trunk/scenes/octisovol.cc   Sat May 20 22:55:42 2006
@@ -22,10 +22,12 @@
 #include <Model/Lights/PointLight.h>
 #include <Model/Lights/HeadLight.h>
 #include <Model/Materials/Phong.h>
+#include <Model/Materials/Lambertian.h>
 #include <Model/Cameras/PinholeCamera.h>
 #include <Core/Geometry/AffineTransform.h>
 #include <Model/AmbientLights/ConstantAmbient.h>
 #include <Model/MiscObjects/CuttingPlane.h>
+#include <SCIRun/Core/Containers/Array3.h>
 
 #include <SCIRun/Core/Thread/Time.h>
 
@@ -38,8 +40,9 @@
 extern "C" 
 Scene* make_scene(const ReadContext& context, const vector<string>& args) {
        
-       string filename = "";
-    string buildfrom_filename;
+    string filename = "";
+    string buildfrom_filename = "";
+
     int tstart = 0;
     int tend = 0;
     double variance = 0.1;
@@ -107,46 +110,60 @@
                        throw IllegalArgument( "octisovol", i, args );
                }
        }
-       
-       // Create the scene.
-       Scene *scene = new Scene();
-       Group *group = new Group();
-
-       Manta::BBox bounds; 
+    
+    char c_filename[2048];
+    char c_buildfrom_filename[2048];
+    strcpy(c_filename, filename.c_str());
+    strcpy(c_buildfrom_filename, buildfrom_filename.c_str());
+       
     OctreeVolume* ov;
    
-    if (filename != "")
+    if (strcmp(c_filename, "")!=0)
     {
-        ov = new OctreeVolume(filename);
+        cerr << "Creating octree volume from existing .otd data." << endl;
+        ov = new OctreeVolume(c_filename);
     }
-    else if (buildfrom_filename != "")
+    else if (strcmp(c_buildfrom_filename,"")!=0)
     {
-        ov = new OctreeVolume(buildfrom_filename, tstart, tend, variance, 
kernel_width, mres_levels, isomin, isomax);
+        cerr << "Creating octree volume from original rectilinear grid 
data." << endl;
+        ov = new OctreeVolume(c_buildfrom_filename, tstart, tend, variance, 
kernel_width, mres_levels, isomin, isomax);
     }
     else
     {
         throw InputError( "octisovol: No volume source specified. Use either 
-file or -buildfrom.");
     }
     
-    Material* mat1 = new Phong(Color(RGBColor(0.05f, 0.3f, 0.6f)), 
Color(RGBColor(1.f, 1.f, 1.f)), 50);
+    // Create the scene.
+       Scene *scene = new Scene();
+       Group *group = new Group();
+
+       Manta::BBox bounds; 
+    
+    //Material* mat1 = new Phong(Color(RGBColor(0.05f, 0.3f, 0.6f)), 
Color(RGBColor(1.f, 1.f, 1.f)), 50);
+    Material* mat1 = new Lambertian(Color(RGBColor(0.05f, 0.3f, 0.6f)));
     IsosurfaceOctreeVolume* iov = new IsosurfaceOctreeVolume(ov, mat1);
     bounds = iov->getBounds();
     group->add(iov);
-
-       LightSet *lights = new LightSet();
-       
-       lights->add( new HeadLight( 2.0, Color(RGB(1.0,1.0,1.0)) ));
-       lights->setAmbientLight( new ConstantAmbient( 
Color(RGBColor(0.2,0.2,0.2) ) ));
-       scene->setLights(lights);
-       
+               
        // Add the tree to the scene.
        scene->setObject( group );
+    
+    float fov = 45.f;
+    float view_dist = 0.5f * bounds[1].data[0] * (1.0f + 1.0f / tanf(0.5f * 
fov));
+    Vector lookat = (bounds[1] - bounds[0]) * 0.5f;
+    Vector eye = lookat;
+    Vector up = Vector(0,0,1);
+    eye.data[0] -= view_dist;
        
        // Set other important scene properties.
-       PinholeCamera *camera = new PinholeCamera(
-                       Vector(bounds[0].data[0]/2, bounds[0].data[1]/2, 
bounds[0].data[2]*2),
-                       Vector(bounds[1].data[0]/2, bounds[1].data[1]/2, 0),
-                       Vector(0,1,0), 50.0 );
+       PinholeCamera *camera = new PinholeCamera(eye, lookat, up, fov);
+    //scene->setCamera(camera);
+
+       LightSet *lights = new LightSet();
+    lights->add( new PointLight(Vector(eye + 25.f*(up + Cross(eye-lookat, 
up))), Color(RGBColor(.6,.1,.1))) );
+       lights->setAmbientLight( new ConstantAmbient( 
Color(RGBColor(0.91,0.9,0.9) ) ));
+       scene->setLights(lights);
+
        
        // Background.
        scene->setBackground( new ConstantBackground( Color(RGB(0.8, 0.8, 
0.8)) ) );




  • [MANTA] r1077 - in trunk: Model/Primitives scenes, knolla, 05/20/2006

Archive powered by MHonArc 2.6.16.

Top of page