Text archives Help
- From: brownlee@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r1541 - in trunk: DynLT Model/Textures scenes
- Date: Tue, 24 Jul 2007 02:42:57 -0600 (MDT)
Author: brownlee
Date: Tue Jul 24 02:42:55 2007
New Revision: 1541
Modified:
trunk/DynLT/DynLTCGT.cc
trunk/DynLT/DynLTCGT.h
trunk/DynLT/DynLTGridSpheres.cc
trunk/DynLT/DynLTParticles.cc
trunk/DynLT/DynLTParticles.h
trunk/Model/Textures/ColorMap.cc
trunk/scenes/dynlt.cc
Log:
dynlt compile and runs with CGT code. CGT code doesn't currently like
bounced rays too much at the moment though
Modified: trunk/DynLT/DynLTCGT.cc
==============================================================================
--- trunk/DynLT/DynLTCGT.cc (original)
+++ trunk/DynLT/DynLTCGT.cc Tue Jul 24 02:42:55 2007
@@ -1,281 +1,34 @@
-
-#include <Core/Color/RegularColorMap.h>
-#include <DynLT/DynLTContext.h>
#include <DynLT/DynLTCGT.h>
-#include <DynLT/DynLTQueue.h>
-#include <DynLT/DynLTWorker.h>
-#include <Interface/AmbientLight.h>
-#include <Interface/LightSet.h>
-#include <Interface/RayPacket.h>
-
-#include <iostream>
-using std::cerr;
-
-using namespace Manta;
-using namespace SCIRun;
+#include <Model/Readers/ParticleNRRD.h>
-#define UPDATE_TIME 2.5
-DynLTCGT::DynLTCGT(DynLTQueue* queue,
- float* spheres, int nspheres, int nvars,
- int ncells, int depth, Real radius,
- int ridx, RegularColorMap* cmap, int
cidx) :
- queue(queue), ParticleGrid(cidx)
+namespace Manta
{
- cerr<<"Initializing DynLTGridSpheres\n";
- plts.resize(nspheres);
- valid.resize(nspheres);
- allocated.resize(nspheres);
- requested.resize(nspheres);
-#ifdef USE_STATS_COLLECTOR
- latency.resize(nspheres);
- texgen.resize(nspheres);
-#endif
- for (unsigned int i=0; i<nspheres; ++i) {
- plts[i]=0;
- requested[i]=0;
- allocated[i]=false;
- valid[i]=false;
-#ifdef USE_STATS_COLLECTOR
- latency[i]=0;
- texgen[i]=0;
-#endif
- }
-
- // XXX: hard coded for now
- // textureMode=AmbientOcclusion;
- textureMode=GlobalIllumination;
-}
-DynLTCGT::~DynLTCGT(void)
+DynLTCGT::DynLTCGT(ParticleNRRD& pnrrd, DynLTQueue* queue, float* spheres,
+ int nspheres, int nvars, int ncells, int depth,
+ Real radius, int ridx, RegularColorMap* cmap, int cidx)
+ : DynLTGridSpheres(queue, spheres, nspheres, nvars, ncells, depth,
radius, ridx, cmap, cidx)
{
- // Do nothing
+ //ParticleNRRD pnrrd(nrrdFile);
+ grid = new ParticleGrid(pnrrd, radius, -1, cidx, this);
}
-void DynLTCGT::shade(const RenderContext& context,
- RayPacket& rays) const
+void DynLTCGT::intersect(const RenderContext& context,
+ RayPacket& packet) const
{
- switch (textureMode) {
- case AmbientOcclusion:
- shadeAmbient(context, rays);
- break;
- case GlobalIllumination:
- default:
- shadeGlobal(context, rays);
- break;
- }
-}
-
-void DynLTCGT::shadeAmbient(const RenderContext& context,
- RayPacket& rays) const
-{
- ColorArray ambient;
-
- for (unsigned int i=rays.begin(); i<rays.end(); ) {
- // Find a run of rays that hit the same particle
- int offset=rays.scratchpad<int>(i);
- unsigned int end=i + 1;
- while (end < rays.end() && rays.scratchpad<int>(end)==offset)
- ++end;
-
- int particle = offset/nvars;
- //compute ambient light
- RayPacket sub(rays, i , end);
- if (valid[particle]) {
- // Compute diffuse colors
- Packet<Color> diffuse;
- //mapDiffuseColors(diffuse, sub);
-
- // Compute textured ambient luminance // TODO:
- sub.computeTextureCoordinates2(context);
-
- for (unsigned int i=sub.begin(); i<sub.end(); ++i) {
- Real luminance=computeLuminance(i, sub, particle);
- for (int j=0; j < Color::NumComponents; ++j)
- ambient[j][i]=luminance;
- }
- } else {
- // Request texture generation, if necessary
- if (requested[particle]==0.) {
-#ifdef USE_STATS_COLLECTOR
- // Store request time
- latency[particle]=Time::currentSeconds();
-
- // Increment number of requests
- DynLTStatsCollector::TexturesRequestedPerFrame.increment();
-
- // Increment number of visible particles
- DynLTStatsCollector::NumberVisiblePerFrame.increment();
-#endif
-
- // Create and post message
- double priority=computePriority(rays.getMinT(i));
- //TODO: DynLTMessage msg(particle, priority, this);
- ///TODO: if (queue->trySend(msg))
- // requested[particle]=priority;
- } else {
-#ifdef UPDATE_TIME
- if (Time::currentSeconds() - requested[particle] > UPDATE_TIME) {
- // Update priority only after UPDATE_TIME seconds
- requested[particle]=computePriority(rays.getMinT(i));
- queue->updatePriority(particle, requested[particle]);
-
-#ifdef USE_STATS_COLLECTOR
- // Update request time
- latency[particle]=Time::currentSeconds();
-
- // Updates count as a new request --> increment number of requests
- DynLTStatsCollector::TexturesRequestedPerFrame.increment();
-#endif
- }
-#else
- // Update priority
- requested[particle]=computePriority(rays.getMinT(i));
- queue->updatePriority(particle, requested[particle]);
-
-#ifdef USE_STATS_COLLECTOR
- // Update request time
- latency[particle]=Time::currentSeconds();
-
- // Updates count as a new request --> increment number of requests
- DynLTStatsCollector::TexturesRequestedPerFrame.increment();
-#endif
-#endif // UPDATE_TIME
- }
-
- // Use default ambient light while texture is invalid
- activeLights->getAmbientLight()->computeAmbient(context, sub, ambient);
- }
-
- i=end;
- }
-
- // Shade the rays
- // TODO: GridSpheres::lambertianShade(context, rays, ambient);
+ grid->intersect(context, packet);
}
-void DynLTCGT::shadeGlobal(const RenderContext& context,
- RayPacket& rays) const
+void DynLTCGT::preprocess(const PreprocessContext& context)
{
- for (unsigned int i=rays.begin(); i<rays.end(); ) {
- // Find a run of rays that hit the same particle
- int offset=rays.scratchpad<int>(i);
- unsigned int end=i + 1;
- while (end < rays.end() && rays.scratchpad<int>(end)==offset)
- ++end;
-
- int particle=offset/nvars;
-
- // Shade the rays
- RayPacket sub(rays, i, end);
- if (valid[particle]) {
- // Compute diffuse colors
- Packet<Color> diffuse;
- //TODO: mapDiffuseColors(diffuse, rays);
-
- // Compute textured luminance
- sub.computeTextureCoordinates2(context);
-
- // XXX - Using the ambient may just be a hack; DynLTWorker might need
to
- // account for it, or maybe it's just wrong given that we're
- // computing global illumination (except that the background
doesn't
- // contributed)... I don't know, and at this point, I don't
really
- // care!
-#define USE_AMBIENT 1
-#ifdef USE_AMBIENT
- ColorArray ambient;
- activeLights->getAmbientLight()->computeAmbient(context, rays,
ambient);
-#endif
-
- for (unsigned int i=sub.begin(); i<sub.end(); ++i) {
-#ifdef USE_AMBIENT
- Real luminance=computeLuminance(i, sub, particle);
- luminance += 0.3*ambient[0][i] + 0.6*ambient[1][i] +
0.1*ambient[2][i];
-
- sub.setColor(i, diffuse.get(i)*luminance);
-#else
- Real luminance=computeLuminance(i, sub, particle);
- sub.setColor(i, diffuse.get(i)*luminance);
-#endif
- }
- } else {
- // Request texture generation, if necessary
- if (requested[particle]==0.) {
-#ifdef USE_STATS_COLLECTOR
- // Store request time
- latency[particle]=Time::currentSeconds();
-#endif
+ static bool once = false;
+ if (once)
+ return;
+ once = true;
+ DynLTGridSpheres::preprocess(context);
+ grid->preprocess(context);
- // Create and post message
- double priority=computePriority(rays.getMinT(i));
- //TODO: DynLTMessage msg(particle, priority, this);
- //TODO: if (queue->trySend(msg))
- // requested[particle]=priority;
-
-#ifdef USE_STATS_COLLECTOR
- // Increment number of requests
- DynLTStatsCollector::TexturesRequestedPerFrame.increment();
-#endif
- } else {
-#ifdef USE_STATS_COLLECTOR
- // Update request time
- latency[particle]=Time::currentSeconds();
-#endif
-
-#ifdef UPDATE_TIME
- // Update priority only after UPDATE_TIME seconds
- if (Time::currentSeconds() - requested[particle] > UPDATE_TIME) {
- requested[particle]=computePriority(rays.getMinT(i));
- queue->updatePriority(particle, requested[particle]);
- }
-#else
- requested[particle]=computePriority(rays.getMinT(i));
- queue->updatePriority(particle, requested[particle]);
-#endif
- }
-
- // Use Lambertian shading while texture is invalid
- //TODO: GridSpheres::shade(context, sub);
- }
-
- i=end;
- }
}
-Real DynLTCGT::computeLuminance(unsigned int ray_idx, RayPacket& rays,
- unsigned int particle) const
-{
- // Wrap in x (assumes xres is a power of two)
- Real x=rays.getTexCoords2(ray_idx, 0)*XRES;
- int lx=static_cast<int>(x) & (XRES - 1);
- int hx=(lx + 1) & (XRES - 1);
- Real wx=x - lx;
-
- // Clamp in y
- Real y=rays.getTexCoords2(ray_idx, 1);
- int ly;
- Real wy;
- if (y < 0) {
- ly=0;
- wy=0;
- } else {
- y *= YRES - 1;
- ly=static_cast<int>(y);
- if (ly > YRES - 1) {
- ly=YRES - 1;
- wy=0;
- } else {
- wy=y - ly;
- }
- }
-
- int hy=ly + 1;
-
- // Bi-linearly interpolate
- Real a=(plts[particle]->texture[lx][ly]*(1 - wx) +
- plts[particle]->texture[hx][ly]*wx);
- Real b=(plts[particle]->texture[lx][hy]*(1 - wx) +
- plts[particle]->texture[hx][hy]*wx);
-
- return a*(1 - wy) + b*wy;
}
Modified: trunk/DynLT/DynLTCGT.h
==============================================================================
--- trunk/DynLT/DynLTCGT.h (original)
+++ trunk/DynLT/DynLTCGT.h Tue Jul 24 02:42:55 2007
@@ -1,4 +1,3 @@
-
#ifndef Manta_DynLT_DynLTCGT_h
#define Manta_DynLT_DynLTCGT_h
@@ -7,13 +6,9 @@
#include <Model/Primitives/GridSpheres.h>
#include <SCIRun/Core/Thread/Mailbox.h>
#include <SCIRun/Core/Thread/Time.h>
-#include <Model/Groups/private/ParticleCGT.h>
-#include <Interface/Texture.h>
-#include <Model/Materials/LitMaterial.h>
-#include <Model/Primitives/PrimitiveCommon.h>
#include <DynLT/DynLTGridSpheres.h>
-
-
+#include <Model/Groups/private/ParticleCGT.h>
+#include <string>
// XXX: temporary
#include <iostream>
@@ -26,143 +21,25 @@
#define XRES 16
#define YRES 16
+using namespace std;
namespace Manta {
- class DynLTCGT : public ParticleGrid, public LitMaterial, public
TexCoordMapper
- {
- public:
- enum {
- AmbientOcclusion,
- GlobalIllumination
- } TextureMode;
-
- DynLTCGT(DynLTQueue* queue, float* spheres,
+class DynLTCGT : public DynLTGridSpheres
+{
+public:
+ virtual void preprocess(const PreprocessContext&);
+ DynLTCGT(ParticleNRRD& pnrrd, DynLTQueue* queue, float* spheres,
int nspheres, int nvars, int ncells, int depth,
Real radius, int ridx, RegularColorMap* cmap, int cidx);
- ~DynLTCGT(void);
-
- void shade(const RenderContext& context, RayPacket& rays) const;
+ virtual void intersect(const RenderContext& context,
+ RayPacket& packet) const;
+private:
+ ParticleGrid * grid;
- unsigned int getNParticles(void) const { return nspheres; }
+};
- const LightSet* getActiveLights(void) const { return activeLights; }
-
- unsigned int getTextureMode(void) const { return textureMode; }
-
- void setTextureMode(unsigned int mode)
- {
- if (textureMode != mode) {
- invalidateTextures();
- textureMode=mode;
- }
- }
-
- Vector getCenter(int particle) const
- {
- float* data=spheres + particle*nvars;
- return Vector(data[0], data[1], data[2]);
- }
-
- Real getRadius(int particle) const
- {
- float* data=spheres + particle*nvars;
- if (ridx>0) {
- if (data[ridx] <= 0)
- return radius;
- else
- return data[ridx];
- }
-
- return radius;
- }
-
- bool isValid(int idx) {
- return valid[idx];
- }
-
- bool isAllocated(int idx) {
- return allocated[idx];
- }
-
- void setValid(int idx) {
- valid[idx]=true;
-
-#ifdef USE_STATS_COLLECTOR
- // Compute latency and increment counter
- latency[idx]=Time::currentSeconds() - latency[idx];
-
DynLTStatsCollector::TexGenLatency.increment(static_cast<float>(latency[idx]));
-#endif
- }
-
- void allocate(int idx) {
- plts[idx]=new DynLT();
- allocated[idx]=true;
- }
-
- void dilate(const DynLTContext* context, int idx) {
- plts[idx]->dilate(context);
- }
-
- DynLT* getTexture(int idx) {
- return plts[idx];
- }
-
- double computePriority(Real t) const {
- // Time-stamp only
- // return Time::currentSeconds();
-
- // Distance only (closest first)
- // return DBL_MAX - t;
-
- // Weighted combination of time-stamp and distance
- return 0.1*Time::currentSeconds() - 10.*t;
- }
-
- void resetRequested(int idx) {
- requested[idx]=0.;
- }
-
-#ifdef USE_STATS_COLLECTOR
- void setTexGenTime(int idx, double time)
- {
- // Set texture generation time and increment counters
- texgen[idx]=time;so
-
DynLTStatsCollector::TexGenTime.increment(static_cast<float>(texgen[idx]));
- DynLTStatsCollector::TexturesGeneratedPerFrame.increment();
- }
-#endif
+}
- private:
- void shadeAmbient(const RenderContext& context, RayPacket& rays) const;
- void shadeGlobal(const RenderContext& context, RayPacket& rays) const;
- Real computeLuminance(unsigned int ray_idx, RayPacket& rays,
- unsigned int particle) const;
-
- void invalidateTextures(void)
- {
- for (unsigned int i=0; i<nspheres; ++i) {
- requested[i]=0;
- valid[i]=false;
- }
- }
-
- DynLTQueue* queue;
- mutable vector<double> requested;
- vector<bool> allocated;
- vector<bool> valid;
- vector<DynLT*> plts;
- int nspheres, nvars, ncells, depth, ridx, cidx;
- Real radius;
- float* spheres;
-
- unsigned int textureMode;
-
-#ifdef USE_STATS_COLLECTOR
- mutable vector<double> latency;
- mutable vector<double> texgen;
#endif
- };
-}
-#endif // Manta_DynLT_DynLTGridSpheres_h
Modified: trunk/DynLT/DynLTGridSpheres.cc
==============================================================================
--- trunk/DynLT/DynLTGridSpheres.cc (original)
+++ trunk/DynLT/DynLTGridSpheres.cc Tue Jul 24 02:42:55 2007
@@ -44,8 +44,8 @@
}
// XXX: hard coded for now
- // textureMode=AmbientOcclusion;
- textureMode=GlobalIllumination;
+ textureMode=AmbientOcclusion;
+ //textureMode=GlobalIllumination;
}
DynLTGridSpheres::~DynLTGridSpheres(void)
@@ -62,7 +62,7 @@
break;
case GlobalIllumination:
default:
- shadeGlobal(context, rays);
+ shadeGlobal(context, rays);
break;
}
}
@@ -80,7 +80,8 @@
++end;
int particle=offset/nvars;
-
+ if (particle < 0 || particle > plts.size())
+ { cout << "particle out of bounds\n"; exit(1);}
// Compute ambient light for the rays
RayPacket sub(rays, i, end);
if (valid[particle]) {
@@ -167,7 +168,8 @@
++end;
int particle=offset/nvars;
-
+if (particle < 0 || particle > plts.size())
+ { cout << "particle: " << particle << endl; return; }
// Shade the rays
RayPacket sub(rays, i, end);
if (valid[particle]) {
Modified: trunk/DynLT/DynLTParticles.cc
==============================================================================
--- trunk/DynLT/DynLTParticles.cc (original)
+++ trunk/DynLT/DynLTParticles.cc Tue Jul 24 02:42:55 2007
@@ -4,6 +4,7 @@
#include <DynLT/DynLTGridSpheres.h>
+#include <DynLT/DynLTCGT.h>
#include <DynLT/DynLTParticles.h>
#include <Model/Primitives/GridSpheres.h>
#include <Model/Readers/ParticleNRRD.h>
@@ -61,6 +62,54 @@
in.close();
}
+
+//overloaded constructor to use CGT instead of gridspheres
+DynLTParticles::DynLTParticles(int type, const string& filename, int ncells,
int depth,
+Real radius, int ridx, RegularColorMap* cmap,
+ int cidx, DynLTQueue* queue, int min, int
max) :
+ tstep(0)
+{
+ // Check for a single timestep
+ bool isNrrd = (filename.find(".nrrd", 0) != string::npos ||
+ filename.find(".nhdr", 0) != string::npos);
+ if (isNrrd) {
+ ParticleNRRD pnrrd(filename);
+ add(new DynLTCGT(pnrrd, queue, pnrrd.getParticleData(),
+ pnrrd.getNParticles(), pnrrd.getNVars(), ncells,
+ depth, radius, ridx, cmap, cidx));
+ return;
+ }
+
+ // Load multiple timesteps
+ ifstream in(filename.c_str());
+ if (!in.is_open())
+ throw InputError("Failed to open \"" + filename + "\" for reading\n");
+
+ string fname;
+ unsigned int nskipped=0;
+ unsigned int nloaded=0;
+ while (!in.eof() && min + nloaded < max) {
+ // Read the timestep filename
+ in>>fname;
+
+ // Ignore timesteps below the minimum
+ if (nskipped<min) {
+ ++nskipped;
+ continue;
+ }
+
+ // Load the particle data
+ ParticleNRRD pnrrd(fname);
+ add(new DynLTCGT(pnrrd, queue, pnrrd.getParticleData(),
+ pnrrd.getNParticles(), pnrrd.getNVars(), ncells,
+ depth, radius, ridx, cmap, cidx));
+
+ ++nloaded;
+ }
+
+ in.close();
+}
+
DynLTParticles::~DynLTParticles(void)
{
Modified: trunk/DynLT/DynLTParticles.h
==============================================================================
--- trunk/DynLT/DynLTParticles.h (original)
+++ trunk/DynLT/DynLTParticles.h Tue Jul 24 02:42:55 2007
@@ -19,10 +19,14 @@
DynLTParticles(const string& filename, int ncells, int depth, Real
radius,
int ridx, RegularColorMap* cmap, int cidx, DynLTQueue*
queue,
int min=0, int max=INT_MAX);
- ~DynLTParticles(void);
+ DynLTParticles(int type, const string& filename, int ncells, int depth,
Real radius,
+ int ridx, RegularColorMap* cmap, int cidx, DynLTQueue*
queue,
+ int min=0, int max=INT_MAX);
+
+ ~DynLTParticles(void);
- void intersect(const RenderContext& context, RayPacket& rays) const;
- void computeBounds(const PreprocessContext& context, BBox& bbox) const;
+ virtual void intersect(const RenderContext& context, RayPacket& rays)
const;
+ virtual void computeBounds(const PreprocessContext& context, BBox& bbox)
const;
unsigned int getNParticles(int tstep) const
{
Modified: trunk/Model/Textures/ColorMap.cc
==============================================================================
--- trunk/Model/Textures/ColorMap.cc (original)
+++ trunk/Model/Textures/ColorMap.cc Tue Jul 24 02:42:55 2007
@@ -43,7 +43,8 @@
for (int i = rays.begin(); i < rays.end(); ++i) {
const Real value = rays.scratchpad<Real>(i);
const Real normalized = (value - min)*inv_range;
- //if (!(normalized >= 0.0 && normalized <= 1.0))
+
+// if (!(normalized >= 0.0 && normalized <= 1.0))
// cout << normalized << endl;
//assert(normalized >= 0.0 && normalized <= 1.0);
const int idx = SCIRun::Clamp(static_cast<int>(ncolors*normalized), 0,
ncolors);
Modified: trunk/scenes/dynlt.cc
==============================================================================
--- trunk/scenes/dynlt.cc (original)
+++ trunk/scenes/dynlt.cc Tue Jul 24 02:42:55 2007
@@ -6,6 +6,7 @@
#include <Core/Util/Args.h>
#include <DynLT/DynLTContext.h>
#include <DynLT/DynLTGridSpheres.h>
+#include <DynLT/DynLTCGT.h>
#include <DynLT/DynLTParticles.h>
#include <DynLT/DynLTQueue.h>
#include <DynLT/DynLTStatsCollector.h>
@@ -268,7 +269,10 @@
else //CGT
{
//TODO: insert CGT grid stuff here
+ tsteps = new DynLTParticles(1, fname, ncells, depth, radius, ridx,
cmap, cidx, queue);
+ queue->resizeHeapIdx(((DynLTParticles*)tsteps)->getNParticles(0));
}
+
// Initialize the scene
if (env_fname != "" && use_envmap)
scene->setBackground(bg);
- [MANTA] r1541 - in trunk: DynLT Model/Textures scenes, brownlee, 07/24/2007
Archive powered by MHonArc 2.6.16.