Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r516 - in branches/fire: Model/Groups Model/Materials Model/Primitives scenes


Chronological Thread 
  • From: vpegorar@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r516 - in branches/fire: Model/Groups Model/Materials Model/Primitives scenes
  • Date: Tue, 30 Aug 2005 13:38:29 -0600 (MDT)

Author: vpegorar
Date: Tue Aug 30 13:38:27 2005
New Revision: 516

Added:
   branches/fire/Model/Materials/InhomogeneousParticipatingMedium.cc
   branches/fire/Model/Materials/InhomogeneousParticipatingMedium.h
Modified:
   branches/fire/Model/Groups/GriddedGroup.h
   branches/fire/Model/Materials/CMakeLists.txt
   branches/fire/Model/Primitives/Cube.cc
   branches/fire/scenes/primtest.cc
Log:
Adding InhomogeneousParticipatingMedium class (does not quite take advantage 
of the ray packets yet).

Modified: branches/fire/Model/Groups/GriddedGroup.h
==============================================================================
--- branches/fire/Model/Groups/GriddedGroup.h   (original)
+++ branches/fire/Model/Groups/GriddedGroup.h   Tue Aug 30 13:38:27 2005
@@ -1,152 +1,168 @@
-
-#ifndef Manta_Model_GriddedGroup_h
-#define Manta_Model_GriddedGroup_h
-
-#include <vector>
-#include <Model/Groups/Group.h>
-#include <Core/Geometry/PointVector.h>
-#include <Interface/RayPacket.h>
-
-namespace Manta {
-
-  template<typename T>
-  class Array3 {
-   public:
-    Array3() {
-      nx = ny = nz = extra = 0;
-      xidx = yidx = zidx = 0;
-      data = 0;
-    }
-    Array3(int nx, int ny, int nz, int extra = 0) {
-      xidx = yidx = zidx = 0;
-      data = 0;
-      resize(nx, ny, nz, extra);
-    }
-    ~Array3() {
-      resize(0, 0, 0);
-    }
-
-    void resize(int newnx, int newny, int newnz, int newextra = 0) {
-      if(xidx)
-        delete[] xidx;
-      if(yidx)
-        delete[] yidx;
-      if(zidx)
-        delete[] zidx;
-      if(data)
-        delete[] data;
-      nx = newnx; ny = newny; nz = newnz; extra = newextra;
-      int total = nx*ny*nz+extra;
-      if(total != 0){
-        data = new T[total];
-        allocateAndInitializeStride(xidx, nx, 1);
-        allocateAndInitializeStride(yidx, ny, nx);
-        allocateAndInitializeStride(zidx, nz, nx*ny);
-      } else {
-        xidx = yidx = zidx = 0;
-        data = 0;
-      }
-    }
-
-    void resizeZMajor(int newnx, int newny, int newnz, int newextra = 0) {
-      if(xidx)
-        delete[] xidx;
-      if(yidx)
-        delete[] yidx;
-      if(zidx)
-        delete[] zidx;
-      if(data)
-        delete[] data;
-      nx = newnx; ny = newny; nz = newnz; extra = newextra;
-      int total = nx*ny*nz+extra;
-      if(total != 0){
-        data = new T[total];
-        allocateAndInitializeStride(xidx, nx, nz*ny);
-        allocateAndInitializeStride(yidx, ny, nz);
-        allocateAndInitializeStride(zidx, nz, 1);
-      } else {
-        xidx = yidx = zidx = 0;
-        data = 0;
-      }
-    }
-
-    void initialize(const T& value) {
-      int total = nx*ny*nz+extra;
-      for(int i=0;i<total;i++)
-        data[i] = value;
-    }
-
-    T& operator()(int x, int y, int z) {
-      return data[xidx[x] + yidx[y] + zidx[z]];
-    }
-    const T& operator()(int x, int y, int z) const {
-      return data[xidx[x] + yidx[y] + zidx[z]];
-    }
-    int getIndex(int x, int y, int z) const {
-      return xidx[x] + yidx[y] + zidx[z];
-    }
-    T& operator[](int idx) {
-      return data[idx];
-    }
-    const T& operator[](int idx) const {
-      return data[idx];
-    }
-
-    int getNx() const {
-      return nx;
-    }
-    int getNy() const {
-      return ny;
-    }
-    int getNz() const {
-      return nz;
-    }
-
-
-   private:
-    Array3(const Array3&);
-    Array3& operator=(const Array3&);
-
-    int nx, ny, nz, extra;
-    int* xidx;
-    int* yidx;
-    int* zidx;
-    T* data;
-
-    void allocateAndInitializeStride(int*& idx, int num, int stride) {
-      idx = new int[num];
-      for(int i=0;i<num;i++)
-        idx[i] = stride*i;
-    }
-  };
-
-  class GriddedGroup : public Group {
-   public:
-    GriddedGroup( std::vector< string > const &args );
-    GriddedGroup();
-    virtual ~GriddedGroup();
-
-    virtual void preprocess( PreprocessContext const & );
-    virtual void intersect( RenderContext const &context, RayPacket &rays ) 
const;
-    static Group* create( vector< string > const &args );
-
-   private:
-    GriddedGroup(const GriddedGroup&);
-    GriddedGroup& operator=(const GriddedGroup&);
-
-    double cellfactor;
-    Point min, max;
-    Vector diag;
-    Vector cellsize;
-    Vector inv_cellsize;
-    Array3<int> cells;
-    const Object** lists;
-
-    void transformToLattice(const BBox& box,
-                          int& sx, int& sy, int& sz, int& ex, int& ey, int& 
ez) const;
-
-  };
-
-}
-
-#endif
+
+#ifndef Manta_Model_GriddedGroup_h
+#define Manta_Model_GriddedGroup_h
+
+#include <vector>
+#include <Model/Groups/Group.h>
+#include <Core/Geometry/PointVector.h>
+#include <Interface/RayPacket.h>
+
+namespace Manta {
+
+  template<typename T>
+  class Array3 {
+   public:
+    Array3() {
+      nx = ny = nz = extra = 0;
+      xidx = yidx = zidx = 0;
+      data = 0;
+    }
+    Array3(int nx, int ny, int nz, int extra = 0) {
+      xidx = yidx = zidx = 0;
+      data = 0;
+      resize(nx, ny, nz, extra);
+    }
+    ~Array3() {
+      resize(0, 0, 0);
+    }
+
+    void resize(int newnx, int newny, int newnz, int newextra = 0) {
+      if(xidx)
+        delete[] xidx;
+      if(yidx)
+        delete[] yidx;
+      if(zidx)
+        delete[] zidx;
+      if(data)
+        delete[] data;
+      nx = newnx; ny = newny; nz = newnz; extra = newextra;
+      int total = nx*ny*nz+extra;
+      if(total != 0){
+        data = new T[total];
+        allocateAndInitializeStride(xidx, nx, 1);
+        allocateAndInitializeStride(yidx, ny, nx);
+        allocateAndInitializeStride(zidx, nz, nx*ny);
+      } else {
+        xidx = yidx = zidx = 0;
+        data = 0;
+      }
+    }
+
+    void resizeZMajor(int newnx, int newny, int newnz, int newextra = 0) {
+      if(xidx)
+        delete[] xidx;
+      if(yidx)
+        delete[] yidx;
+      if(zidx)
+        delete[] zidx;
+      if(data)
+        delete[] data;
+      nx = newnx; ny = newny; nz = newnz; extra = newextra;
+      int total = nx*ny*nz+extra;
+      if(total != 0){
+        data = new T[total];
+        allocateAndInitializeStride(xidx, nx, nz*ny);
+        allocateAndInitializeStride(yidx, ny, nz);
+        allocateAndInitializeStride(zidx, nz, 1);
+      } else {
+        xidx = yidx = zidx = 0;
+        data = 0;
+      }
+    }
+
+    void initialize(const T& value) {
+      int total = nx*ny*nz+extra;
+      for(int i=0;i<total;i++)
+        data[i] = value;
+    }
+
+    T& operator()(int x, int y, int z) {
+      return data[xidx[x] + yidx[y] + zidx[z]];
+    }
+    const T& operator()(int x, int y, int z) const {
+      return data[xidx[x] + yidx[y] + zidx[z]];
+    }
+    int getIndex(int x, int y, int z) const {
+      return xidx[x] + yidx[y] + zidx[z];
+    }
+    T& operator[](int idx) {
+      return data[idx];
+    }
+    const T& operator[](int idx) const {
+      return data[idx];
+    }
+
+    int getNx() const {
+      return nx;
+    }
+    int getNy() const {
+      return ny;
+    }
+    int getNz() const {
+      return nz;
+    }
+       bool sameDimensions(Array3 & array) const
+       {
+               return  nx == array.nx &&
+                               ny == array.ny &&
+                               nz == array.nz ;
+       }
+       void getMinMax(T * min, T * max) const
+       {
+               unsigned int i, total = nx * ny * nz;
+
+               *min = *max = data[0];
+               for(i=1; i<total; i++)
+               {
+                       if              (*min > data[i]) *min = data[i];
+                       else if (*max < data[i]) *max = data[i];
+               }
+       }
+
+   private:
+    Array3(const Array3&);
+    Array3& operator=(const Array3&);
+
+    int nx, ny, nz, extra;
+    int* xidx;
+    int* yidx;
+    int* zidx;
+    T* data;
+
+    void allocateAndInitializeStride(int*& idx, int num, int stride) {
+      idx = new int[num];
+      for(int i=0;i<num;i++)
+        idx[i] = stride*i;
+    }
+  };
+
+  class GriddedGroup : public Group {
+   public:
+    GriddedGroup( std::vector< string > const &args );
+    GriddedGroup();
+    virtual ~GriddedGroup();
+
+    virtual void preprocess( PreprocessContext const & );
+    virtual void intersect( RenderContext const &context, RayPacket &rays ) 
const;
+    static Group* create( vector< string > const &args );
+
+   private:
+    GriddedGroup(const GriddedGroup&);
+    GriddedGroup& operator=(const GriddedGroup&);
+
+    double cellfactor;
+    Point min, max;
+    Vector diag;
+    Vector cellsize;
+    Vector inv_cellsize;
+    Array3<int> cells;
+    const Object** lists;
+
+    void transformToLattice(const BBox& box,
+                          int& sx, int& sy, int& sz, int& ex, int& ey, int& 
ez) const;
+
+  };
+
+}
+
+#endif

