Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r1062 - in trunk: Core/Color Engine/Control Model/Primitives Model/Textures scenes


Chronological Thread 
  • From: cgribble@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r1062 - in trunk: Core/Color Engine/Control Model/Primitives Model/Textures scenes
  • Date: Tue, 16 May 2006 12:45:25 -0600 (MDT)

Author: cgribble
Date: Tue May 16 12:45:24 2006
New Revision: 1062

Added:
   trunk/Model/Textures/DynPLT.cc
   trunk/Model/Textures/DynPLT.h
Modified:
   trunk/Core/Color/GrayColor.h
   trunk/Engine/Control/DynPLTWorker.cc
   trunk/Engine/Control/DynPLTWorker.h
   trunk/Model/Primitives/DynPLTParticle.h
   trunk/Model/Textures/CMakeLists.txt
   trunk/Model/Textures/ImageTexture.h
   trunk/scenes/dynplt.cc
Log:
SCIRun/Core/Containers/Array1.h
  Added missing #include<Assert.h>

Core/Color/GrayColor.h
  Added ComponentType typedef for use with ImageTexture

Model/Primitives/DynPLTParticle.h
Model/Textures/DynPLT.h
Model/Textures/DynPLT.cc
Model/Textures/CMakeLists.txt
  Added stubs for lazily evaluated precomputed luminance textures; removed 
class
    from DynPLTParticle

Engine/Control/DynPLTWorker.cc
Engine/Control/DynPLTWorker.h
  Added DynPLTContext for sharing/tracking texture generation parameters

scenes/dynplt.cc
  Create a DynPLTContext

Model/Textures/ImageTexture.h
  Update mapValues interface


