Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r1098 - in trunk: Engine/Control Image Model Model/Backgrounds Model/Primitives Model/Textures scenes


Chronological Thread 
  • From: cgribble@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r1098 - in trunk: Engine/Control Image Model Model/Backgrounds Model/Primitives Model/Textures scenes
  • Date: Mon, 5 Jun 2006 14:22:09 -0600 (MDT)

Author: cgribble
Date: Mon Jun  5 14:22:05 2006
New Revision: 1098

Added:
   trunk/Image/PPMFile.cc
   trunk/Image/PPMFile.h
   trunk/Model/Backgrounds/EnvMapBackground.cc
   trunk/Model/Backgrounds/EnvMapBackground.h
Modified:
   trunk/Engine/Control/DynPLTWorker.cc
   trunk/Engine/Control/DynPLTWorker.h
   trunk/Image/CMakeLists.txt
   trunk/Model/Backgrounds/CMakeLists.txt
   trunk/Model/CMakeLists.txt
   trunk/Model/Primitives/DynPLTGridSpheres.cc
   trunk/Model/Textures/ImageTexture.h
   trunk/scenes/dynplt.cc
   trunk/scenes/pnrrd.cc
Log:
Image/PPMFile.cc
Image/PPMFile.h
Image/CMakeLists.txt
  Added ability to read/write PPM image files

Model/Textures/ImageTexture.h
  Removed unnessary (and probably broken) constructor

Model/Primitives/DynPLTGridSpheres.cc
  Fixed typo in function prototype (now compiles properly if Real type is
    double) 

Model/Backgrounds/EnvMapBackground.cc
Model/Backgrounds/EnvMapBackground.h
Model/Backgrounds/CMakeLists.txt
Model/CMakeLists.txt
  Added a cylindrical environment map based on PPM image files
  Seam is visible; not sure why, yet, but it works (mostly)

Engine/Control/DynPLTWorker.cc
Engine/Control/DynPLTWorker.h
  Added Background* to DynPLTContext, can be used to specify a background to 
be
    used during texture generation other than the one used by the dynplt scene
  Fixed bug in mapping pre-generated samples to samples in the hemisphere by
    adding a shift to forces [-0.5, 0.5] --> [0, 1]

scenes/pnrrd.cc
  Added "-envmap" cmdln parameter for using cylindrical environment maps

scenes/dynplt.cc
  Added "-envmap" cmdln parameter for using a cylindrical environment map 
during
    texture generation
  If "-envmap bg <filename>" is specified, then environment map will also be 
used
    during interactive rendering


Modified: trunk/Engine/Control/DynPLTWorker.cc
==============================================================================
--- trunk/Engine/Control/DynPLTWorker.cc        (original)
+++ trunk/Engine/Control/DynPLTWorker.cc        Mon Jun  5 14:22:05 2006
@@ -21,10 +21,14 @@
 DynPLTContext::DynPLTContext(SCIRun::Mailbox<DynPLTMessage>* queue,
                              Scene* scene, unsigned int ngroups,
                              unsigned int nsamples, unsigned int max_depth,
-                             bool dilate, Real Kd, Real Ka) :
+                             bool dilate, Background* background, Real Kd,
+                             Real Ka) :
   queue(queue), scene(scene), ngroups(ngroups), nsamples(nsamples),
