Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r1092 - in trunk: Core Core/Color Core/Geometry Engine/Control Model/Primitives scenes


Chronological Thread 
  • From: cgribble@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r1092 - in trunk: Core Core/Color Core/Geometry Engine/Control Model/Primitives scenes
  • Date: Tue, 30 May 2006 20:16:03 -0600 (MDT)

Author: cgribble
Date: Tue May 30 20:15:58 2006
New Revision: 1092

Added:
   trunk/Core/Color/RegularColorMap.cc
   trunk/Core/Color/RegularColorMap.h
   trunk/Core/Geometry/ScalarTransform1D.h
Modified:
   trunk/Core/CMakeLists.txt
   trunk/Engine/Control/DynPLTWorker.cc
   trunk/Engine/Control/DynPLTWorker.h
   trunk/Model/Primitives/DynPLTGridSpheres.cc
   trunk/Model/Primitives/DynPLTGridSpheres.h
   trunk/Model/Primitives/GridSpheres.cc
   trunk/Model/Primitives/GridSpheres.h
   trunk/scenes/dynplt.cc
   trunk/scenes/pnrrd.cc
Log:
Core/Geometry/ScalarTransform1D.h
Core/Color/RegularColorMap.cc
Core/Color/RegularColorMap.h
Core/CMakeLists.txt
  Added RegularColorMap from RTRT (limited functionality)

Model/Primitives/DynPLTGridSpheres.cc
Model/Primitives/DynPLTGridSpheres.h
Model/Primitives/GridSpheres.cc
Model/Primitives/GridSpheres.h
  Added RegularColorMap
  Added mapDiffuseColors(...) to GridSpheres for color mapping

Engine/Control/DynPLTWorker.cc
Engine/Control/DynPLTWorker.h
  Added Kd/Ka to DynPLTContext
  Use diffuse/ambient term

scenes/dynplt.cc
scenes/pnrrd.cc
  Commented out bookmark views
  Added color mapping


Modified: trunk/Core/CMakeLists.txt
==============================================================================
--- trunk/Core/CMakeLists.txt   (original)
+++ trunk/Core/CMakeLists.txt   Tue May 30 20:15:58 2006
@@ -7,7 +7,9 @@
      Color/RGBColor.h
      Color/RGBColor.cc
      Color/GrayColor.h