Modified: trunk/Core/Color/GrayColor.h
==============================================================================
--- trunk/Core/Color/GrayColor.h        (original)
+++ trunk/Core/Color/GrayColor.h        Tue May 16 12:45:24 2006
@@ -9,6 +9,8 @@
 namespace Manta {
   class GrayColor {
   public:
+    typedef float ComponentType;
+
     GrayColor()
     {
     }

Modified: trunk/Engine/Control/DynPLTWorker.cc
==============================================================================
--- trunk/Engine/Control/DynPLTWorker.cc        (original)
+++ trunk/Engine/Control/DynPLTWorker.cc        Tue May 16 12:45:24 2006
@@ -1,20 +1,58 @@
 #include <Engine/Control/DynPLTWorker.h>
 #include <Model/Primitives/DynPLTParticle.h>
-
-// XXX:  temporary
-#include <Core/Math/MT_RNG.h>
-
-#include <iostream>
-#include <unistd.h>
-// end XXX
+#include <SCIRun/Core/Math/MiscMath.h>
 
 using namespace Manta;
 
-DynPLTWorker::DynPLTWorker(unsigned int id,
-                           SCIRun::Mailbox<const DynPLTParticle*>* queue) :
-  id(id), queue(queue)
+DynPLTContext::DynPLTContext(SCIRun::Mailbox<const DynPLTParticle*>* queue,
+                             unsigned int ngroups, unsigned int nsamples,
+                             unsigned int max_depth) :
+  queue(queue), ngroups(ngroups), nsamples(nsamples), max_depth(max_depth)
 {
-  // Do nothing
+  // Ensure nsamples is a perfect square
+  
nsamples_root=static_cast<int>(SCIRun::Ceil(SCIRun::Sqrt(static_cast<Real>(nsamples))));
+  unsigned int squared=nsamples_root*nsamples_root;
+  if (squared != nsamples)
+    nsamples=squared;
+}
+
+DynPLTWorker::DynPLTWorker(DynPLTContext* dynplt_ctx, unsigned int id) :
+  dynplt_ctx(dynplt_ctx), id(id)
+{
+  // Seed the random number generator
+  rng.seed_rng(100 + id);
+
+  // Generate groups of random 2D sample points
+  sample_groups.resize(dynplt_ctx->ngroups);
+  for (unsigned int i=0; i<dynplt_ctx->ngroups; ++i) {
+    sample_groups[i].resize(dynplt_ctx->nsamples);
+
+    // Generate random (u, v) offsets into the texel
+    unsigned int idx=0;
+    unsigned int nsamples_root=dynplt_ctx->nsamples_root;
+    Real delta=1/static_cast<Real>(nsamples_root);
+    Real u=0;
+    for (unsigned int j=0; j<nsamples_root; ++j) {
+      Real v=0;
+      for (unsigned int k=0; k<nsamples_root; ++k) {
+        sample_groups[i][idx++]=Vector2D(u + delta*rng.gendrand(),
+                                         v + delta*rng.gendrand());
+        v += delta;
+      }
+
+      u += delta;
+    }
+
+    // Shuffle the sample points
+    unsigned int nsamples=dynplt_ctx->nsamples;
+    unsigned int max_idx=nsamples - 1;
+    for (unsigned int j=0; j<nsamples; ++j) {
+      unsigned int target=static_cast<unsigned int>(max_idx*rng.gendrand());
+      Vector2D tmp=sample_groups[i][j];
+      sample_groups[i][j]=sample_groups[i][target];
+      sample_groups[i][target]=tmp;
+    }
+  }
 }
 
 DynPLTWorker::~DynPLTWorker(void)
@@ -24,25 +62,48 @@
 
 void DynPLTWorker::run(void)
 {
-  // XXX:  temporary
-  MT_RNG rng;
-  rng.seed_rng(id + 100);
-  // end XXX
-
   const DynPLTParticle* particle;
-  while (particle=queue->receive()) {
+  while (particle=dynplt_ctx->queue->receive()) {
     if (particle->valid)
       continue;
 
-    // render particle's texture
-
-    // XXX:  temporary
-    unsigned int time=static_cast<unsigned int>(5*rng.gendrand());
-    // std::cout<<"DynPLTWorker["<<id<<"]::run - sleeping for "<<time<<" 
seconds\n";
-    sleep(time);
-    // std::cout<<"DynPLTWorker["<<id<<"]::run - set particle->valid = 
true!\n";
-    // end XXX
-
+    // Render particle's texture
+    // grab next available texture from pool (TrivialAllocator-style?)
+    //
+    // for each texel (u, v)
+    //   for each sample in texel
+    //     grab randome 2D sample point in (u, v) space of texel
+    //     project point onto particle's surface --> x, y, z
+    //     set origin = center + radius*Vector(x, y, z)
+    //     set normal = Vector(x, y, z).normal()
+    //     for (depth=0; depth<max_depth; ++depth)
+    //       compte direct lighting at origin
+    //       dir = generate random cosine-weighted direction on the 
hemisphere
+    //       dir.normalize();
+    //       Ray ray(origin, dir);
+    //       trace ray into geometry
+    //       if intersect
+    //         set origin = ray.origin() + hit.min_t*ray.direction();
+    //         set normal = hit.hit_prim->normal(origin);
+    //         set dotprod = dot(normal, -ray.direction());
+    //         if (dotprod < 0)
+    //           either inside another sphere or point is coincident with 
another
+    //           sphere:  inside(u, v) += 1;
+    //           break;
+    //       else
+    //         accumulate bg color
+    //     end loop over depth
+    //
+    //     store result:  texture(u, v) += result;
+    //   end loop over samples
+    //
+    //   normalize result:  texture(u, v) *= inv_num_samples
+    // end loop over texels
+    //
+    // if (dilate)
+    //   texture.dilate();
+    // 
+    // particle.setDynPLT(texture);
     particle->valid=true;
   }
 }

Modified: trunk/Engine/Control/DynPLTWorker.h
==============================================================================
--- trunk/Engine/Control/DynPLTWorker.h (original)
+++ trunk/Engine/Control/DynPLTWorker.h Tue May 16 12:45:24 2006
@@ -2,6 +2,10 @@
 #ifndef Manta_Engine_DynPLTWorker_h
 #define Manta_Engine_DynPLTWorker_h
 
+#include <Core/Math/MT_RNG.h>
+#include <Core/Math/vector2d.h>
+#include <SCIRun/Core/Containers/Array1.h>
+#include <SCIRun/Core/Containers/Array2.h>
 #include <SCIRun/Core/Thread/Mailbox.h>
 #include <SCIRun/Core/Thread/Runnable.h>
 
@@ -9,17 +13,43 @@
 {
   class DynPLTParticle;
 
+  class DynPLTContext
+  {
+  public:
+    DynPLTContext(SCIRun::Mailbox<const DynPLTParticle*>* queue,
+                  unsigned int ngroups, unsigned int nsamples,
+                  unsigned int max_depth);
+    ~DynPLTContext(void) { }
+
+    // DynPLT work queue
+    SCIRun::Mailbox<const DynPLTParticle*>* queue;
+
+    // Texture generation parameters
+    unsigned int ngroups;
+    unsigned int nsamples;
+    unsigned int nsamples_root;
+    unsigned int max_depth;
+
+    // Texture dilation parameters
+    bool dilate;
+    unsigned int support;
+    unsigned int use_weighted_avg;
+    Real threshold;
+  };
+
   class DynPLTWorker : public SCIRun::Runnable
   {
   public:
-    DynPLTWorker(unsigned int id, SCIRun::Mailbox<const DynPLTParticle*>* 
queue);
+    DynPLTWorker(DynPLTContext* dynplt_ctx, unsigned int id);
     virtual ~DynPLTWorker(void);
     
     virtual void run(void);
 
   private:
+    DynPLTContext* dynplt_ctx;
     unsigned int id;
-    SCIRun::Mailbox<const DynPLTParticle*>* queue;
+    MT_RNG rng;
+    SCIRun::Array1<SCIRun::Array1<Vector2D> > sample_groups;
   };
 }
 

Modified: trunk/Model/Primitives/DynPLTParticle.h
==============================================================================
--- trunk/Model/Primitives/DynPLTParticle.h     (original)
+++ trunk/Model/Primitives/DynPLTParticle.h     Tue May 16 12:45:24 2006
@@ -2,24 +2,12 @@
 #ifndef Manta_Model_DynPLTParticle_h
 #define Manta_Model_DynPLTParticle_h
 
-// #include <Core/Color/GrayColor.h>
+#include <Core/Color/GrayColor.h>
 #include <Model/Primitives/Sphere.h>
-// #include <Model/Textures/ImageTexture.h>
+#include <Model/Textures/ImageTexture.h>
 
 namespace Manta {
-  // XXX:  where does this go?
-  class DynPLT
-  {
-  public:
-    DynPLT(unsigned int res=16);
-
-  private:
-    // ImageTexture<GrayColor> texture;
-    // ImageTexture<GrayColor> inside;
-
-    void dilate(void);
-  };
-  // end XXX
+  class DynPLT;
 
   class DynPLTParticle : public Sphere
   {
@@ -38,6 +26,11 @@
     const DynPLT* getDynPLT(void) const
     {
       return plt;
+    }
+
+    void setDynPLT(DynPLT* new_plt)
+    {
+      plt=new_plt;
     }
 
     mutable bool valid;

Modified: trunk/Model/Textures/CMakeLists.txt
==============================================================================
--- trunk/Model/Textures/CMakeLists.txt (original)
+++ trunk/Model/Textures/CMakeLists.txt Tue May 16 12:45:24 2006
@@ -22,3 +22,10 @@
      )
 
 
+IF(BUILD_DYNPLT)
+   SET(Manta_Textures_SRCS
+       ${Manta_Textures_SRCS}
+       Textures/DynPLT.h
+       Textures/DynPLT.cc
+   )
+ENDIF(BUILD_DYNPLT)

Added: trunk/Model/Textures/DynPLT.cc
==============================================================================
--- (empty file)
+++ trunk/Model/Textures/DynPLT.cc      Tue May 16 12:45:24 2006
@@ -0,0 +1,9 @@
+
+#include <Model/Textures/DynPLT.h>
+
+using namespace Manta;
+
+DynPLT::DynPLT(void)
+{
+  // stub - do nothing
+}

Added: trunk/Model/Textures/DynPLT.h
==============================================================================
--- (empty file)
+++ trunk/Model/Textures/DynPLT.h       Tue May 16 12:45:24 2006
@@ -0,0 +1,22 @@
+
+#ifndef Manta_Texture_DynPLT_h
+#define Manta_Texture_DynPLT_h
+
+// #include <Core/Color/GrayColor.h>
+// #include <Model/Textures/ImageTexture.h>
+
+namespace Manta {
+  class DynPLT
+  {
+  public:
+    DynPLT(void);
+
+  private:
+    // ImageTexture<GrayColor> texture;
+    // ImageTexture<GrayColor> inside;
+
+    void dilate(void);
+  };
+}
+
+#endif

Modified: trunk/Model/Textures/ImageTexture.h
==============================================================================
--- trunk/Model/Textures/ImageTexture.h (original)
+++ trunk/Model/Textures/ImageTexture.h Tue May 16 12:45:24 2006
@@ -80,7 +80,7 @@
     ImageTexture(const Image* image);
     virtual ~ImageTexture() {}
 
-    virtual void mapValues(Packet<Color>& results,
+    virtual void mapValues(Packet<ValueType>& results,
                            const RenderContext&,
                            RayPacket& rays) const;
 
@@ -225,7 +225,7 @@
   }
 
   template< class ValueType >
-  void ImageTexture< ValueType >::mapValues(Packet<Color>& results,
+  void ImageTexture< ValueType >::mapValues(Packet<ValueType>& results,
                                             const RenderContext& context,
                                             RayPacket& rays) const
   {

Modified: trunk/scenes/dynplt.cc
==============================================================================
--- trunk/scenes/dynplt.cc      (original)
+++ trunk/scenes/dynplt.cc      Tue May 16 12:45:24 2006
@@ -71,13 +71,20 @@
   unsigned int size=100; // XXX:  this should be a cmdln parameter
   Mailbox<const DynPLTParticle*>* queue=new Mailbox<const 
DynPLTParticle*>("DynPLT Work Queue", size);
   
+  // Create DynPLTContext
+  unsigned int ngroups=100; // XXX:  this should be a cmdln parameter
+  unsigned int nsamples=49; // XXX:  this should be a cmdln parameter
+  unsigned int max_depth=3; // XXX:  this should be a cmdln parameter
+  DynPLTContext*dynplt_ctx=new DynPLTContext(queue, ngroups, nsamples,
+                                             max_depth);
+
   // Create DynPLTWorker threads
   // workers.resize(nthreads);
   for (unsigned int i=0; i<nthreads; ++i) {
     ostringstream name;
-    name<<"DynPLTWorker "<<i;
-    Thread* thread=new Thread(new DynPLTWorker(i, queue), 
name.str().c_str(), 0,
-                              Thread::NotActivated);
+    name<<"DynPLT Worker "<<i;
+    Thread* thread=new Thread(new DynPLTWorker(dynplt_ctx, i),
+                              name.str().c_str(), 0, Thread::NotActivated);
     // thread->setStackSize(RENDER_THREAD_STACKSIZE);
     thread->activate(false);
     // workers[i]=thread;




  • [MANTA] r1062 - in trunk: Core/Color Engine/Control Model/Primitives Model/Textures scenes, cgribble, 05/16/2006

Archive powered by MHonArc 2.6.16.

Top of page