-  max_depth(max_depth), dilate(dilate), Kd(Kd), Ka(Ka)
+  max_depth(max_depth), dilate(dilate), background(background), Kd(Kd), 
Ka(Ka)
 {
+  if (!background)
+    background=scene->getBackground();
+
   // Ensure that the number of samples is a perfect square
   
nsamples_root=static_cast<int>(SCIRun::Ceil(SCIRun::Sqrt(static_cast<Real>(nsamples))));
   unsigned int squared=nsamples_root*nsamples_root;
@@ -280,6 +284,8 @@
             while (end < rays.end() && !rays.wasHit(end))
               ++end;
 
+            // Only rays that don't intersect other objects contribute to the
+            // ambient illumination at this texel
             ambient += end - i;
 
             i=end;
@@ -430,9 +436,9 @@
             Vector v1=Cross(normal, v0);
             v0.normalize();
             v1.normalize();
-
+            
             // Generate a random direction in the hemisphere
-            Vector2D hemi=sample_groups[hidx[d]][i];
+            Vector2D hemi=sample_groups[hidx[d]][i] + VectorT<Real, 2>(0.5, 
0.5);
             Real hphi=2.0*M_PI*hemi.x();
             Real hr=SCIRun::Sqrt(hemi.y());
             Real hx=hr*cos(hphi);
@@ -508,7 +514,7 @@
 
               // Shade the rays, and accumulate background color
               RayPacket sub(rays, i, end);
-              context->scene->getBackground()->shade(rctx, sub);
+              context->background->shade(rctx, sub);
 
               for (unsigned int j=sub.begin(); j<sub.end(); ++j)
                 ambient += sub.getColor(j).luminance();

Modified: trunk/Engine/Control/DynPLTWorker.h
==============================================================================
--- trunk/Engine/Control/DynPLTWorker.h (original)
+++ trunk/Engine/Control/DynPLTWorker.h Mon Jun  5 14:22:05 2006
@@ -12,6 +12,7 @@
 
 namespace Manta
 {
+  class Background;
   class MantaInterface;
   class RayPacket;
   class Scene;
@@ -24,7 +25,7 @@
     DynPLTContext(SCIRun::Mailbox<DynPLTMessage>* queue, Scene* scene,
                   unsigned int ngroups, unsigned int nsamples,
                   unsigned int max_depth, bool dilate,
-                  Real Kd=0.6, Real Ka=0.4);
+                  Background* background=0, Real Kd=0.6, Real Ka=0.4);
     ~DynPLTContext(void) { }
 
     // DynPLT work queue
@@ -32,6 +33,7 @@
 
     // Manta scene
     Scene* scene;
+    Background* background;
 
     // Texture generation parameters
     unsigned int ngroups;

Modified: trunk/Image/CMakeLists.txt
==============================================================================
--- trunk/Image/CMakeLists.txt  (original)
+++ trunk/Image/CMakeLists.txt  Mon Jun  5 14:22:05 2006
@@ -28,6 +28,8 @@
 ADD_LIBRARY (Manta_Image 
              NullImage.cc
              NullImage.h
+            PPMFile.cc
+            PPMFile.h
              Pixel.h
              SimpleImageBase.h
              SimpleImageBase.cc

Added: trunk/Image/PPMFile.cc
==============================================================================
--- (empty file)
+++ trunk/Image/PPMFile.cc      Mon Jun  5 14:22:05 2006
@@ -0,0 +1,157 @@
+#include <Core/Exceptions/UnknownPixel.h>
+#include <Core/Exceptions/InputError.h>
+#include <Core/Exceptions/OutputError.h>
+#include <Image/PPMFile.h>
+#include <Image/Pixel.h>
+#include <Image/SimpleImage.h>
+
+#include <fstream>
+using std::ifstream;
+using std::ofstream;
+
+#include <iostream>
+using std::cerr;
+
+#include <string>
+using std::string;
+
+using namespace Manta;
+using namespace SCIRun;
+
+void eatPPMCommentsWhitespace(ifstream& str)
+{
+  char c;
+  str.get(c);
+  while (true) {
+    if (c==' '||c=='\t'||c=='\n') {
+      str.get(c);
+      continue;
+    } else if (c=='#') {
+      str.get(c);
+      while (c!='\n')
+        str.get(c);
+    } else {
+      str.unget();
+      break;
+    }
+  }
+}
+
+extern "C" void writePPM(Image const* image, string const& filename,
+                         int which)
+{
+  // Validate image type
+  if (typeid(*image) != typeid(SimpleImage<RGB8Pixel>)) {
+    throw UnknownPixel("Unsupported image type for PPM output");
+  }
+
+  // Open PPM file and write header
+  ofstream out(filename.c_str());
+  if (!out.is_open())
+    throw InputError("Failed to open \"" + filename + "\" for writing\n");
+
+  out<<"P6\n# Binary PPM image created with Manta\n";
+
+  bool stereo;
+  int width, height;
+  image->getResolution(stereo, width, height);
+  out<<width<<" "<<height<<"\n";
+  out<<"255\n";
+
+  // Write the data
+  RGB8Pixel* pixels=dynamic_cast<SimpleImage<RGB8Pixel> const 
*>(image)->getRawPixels(0);
+  RGBColor rgb;
+  unsigned char color[3];
+  for (unsigned v=0; v<height; ++v) {
+    for (unsigned u=0; u<width; ++u) {
+      convertToRGBColor(rgb, pixels[v*width + u]);
+      color[0]=static_cast<unsigned char>(rgb.r()*255);
+      color[1]=static_cast<unsigned char>(rgb.g()*255);
+      color[2]=static_cast<unsigned char>(rgb.b()*255);
+
+      out.write(reinterpret_cast<char*>(color), 3*sizeof(unsigned char));
+    }
+  }
+}
+
+extern "C" Image* readPPM(const string& filename)
+{
+  // Open PPM file
+  ifstream in(filename.c_str());
+  if (!in.is_open())
+    throw InputError("Failed to open \"" + filename + "\" for reading\n");
+
+  // Read magic number
+  string magic;
+  in>>magic;
+  if (magic != "P6" && magic != "P3" && magic != "P5" && magic != "P2")
+    throw InputError("Unrecognized PPM magic \"" + magic + "\"\n");
+
+  // Read resolution and max value
+  unsigned int width, height, maximum;
+  eatPPMCommentsWhitespace(in);
+  in>>width>>height;
+  eatPPMCommentsWhitespace(in);
+  in>>maximum;
+
+  // Eat only the trailing '\n' (if it's there)
+  {
+    char c;
+    while (true) {
+      in.get(c);
+      if (c=='\n')
+       break;
+    }
+  }
+
+  // Create an image
+  Image* image=new SimpleImage<RGB8Pixel>(false, width, height);
+  RGB8Pixel* pixels=dynamic_cast<SimpleImage<RGB8Pixel> const 
*>(image)->getRawPixels(0);
+  Real invmax=1/static_cast<Real>(maximum);
+  RGB8Pixel pixel;
+
+  // Read the data
+  if (magic=="P6") {
+    unsigned char color[3];
+    for (unsigned v=0; v<height; ++v) {
+      for (unsigned u=0; u<width; ++u) {
+       in.read(reinterpret_cast<char*>(color), 3*sizeof(unsigned char));
+        convertToPixel(pixel, RGBColor(color[0]*invmax, color[1]*invmax,
+                                       color[2]*invmax));
+        pixels[v*width + u]=pixel;
+      }
+    }
+  } else if (magic=="P3") {
+    int r, g, b;
+    for (unsigned v=0; v<height; ++v) {
+      for (unsigned u=0; u<width; ++u) {
+       in>>r>>g>>b;
+        convertToPixel(pixel, RGBColor(r*invmax, g*invmax, b*invmax));
+        pixels[v*width + u]=pixel;
+      }
+    }
+  } else if (magic=="P5") {
+    unsigned char gray[1];
+    for (unsigned v=0; v<height; ++v) {
+      for (unsigned u=0; u<width; ++u) {
+       in.read(reinterpret_cast<char*>(gray), 1*sizeof(unsigned char));
+        convertToPixel(pixel, RGBColor(gray[0]*invmax, gray[1]*invmax,
+                                       gray[2]*invmax));
+        pixels[v*width + u]=pixel;
+      }
+    }
+  } else if (magic=="P2") {
+    int gray;
+    for (unsigned v=0; v<height; ++v) {
+      for (unsigned u=0; u<width; ++u) {
+        in>>gray;
+        convertToPixel(pixel, RGBColor(gray*invmax, gray*invmax, 
gray*invmax));
+        pixels[v*width + u]=pixel;
+      }
+    }
+  } else {
+    throw InputError("Unrecognized PPM magic \"" + magic + "\"\n");
+  }
+
+  return image;
+}

Added: trunk/Image/PPMFile.h
==============================================================================
--- (empty file)
+++ trunk/Image/PPMFile.h       Mon Jun  5 14:22:05 2006
@@ -0,0 +1,15 @@
+#ifndef Manta_Image_PPMFile_h
+#define Manta_Image_PPMFile_h
+
+#include <string>
+
+namespace Manta
+{
+  class Image;
+
+  extern "C" void writePPM(Image const *image, std::string const &filename,
+                           int which=0);
+  extern "C" Image* readPPM(const std::string &filename);
+}
+
+#endif // Manta_Image_PPMFile_h

Modified: trunk/Model/Backgrounds/CMakeLists.txt
==============================================================================
--- trunk/Model/Backgrounds/CMakeLists.txt      (original)
+++ trunk/Model/Backgrounds/CMakeLists.txt      Mon Jun  5 14:22:05 2006
@@ -1,6 +1,7 @@
 
 SET (Manta_Backgrounds_SRCS
      Backgrounds/ConstantBackground.cc
+     Backgrounds/EnvMapBackground.cc
      Backgrounds/LinearBackground.cc
      Backgrounds/TextureBackground.cc
      )

Added: trunk/Model/Backgrounds/EnvMapBackground.cc
==============================================================================
--- (empty file)
+++ trunk/Model/Backgrounds/EnvMapBackground.cc Mon Jun  5 14:22:05 2006
@@ -0,0 +1,73 @@
+
+#include <Image/PPMFile.h>
+#include <Image/Pixel.h>
+#include <Image/SimpleImage.h>
+#include <Interface/RayPacket.h>
+#include <Model/Backgrounds/EnvMapBackground.h>
+#include <SCIRun/Core/Math/Trig.h>
+
+using namespace Manta;
+
+static Real OneOverTwoPi=static_cast<Real>(1/(2*M_PI));
+static Real PiOverTwo=static_cast<Real>(M_PI/2);
+
+EnvMapBackground::EnvMapBackground(const std::string& filename,
+                                   const Vector& right, const Vector& up)
+{
+  // Create an image texture
+  Image* ppmImage=readPPM(filename);
+  image=new ImageTexture<Color>(ppmImage);
+  image->setInterpolationMethod(ImageTexture<Color>::Bilinear);
+  image->setVEdgeBehavior(ImageTexture<Color>::Clamp);
+
+  // Initialize an orthonormal basis
+  U=right.normal();
+  V=Cross(up, U).normal();
+  W=Cross(U, V);
+}
+
+EnvMapBackground::~EnvMapBackground(void)
+{
+  if (image)
+    delete image;
+}
+
+void EnvMapBackground::preprocess(const PreprocessContext&)
+{
+  // Do nothing
+}
+
+void EnvMapBackground::shade(const RenderContext& context, RayPacket& rays) 
const
+{
+  for (int i=rays.begin(); i<rays.end(); ++i) {
+    const Vector inDir(rays.getDirection(i));
+    Vector dir(-Dot(inDir, U), -Dot(inDir, V), -Dot(inDir, W));
+    VectorT<Real, 2> texcoords;
+
+    // Compute and scale u
+    //   result of Atan2(y, x) is arctan(y/x) with the quadrant determined by
+    //     signs of both arguments, so it is in [-Pi, Pi]
+    //   result + Pi is in [0, TwoPi]
+    //   result/TwoPi is in [0, 1]
+    texcoords[0]=(Atan2(dir.y(), -dir.x()) + Pi)*OneOverTwoPi;
+    
+    // Compute and scale v
+    //   result of Acos(z) is in [0, Pi]
+    //   PiOverTwo - result is in [PiOver2, -PiOver2]
+    //   Sin(result) is in [1, -1]
+    //   1 + result is in [0, 2]
+    //   0.5*result is in [0, 1]
+    texcoords[1]=0.5*(1 + Sin(PiOverTwo - Acos(dir.z())));
+
+    rays.setTexCoords(i, texcoords);
+  }
+
+  rays.setFlag(RayPacket::HaveTexture2);
+
+  // Look up the pixel colors
+  Packet<Color> colors;
+  image->mapValues(colors, context, rays);
+
+  for (unsigned int i=rays.begin(); i<rays.end(); ++i)
+    rays.setColor(i, colors.get(i));
+}

Added: trunk/Model/Backgrounds/EnvMapBackground.h
==============================================================================
--- (empty file)
+++ trunk/Model/Backgrounds/EnvMapBackground.h  Mon Jun  5 14:22:05 2006
@@ -0,0 +1,29 @@
+
+#ifndef Manta_Model_EnvMapBackground_h
+#define Manta_Model_EnvMapBackground_h
+
+#include <Core/Color/Color.h>
+#include <Interface/Background.h>
+#include <Model/Textures/ImageTexture.h>
+
+#include <string>
+
+namespace Manta
+{
+  class EnvMapBackground : public Background {
+  public:
+    EnvMapBackground(const std::string& filename,
+                     const Vector& right=Vector(1, 0, 0),
+                     const Vector& up=Vector(0, 0, 1));
+    virtual ~EnvMapBackground(void);
+
+    virtual void preprocess(const PreprocessContext& context);
+    virtual void shade(const RenderContext& context, RayPacket& rays) const;
+
+  private:
+    ImageTexture<Color>* image;
+    Vector U, V, W;
+  };
+}
+
+#endif

Modified: trunk/Model/CMakeLists.txt
==============================================================================
--- trunk/Model/CMakeLists.txt  (original)
+++ trunk/Model/CMakeLists.txt  Mon Jun  5 14:22:05 2006
@@ -35,7 +35,7 @@
              ${Manta_Textures_SRCS}
              )
 
-TARGET_LINK_LIBRARIES(Manta_Model Manta_Interface Manta_Core)
+TARGET_LINK_LIBRARIES(Manta_Model Manta_Interface Manta_Core Manta_Image)
 
 IF(BUILD_DYNPLT)
    TARGET_LINK_LIBRARIES(Manta_Model

Modified: trunk/Model/Primitives/DynPLTGridSpheres.cc
==============================================================================
--- trunk/Model/Primitives/DynPLTGridSpheres.cc (original)
+++ trunk/Model/Primitives/DynPLTGridSpheres.cc Mon Jun  5 14:22:05 2006
@@ -14,7 +14,7 @@
 
 DynPLTGridSpheres::DynPLTGridSpheres(SCIRun::Mailbox<DynPLTMessage>* queue,
                                      float* spheres, int nspheres, int nvars,
-                                     int ncells, int depth, float radius,
+                                     int ncells, int depth, Real radius,
                                      int ridx, RegularColorMap* cmap, int 
cidx) :
   queue(queue), GridSpheres(spheres, nspheres, nvars, ncells, depth, radius,
                             ridx, cmap, cidx)

Modified: trunk/Model/Textures/ImageTexture.h
==============================================================================
--- trunk/Model/Textures/ImageTexture.h (original)
+++ trunk/Model/Textures/ImageTexture.h Mon Jun  5 14:22:05 2006
@@ -78,7 +78,6 @@
   class ImageTexture : public Texture< ValueType > {
   public:
     ImageTexture(const Image* image);
-    ImageTexture(unsigned int xres, unsigned int yres);
     virtual ~ImageTexture() {}
 
     virtual void mapValues(Packet<ValueType>& results,
@@ -156,7 +155,6 @@
           low = static_cast<int>(val);
           if (low > size-2) {
             low = size-2;
-            weight_high = 0;
           } else {
             weight_high = val - low;
           }
@@ -223,15 +221,6 @@
         }
       }
     }
-  }
-
-  template< class ValueType >
-  ImageTexture< ValueType >::ImageTexture(unsigned int xres, unsigned int 
yres) :
-    scale(VectorT< ScalarType, 2 >(1, 1)),
-    interpolation_method(NearestNeighbor),
-    u_edge(Wrap), v_edge(Wrap)
-  {
-    texture.resize(xres, yres);
   }
 
   template< class ValueType >