-     Color/GrayColor.cc)
+     Color/GrayColor.cc
+     Color/RegularColorMap.h
+     Color/RegularColorMap.cc)
 SET (CORE_SOURCES ${CORE_SOURCES}
      Exceptions/BadPrimitive.h
      Exceptions/BadPrimitive.cc
@@ -29,6 +31,7 @@
      Geometry/AffineTransformT.cc
      Geometry/BBox.h
      Geometry/Ray.h
+     Geometry/ScalarTransform1D.h
      Geometry/Vector.cc
      Geometry/Vector.h
      Geometry/VectorT.cc

Added: trunk/Core/Color/RegularColorMap.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Color/RegularColorMap.cc Tue May 30 20:15:58 2006
@@ -0,0 +1,217 @@
+
+#include <Core/Color/Color.h>
+#include <Core/Color/RegularColorMap.h>
+
+#include <fstream>
+using std::ifstream;
+
+#include <iostream>
+using std::cerr;
+
+#include <string>
+using std::string;
+
+using namespace Manta;
+
+RegularColorMap::RegularColorMap(const char* filename, unsigned int size) :
+  blended(size), new_blended(size)
+{
+  if (!fillColor(filename, colors)) {
+    cerr<<"RegularColorMap::RegularColorMap("<<filename
+         <<"):  Unable to load colormap from file, using default\n";
+    fillColor(GrayScale, colors);
+  }
+
+  fillBlendedColors(blended);
+  lookup.setResultsPtr(&blended);
+}
+
+RegularColorMap::RegularColorMap(Array1<Color>& colors, unsigned int size) :
+  colors(colors), blended(size), new_blended(size)
+{
+  fillBlendedColors(blended);
+  lookup.setResultsPtr(&blended);
+}
+
+RegularColorMap::RegularColorMap(unsigned int type, unsigned int size) :
+  blended(size), new_blended(size)
+{
+  fillColor(type, colors);
+  fillBlendedColors(blended);
+  lookup.setResultsPtr(&blended);
+}
+
+void RegularColorMap::fillColor(unsigned int type, Array1<Color> &colors)
+{
+  // Make sure we are dealing with a clean array
+  colors.remove_all();
+
+  // Add colors base on color map type
+  switch (type) {
+  case InvRainbow:
+    colors.add(Color(RGB(0, 0, 1)));
+    colors.add(Color(RGB(0, 0.40000001, 1)));
+    colors.add(Color(RGB(0, 0.80000001, 1)));
+    colors.add(Color(RGB(0, 1, 0.80000001)));
+    colors.add(Color(RGB(0, 1, 0.40000001)));
+    colors.add(Color(RGB(0, 1, 0)));
+    colors.add(Color(RGB(0.40000001, 1, 0)));
+    colors.add(Color(RGB(0.80000001, 1, 0)));
+    colors.add(Color(RGB(1, 0.91764706, 0)));
+    colors.add(Color(RGB(1, 0.80000001, 0)));
+    colors.add(Color(RGB(1, 0.40000001, 0)));
+    colors.add(Color(RGB(1, 0, 0)));
+    break;
+  case Rainbow:
+    colors.add(Color(RGB(1, 0, 0)));
+    colors.add(Color(RGB(1, 0.40000001, 0)));
+    colors.add(Color(RGB(1, 0.80000001, 0)));
+    colors.add(Color(RGB(1, 0.91764706, 0)));
+    colors.add(Color(RGB(0.80000001, 1, 0)));
+    colors.add(Color(RGB(0.40000001, 1, 0)));
+    colors.add(Color(RGB(0, 1, 0)));
+    colors.add(Color(RGB(0, 1, 0.40000001)));
+    colors.add(Color(RGB(0, 1, 0.80000001)));
+    colors.add(Color(RGB(0, 0.80000001, 1)));
+    colors.add(Color(RGB(0, 0.40000001, 1)));
+    colors.add(Color(RGB(0, 0, 1)));
+    break;
+  case InvBlackBody:
+    colors.add(Color(RGB(1, 1, 1)));
+    colors.add(Color(RGB(1, 1, 0.70588237)));
+    colors.add(Color(RGB(1, 0.96862745, 0.47058824)));
+    colors.add(Color(RGB(1, 0.89411765, 0.3137255)));
+    colors.add(Color(RGB(1, 0.80000001, 0.21568628)));
+    colors.add(Color(RGB(1, 0.63921571, 0.078431375)));
+    colors.add(Color(RGB(1, 0.47058824, 0)));
+    colors.add(Color(RGB(0.90196079, 0.27843139, 0)));
+    colors.add(Color(RGB(0.78431374, 0.16078432, 0)));
+    colors.add(Color(RGB(0.60000002, 0.070588239, 0)));
+    colors.add(Color(RGB(0.40000001, 0.0078431377, 0)));
+    colors.add(Color(RGB(0.20392157, 0, 0)));
+    colors.add(Color(RGB(0, 0, 0)));
+    break;
+  case BlackBody:
+    colors.add(Color(RGB(0, 0, 0)));
+    colors.add(Color(RGB(0.20392157, 0, 0)));
+    colors.add(Color(RGB(0.40000001, 0.0078431377, 0)));
+    colors.add(Color(RGB(0.60000002, 0.070588239, 0)));
+    colors.add(Color(RGB(0.78431374, 0.16078432, 0)));
+    colors.add(Color(RGB(0.90196079, 0.27843139, 0)));
+    colors.add(Color(RGB(1, 0.47058824, 0)));
+    colors.add(Color(RGB(1, 0.63921571, 0.078431375)));
+    colors.add(Color(RGB(1, 0.80000001, 0.21568628)));
+    colors.add(Color(RGB(1, 0.89411765, 0.3137255)));
+    colors.add(Color(RGB(1, 0.96862745, 0.47058824)));
+    colors.add(Color(RGB(1, 1, 0.70588237)));
+    colors.add(Color(RGB(1, 1, 1)));
+    break;
+  case GrayScale:
+    colors.add(Color(RGB(0,0,0)));
+    colors.add(Color(RGB(1,1,1)));
+    break;
+  case InvGrayScale:
+    colors.add(Color(RGB(1,1,1)));
+    colors.add(Color(RGB(0,0,0)));
+    break;
+  case InvRainbowIso:
+    colors.add(Color(RGB(0.528, 0.528, 1.0)));
+    colors.add(Color(RGB(0.304, 0.5824, 1.0)));
+    colors.add(Color(RGB(0.0, 0.6656, 0.832)));
+    colors.add(Color(RGB(0.0, 0.712, 0.5696)));
+    colors.add(Color(RGB(0.0, 0.744, 0.2976)));
+    colors.add(Color(RGB(0.0, 0.76, 0.0)));
+    colors.add(Color(RGB(0.304, 0.76, 0.0)));
+    colors.add(Color(RGB(0.5504, 0.688, 0.0)));
+    colors.add(Color(RGB(0.68, 0.624, 0.0)));
+    colors.add(Color(RGB(0.752, 0.6016, 0.0)));
+    colors.add(Color(RGB(1.0, 0.5008, 0.168)));
+    colors.add(Color(RGB(1.0, 0.424, 0.424)));
+    break;
+  default:
+    cerr<<"RegularColorMap::fillColor(type="<<type
+        <<"):  Invalid type, using gray scale\n";
+    colors.add(Color(RGB(1,1,1)));
+    colors.add(Color(RGB(0,0,0)));
+  }
+}
+
+bool RegularColorMap::fillColor(const char* file, Array1<Color>& colors)
+{
+  char *me="RegularColorMap::fillColor(file)";
+  Array1<Color> new_colors;
+  ifstream infile(file);
+  if (!infile) {
+    cerr<<me<<":  Color map file, "<<file<<", cannot be opened for 
reading\n";
+    return false;
+  }
+
+  float r=0;
+  infile>>r;
+  float max=r;
+  do {
+    // Slurp up the colors
+    float g=0;
+    float b=0;
+    infile>>g>>b;
+
+    if (r>max)
+      max=r;
+    if (g>max)
+      max=g;
+    if (b>max)
+      max=b;
+
+    new_colors.add(Color(RGB(r,g,b)));
+    infile>>r;
+  } while(infile);
+
+  if (max>1) {
+    cerr<<me<<":  Renormalizing colors for range of 0 to 255\n";
+    Real inv255=1/static_cast<Real>(255);
+    for (unsigned int i=0; i < new_colors.size(); ++i)
+      new_colors[i]=new_colors[i] * inv255;
+  }
+
+  // Copy the contents of new_colors to colors
+  colors=new_colors;
+
+  return true;
+}
+
+void RegularColorMap::fillBlendedColors(Array1<Color>& blended)
+{
+  ScalarTransform1D<int, Color> my_lookup;
+  my_lookup.setResultsPtr(&colors);
+  my_lookup.scale(0, blended.size() - 1);
+
+  for (unsigned int i=0; i < blended.size(); ++i)
+    blended[i]=my_lookup.interpolate(i);
+}
+
+unsigned int RegularColorMap::parseType(const char* type) {
+  string type_string(type);
+  if (type_string == "InvRainbowIso" || type_string == "invrainbowiso" ||
+      type_string == "iril")
+    return InvRainbowIso;
+  else if (type == "InvRainbow" || type_string == "invrainbow" ||
+           type_string == "ir")
+    return InvRainbow;
+  else if (type_string == "Rainbow" || type_string == "rainbow" ||
+           type_string == "r")
+    return Rainbow;
+  else if (type_string == "InvBlackBody" || type_string == "invblackbody" ||
+           type_string == "ib")
+    return InvBlackBody;
+  else if (type_string == "BlackBody" || type_string == "blackbody" ||
+           type_string == "b")
+    return BlackBody;
+  else if (type_string == "InvGrayScale" || type_string == "invgrayscale" ||
+           type_string == "ig")
+    return InvGrayScale;
+  else if (type_string == "GrayScale" || type_string == "grayscale" ||
+           type_string == "g")
+    return GrayScale;
+
+  return Unknown;
+}

Added: trunk/Core/Color/RegularColorMap.h
==============================================================================
--- (empty file)
+++ trunk/Core/Color/RegularColorMap.h  Tue May 30 20:15:58 2006
@@ -0,0 +1,46 @@
+
+#ifndef Manta_Core_RegularColorMap_h
+#define Manta_Core_RegularColorMap_h
+
+#include <Core/Geometry/ScalarTransform1D.h>
+#include <SCIRun/Core/Containers/Array1.h>
+
+namespace Manta
+{
+  class RegularColorMap
+  {
+  public:
+    RegularColorMap(const char* filename, unsigned int size=256);
+    RegularColorMap(Array1<Color>& colors, unsigned int size=256);
+    RegularColorMap(unsigned int type=RegularColorMap::InvRainbowIso,
+                    unsigned int size=256);
+
+    virtual ~RegularColorMap(void) { }
+
+    static unsigned int parseType(const char* type);
+
+    enum {
+      InvRainbowIso=0,
+      InvRainbow,
+      Rainbow,
+      InvGrayScale,
+      GrayScale,
+      InvBlackBody,
+      BlackBody,
+      Unknown
+    };
+
+    ScalarTransform1D<float, Color> lookup;
+    Array1<Color> blended;
+
+  protected:
+    bool fillColor(const char* filename, Array1<Color>& colors);
+    void fillColor(unsigned int type, Array1<Color>& colors);
+    void fillBlendedColors(Array1<Color>& blended);
+
+    Array1<Color> colors;
+    Array1<Color> new_blended;
+  };
+}
+
+#endif // Manta_Core_RegularColorMap_h

Added: trunk/Core/Geometry/ScalarTransform1D.h
==============================================================================
--- (empty file)
+++ trunk/Core/Geometry/ScalarTransform1D.h     Tue May 30 20:15:58 2006
@@ -0,0 +1,158 @@
+
+#ifndef Manta_Core_ScalarTransform1D_h
+#define Manta_Core_ScalarTransform1D_h
+
+#include <MantaTypes.h>
+#include <SCIRun/Core/Containers/Array1.h>
+#include <SCIRun/Core/Math/MiscMath.h>
+
+using SCIRun::Array1;
+
+namespace Manta
+{
+  // LType is the lookup type - it should be a scalar
+  // RType is the result type - can be any type
+  template<class LType, class RType>
+  class ScalarTransform1D
+  {
+  public:
+    ScalarTransform1D(Array1<RType>* results=0);
+    ScalarTransform1D(const Array1<RType> &r);
+    ~ScalarTransform1D(void);
+
+    inline int getLookupIndex(const LType value) const {
+      return static_cast<int>((value - min)*inv_range*(results.size() - 1));
+    }
+
+    inline RType lookup(const LType value) const {
+      return (*results)[getLookupIndex(value)];
+    }
+
+    inline int getBoundLookupIndex(const LType value) const {
+      int idx=getLookupIndex(value);
+      return SCIRun::Clamp(index, 0, results->size() - 1);
+    }
+
+    inline RType lookupBound(const LType value) const {
+      return (*results)[getBoundLookupIndex(value)];
+    }
+
+    inline int getLookupIndex(const LType value, const LType min_,
+                              const LType max_) const {
+      int idx=static_cast<int>((value - min_)/(max_ - min_)*results->size() 
- 1);
+      return SCIRun::Clamp(index, 0, results->size() - 1);
+    }
+
+    inline RType lookup(const LType value, const LType min_,
+                        const LType max_) const {
+      return (*results)[get_lookup_index(value,min_,max_)];
+    }
+
+    inline RType lookupWithIndex(const int idx) const {
+      return (*results)[SCIRun::Clamp(idx, 0, results->size() - 1)];
+    }
+
+    inline RType& operator[](const int idx) const {
+      return (*results)[idx];
+    }
+
+    inline RType interpolate(const LType value) const {
+      double step=(value - min)*inv_range*(results->size() - 1);
+      int x_low=SCIRun::Clamp((int)step, 0, results->size() - 2);
+      double x_weight_low=(x_low + 1) - step;
+      return (*results)[x_low]*x_weight_low +
+        (*results)[x_low + 1]*(1 - x_weight_low);
+    }
+  
+    Array1<RType> *getResultsPtr(void) {
+      return results;
+    }
+
+    Array1<RType> &getResultsRef(void) {
+      return *results;
+    }
+
+    // This function could cause problems in parallel, so watch out!
+    void setResultsPtr(Array1<RType> *results_) {
+      if (nuke)
+        delete results;
+
+      nuke=false;
+      results=results_;
+    }
+
+    // If you want the results pointer to not be deleted (in the case
+    // where it was created by ScalarTransform1D you need to call this
+    // function.  This will prevent the class from deleting the memory.
+    void dontNuke(void) {
+      nuke=false;
+    }
+  
+    void getMinMax(LType& min_, LType& max_) const;
+    void scale(LType min_, LType max_);
+    bool isScaled() const { return is_scaled; } 
+
+    inline int size() const { return results->size(); }
+
+  private:
+    Array1<RType>* results;
+    LType min, max;
+    Real inv_range;
+    bool is_scaled;
+    bool nuke;
+  };
+
+  template<class LType, class RType>
+  ScalarTransform1D<LType,RType>::ScalarTransform1D(Array1<RType> *results) :
+    results(results), min(0), max(1), inv_range(1), is_scaled(false),
+    nuke(false)
+  {
+    // Do nothing
+  }
+
+  template<class LType, class RType>
+  ScalarTransform1D<LType,RType>::ScalarTransform1D(const Array1<RType> &r):
+    min(0), max(1), inv_range(1), is_scaled(false), nuke(true)
+  {
+    results=new Array1<RType>(r);
+  }
+
+  template<class LType, class RType>
+  ScalarTransform1D<LType,RType>::~ScalarTransform1D()
+  {
+    if (nuke)
+      if (results != 0)
+        delete results;
+  }
+
+  template<class LType, class RType>
+  void ScalarTransform1D<LType,RType>::getMinMax(LType &min_, LType &max_) 
const
+  {
+    min_=min;
+    max_=max;
+  }
+  
+  template<class LType, class RType>
+  void ScalarTransform1D<LType,RType>::scale(LType min_, LType max_)
+  {
+    min=min_;
+    max=max_;
+
+    // Make sure that min and max are in the right order
+    if (min > max) {
+      LType t=min;
+      min=max;
+      max=t;
+    }
+
+    // Set inv_range to 0 if min and max equal each other
+    if (min == max)
+      inv_range=0;
+    else
+      inv_range=1/static_cast<Real>(max - min);
+
+    is_scaled=true;
+  }
+}
+
+#endif // Manta_Core_ScalarTransform1D_h

Modified: trunk/Engine/Control/DynPLTWorker.cc
==============================================================================
--- trunk/Engine/Control/DynPLTWorker.cc        (original)
+++ trunk/Engine/Control/DynPLTWorker.cc        Tue May 30 20:15:58 2006
@@ -21,9 +21,9 @@
 DynPLTContext::DynPLTContext(SCIRun::Mailbox<DynPLTMessage>* queue,
                              Scene* scene, unsigned int ngroups,
                              unsigned int nsamples, unsigned int max_depth,
-                             bool dilate) :
+                             bool dilate, Real Kd, Real Ka) :
   queue(queue), scene(scene), ngroups(ngroups), nsamples(nsamples),