Modified: branches/fire/Model/Materials/CMakeLists.txt
==============================================================================
--- branches/fire/Model/Materials/CMakeLists.txt        (original)
+++ branches/fire/Model/Materials/CMakeLists.txt        Tue Aug 30 13:38:27 
2005
@@ -1,12 +1,13 @@
-
-
-
-SET (Manta_Materials_SRCS
-     Materials/Checker.cc
-     Materials/Dielectric.cc
-     Materials/Flat.cc
-     Materials/Lambertian.cc
-     Materials/LitMaterial.cc
-     Materials/MetalMaterial.cc
-     Materials/Phong.cc
-     )
+
+
+
+SET (Manta_Materials_SRCS
+     Materials/Checker.cc
+     Materials/Dielectric.cc
+     Materials/Flat.cc
+     Materials/Lambertian.cc
+     Materials/LitMaterial.cc
+     Materials/MetalMaterial.cc
+     Materials/InhomogeneousParticipatingMedium.cc
+     Materials/Phong.cc
+     )

Added: branches/fire/Model/Materials/InhomogeneousParticipatingMedium.cc
==============================================================================
--- (empty file)
+++ branches/fire/Model/Materials/InhomogeneousParticipatingMedium.cc   Tue 
Aug 30 13:38:27 2005
@@ -0,0 +1,380 @@
+
+#include <math.h>
+#include <Model/Materials/InhomogeneousParticipatingMedium.h>
+#include <Model/Readers/VolumeReader.h>
+#include <Interface/Scene.h>
+#include <Interface/Renderer.h>
+#include <Interface/RayPacket.h>
+
+using namespace Manta;
+
+#define FAST_GRADIENT
+
+
+// 
--------------------------------------------------------------------------------------
+// --- Constructor
+// 
--------------------------------------------------------------------------------------
+InhomogeneousParticipatingMedium::InhomogeneousParticipatingMedium(    const 
char * absorptionCoefficientFileName,
+                                                                             
                                                          const char * 
emittedLightFileName,
+                                                                             
                                                          ColorMap   * 
emittedLightColorMap,
+                                                                             
                                                          const char * 
refractiveIndexFileName,
+                                                                             
                                                          const Point & 
minBound, const Point & maxBound,
+                                                                             
                                                          double 
cellStepSize, double metersPerUnit)
+{
+       m_DefaultVolume = NULL;
+
+       if (absorptionCoefficientFileName)
+       {
+               m_AbsorptionCoefficient = new Array3<float>();
+               ReadVolumeFile(absorptionCoefficientFileName, 
*m_AbsorptionCoefficient);
+               m_DefaultVolume = m_AbsorptionCoefficient;
+       }
+       else
+               m_AbsorptionCoefficient = NULL;
+
+       if (emittedLightFileName)
+       {
+               m_EmittedLight = new Array3<float>();
+               ReadVolumeFile(emittedLightFileName, *m_EmittedLight);
+               m_DefaultVolume = m_EmittedLight;
+       }
+       else
+               m_EmittedLight = NULL;
+
+       if (refractiveIndexFileName)
+       {
+               m_RefractiveIndex = new Array3<float>();
+               ReadVolumeFile(refractiveIndexFileName, *m_RefractiveIndex);
+               m_DefaultVolume = m_RefractiveIndex;
+       }
+       else
+               m_RefractiveIndex = NULL;
+
+       if (!m_DefaultVolume)
+       {
+               fprintf(stderr, "Error : 
InhomogeneousParticipatingMedium::InhomogeneousParticipatingMedium() : no 
volume provided\n");
+               exit(0);
+       }
+
+       if ((m_AbsorptionCoefficient && 
!m_DefaultVolume->sameDimensions(*m_AbsorptionCoefficient)) ||
+               (m_EmittedLight          && 
!m_DefaultVolume->sameDimensions(*m_EmittedLight         )) ||
+               (m_RefractiveIndex       && 
!m_DefaultVolume->sameDimensions(*m_RefractiveIndex      )) )
+       {
+               fprintf(stderr, "Error : 
InhomogeneousParticipatingMedium::InhomogeneousParticipatingMedium() : 
mismatching volume sizes\n");
+               exit(0);
+       }
+
+       m_Bounds[0] = minBound;
+       m_Bounds[1] = maxBound;
+
+       Vector diag = m_Bounds[1] - m_Bounds[0];
+       m_CellSize = diag * Vector(     1.0 / 
(double)(m_DefaultVolume->getNx()-1),
+                                                               1.0 / 
(double)(m_DefaultVolume->getNy()-1),
+                                                               1.0 / 
(double)(m_DefaultVolume->getNz()-1));
+       m_WorldStepSize = cellStepSize * m_CellSize.length() / sqrt(3.0);
+
+       m_MetersPerUnit = metersPerUnit;
+
+       if (m_EmittedLight)
+       {
+               if (emittedLightColorMap)
+                       m_EmittedLightColorMap = emittedLightColorMap;
+               else
+               {
+                       float min, max;
+                       m_EmittedLight->getMinMax(&min, &max);
+                       m_EmittedLightColorMap = new ColorMap(RAINBOW_COLORS, 
min, max);
+               }
+       }
+       else
+               m_EmittedLightColorMap = NULL;
+}
+
+
+// 
--------------------------------------------------------------------------------------
+// --- Destructor
+// 
--------------------------------------------------------------------------------------
+InhomogeneousParticipatingMedium::~InhomogeneousParticipatingMedium()
+{
+       delete m_AbsorptionCoefficient;
+       delete m_EmittedLight;
+       delete m_EmittedLightColorMap;
+       delete m_RefractiveIndex;
+}
+
+
+// 
--------------------------------------------------------------------------------------
+// --- Preprocess
+// 
--------------------------------------------------------------------------------------
+void InhomogeneousParticipatingMedium::preprocess(const PreprocessContext & 
context)
+{
+}
+
+
+// 
--------------------------------------------------------------------------------------
+// --- Get the Color
+// 
--------------------------------------------------------------------------------------
+void InhomogeneousParticipatingMedium::shade(const RenderContext & context, 
RayPacket & rays) const
+{
+       rays.normalizeDirections();
+
+       for(int rayInd = 0; rayInd < rays.getSize(); rayInd++)
+       {
+               RayPacket::Element & e = rays.get(rayInd);
+               Ray & ray = e.ray;
+               Point hitPosition;
+               double t, tenter, texit;
+               int hitLattice[3];
+               float accumTransmittance, hitLatticef[3], 
previousRefractiveIndex;
+               Color accumColor;
+
+               accumColor = Color(RGB(0.0f, 0.0f, 0.0f));
+               accumTransmittance = 1.0f;
+
+               previousRefractiveIndex = - 1.0f;
+
+//             if (hit.m_Inside)       tenter = 0.0;// need to figure a way 
to check if inside or not, assume outside for now
+//             else
+                       tenter = e.hitInfo.minT();
+
+               RayPacketData rpData;
+               RayPacket lRays(rpData, 1, rays.getDepth()+1, 
RayPacket::NormalizedDirections);
+               lRays.useLocalColors();
+               Ray & lRay = lRays.get(0).ray;
+
+               lRay.set(ray.origin() + tenter * ray.direction(), 
ray.direction());
+               lRays.resetHit();
+               context.scene->getObject()->intersect(context, lRays);
+               if (lRays.get(0).hitInfo.wasHit())      texit = 
lRays.get(0).hitInfo.minT();
+               else                                                          
  texit = -1.0;
+               t = 0.0;
+
+               while(t < texit)
+               {
+                       hitPosition = lRay.origin() + t * lRay.direction();
+                       hitLatticef[0] = (float)((hitPosition.x() - 
m_Bounds[0].x()) / m_CellSize.x());
+                       hitLatticef[1] = (float)((hitPosition.y() - 
m_Bounds[0].y()) / m_CellSize.y());
+                       hitLatticef[2] = (float)((hitPosition.z() - 
m_Bounds[0].z()) / m_CellSize.z());
+                       hitLattice[0] = (int)floor(hitLatticef[0]);
+                       hitLattice[1] = (int)floor(hitLatticef[1]);
+                       hitLattice[2] = (int)floor(hitLatticef[2]);
+
+                       if (0 <= hitLattice[0] && hitLattice[0] < 
(int)m_DefaultVolume->getNx() - 1 &&
+                               0 <= hitLattice[1] && hitLattice[1] < 
(int)m_DefaultVolume->getNy() - 1 &&
+                               0 <= hitLattice[2] && hitLattice[2] < 
(int)m_DefaultVolume->getNz() - 1 )
+                       {
+                               float wx, wy, wz, wx1, wy1, wz1, 
transmittance, absCoeff;
+                               Color sourceColor;
+                               double tIntegration;
+
+                               wx = hitLatticef[0] - (float)hitLattice[0];
+                               wy = hitLatticef[1] - (float)hitLattice[1];
+                               wz = hitLatticef[2] - (float)hitLattice[2];
+                               wx1 = 1.0f - wx;
+                               wy1 = 1.0f - wy;
+                               wz1 = 1.0f - wz;
+
+                               if (m_RefractiveIndex)
+                               {
+                                       float refrInd = wx1 * ( wy1 * ( wz1 * 
(*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]  , hitLattice[2]  ) +
+                                                                             
                          wz  * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]  , hitLattice[2]+1) ) +
+                                                                             
          wy  * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]  ) +
+                                                                             
                          wz  * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]+1) ) ) +