Modified: trunk/scenes/dynplt.cc
==============================================================================
--- trunk/scenes/dynplt.cc      (original)
+++ trunk/scenes/dynplt.cc      Mon Jun  5 14:22:05 2006
@@ -9,6 +9,7 @@
 #include <Interface/Scene.h>
 #include <Model/AmbientLights/ConstantAmbient.h>
 #include <Model/Backgrounds/ConstantBackground.h>
+#include <Model/Backgrounds/EnvMapBackground.h>
 #include <Model/Groups/Group.h>
 #include <Model/Lights/PointLight.h>
 #include <Model/Materials/DynPLTMaterial.h>
@@ -33,6 +34,8 @@
 {
   Group* world=0;
   int cidx=0;
+  string env_fname="";
+  bool use_envmap=false;
   string fname="";
   int depth=1;
   bool dilate=false;
@@ -65,6 +68,22 @@
         throw IllegalArgument("scene dynplt -depth", i, args);
     } else if (arg=="-dilate") {
       dilate=true;
+    } else if (arg=="-envmap") {
+      string s;
+      if (!getStringArg(i, args, s))
+        throw IllegalArgument("scene dynplt -envmap", i, args);
+
+      if (s[0] != '-') {
+        if (s=="bg") {
+          use_envmap=true;
+          if (!getStringArg(i, args, env_fname))
+            throw IllegalArgument("scene dynplt -envmap", i, args);
+        } else {
+          env_fname=s;
+        }
+      } else {
+        throw IllegalArgument("scene dynplt -envmap", i, args);
+      }
     } else if (arg=="-i") {
       if (!getStringArg(i, args, fname))
         throw IllegalArgument("scene dynplt -i", i, args);
@@ -95,18 +114,20 @@
         throw IllegalArgument("scene dynplt -qsize", i, args);
     } else {
       cerr<<"Valid options for scene dynplt:\n";
-      // cerr<<"  -bv <string>      bounding volume {bvh|grid|group}\n";
-      cerr<<"  -depth <int>      grid depth\n";
-      cerr<<"  -dilate           dilate textures during generation\n";
-      cerr<<"  -i <string>       particle data filename\n";
-      cerr<<"  -nbounces <int>   number of indirect nbounces\n";
-      cerr<<"  -ncells <int>     grid resolution\n";
-      cerr<<"  -ngroups <int>    number of sample groups\n";
-      cerr<<"  -nsamples <int>   number of samples/texel\n";
-      cerr<<"  -nthreads <int>   number of dynplt workers\n";
-      cerr<<"  -qsize <int>      queue qsize\n";
-      cerr<<"  -radius <float>   particle radius\n";
-      cerr<<"  -ridx <int>       radius index\n";
+      // cerr<<"  -bv <string>           bounding volume {bvh|grid|group}\n";
+      cerr<<"  -cidx <int>             data value index for color mapping\n";
+      cerr<<"  -depth <int>            grid depth\n";
+      cerr<<"  -dilate                 dilate textures during generation\n";
+      cerr<<"  -envmap [bg] <string>   environment map filename\n";
+      cerr<<"  -i <string>             particle data filename\n";
+      cerr<<"  -nbounces <int>         number of indirect nbounces\n";
+      cerr<<"  -ncells <int>           grid resolution\n";
+      cerr<<"  -ngroups <int>          number of sample groups\n";
+      cerr<<"  -nsamples <int>         number of samples/texel\n";
+      cerr<<"  -nthreads <int>         number of dynplt workers\n";
+      cerr<<"  -qsize <int>            maximum queue qsize\n";
+      cerr<<"  -radius <float>         particle radius\n";
+      cerr<<"  -ridx <int>             radius index\n";
       throw IllegalArgument("scene dynplt", i, args);
     }
   }