-  max_depth(max_depth), dilate(dilate)
+  max_depth(max_depth), dilate(dilate), Kd(Kd), Ka(Ka)
 {
   // Ensure that the number of samples is a perfect square
   
nsamples_root=static_cast<int>(SCIRun::Ceil(SCIRun::Sqrt(static_cast<Real>(nsamples))));
@@ -138,7 +138,8 @@
           hidx[d]=static_cast<unsigned int>(ngroups*rng.gendrand());
 
         for (unsigned int s=0; s<nsamples; s += RayPacket::MaxSize) {
-          Real result=0;
+          Real diffuse=0;
+          Real ambient=0;
           Packet<Real> atten;
 
           // Initialize a ray packet
@@ -213,7 +214,7 @@
                   Vector shadowdir=shadowRays.getDirection(i);
                   Real cos_theta=Dot(shadowdir, normal);
                   Color light=shadowRays.getColor(i);
-                  result += atten.get(i)*light.luminance()*cos_theta;
+                  diffuse += atten.get(i)*light.luminance()*cos_theta;
                 }
               }
               
@@ -314,7 +315,7 @@
                 scene->getBackground()->shade(rctx, sub);
 
                 for (unsigned int j=sub.begin(); j<sub.end(); ++j)
-                  result += sub.getColor(j).luminance();
+                  ambient += sub.getColor(j).luminance();
 
                 i=end;
               }
