Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r1367 - in trunk: Engine/PixelSamplers Model/Primitives Model/Textures UserInterface scenes


Chronological Thread 
  • From: thiago@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r1367 - in trunk: Engine/PixelSamplers Model/Primitives Model/Textures UserInterface scenes
  • Date: Sat, 5 May 2007 02:24:37 -0600 (MDT)

Author: thiago
Date: Sat May  5 02:24:34 2007
New Revision: 1367

Modified:
   trunk/Engine/PixelSamplers/TimeViewSampler.cc
   trunk/Engine/PixelSamplers/TimeViewSampler.h
   trunk/Model/Primitives/Heightfield.cc
   trunk/Model/Textures/HeightColorMap.cc
   trunk/Model/Textures/HeightColorMap.h
   trunk/UserInterface/XWindowUI.cc
   trunk/scenes/vorpal.cc
Log:
scenes/vorpal.cc:
  Some updates. Nothing special.

UserInterface/XWindowUI.cc:
  "Fixed" mouse controls to behave like Maya.
  -left button for rotate
  -middle button for pan
  -right for dolly
  -right+shift for zoom/fov

Model/Textures/HeightColorMap.cc
Model/Textures/HeightColorMap.h:
  Exposed more of the hsv functionality to the outside world. This
  should probably go into its own class or somewhere else...

Model/Primitives/Heightfield.cc:
  Fixed off by 1 traversal bug.

Engine/PixelSamplers/TimeViewSampler.cc
Engine/PixelSamplers/TimeViewSampler.h:
  can now toggle through various types of colormaps for timeview.
  added HSV with S=1 colormap.


Modified: trunk/Engine/PixelSamplers/TimeViewSampler.cc
==============================================================================
--- trunk/Engine/PixelSamplers/TimeViewSampler.cc       (original)
+++ trunk/Engine/PixelSamplers/TimeViewSampler.cc       Sat May  5 02:24:34 
2007
@@ -28,7 +28,8 @@
 TimeViewSampler::TimeViewSampler(const vector<string>& args)
   : child(0),
     scale(1.e5),
-    active(true)
+    active(true),
+    state(0)
 {
   int argc = static_cast<int>(args.size());
   for(int i = 0; i<argc;i++){
@@ -94,10 +95,21 @@
     // fragments.  Note that if there are no fragments (must be a
     // really rare case), you will end up with a inf for color.
     // That's OK, because you won't use it in that case.
-    ColorComponent color = deltaTime*scale/(fragment.end()-fragment.begin());
     for(int i=fragment.begin();i<fragment.end();++i) {
-      for ( int c = 0; c < Color::NumComponents; c++ )
-        fragment.color[c][i] = color;
+
+      if (state == 0 && Color::NumComponents == 3) {
+        float R, G, B;
+        float x = deltaTime*scale/(fragment.end()-fragment.begin());
+        HeightColorMap::hsv_to_rgb(R, G, B, x, 1, x);
+        fragment.color[0][i] = R;
+        fragment.color[1][i] = G;
+        fragment.color[2][i] = B;
+      }
+      else {
+        ColorComponent color = 
deltaTime*scale/(fragment.end()-fragment.begin());
+        for ( int c = 0; c < Color::NumComponents; c++ )
+          fragment.color[c][i] = color;
+      }
     }
   }
 }
@@ -131,20 +143,24 @@
   // Check to see if there is a TimeViewSampler already running
   TimeViewSampler* tvps = dynamic_cast<TimeViewSampler*>(ps);
   if (tvps != NULL) {
-    // We have a winner.  Let's swap it out.
+    // We have a winner.  Let's update the state and swap it out if
+    // it's old.
     timeView = tvps;
-    ps = tvps->getPixelSampler();
-    // If the child is NULL, don't stuff it back in.
-    if (ps != NULL) {
-      manta_interface->setPixelSampler(ps);
-    } else {
-      cerr << "TimeViewSampler has no child, so it can't be turned off\n";
+    if (++timeView->state >= NUM_STATES) {
+      ps = tvps->getPixelSampler();
+      // If the child is NULL, don't stuff it back in.
+      if (ps != NULL) {
+        manta_interface->setPixelSampler(ps);
+      } else {
+        cerr << "TimeViewSampler has no child, so it can't be turned off\n";
+      }
     }
   } else {
     // The pixel sampler in the engine isn't a TimeViewSampler, so
     // let's make it a child of one.
     timeView->setPixelSampler(ps);
     manta_interface->setPixelSampler(timeView);
+    timeView->state = 0;
   }
   return timeView;
 }

Modified: trunk/Engine/PixelSamplers/TimeViewSampler.h
==============================================================================
--- trunk/Engine/PixelSamplers/TimeViewSampler.h        (original)
+++ trunk/Engine/PixelSamplers/TimeViewSampler.h        Sat May  5 02:24:34 
2007
@@ -3,6 +3,8 @@
 
 #include <MantaTypes.h>
 #include <Interface/PixelSampler.h>