+                                                                       wx  * 
( wy1 * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]  , 
hitLattice[2]  ) +
+                                                                             
                          wz  * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]  , hitLattice[2]+1) ) +
+                                                                             
          wy  * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]  ) +
+                                                                             
                          wz  * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]+1) ) ) ;
+
+                                       if (previousRefractiveIndex > 0.0f && 
previousRefractiveIndex != refrInd)
+                                       {
+                                               Vector hitNormal;
+                                               double cosTheta, cosTheta2, 
eta;
+#ifdef FAST_GRADIENT
+                                               int hitLRn[3];
+
+                                               hitLRn[0] = hitLattice[0] + 
(int)(wx + 0.5f);
+                                               hitLRn[1] = hitLattice[1] + 
(int)(wy + 0.5f);
+                                               hitLRn[2] = hitLattice[2] + 
(int)(wz + 0.5f);
+
+                                               if              (hitLRn[0] == 
0)                                                                
hitNormal[0] = (double)((*m_RefractiveIndex)(hitLRn[0]+1, hitLRn[1]  , 
hitLRn[2]  ) - (*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]  , hitLRn[2]  )) / 
 m_CellSize.x();
+                                               else if (hitLRn[0] == 
m_RefractiveIndex->getNx() - 1)   hitNormal[0] = 
(double)((*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]  , hitLRn[2]  ) - 
(*m_RefractiveIndex)(hitLRn[0]-1, hitLRn[1]  , hitLRn[2]  )) /  
m_CellSize.x();
+                                               else                          
                                                                          