@@ -330,7 +331,7 @@
           }
 
           // Store the result
-          dynplt->texture[u][v] += result;
+          dynplt->texture[u][v] += context->Ka*ambient + context->Kd*diffuse;
         }
 
         // Normalize the texel

Modified: trunk/Engine/Control/DynPLTWorker.h
==============================================================================
--- trunk/Engine/Control/DynPLTWorker.h (original)
+++ trunk/Engine/Control/DynPLTWorker.h Tue May 30 20:15:58 2006
@@ -23,7 +23,8 @@
   public:
     DynPLTContext(SCIRun::Mailbox<DynPLTMessage>* queue, Scene* scene,
                   unsigned int ngroups, unsigned int nsamples,
-                  unsigned int max_depth, bool dilate);
+                  unsigned int max_depth, bool dilate,
+                  Real Kd=0.6, Real Ka=0.4);
     ~DynPLTContext(void) { }
 
     // DynPLT work queue
@@ -37,6 +38,8 @@
     unsigned int nsamples;
     unsigned int nsamples_root;
     unsigned int max_depth;
+    Real Ka;
+    Real Kd;
 
     // Texture dilation parameters
     bool dilate;

Modified: trunk/Model/Primitives/DynPLTGridSpheres.cc
==============================================================================
--- trunk/Model/Primitives/DynPLTGridSpheres.cc (original)
+++ trunk/Model/Primitives/DynPLTGridSpheres.cc Tue May 30 20:15:58 2006
@@ -1,4 +1,5 @@
 