+#include <Model/Textures/HeightColorMap.h>
+
 #include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
@@ -42,10 +44,11 @@
     //////////////////////////////////////
     // User interface helpers
 
-    // This will turn on and off the timeView display on the
-    // manta_interface.  Both parameters must be non-NULL.  If
-    // non-NULL the function returns the TimeViewSampler associated
-    // with the manta_interface, otherwise it returns timeView.
+    // This will toggle the timeView display from off, through the
+    //different time views, and back to off on the manta_interface.
+    //Both parameters must be non-NULL.  If non-NULL the function
+    //returns the TimeViewSampler associated with the manta_interface,
+    //otherwise it returns timeView.
     static TimeViewSampler* toggleTimeView(MantaInterface* manta_interface,
                                            TimeViewSampler* timeView);
 
@@ -60,6 +63,9 @@
     
     PixelSampler* child;
     ColorComponent scale;
+
+    int state;
+    static const int NUM_STATES = 2;
     bool active;
   };
 }

Modified: trunk/Model/Primitives/Heightfield.cc
==============================================================================
--- trunk/Model/Primitives/Heightfield.cc       (original)
+++ trunk/Model/Primitives/Heightfield.cc       Sat May  5 02:24:34 2007
@@ -144,8 +144,8 @@
   barrier.wait(numProc);  
 
   //being tricky here and using the fact that data is contiguously allocated