@@ -122,8 +143,11 @@
                                                            nthreads*qsize);
   
   // Create DynPLTContext
+  Background* bg;
+  if (env_fname != "")
+    bg=new EnvMapBackground(env_fname);
   DynPLTContext* dpltctx=new DynPLTContext(queue, scene, ngroups, nsamples,
-                                           max_depth, dilate);
+                                           max_depth, dilate, bg /*, kd, 
ka*/);
 
   // Create DynPLTWorker threads
   for (unsigned int i=0; i<nthreads; ++i) {
@@ -146,7 +170,6 @@
 
   // Load particle data, add particles to group
   ParticleNRRD pnrrd(fname);
-#if 1
   DynPLTGridSpheres* spheres=new DynPLTGridSpheres(queue,
                                                    pnrrd.getParticleData(),
                                                    pnrrd.getNParticles(),
@@ -154,24 +177,12 @@
                                                    ncells, depth, radius, 
ridx,
                                                    cmap, cidx);
   world->add(spheres);
-#else
-  float* pdata=pnrrd.getParticleData();
-  for (unsigned int i=0; i<pnrrd.getNParticles(); ++i) {
-    unsigned int idx=i*pnrrd.getNVars();
-    Real x=pdata[idx];
-    Real y=pdata[idx + 1];
-    Real z=pdata[idx + 2];
-    
-    if (ridx>=0)
-      radius=pdata[idx + ridx];
-    
-    Material* dynplt=new DynPLTMaterial(queue, Color(RGB(0, 1, 0)));
-    world->add(new Sphere(dynplt, Vector(x, y, z), radius));
-  }
-#endif
 
   // Initialize the scene
-  scene->setBackground(new ConstantBackground(Color(RGB(1, 1, 1))));
+  if (bg && use_envmap)
+    scene->setBackground(new EnvMapBackground(env_fname));
+  else
+    scene->setBackground(new ConstantBackground(Color(RGB(0, 0, 0))));
   scene->setObject(world);
 
   // Add lights

Modified: trunk/scenes/pnrrd.cc
==============================================================================
--- trunk/scenes/pnrrd.cc       (original)
+++ trunk/scenes/pnrrd.cc       Mon Jun  5 14:22:05 2006
@@ -8,6 +8,7 @@
 #include <Interface/Scene.h>
 #include <Model/AmbientLights/ConstantAmbient.h>
 #include <Model/Backgrounds/ConstantBackground.h>
+#include <Model/Backgrounds/EnvMapBackground.h>
 #include <Model/Groups/Group.h>
 #include <Model/Lights/PointLight.h>
 #include <Model/Materials/Lambertian.h>
@@ -27,6 +28,7 @@
 {
   int argc=static_cast<int>(args.size());
   int cidx=0;
+  string env_fname="";
   string fname="";
   int depth=1;
   int ncells=2;
@@ -49,6 +51,9 @@
     } else if (arg=="-depth") {
       if (!getIntArg(i, args, depth))
         throw IllegalArgument("scene pnrrd -depth", i, args);
+    } else if (arg=="-envmap") {
+      if (!getStringArg(i, args, env_fname))
+        throw IllegalArgument("scene pnrrd -envmap", i, args);
     } else if (arg=="-i") {
       if (!getStringArg(i, args, fname))
         throw IllegalArgument("scene pnrrd -i", i, args);
@@ -63,12 +68,14 @@
         throw IllegalArgument("scene pnrrd -ridx", i, args);
     } else {
       cerr<<"Valid options for scene pnrrd:\n";
-      // cerr<<"  -bv <string>      bounding volume {bvh|grid|group}\n";
-      cerr<<"  -depth <int>      grid depth\n";
-      cerr<<"  -ncells <int>     grid resolution\n";
-      cerr<<"  -i <string>       filename\n";
-      cerr<<"  -radius <float>   particle radius\n";
-      cerr<<"  -ridx <int>       radius index\n";
+      // cerr<<"  -bv <string>       bounding volume {bvh|grid|group}\n";
+      cerr<<"  -cidx <int>        data value index for color mapping\n";
+      cerr<<"  -depth <int>       grid depth\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";
       throw IllegalArgument("scene pnrrd", i, args);
     }
   }
