Manta Interactive Ray Tracer Development Mailing List

Text archives Help


Re: [Manta] r2050 - in trunk: Model/Primitives Model/Textures scenes


Chronological Thread 
  • From: Roni Choudhury <roni@cs.utah.edu>
  • To: Carson Brownlee <brownlee@cs.utah.edu>
  • Cc: manta@sci.utah.edu
  • Subject: Re: [Manta] r2050 - in trunk: Model/Primitives Model/Textures scenes
  • Date: Tue, 12 Feb 2008 13:01:26 -0700

ValuePrimitive is templated on type, and the ValueColormap is templated on the same type. So you need a way to interpolate vector values or whatever, and then you can have more or less general value-to-color maps.

roni

Carson Brownlee wrote:
Certainly is cleaner, if memory servers ColorMap was just created specifically for the DynLT sphere code. I would vote for leaving it there(especially because it is still used), as it seems like a good way of handling colormapping something like a heightmap or say a custom sphere intersection class that is really just one primitive. Though your right that the scratchpad is probably better off avoided when possible. I could have sworn doing something like this before, but couldn't you also assign a texture coordinate? That way you could also have 1d/2d/3d color lookups, but of course you might be using textures on those primitives too (as we were).
only thing I see from glancing at yours is that it only supports one value, but often times you might want to map several values to a given sphere in case you want to examine different indexes into the data. That and mapValues seems to overwrite the color, does this break texturing/lighting? I don't remember exactly.
Carson


On Feb 12, 2008, at 12:11 AM, Roni Choudhury wrote:

To my horror and shame I see that there is already a color mapping mechanism in Manta...but I think it has some problems.

I'm referring to Model/Textures/ColorMap.{h|cc}. It pulls the scalar value from the scratchpad, which last night I decided is a bad idea mainly because it places policy requirements on the scratchpad about where colormapping scalars are supposed to go, and that is bad because it's not the kind of thing the scratchpad is meant for. You theoretically end up with an "FCC problem" in which someone has to regulate what parts of the scratchpad are allowed to be used for specific functions. As I understand it, values placed into a scratchpad by some class should only be accessed by that class, eliminating the regulatory problem (or at least, solving it by keeping policies internal to each class that uses the scratchpad). One example of how things can go wrong: if the ColorMap texture is applied to an Instance, incorrect color values will appear on screen, as the Instance uses the scratchpad for its own purposes after allowing its underlying primitive to use it first. Another problem is that general primitives cannot be used with ColorMap, since they don't place scalar values in the scratchpad. For a general solution, you need something like the ValuePrimitive I added today.

The ValuePrimitive/ValueColormap pair of classes allows for colormapping without placing unenforceable policy requirements on the scratchpad, and they allow for any existing primitive to become colormappable.

Anyway, I'm just letting people know why I checked in a new thing that seems to already exist in Manta. If there's a problem with any of this, let me know.

roni

roni@sci.utah.edu wrote:
Author: roni
Date: Mon Feb 11 21:47:16 2008
New Revision: 2050
Added:
trunk/Model/Primitives/ValuePrimitive.h
trunk/Model/Textures/ValueColormap.h
trunk/scenes/valuecolormaptest.cc
Modified:
trunk/Model/Primitives/CMakeLists.txt
trunk/Model/Textures/CMakeLists.txt
trunk/scenes/CMakeLists.txt
Log:
Adding a basic mechanism for colormapping on value.
Model/Primitives/ValuePrimitive.h:
A decorator class that wraps and exports the interface of any
primitive (inline, so there should not be much performance penalty),
but also adds setValue() and getValue() methods.
Model/Textures/ValueColormap.h:
Texture that can only be applied to ValuePrimitive primitives.  When
given a ValuePrimitive, associates some color to it based on the
value in the primitive and the range the ValueColormap is working
with.
TODO: needs a general colormap mechanism (for now it simply does
red-to-blue).
scenes/valuecolormaptest.cc:
A scene for testing the new mechanism.  No arguments.
scenes/CMakeLists.txt:
Model/Primitives/CMakeLists.txt:
Model/Textures/CMakeLists.txt:
Plugging new classes and scene in.
Modified: trunk/Model/Primitives/CMakeLists.txt
==============================================================================
--- trunk/Model/Primitives/CMakeLists.txt    (original)
+++ trunk/Model/Primitives/CMakeLists.txt    Mon Feb 11 21:47:16 2008
@@ -46,6 +46,7 @@
   Primitives/TessellatedCylinder.h
   Primitives/Torus.cc
   Primitives/Torus.h