-  int start = proc*(nx*ny+1)/numProc;
-  int end = (proc+1)*(nx*ny+1)/numProc;
+  int start = proc*( (nx+1)*(ny+1) )/numProc;
+  int end = (proc+1)*( (nx+1)*(ny+1) )/numProc;
   for (int i = start; i < end; ++i) {
     float val = 0;
     //lets hope this loop gets unrolled!
@@ -197,7 +197,6 @@
 
   for(int rayIndex=rays.begin(); rayIndex<rays.end(); rayIndex++) {
     Ray ray = rays.getRay(rayIndex);
-
 
     // Step 2
     Vector idir = rays.getInverseDirection(rayIndex);

Modified: trunk/Model/Textures/HeightColorMap.cc
==============================================================================
--- trunk/Model/Textures/HeightColorMap.cc      (original)
+++ trunk/Model/Textures/HeightColorMap.cc      Sat May  5 02:24:34 2007
@@ -34,11 +34,9 @@
 using namespace Manta;
 
 
-void hsv_to_rgb(float H, float &R, float &G, float &B)
+void HeightColorMap::hsv_to_rgb(float &R, float &G, float &B, 
+                                float H, float S, float V)
 {
-  float S = 1;
-  float V = 1;
-  
   H *= 6.0;
   float i = floor(H);
   float f = H - i;
@@ -97,7 +95,7 @@
     Real height = rays.getHitPosition(i).z() - min_height;
     Real normalized_height = height * inv_range;
     float r, g, b;
-    hsv_to_rgb(normalized_height, r, g, b);
+    hsv_to_rgb(r, g, b, normalized_height, 1, 1);
       
     results.set(i, Color( RGB( (ColorComponent)r,
                                (ColorComponent)g,

Modified: trunk/Model/Textures/HeightColorMap.h
==============================================================================
--- trunk/Model/Textures/HeightColorMap.h       (original)
+++ trunk/Model/Textures/HeightColorMap.h       Sat May  5 02:24:34 2007
@@ -41,13 +41,21 @@
   
   class HeightColorMap : public Texture<Color> {
   public:
-    HeightColorMap(Real min_height, Real max_height) :
-      min_height(min_height), max_height(max_height) 
+    HeightColorMap(Real min_height, Real max_height)
     {
-      inv_range = 1.0 / (max_height - min_height);
+      setRange(min_height, max_height);
     }
     virtual ~HeightColorMap() { }
     
+    void setRange(Real min, Real max) {
+      min_height = min;
+      max_height = max;
+      inv_range = 1.0 / (max_height - min_height);
+    }
+
+    static void hsv_to_rgb(float &R, float &G, float &B,
+                           float H, float S, float V);
+
     virtual void mapValues(Packet<Color>& results,
                            const RenderContext&,
                            RayPacket& rays) const;

Modified: trunk/UserInterface/XWindowUI.cc
==============================================================================
--- trunk/UserInterface/XWindowUI.cc    (original)
+++ trunk/UserInterface/XWindowUI.cc    Sat May  5 02:24:34 2007
@@ -525,16 +525,16 @@
 
 void XWindowUI::register_default_mouse()
 {
-  register_mouse(0, Button3,
+  register_mouse(ShiftMask, Button3,
                  "change field of view",
                  Callback::create(this, &XWindowUI::mouse_fov));
-  register_mouse(ShiftMask, Button3,
+  register_mouse(0, Button3,
                  "dolly to/from lookat",
                  Callback::create(this, &XWindowUI::mouse_dolly));
-  register_mouse(0, Button2,
+  register_mouse(0, Button1,
                  "rotate",
                  Callback::create(this, &XWindowUI::mouse_rotate));
-  register_mouse(0, Button1,
+  register_mouse(0, Button2,
                  "translate",
                  Callback::create(this, &XWindowUI::mouse_translate));
   register_mouse(ControlMask, Button1,

Modified: trunk/scenes/vorpal.cc
==============================================================================
--- trunk/scenes/vorpal.cc      (original)
+++ trunk/scenes/vorpal.cc      Sat May  5 02:24:34 2007
@@ -15,6 +15,7 @@
 #include <Model/MiscObjects/KeyFrameAnimation.h>
 #include <Model/Primitives/Sphere.h>
 #include <Model/Primitives/Heightfield.h>
+#include <Model/Readers/PlyReader.h>
 #include <Core/Math/MinMax.h>
 #include <sgi_stl_warnings_off.h>
 #include <string>
@@ -26,7 +27,8 @@
 using namespace std;
 
 
-Group* readParticles(const string& particles_filename, Vector& maxBound)
+Group* readParticles(const string& particles_filename, Vector& maxBound,
+                     HeightColorMap *heightMap)
 {
   ifstream in(particles_filename.c_str());
   if(!in){
@@ -49,10 +51,10 @@
   maxBound = Vector( (max_x-min_x)/max_dim, (max_y-min_y)/max_dim, 1);
 
   Group *particles = new Group;
-//   Material *particle_matl = new Lambertian(Color(RGB(.2,.6,.2)));
+//    Material *particle_matl = new Lambertian(Color(RGB(.2,.6,.2)));
 
-  Material *particle_matl =new Phong(Color(RGB(0xCD/255.0, 
0x7f/255.0,0x32/255.0)), 
-                                     Color(RGB(.7,.7,.7)),
+  Material *particle_matl =new Phong(heightMap// Color(RGB(0xCD/255.0, 
0x7f/255.0,0x32/255.0))
+                                     ,new 
Constant<Color>(Color(RGB(.7,.7,.7))),
                                      64, 0);
 //   Material *particle_matl =new Phong(Color(RGB(0xCD/255.0, 
0x7f/255.0,0x32/255.0)), 
 //                                      Color(RGB(.7,.7,.7)),
@@ -98,64 +100,106 @@
   Group *group = new Group;
 
   Vector minBound(0, 0, 0), maxBound;
-  Group *particles1 = readParticles(particles_filename, maxBound);
+  HeightColorMap *heightMap = new HeightColorMap(0, 1);
+
+  Group *particles1 = readParticles(particles_filename, maxBound, heightMap);
 
   string particles2_filename = 
"/home/sci/thiago/work/Fusion/vorpal/code/cropped_particles_5e10_intel";
-  Group *particles2 = readParticles(particles_filename, maxBound);
+  Group *particles2 = readParticles(particles_filename, maxBound, heightMap);
 
   string particles3_filename = 
"/home/sci/thiago/work/Fusion/vorpal/code/cropped_particles_1e11_intel";
-  Group *particles3 = readParticles(particles_filename, maxBound);
-    
-  KeyFrameAnimation *particle_animation = new 
KeyFrameAnimation(KeyFrameAnimation::linear);
-  particle_animation->startAnimation();
-  particle_animation->push_back(particles1);
-  particle_animation->push_back(particles2);
-  particle_animation->push_back(particles3);
-  particle_animation->setDuration(10);
-  particle_animation->useAccelerationStructure(new DynBVH());
+  Group *particles3 = readParticles(particles_filename, maxBound, heightMap);
 
   Heightfield* heightfield = new Heightfield(NULL, 
heightfield_filename.c_str(), minBound, maxBound);
-  BBox bbox;
-  PreprocessContext preprocessContext;
-  heightfield->computeBounds(preprocessContext, bbox);
-  heightfield->setMaterial(new Lambertian(new 
HeightColorMap(bbox.getMin().z(), bbox.getMax().z())));
+  heightfield->setMaterial(new Lambertian(heightMap));
 
   string heightfield2_filename = 
"/home/sci/thiago/work/Fusion/vorpal/code/vorpal_10k_rand1.hf";
   Heightfield* heightfield2 = new Heightfield(NULL, 
heightfield2_filename.c_str(), minBound, maxBound);
-  heightfield2->setMaterial(new Lambertian(new 
HeightColorMap(bbox.getMin().z(), bbox.getMax().z())));
+  heightfield2->setMaterial(new Lambertian(heightMap));
 
   string heightfield3_filename = 
"/home/sci/thiago/work/Fusion/vorpal/code/vorpal_10k_rand2.hf";
   Heightfield* heightfield3 = new Heightfield(NULL, 
heightfield3_filename.c_str(), minBound, maxBound);
-  heightfield3->setMaterial(new Lambertian(new 
HeightColorMap(bbox.getMin().z(), bbox.getMax().z())));
+  heightfield3->setMaterial(new Lambertian(heightMap));
 
-//   if ( mapr )
-//     prim->setTexCoordMapper( mapr );
-  
+  BBox bbox;
+  PreprocessContext preprocessContext;
+  heightfield->computeBounds(preprocessContext, bbox);
+  heightfield2->computeBounds(preprocessContext, bbox);
+  heightfield3->computeBounds(preprocessContext, bbox);
 
+  heightMap->setRange(bbox.getMin().z(), bbox.getMax().z());
 
-  KeyFrameAnimation *animation = new 
KeyFrameAnimation(KeyFrameAnimation::linear);
-  animation->startAnimation();
-  Group *frame1 = new Group();
-  Group *frame2 = new Group();
-  Group *frame3 = new Group();
-  frame1->add(heightfield);
-  frame2->add(heightfield2);
-  frame3->add(heightfield3);
-  animation->push_back(frame1);
-  animation->push_back(frame2);
-  animation->push_back(frame3);
-  animation->setDuration(10);
+
+  KeyFrameAnimation *particle_animation = new 
KeyFrameAnimation(KeyFrameAnimation::linear);
+
+  particles1->add(heightfield);
+  particles2->add(heightfield2);
+  particles3->add(heightfield3);
+
+  particle_animation->push_back(particles1);
+  particle_animation->push_back(particles2);
+  particle_animation->push_back(particles3);
+  particle_animation->setDuration(10);
+  particle_animation->useAccelerationStructure(new DynBVH());
+
+//   KeyFrameAnimation *animation = new 
KeyFrameAnimation(KeyFrameAnimation::linear);
+//   Group *frame1 = new Group();
+//   Group *frame2 = new Group();
+//   Group *frame3 = new Group();
+//   frame1->add(heightfield);
+//   frame2->add(heightfield2);
+//   frame3->add(heightfield3);
+//   animation->push_back(frame1);
+//   animation->push_back(frame2);
+//   animation->push_back(frame3);
+//   animation->setDuration(10);
+//   animation->startAnimation();
+//   //animation->pauseAnimation();
+//   animation->useAccelerationStructure(new DynBVH());
+//   group->add(animation);
   
 //   AccelerationStructure *as = new DynBVH;
-//   as->rebuild(particles);
+//   as->rebuild(animation);
   group->add(particle_animation);  
-  group->add(animation);
+
+
+  AffineTransform modelTransform;
+  modelTransform.initWithScale(Vector(10, 10, 10));
+  modelTransform.rotate(Vector(1,0,0), 1.57);
+  modelTransform.translate(Vector(4, 3.5, 0));
+
+  
+  Material *model_matl =
+    new Phong(Color(RGB(.8, .4, .6)), 
+                                  Color(RGB(.7,.7,.7)),
+                                  64, 0);
+//     new Lambertian(Color(RGB(.2,.6,.2)));
+
+//   Group *modelGroup = new Group;
+//   string modelName = 
"/usr/sci/data/Geometry/Stanford_Sculptures/bun_zipper.ply";
+//   if (!readPlyFile(modelName, modelTransform, modelGroup, 0, model_matl))
+//        printf("error loading or reading ply file: %s\n", 
modelName.c_str()); //would be better to throw an error.
+
+
+//   AccelerationStructure *staticScene = new DynBVH();
+//   staticScene->rebuild(modelGroup);
+//   group->add(staticScene);
+  //  group->add(animation);
+
+  particle_animation->startAnimation();
+//   particle_animation->pauseAnimation();
+
+  AccelerationStructure *fullScene = new DynBVH();
+  fullScene->rebuild(group);
+  Group *sceneGroup = new Group();
+  sceneGroup->add(fullScene);
+
 
   Scene* scene = new Scene();
   scene->setBackground(new LinearBackground(Color(RGB(0.2, 0.4, 0.9)),
                                             Color(RGB(0.0,0.0,0.0)),
                                             Vector(0,1,0)));
-  scene->setObject(group);
+  scene->setObject(sceneGroup);
 
   LightSet* lights = new LightSet();
 




  • [MANTA] r1367 - in trunk: Engine/PixelSamplers Model/Primitives Model/Textures UserInterface scenes, thiago, 05/05/2007

Archive powered by MHonArc 2.6.16.

Top of page