@@ -82,31 +89,18 @@
 
   // Load particle data, add particles to group
   ParticleNRRD pnrrd(fname);
-#if 1
   GridSpheres* spheres=new GridSpheres(pnrrd.getParticleData(),
                                        pnrrd.getNParticles(), 
pnrrd.getNVars(),
                                        ncells, depth, radius, ridx, cmap,
                                        cidx);
   world->add(spheres);
-#else
-  float* pdata=pnrrd.getParticleData();
-  for (unsigned int i=0; i<pnrrd.getNParticles(); ++i) {
-    unsigned int idx=i*pnrrd.getNVars();
-    Real x=pdata[idx];
-    Real y=pdata[idx + 1];
-    Real z=pdata[idx + 2];
-    
-    if (ridx>=0)
-      radius=pdata[idx + ridx];
-    
-    Material* white=new Lambertian(Color(RGB(1, 1, 1)));
-    world->add(new Sphere(white, Vector(x, y, z), radius));
-  }
-#endif
 
   // Create scene
   Scene* scene=new Scene();
-  scene->setBackground(new ConstantBackground(Color(RGB(0, 0, 0))));
+  if (env_fname != "")
+    scene->setBackground(new EnvMapBackground(env_fname));
+  else
+    scene->setBackground(new ConstantBackground(Color(RGB(0, 0, 0))));
   scene->setObject(world);
 
   LightSet* lights=new LightSet();




  • [MANTA] r1098 - in trunk: Engine/Control Image Model Model/Backgrounds Model/Primitives Model/Textures scenes, cgribble, 06/05/2006

Archive powered by MHonArc 2.6.16.

Top of page