+     Primitives/ValuePrimitive.h
   Primitives/WaldTriangle.h
   Primitives/WaldTriangle.cc
   Primitives/BumpPrimitive.h
Added: trunk/Model/Primitives/ValuePrimitive.h
==============================================================================
--- (empty file)
+++ trunk/Model/Primitives/ValuePrimitive.h    Mon Feb 11 21:47:16 2008
@@ -0,0 +1,70 @@
+#ifndef Manta_Model_Primitives_ValuePrimitive_h
+#define Manta_Model_Primitives_ValuePrimitive_h
+
+#include <Interface/Primitive.h>
+
+namespace Manta {
+  template<typename T>
+  class ValuePrimitive : public Primitive {
+  public:
+    typedef T ValueType;
+
+  public:
+    ValuePrimitive(Primitive *prim) : prim(prim) {}
+ ValuePrimitive(Primitive *prim, const T& val) : prim(prim), val(val) {}
+
+    // Object interface.
+ void computeBounds(const PreprocessContext& context, BBox& bbox) const {
+      prim->computeBounds(context, bbox);
+    }
+
+    // Primitive interface.
+    void preprocess(const PreprocessContext& context){
+      prim->preprocess(context);
+    }
+
+    void intersect(const RenderContext& context,
+                   RayPacket& rays) const {
+      prim->intersect(context, rays);
+      for(int i=rays.begin(); i<rays.end(); i++){
+        if(rays.getHitPrimitive(i) == this->prim)
+          rays.setHitPrimitive(i, this);
+      }
+    }
+
+    void computeNormal(const RenderContext& context,
+                       RayPacket& rays) const {
+      prim->computeNormal(context, rays);
+    }
+
+    void computeSurfaceDerivatives(const RenderContext& context,
+                                   RayPacket& rays) const {
+      prim->computeSurfaceDerivatives(context, rays);
+    }
+
+    void setTexCoordMapper(const TexCoordMapper* new_tex){
+      prim->setTexCoordMapper(new_tex);
+    }
+
+    void getRandomPoints(Packet<Vector>& points,
+                         Packet<Vector>& normals,
+                         Packet<Real>& pdfs,
+                         const RenderContext& context,
+                         RayPacket& rays) const {
+      prim->getRandomPoints(points, normals, pdfs, context, rays);
+    }
+
+    // ValuePrimitive interface.
+    T getValue() const { return val; }
+
+    void setValue(const T& newval) {
+      val = newval;
+    }
+
+  private:
+    Primitive *prim;
+    T val;
+  };
+}
+
+#endif
Modified: trunk/Model/Textures/CMakeLists.txt
==============================================================================
--- trunk/Model/Textures/CMakeLists.txt    (original)
+++ trunk/Model/Textures/CMakeLists.txt    Mon Feb 11 21:47:16 2008
@@ -23,6 +23,7 @@
   Textures/OakTexture.h
   Textures/TexCoordTexture.cc
   Textures/TexCoordTexture.h
+     Textures/ValueColormap.h
   Textures/WoodTexture.cc
   Textures/WoodTexture.h
   )