+#include <Core/Color/RegularColorMap.h>
 #include <Interface/RayPacket.h>
 #include <Engine/Control/DynPLTWorker.h>
 #include <Model/Primitives/DynPLTGridSpheres.h>
@@ -9,7 +10,12 @@
 using namespace Manta;
 using namespace SCIRun;
 
-void DynPLTGridSpheres::init(int nspheres)
+DynPLTGridSpheres::DynPLTGridSpheres(SCIRun::Mailbox<DynPLTMessage>* queue,
+                                     float* spheres, int nspheres, int nvars,
+                                     int ncells, int depth, float radius,
+                                     int ridx, RegularColorMap* cmap, int 
cidx) :
+  queue(queue), GridSpheres(spheres, nspheres, nvars, ncells, depth, radius,
+                            ridx, cmap, cidx)
 {
   cerr<<"Initializing DynPLTGridSpheres\n";
   plts.resize(nspheres);
@@ -22,27 +28,6 @@
   }
 }
 
-DynPLTGridSpheres::DynPLTGridSpheres(SCIRun::Mailbox<DynPLTMessage>* queue,
-                                     const Color& color, float* spheres,
-                                     int nspheres, int nvars, int ncells,
-                                     int depth, float radius, int ridx) :
-  queue(queue), GridSpheres(color, spheres, nspheres, nvars, ncells, depth,
-                            radius, ridx)
-{
-  init(nspheres);
-}
-
-DynPLTGridSpheres::DynPLTGridSpheres(SCIRun::Mailbox<DynPLTMessage>* queue,
-                                     const Texture<Color>* colorfn,
-                                     float* spheres, int nspheres, int nvars,
-                                     int ncells, int depth, float radius,
-                                     int ridx) :
-  queue(queue), GridSpheres(colorfn, spheres, nspheres, nvars, ncells, depth,
-                            radius, ridx)
-{
-  init(nspheres);
-}
-
 DynPLTGridSpheres::~DynPLTGridSpheres(void)
 {
   // Do nothing
@@ -65,7 +50,7 @@
     if (valid[particle]) {
       // Compute diffuse colors
       Packet<Color> diffuse;
-      colortex->mapValues(diffuse, context, sub);
+      mapDiffuseColors(diffuse, rays);
     
       // Compute textured luminance
       sub.computeTextureCoordinates2(context);

Modified: trunk/Model/Primitives/DynPLTGridSpheres.h
==============================================================================
--- trunk/Model/Primitives/DynPLTGridSpheres.h  (original)
+++ trunk/Model/Primitives/DynPLTGridSpheres.h  Tue May 30 20:15:58 2006
@@ -14,6 +14,7 @@
 namespace Manta {
   class DynPLTContext;
   class DynPLTGridSpheres;
+  class RegularColorMap;
 
   class DynPLT {
   public:
@@ -49,13 +50,9 @@
   class DynPLTGridSpheres : public GridSpheres
   {
   public:
-    DynPLTGridSpheres(SCIRun::Mailbox<DynPLTMessage>* queue, const Color& 
color,
-                      float* spheres, int nspheres, int nvars, int ncells,
-                      int depth, float radius, int ridx);
-    DynPLTGridSpheres(SCIRun::Mailbox<DynPLTMessage>* queue,
-                      const Texture<Color>* colorfn, float* spheres,
+    DynPLTGridSpheres(SCIRun::Mailbox<DynPLTMessage>* queue, float* spheres,
                       int nspheres, int nvars, int ncells, int depth,
-                      float radius, int ridx);
+                      Real radius, int ridx, RegularColorMap* cmap, int 
cidx);
     ~DynPLTGridSpheres(void);
 
     void shade(const RenderContext& context, RayPacket& rays) const;
@@ -85,8 +82,6 @@
     mutable vector<DynPLT*> plts;
 
   private:
-    void init(int);
-
     SCIRun::Mailbox<DynPLTMessage>* queue;
     mutable vector<bool> requested;
   };

Modified: trunk/Model/Primitives/GridSpheres.cc
==============================================================================
--- trunk/Model/Primitives/GridSpheres.cc       (original)
+++ trunk/Model/Primitives/GridSpheres.cc       Tue May 30 20:15:58 2006
@@ -1,4 +1,5 @@
 
+#include <Core/Color/RegularColorMap.h>
 #include <Core/Math/MiscMath.h>
 #include <Core/Math/Trig.h>
 #include <Core/Math/Expon.h>
@@ -24,7 +25,11 @@
 using namespace Manta;
 using namespace SCIRun;
 
-void GridSpheres::init(void)
+GridSpheres::GridSpheres(float* spheres, int nspheres, int nvars, int ncells,
+                         int depth, Real radius, int ridx, RegularColorMap* 
cmap,
+                         int cidx) :
+  spheres(spheres), nspheres(nspheres), nvars(nvars), ncells(ncells),
+  depth(depth), radius(radius), ridx(ridx), cmap(cmap), cidx(cidx)
 {
   if (radius <= 0) {
     if (ridx <= 0)
@@ -62,26 +67,6 @@
   cells=0;
 }
 
-GridSpheres::GridSpheres(const Color& color, float* spheres, int nspheres,
-                         int nvars, int ncells, int depth, float radius,
-                         int ridx) :
-  spheres(spheres), nspheres(nspheres), nvars(nvars), ncells(ncells),
-  depth(depth), radius(radius), inv_radius(1/radius), ridx(ridx)
-{
-  colortex=new Constant<Color>(color);
-  init();
-}
-
-GridSpheres::GridSpheres(const Texture<Color>* colorfn, float* spheres,
-                         int nspheres, int nvars, int ncells, int depth,
-                         float radius, int ridx) :
-  spheres(spheres), nspheres(nspheres), nvars(nvars), ncells(ncells),
-  depth(depth), radius(radius), inv_radius(1/radius), ridx(ridx),
-  colortex(colorfn)
-{
-  init();
-}
-
 GridSpheres::~GridSpheres()
 {
   delete [] min;
@@ -584,7 +569,7 @@
 
   // Compute colors
   Packet<Color> diffuse;
-  colortex->mapValues(diffuse, context, rays);
+  mapDiffuseColors(diffuse, rays);
 
   // Compute ambient contributions for all rays
   ColorArray totalLight;
@@ -913,5 +898,18 @@
         }
       }
     }
+  }
+}
+
+void GridSpheres::mapDiffuseColors(Packet<Color>& diffuse, RayPacket& rays) 
const
+{
+  for (unsigned int i=rays.begin(); i<rays.end(); ++i) {
+    int particle=rays.scratchpad<int>(i);
+    float value=*(spheres + particle + cidx);
+    float minimum=min[cidx];
+    float normalized=(value - minimum)/(max[cidx] - minimum);
+    int ncolors=cmap->blended.size() - 1;
+    int idx=SCIRun::Clamp(static_cast<int>(ncolors*normalized), 0, ncolors);
+    diffuse.set(i, cmap->blended[idx]);
   }
 }

Modified: trunk/Model/Primitives/GridSpheres.h
==============================================================================
--- trunk/Model/Primitives/GridSpheres.h        (original)
+++ trunk/Model/Primitives/GridSpheres.h        Tue May 30 20:15:58 2006
@@ -10,16 +10,14 @@
 #include <Model/Materials/LitMaterial.h>
 
 namespace Manta {
+  class RegularColorMap;
+
   class GridSpheres : public PrimitiveCommon, public LitMaterial,
-    public TexCoordMapper
+                      public TexCoordMapper
   {
   public:
-    GridSpheres(const Color& color, float* spheres, int nspheres,
-                int nvars, int ncells,
-                int depth, float radius, int ridx);
-    GridSpheres(const Texture<Color>* colorfn, float* spheres, int nspheres,
-                int nvars, int ncells,
-                int depth, float radius, int ridx);
+    GridSpheres(float* spheres, int nspheres, int nvars, int ncells, int 
depth,
+                Real radius, int ridx, RegularColorMap* cmap, int cidx);
     ~GridSpheres(void);
 
     void preprocess(const PreprocessContext&);
@@ -43,8 +41,6 @@
       float* min;
     };
 
-    void init(void);
-
     void traverse(int i, RayPacket& rays, int depth,
                   Real tnear,
                   int ix, int iy, int iz,
@@ -61,6 +57,7 @@
                             int& ex, int& ey, int& ez) const;
     int mapIdx(int ix, int iy, int iz, int depth);
     void fillMCell(MCell& mcell, int depth, int startidx) const;
+    void mapDiffuseColors(Packet<Color>& diffuse, RayPacket& rays) const;
 
     float* spheres;
     int nspheres;
@@ -85,7 +82,8 @@
 
     MCell** macrocells;
 
-    const Texture<Color>* colortex;
+    RegularColorMap* cmap;
+    int cidx;
   };
 }
 

