Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r1520 - in trunk: Model/Textures scenes


Chronological Thread 
  • From: cgribble@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r1520 - in trunk: Model/Textures scenes
  • Date: Fri, 20 Jul 2007 13:52:47 -0600 (MDT)

Author: cgribble
Date: Fri Jul 20 13:52:45 2007
New Revision: 1520

Added:
   trunk/Model/Textures/ColorMap.cc
   trunk/Model/Textures/ColorMap.h
Modified:
   trunk/Model/Textures/CMakeLists.txt
   trunk/scenes/pcgt.cc
Log:
Some cleanup in pcgt scene; added ColorMap texture that will map the Real 
value in the ray scratchpad to determine surface color

Modified: trunk/Model/Textures/CMakeLists.txt
==============================================================================
--- trunk/Model/Textures/CMakeLists.txt (original)
+++ trunk/Model/Textures/CMakeLists.txt Fri Jul 20 13:52:45 2007
@@ -3,6 +3,8 @@
 SET( Manta_Textures_SRCS
      Textures/CheckerTexture.cc
      Textures/CheckerTexture.h
+     Textures/ColorMap.cc
+     Textures/ColorMap.h
      Textures/Constant.cc
      Textures/Constant.h
      Textures/ImageTexture.cc

Added: trunk/Model/Textures/ColorMap.cc
==============================================================================
--- (empty file)
+++ trunk/Model/Textures/ColorMap.cc    Fri Jul 20 13:52:45 2007
@@ -0,0 +1,45 @@
+
+/*
+  For more information, please see: http://software.sci.utah.edu
+
+  The MIT License
+
+  Copyright (c) 2005-2006
+  Scientific Computing and Imaging Institute, University of Utah
+
+  License for the specific language governing rights and limitations under
+  Permission is hereby granted, free of charge, to any person obtaining a
+  copy of this software and associated documentation files (the "Software"),
+  to deal in the Software without restriction, including without limitation
+  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+  and/or sell copies of the Software, and to permit persons to whom the
+  Software is furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included
+  in all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+  DEALINGS IN THE SOFTWARE.
+*/
+
+#include <Model/Textures/ColorMap.h>
+#include <Interface/RayPacket.h>
+
+using namespace Manta;
+
+void ColorMap::mapValues(Packet<Color>& results,
+                         const RenderContext& context,
+                         RayPacket& rays) const
+{
+  for (int i = rays.begin(); i < rays.end(); ++i) {
+    const Real value = rays.scratchpad<Real>(i);
+    const Real normalized = (value - min)*inv_range;
+    const int idx = SCIRun::Clamp(static_cast<int>(ncolors*normalized), 0, 
ncolors);
+    results.set(i, cmap.blended[idx]);
+  }
+}

Added: trunk/Model/Textures/ColorMap.h
==============================================================================
--- (empty file)
+++ trunk/Model/Textures/ColorMap.h     Fri Jul 20 13:52:45 2007
@@ -0,0 +1,74 @@
+
+/*
+  For more information, please see: http://software.sci.utah.edu
+
+  The MIT License
+
+  Copyright (c) 2005-2006
+  Scientific Computing and Imaging Institute, University of Utah
+
+  License for the specific language governing rights and limitations under
+  Permission is hereby granted, free of charge, to any person obtaining a
+  copy of this software and associated documentation files (the "Software"),
+  to deal in the Software without restriction, including without limitation
+  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+  and/or sell copies of the Software, and to permit persons to whom the
+  Software is furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included
+  in all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+  DEALINGS IN THE SOFTWARE.
+*/
+
+#ifndef Manta_Model_ColorMap_h
+#define Manta_Model_ColorMap_h
+
+#include <Core/Color/RegularColorMap.h>
+#include <Interface/RayPacket.h>
+#include <Interface/Texture.h>
+#include <Model/Textures/Constant.h>
+
+namespace Manta {
+
+  class RayPacket;
+  class RenderContext;
+  
+  class ColorMap : public Texture<Color>
+  {
+  public:
+    ColorMap(const RegularColorMap& cmap_, Real min_, Real max_) :
+      cmap(cmap_)
+    {
+      setRange(min_, max_);
+      ncolors = cmap.blended.size() - 1;
+    }
+
+    virtual ~ColorMap() {}
+    
+    void setRange(Real min_, Real max_)
+    {
+      min = min_;
+      max = max_;
+      inv_range = 1.0/(max - min);
+    }
+
+    virtual void mapValues(Packet<Color>& results,
+                           const RenderContext&,
+                           RayPacket& rays) const;
+
+  private:
+    RegularColorMap cmap;
+    Real min, max;
+    Real inv_range;
+    int ncolors;
+  };
+}
+
+#endif

Modified: trunk/scenes/pcgt.cc
==============================================================================
--- trunk/scenes/pcgt.cc        (original)
+++ trunk/scenes/pcgt.cc        Fri Jul 20 13:52:45 2007
@@ -15,6 +15,7 @@
 #include <Model/Materials/Lambertian.h>
 #include <Model/Primitives/GridSpheres.h>
 #include <Model/Primitives/Sphere.h>
+#include <Model/Textures/ColorMap.h>
 #include <Model/Readers/ParticleNRRD.h>
 #include <Model/Groups/private/ParticleCGT.h>
 
@@ -32,7 +33,7 @@
   int cidx = 0;
   string env_fname = "";
   string fname = "";
-  double radius = 0.001; //Carson: radius must be smaller than a certain 
value based on the dispersion of the spheres or else the sphere_center method 
doesn't work with macrocells apparently ....  
+  double radius = 0.001;
   int ridx = -1;
   double lx = 10.;
   double ly = 10.;
@@ -66,7 +67,6 @@
       cerr<<"Valid options for scene pcgt:\n";
       cerr<<"  -cidx <int>        data value index for color mapping\n";
       cerr<<"  -envmap <string>   environment map filename\n";
-      cerr<<"  -ncells <int>      grid resolution\n";
       cerr<<"  -i <string>        filename\n";
       cerr<<"  -radius <float>    particle radius\n";
       cerr<<"  -ridx <int>        radius index\n";
@@ -77,38 +77,38 @@
   // Create scene
   Scene* scene = new Scene();
 
+  // Read the data
+  ParticleNRRD pnrrd(fname);
+  unsigned int nparticles = pnrrd.getNParticles();
+  unsigned int nvars = pnrrd.getNVars();
+
   // Create color map
   unsigned int type = RegularColorMap::parseType("InvRainbowIso");
-  RegularColorMap* cmap = new RegularColorMap(type);
+  RegularColorMap cmap(type);
+  float vmin = FLT_MAX;
+  float vmax = -FLT_MAX;
+  for (unsigned int i = 0; i < nparticles; ++i) {
+    float* data = pnrrd.getParticleData() + i*nvars;
+    vmin = std::min(vmin, data[cidx]);
+    vmax = std::max(vmax, data[cidx]);
+  }
 
-  // XXX(cpg) - There are some problems here:
-  //   1.  Get bus error without the random, manually added sphere at (0, 0, 
0)  //Carson: fixed
-  //   2.  I don't understand the scene <- world <- particles <- data 
mapping.
-  //       Why so many layers of groups?  It seems to me that ParticleGrid 
should
-  //       be the scene's primary object, unless we're loading multiple time 
steps
-  //       (see pnrrd.cc).  //Carson:  I was using multiple objects in the 
scene, it has been changed.  The world group doesn't really add any overhead 
that I'm aware of, just a container to add stuff to.
-  //   3.  Doesn't support variable radii  //Carson:  ParticleCGT does 
support variable radii as it uses the Sphere intersection test, you just need 
it in the data file or specify some kind of random radius when you build the 
group of spheres.
-  //   3.  Doesn't support run time color mapping // Carson: a colormapped 
material can be added to the spheres
+  Material* material = new Lambertian(new ColorMap(cmap, vmin, vmax));
 
-  // ***** begin copy (more or less) from ParticleCGTTest.cc *****
-  //Group* world = new Group;
+  // Create particles
   Group* particles = new Group;
-
-  Material* material = new Lambertian(Color(RGB(1, 0, 0)));
-  ParticleNRRD pnrrd(fname);
-  unsigned int nvars = pnrrd.getNVars();
-  for (unsigned int i = 0; i < pnrrd.getNParticles(); i++) {
+  for (unsigned int i = 0; i < nparticles; ++i) {
     float* data = pnrrd.getParticleData() + i*nvars;
     Vector position(data[0], data[1], data[2]);
+    if (ridx >= 0)
+      radius = data[ridx];
+
     particles->add(new Sphere(material, position, radius));
   }
 
   ParticleGrid* grid = new ParticleGrid;
   grid->rebuild(particles);
-  //world->add(grid);
-  //world->add(new Sphere(material, Vector(0,0,0), radius));
   scene->setObject(grid);
-  // ***** end copy *****
 
   // Set background
   if (env_fname != "")




  • [MANTA] r1520 - in trunk: Model/Textures scenes, cgribble, 07/20/2007

Archive powered by MHonArc 2.6.16.

Top of page