Manta Interactive Ray Tracer Development Mailing List

Text archives Help


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


Chronological Thread 
  • From: roni@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [Manta] r2050 - in trunk: Model/Primitives Model/Textures scenes
  • Date: Mon, 11 Feb 2008 21:47:17 -0700 (MST)

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