Modified: trunk/scenes/dynplt.cc
==============================================================================
--- trunk/scenes/dynplt.cc      (original)
+++ trunk/scenes/dynplt.cc      Tue May 30 20:15:58 2006
@@ -1,3 +1,4 @@
+#include <Core/Color/RegularColorMap.h>
 #include <Core/Exceptions/IllegalArgument.h>
 #include <Core/Geometry/Vector.h>
 #include <Core/Util/Args.h>
@@ -31,6 +32,7 @@
 Scene* make_scene(ReadContext const& context, vector<string> const& args)
 {
   Group* world=0;
+  int cidx=0;
   string fname="";
   int depth=1;
   bool dilate=false;
@@ -55,7 +57,10 @@
         throw IllegalArgument("scene dynplt -bv", i, args);
       world=context.manta_interface->makeGroup(s);
 #endif
-    if (arg=="-depth") {
+    if (arg=="-cidx") {
+      if (!getIntArg(i, args, cidx))
+        throw IllegalArgument("scene pnrrd -cidx", i, args);
+    } else if (arg=="-depth") {
       if (!getIntArg(i, args, depth))
         throw IllegalArgument("scene dynplt -depth", i, args);
     } else if (arg=="-dilate") {
@@ -135,14 +140,19 @@
  &DynPLTWorker::terminate));
   }
 