hitNormal[0] = (double)((*m_RefractiveIndex)(hitLRn[0]+1, hitLRn[1]  , 
hitLRn[2]  ) - (*m_RefractiveIndex)(hitLRn[0]-1, hitLRn[1]  , hitLRn[2]  )) / 
(m_CellSize.x() * 2.0);
+                                               if              (hitLRn[1] == 
0)                                                                
hitNormal[1] = (double)((*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]+1, 
hitLRn[2]  ) - (*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]  , hitLRn[2]  )) / 
 m_CellSize.y();
+                                               else if (hitLRn[1] == 
m_RefractiveIndex->getNy() - 1)   hitNormal[1] = 
(double)((*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]  , hitLRn[2]  ) - 
(*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]-1, hitLRn[2]  )) /  
m_CellSize.y();
+                                               else                          
                                                                          
hitNormal[1] = (double)((*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]+1, 
hitLRn[2]  ) - (*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]-1, hitLRn[2]  )) / 
(m_CellSize.y() * 2.0);
+                                               if              (hitLRn[2] == 
0)                                                                
hitNormal[2] = (double)((*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]  , 
hitLRn[2]+1) - (*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]  , hitLRn[2]  )) / 
 m_CellSize.z();
+                                               else if (hitLRn[2] == 
m_RefractiveIndex->getNz() - 1)   hitNormal[2] = 
(double)((*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]  , hitLRn[2]  ) - 
(*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]  , hitLRn[2]-1)) /  
m_CellSize.z();
+                                               else                          
                                                                          