Added: trunk/Model/Textures/ValueColormap.h
==============================================================================
--- (empty file)
+++ trunk/Model/Textures/ValueColormap.h    Mon Feb 11 21:47:16 2008
@@ -0,0 +1,51 @@
+#ifndef Manta_Model_Textures_ValueColormap_h
+#define Manta_Model_Textures_ValueColormap_h
+
+#include <Interface/Texture.h>
+#include <Model/Primitives/ValuePrimitive.h>
+
+namespace Manta {
+  template<typename T, bool DO_SAFE_TYPECASTING=true>
+  class ValueColormap : public Texture<Color> {
+  public:
+    ValueColormap(T min, T max){
+      setRange(min, max);
+    }
+
+    void setRange(T newmin, T newmax){
+      min = newmin;
+      max = newmax;
+      inv_range = 1.0 / (max - min);
+    }
+
+    void mapValues(Packet<Color>& results,
+                   const RenderContext&,
+                   RayPacket& rays) const {
+      for(int i=rays.begin(); i<rays.end(); i++){
+        const ValuePrimitive<T> *prim = 0;
+
+        if(DO_SAFE_TYPECASTING){
+ prim = dynamic_cast<const ValuePrimitive<T> *>(rays.getHitPrimitive(i));
+          if(!prim){
+ throw InternalError("ValueColormap was given primitives that are not ValuePrimitives");
+          }
+        }
+        else{
+ prim = static_cast<const ValuePrimitive<T> *>(rays.getHitPrimitive(i));
+        }
+
+        const T value = prim->getValue();
+        const T factor = (value - min)*inv_range;
+
+        // Red-to-blue for testing.
+        results.set(i, Color(RGB(1.0 - factor, 0.0, factor)));
+      }
+    }
+
+  private:
+    T min, max;
+    T inv_range;
+  };
+}
+
+#endif
Modified: trunk/scenes/CMakeLists.txt
==============================================================================
--- trunk/scenes/CMakeLists.txt    (original)
+++ trunk/scenes/CMakeLists.txt    Mon Feb 11 21:47:16 2008
@@ -107,6 +107,13 @@
 TARGET_LINK_LIBRARIES(scene_tylenol ${MANTA_SCENE_LINK})
ENDIF(SCENE_TYLENOL)
+# Value primitive and colormap testing scene.
+SET(SCENE_VALUE_COLORMAP TRUE CACHE BOOL "value colormap test")
+IF(SCENE_VALUE_COLORMAP)
+   ADD_LIBRARY(scene_value_colormap_test valuecolormaptest.cc)
+   TARGET_LINK_LIBRARIES(scene_value_colormap_test ${MANTA_SCENE_LINK})
+ENDIF(SCENE_VALUE_COLORMAP)
+
# Lazily evaluated LTs for NRRD particle datasets
IF(BUILD_DYNLT)
 ADD_LIBRARY(scene_dynlt dynlt.cc)
Added: trunk/scenes/valuecolormaptest.cc
==============================================================================
--- (empty file)
+++ trunk/scenes/valuecolormaptest.cc    Mon Feb 11 21:47:16 2008
@@ -0,0 +1,39 @@
+#include <Core/Color/ColorDB.h>
+#include <Core/Util/Preprocessor.h>
+#include <Interface/LightSet.h>
+#include <Interface/Scene.h>
+#include <Model/AmbientLights/ConstantAmbient.h>
+#include <Model/Backgrounds/ConstantBackground.h>
+#include <Model/Groups/Group.h>
+#include <Model/Lights/HeadLight.h>
+#include <Model/Materials/Lambertian.h>
+#include <Model/Primitives/Sphere.h>
+#include <Model/Primitives/ValuePrimitive.h>
+#include <Model/Textures/ValueColormap.h>
+
+using namespace Manta;
+
+MANTA_PLUGINEXPORT
+Scene *make_scene(const ReadContext&, const vector<string>& args)
+{
+  ValueColormap<float> *cmap = new ValueColormap<float>(0.0, 5.0);
+  Lambertian *matl = new Lambertian(cmap);
+
+  Group *group = new Group;
+  for(int i=0; i<5; i++){
+ Primitive *prim = new ValuePrimitive<float>(new Sphere(matl, Vector(2.0*i, 0.0, 0.0), 0.6),
+                                                i*1.25);
+    group->add(prim);
+  }
+
+  Scene *scene = new Scene;
+ scene->setBackground(new ConstantBackground(Color(RGBColor(0.6,0.6,0.6))));
+  scene->setObject(group);
+
+  LightSet *lights = new LightSet;
+  lights->add(new HeadLight(3, Color(RGBColor(1,1,1))));
+ lights->setAmbientLight(new ConstantAmbient(ColorDB::getNamedColor("black")));
+  scene->setLights(lights);
+  +  return scene;
+}





Archive powered by MHonArc 2.6.16.

Top of page