+  // Create color map
+  unsigned int type=RegularColorMap::parseType("InvRainbowIso");
+  RegularColorMap* cmap=new RegularColorMap(type);
+
   // Load particle data, add particles to group
   ParticleNRRD pnrrd(fname);
 #if 1
-  DynPLTGridSpheres* spheres=new DynPLTGridSpheres(queue, Color(RGB(0, 1, 
0)),
+  DynPLTGridSpheres* spheres=new DynPLTGridSpheres(queue,
                                                    pnrrd.getParticleData(),
                                                    pnrrd.getNParticles(),
                                                    pnrrd.getNVars(),
-                                                   ncells, depth, radius, 
ridx);
+                                                   ncells, depth, radius, 
ridx,
+                                                   cmap, cidx);
   world->add(spheres);
 #else
   float* pdata=pnrrd.getParticleData();
@@ -161,7 +171,7 @@
 #endif
 
   // Initialize the scene
-  scene->setBackground(new ConstantBackground(Color(RGB(0, 0, 0))));
+  scene->setBackground(new ConstantBackground(Color(RGB(1, 1, 1))));
   scene->setObject(world);
 
   // Add lights
@@ -170,6 +180,7 @@
   lights->setAmbientLight(new ConstantAmbient(Color(RGB(0.4, 0.4, 0.4))));
   scene->setLights(lights);
 