hitNormal[2] = (double)((*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]  , 
hitLRn[2]+1) - (*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]  , hitLRn[2]-1)) / 
(m_CellSize.z() * 2.0);
+#else
+                                               double tmp[4];
+
+                                                       tmp[1] =        wy1 * 
( wz1 * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]  , hitLattice[2]  
) +
+                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]  
, hitLattice[2]+1) ) +
+                                                                             
  wy  * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]+1, 
hitLattice[2]  ) +
+                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]+1) ) ;
+                                                       tmp[2] =        wy1 * 
( wz1 * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]  , hitLattice[2]  
) +
+                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]  
, hitLattice[2]+1) ) +
+                                                                             
  wy  * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]+1, 
hitLattice[2]  ) +
+                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]+1) ) ;
+                                               if (hitLattice[0] == 0)
+                                                       tmp[0] = tmp[1];
+                                               else
+                                                       tmp[0] =        wy1 * 
( wz1 * (*m_RefractiveIndex)(hitLattice[0]-1, hitLattice[1]  , hitLattice[2]  
) +
+                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]-1, hitLattice[1]  
, hitLattice[2]+1) ) +
+                                                                             
  wy  * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]-1, hitLattice[1]+1, 
hitLattice[2]  ) +
+                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]-1, 
hitLattice[1]+1, hitLattice[2]+1) ) ;
+                                               if (hitLattice[0] == 
m_RefractiveIndex->getNx() - 2)
+                                                       tmp[3] = tmp[2];
+                                               else
+                                                       tmp[3] =        wy1 * 
( wz1 * (*m_RefractiveIndex)(hitLattice[0]+2, hitLattice[1]  , hitLattice[2]  
) +
+                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]+2, hitLattice[1]  
, hitLattice[2]+1) ) +
+                                                                             
  wy  * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]+2, hitLattice[1]+1, 