+  /*
   scene->addBookmark("debug 0", Vector(0.06, 26.9721, 0.06),
                      Vector(0.06, 0.06, 0.06), Vector(0, 0, 1), 0.59);
   scene->addBookmark("view 0", Vector(0.02, 1.02, 0.20),
@@ -184,6 +195,7 @@
   scene->addBookmark("view 3", Vector(1.01349, 0.0783629, 0.297803),
                      Vector(0.02, 0.02, 0.2),
                      Vector(-0.0890283, -0.13761, 0.986477), 0.204219);
+  */
 
   return scene;
 }

Modified: trunk/scenes/pnrrd.cc
==============================================================================
--- trunk/scenes/pnrrd.cc       (original)
+++ trunk/scenes/pnrrd.cc       Tue May 30 20:15:58 2006
@@ -1,3 +1,4 @@
+#include <Core/Color/RegularColorMap.h>
 #include <Core/Exceptions/IllegalArgument.h>
 #include <Core/Geometry/Vector.h>
 #include <Core/Util/Args.h>
@@ -25,6 +26,7 @@
 Scene* make_scene(ReadContext const& context, vector<string> const& args)
 {
   int argc=static_cast<int>(args.size());
+  int cidx=0;
   string fname="";
   int depth=1;
   int ncells=2;
@@ -41,7 +43,10 @@
       world=context.manta_interface->makeGroup(s);
     } else
 #endif
-    if (arg=="-depth") {
+    if (arg=="-cidx") {
+      if (!getIntArg(i, args, cidx))
+        throw IllegalArgument("scene pnrrd -cidx", i, args);
+    } else if (arg=="-depth") {
       if (!getIntArg(i, args, depth))
         throw IllegalArgument("scene pnrrd -depth", i, args);
     } else if (arg=="-i") {
@@ -71,13 +76,17 @@
   if (!world)
     world=new Group();
 
+  // Create color map
+  unsigned int type=RegularColorMap::parseType("InvRainbowIso");
+  RegularColorMap* cmap=new RegularColorMap(type);
+
   // Load particle data, add particles to group
   ParticleNRRD pnrrd(fname);
 #if 1
-  GridSpheres* spheres=new GridSpheres(Color(RGB(1, 1, 1)),
-                                       pnrrd.getParticleData(),
+  GridSpheres* spheres=new GridSpheres(pnrrd.getParticleData(),
                                        pnrrd.getNParticles(), 
pnrrd.getNVars(),
-                                       ncells, depth, radius, ridx);
+                                       ncells, depth, radius, ridx, cmap,
+                                       cidx);
   world->add(spheres);
 #else
   float* pdata=pnrrd.getParticleData();
@@ -105,6 +114,7 @@
   lights->setAmbientLight(new ConstantAmbient(Color(RGB(0.4, 0.4, 0.4))));
   scene->setLights(lights);
 
+  /*
   scene->addBookmark("debug 0", Vector(0.06, 26.9721, 0.06),
                      Vector(0.06, 0.06, 0.06), Vector(0, 0, 1), 0.59);
   scene->addBookmark("debug 1", Vector(-10.3318,-2.88089, 24.71),
@@ -122,6 +132,7 @@
   scene->addBookmark("view 2", Vector(-0.83, 0.85, 4.71),
                      Vector(0.02, 0.01, 0.29), Vector(-0.59, -0.59, 0.59),
                      0.59);
+  */
 
   return scene;
 }




  • [MANTA] r1092 - in trunk: Core Core/Color Core/Geometry Engine/Control Model/Primitives scenes, cgribble, 05/30/2006

Archive powered by MHonArc 2.6.16.

Top of page