hitLattice[2]  ) +
+                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]+2, 
hitLattice[1]+1, hitLattice[2]+1) ) ;
+                                               hitNormal[0] = (wx1 * (tmp[2] 
- tmp[0]) + wx * (tmp[3] - tmp[1])) / (2.0 * m_CellSize.x());
+
+                                                       tmp[1] =        wx1 * 
( wz1 * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]  , hitLattice[2]  
) +
+                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]  
, hitLattice[2]+1) ) +
+                                                                             
  wx  * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]  , 
hitLattice[2]  ) +
+                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]  
, hitLattice[2]+1) ) ;
+                                                       tmp[2] =        wx1 * 
( wz1 * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]+1, hitLattice[2]  
) +
+                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]+1) ) +
+                                                                             
  wx  * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]+1, 
hitLattice[2]  ) +
+                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]+1) ) ;
+                                               if (hitLattice[1] == 0)
+                                                       tmp[0] = tmp[1];
+                                               else
+                                                       tmp[0] =        wx1 * 
( wz1 * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]-1, hitLattice[2]  
) +
+                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]-1, hitLattice[2]+1) ) +
+                                                                             
  wx  * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]-1, 
hitLattice[2]  ) +
+                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]-1, hitLattice[2]+1) ) ;
+                                               if (hitLattice[1] == 
m_RefractiveIndex->getNy() - 2)
+                                                       tmp[3] = tmp[2];
+                                               else
+                                                       tmp[3] =        wx1 * 
( wz1 * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]+2, hitLattice[2]  
) +
+                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]+2, hitLattice[2]+1) ) +
+                                                                             
  wx  * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]+2, 
hitLattice[2]  ) +
+                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]+2, hitLattice[2]+1) ) ;
+                                               hitNormal[1] = (wy1 * (tmp[2] 
- tmp[0]) + wy * (tmp[3] - tmp[1])) / (2.0 * m_CellSize.y());
+
+                                                       tmp[1] =        wx1 * 
( wy1 * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]  , hitLattice[2]  
) +
+                                                                             
                  wy  * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]  ) ) +
+                                                                             
  wx  * ( wy1 * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]  , 
hitLattice[2]  ) +
+                                                                             
                  wy  * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]  ) ) ;
+                                                       tmp[2] =        wx1 * 
( wy1 * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]  , 
hitLattice[2]+1) +
+                                                                             
                  wy  * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]+1) ) +
+                                                                             
  wx  * ( wy1 * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]  , 
hitLattice[2]+1) +
+                                                                             
                  wy  * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]+1) ) ;
+                                               if (hitLattice[2] == 0)
+                                                       tmp[0] = tmp[1];
+                                               else
+                                                       tmp[0] =        wx1 * 
( wy1 * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]  , 
hitLattice[2]-1) +
+                                                                             
                  wy  * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]-1) ) +
+                                                                             
  wx  * ( wy1 * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]  , 
hitLattice[2]-1) +
+                                                                             
                  wy  * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]-1) ) ;
+                                               if (hitLattice[2] == 
m_RefractiveIndex->getNz() - 2)
+                                                       tmp[3] = tmp[2];
+                                               else
+                                                       tmp[3] =        wx1 * 
( wy1 * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]  , 
hitLattice[2]+2) +
+                                                                             
                  wy  * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]+2) ) +
+                                                                             
  wx  * ( wy1 * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]  , 
hitLattice[2]+2) +
+                                                                             
                  wy  * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]+2) ) ;
+                                               hitNormal[2] = (wz1 * (tmp[2] 
- tmp[0]) + wz * (tmp[3] - tmp[1])) / (2.0 * m_CellSize.z());
+#endif
+
+                                               if (hitNormal.normalize() == 
0.0)
+                                                       hitNormal = 
lRay.direction();
+
+                                               cosTheta = - Dot(hitNormal, 
lRay.direction());
+                                               if (cosTheta < 0.0)
+                                               {
+                                                       cosTheta = - cosTheta;
+                                                       hitNormal = - 
hitNormal;
+                                               }
+                                               eta = refrInd / 
previousRefractiveIndex;
+
+                                               cosTheta2 = 1.0 + 
((cosTheta*cosTheta - 1.0) / (eta*eta));
+
+                                               if (cosTheta2 < 0.0)    // 
Total reflection
+                                               {
+                                                       lRay.set(hitPosition, 
lRay.direction() + (2.0*cosTheta)*hitNormal);
+                                               }
+                                               else                          
          // Compute transmission
+                                               {
+                                                       cosTheta2 = 
sqrt(cosTheta2);
+                                                       lRay.set(hitPosition, 
(1.0 / eta) * lRay.direction() + (cosTheta / eta - cosTheta2) * hitNormal);
+                                               }
+
+                                               lRays.resetHit();
+                                               
context.scene->getObject()->intersect(context, lRays);
+                                               if 
(lRays.get(0).hitInfo.wasHit())      texit = lRays.get(0).hitInfo.minT();
+                                               else                          
                                  texit = -1.0;
+                                               t = 0.0;
+                                       }
+
+                                       previousRefractiveIndex = refrInd;
+                               }
+
+                               tIntegration = texit - t;
+                               if (tIntegration > m_WorldStepSize)
+                                       tIntegration = m_WorldStepSize;
+
+                               if (m_AbsorptionCoefficient)
+                               {
+                                       absCoeff =      wx1 * ( wy1 * ( wz1 * 
(*m_AbsorptionCoefficient)(hitLattice[0]  , hitLattice[1]  , hitLattice[2]  ) 
+
+                                                                             
                  wz  * (*m_AbsorptionCoefficient)(hitLattice[0]  , 
hitLattice[1]  , hitLattice[2]+1) ) +
+                                                                             
  wy  * ( wz1 * (*m_AbsorptionCoefficient)(hitLattice[0]  , hitLattice[1]+1, 
hitLattice[2]  ) +
+                                                                             
                  wz  * (*m_AbsorptionCoefficient)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]+1) ) ) +
+                                                               wx  * ( wy1 * 
( wz1 * (*m_AbsorptionCoefficient)(hitLattice[0]+1, hitLattice[1]  , 
hitLattice[2]  ) +
+                                                                             
                  wz  * (*m_AbsorptionCoefficient)(hitLattice[0]+1, 
hitLattice[1]  , hitLattice[2]+1) ) +
+                                                                             
  wy  * ( wz1 * (*m_AbsorptionCoefficient)(hitLattice[0]+1, hitLattice[1]+1, 
hitLattice[2]  ) +
+                                                                             
                  wz  * (*m_AbsorptionCoefficient)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]+1) ) ) ;
+                               }
+                               else
+                                       absCoeff = 0.0f;
+
+                               if (m_EmittedLight && absCoeff > 0.0f)
+                               {
+                                       float elValue = wx1 * ( wy1 * ( wz1 * 
(*m_EmittedLight)(hitLattice[0]  , hitLattice[1]  , hitLattice[2]  ) +
+                                                                             
                          wz  * (*m_EmittedLight)(hitLattice[0]  , 
hitLattice[1]  , hitLattice[2]+1) ) +
+                                                                             
          wy  * ( wz1 * (*m_EmittedLight)(hitLattice[0]  , hitLattice[1]+1, 
hitLattice[2]  ) +
+                                                                             
                          wz  * (*m_EmittedLight)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]+1) ) ) +
+                                                                       wx  * 
( wy1 * ( wz1 * (*m_EmittedLight)(hitLattice[0]+1, hitLattice[1]  , 
hitLattice[2]  ) +
+                                                                             
                          wz  * (*m_EmittedLight)(hitLattice[0]+1, 
hitLattice[1]  , hitLattice[2]+1) ) +
+                                                                             
          wy  * ( wz1 * (*m_EmittedLight)(hitLattice[0]+1, hitLattice[1]+1, 
hitLattice[2]  ) +
+                                                                             
                          wz  * (*m_EmittedLight)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]+1) ) ) ;
+                                       
m_EmittedLightColorMap->Lookup(elValue, sourceColor);
+                               }
+                               else
+                                       sourceColor = Color(RGB(0.0f, 0.0f, 
0.0f));
+
+                               if (absCoeff > 0.0f)
+                               {
+                                       transmittance = expf(- absCoeff * 
(float)(tIntegration * m_MetersPerUnit));
+                                       accumColor += sourceColor * 
(accumTransmittance * (1.0f - transmittance));
+                                       accumTransmittance *= transmittance;
+                               }
+                       }
+
+                       t += m_WorldStepSize;
+               }
+
+               if (rays.getDepth() < 
context.scene->getRenderParameters().maxDepth)    // Transmitted ray
+               {
+                       if (lRays.get(0).hitInfo.wasHit())
+                       {
+                               if (lRays.get(0).hitInfo.hitMaterial() == 
this)
+                               {
+                                       lRay.setOrigin(lRay.origin() + 
lRay.direction() * texit);
+                                       lRays.resetHit();
+                                       context.renderer->traceRays(context, 
lRays);
+                               }
+                               else
+                                       
lRays.get(0).hitInfo.hitMaterial()->shade(context, lRays);
+
+                               accumColor = accumColor + 
*(lRays.get(0).color) * accumTransmittance;
+                       }
+               }
+
+               rays.setResult(rayInd, accumColor);
+       }
+}

Added: branches/fire/Model/Materials/InhomogeneousParticipatingMedium.h
==============================================================================
--- (empty file)
+++ branches/fire/Model/Materials/InhomogeneousParticipatingMedium.h    Tue 
Aug 30 13:38:27 2005
@@ -0,0 +1,43 @@
+
+#ifndef Manta_Model_InhomogeneousParticipatingMedium_h
+#define Manta_Model_InhomogeneousParticipatingMedium_h
+
+#include <Interface/Context.h>
+#include <Interface/Material.h>
+#include <Core/Geometry/PointVector.h>
+#include <Model/Groups/GriddedGroup.h> // Array3
+#include <Core/Util/ColorMap.h>
+
+namespace Manta
+{
+       class InhomogeneousParticipatingMedium : public Material
+       {
+
+       private:
+
+               Array3<float> * m_DefaultVolume;
+               Array3<float> * m_AbsorptionCoefficient;
+               Array3<float> * m_EmittedLight;
+               ColorMap *              m_EmittedLightColorMap;
+               Array3<float> * m_RefractiveIndex;
+               Point                   m_Bounds[2];
+               Vector                  m_CellSize;
+               double                  m_WorldStepSize;
+               double                  m_MetersPerUnit;
+
+       public:
+
+                                               
InhomogeneousParticipatingMedium(       const char * 
absorptionCoefficientFileName,
+                                                                             
                                          const char * emittedLightFileName,
+                                                                             
                                          ColorMap   * emittedLightColorMap,
+                                                                             
                                          const char * 
refractiveIndexFileName,
+                                                                             
                                          const Point & minBound, const Point 
& maxBound,
+                                                                             
                                          double cellStepSize, double 
metersPerUnit);
+               virtual                 ~InhomogeneousParticipatingMedium();
+
+               virtual void    preprocess(const PreprocessContext & context);
+               virtual void    shade(const RenderContext & context, 
RayPacket & rays) const;
+       };
+}
+
+#endif

Modified: branches/fire/Model/Primitives/Cube.cc
==============================================================================
--- branches/fire/Model/Primitives/Cube.cc      (original)
+++ branches/fire/Model/Primitives/Cube.cc      Tue Aug 30 13:38:27 2005
@@ -70,7 +70,10 @@
       tfar = Min(t2, tfar);
 
       if(tnear <= tfar)
+         {
        e.hitInfo.hit(tnear, material, this, tex);
+       e.hitInfo.hit(tfar , material, this, tex);
+         }
     }
   }
   else {
@@ -111,7 +114,10 @@
       tfar = Min(t2, tfar);
 
       if(tnear <= tfar)
+         {
        e.hitInfo.hit(tnear, material, this, tex);
+       e.hitInfo.hit(tfar , material, this, tex);
+         }
     }
   }
 }

Modified: branches/fire/scenes/primtest.cc
==============================================================================
--- branches/fire/scenes/primtest.cc    (original)
+++ branches/fire/scenes/primtest.cc    Tue Aug 30 13:38:27 2005
@@ -15,6 +15,8 @@
 #include <Model/Materials/Lambertian.h>
 #include <Model/Materials/MetalMaterial.h>
 #include <Model/Materials/Phong.h>
+#include <Model/Materials/InhomogeneousParticipatingMedium.h>
+#include <Core/Util/ColorMap.h>
 #include <Model/Instances/Instance.h>
 #include <Model/Instances/InstanceRT.h>
 #include <Model/Instances/InstanceRST.h>
@@ -161,9 +163,9 @@
   }
   else if(material == "image")
   {
-    Image *img = readTGA( imageName );
-    matl = new Lambertian( new ImageTexture( img, 1.0, 1.0 ) );
-    mapr = new UniformMapper();
+//    Image *img = readTGA( imageName );
+//    matl = new Lambertian( new ImageTexture( img, 1.0, 1.0 ) );
+//    mapr = new UniformMapper();
   }
   else
     throw IllegalArgument("Unknown material type for primtest: "+material, 
0, args);
@@ -254,6 +256,19 @@
     if ( mapr )
         prim->setTexCoordMapper( mapr );
     group->add(prim);
+  } else if (primtype == "volume") {
+       ColorMap * colorMap = new ColorMap(BLACK_BODY_RADIATION, 298.0f, 
2234.0f);
+       Material * matIPM = new InhomogeneousParticipatingMedium(       
"../Data/heptane/abskgIN_M00_0450.nrrd",
+                                                                             
                                                  
"../Data/heptane/tempIN_M00_0450.nrrd",
+                                                                             
                                                  NULL, //colorMap,
+                                                                             
                                                  NULL, 
//"../Data/heptane/refrIN_M00_0450.nrrd",
+                                                                             
                                                  Point(-0.21, -0.21, 0.19), 
Point(0.21, 0.21, 0.61),
+                                                                             
                                                  0.5, 20.0);
+       Material * matL = new Lambertian(Color(RGB(.6,0,0)));
+       Primitive * primC = new Cube(matIPM, Point(-0.2, -0.2, 0.2), 0.4, 
0.4, 0.4);
+       Primitive * primS = new Sphere(matL, Point(0.0, 0.0, 0.4), 0.1);
+       group->add(primC);
+//     group->add(primS);
   } else {
     throw IllegalArgument("Unknown primitive type for primtest: "+primtype, 
0, args);
   }




  • [MANTA] r516 - in branches/fire: Model/Groups Model/Materials Model/Primitives scenes, vpegorar, 08/30/2005

Archive powered by MHonArc 2.6.16.

Top of page