Text archives Help
- From: cgribble@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r1100 - in trunk: Engine/Control Model/Groups Model/Readers scenes
- Date: Wed, 7 Jun 2006 09:58:54 -0600 (MDT)
Author: cgribble
Date: Wed Jun 7 09:58:53 2006
New Revision: 1100
Added:
trunk/Model/Groups/TimeSteppedParticles.cc
trunk/Model/Groups/TimeSteppedParticles.h
Modified:
trunk/Engine/Control/DynPLTWorker.cc
trunk/Engine/Control/DynPLTWorker.h
trunk/Model/Groups/CMakeLists.txt
trunk/Model/Readers/ParticleNRRD.cc
trunk/Model/Readers/ParticleNRRD.h
trunk/scenes/dynplt.cc
trunk/scenes/pnrrd.cc
Log:
Model/Groups/CMakeLists.txt
Model/Groups/TimeSteppedParticles.cc
Model/Groups/TimeSteppedParticles.h
Added a subclass of Group for loading a time-varying series of NRRD particle
data
If the filename ends with ".nrrd", only a single timestep is loaded;
otherwise,
the file is opened, and it loads the data from each timestep name listed
in
the file
An simple interface exists for cycling through the timesteps; a GUI will
invoke these to allow stepping or animation
Model/Readers/ParticleNRRD.h
Model/Readers/ParticleNRRD.cc
Use exceptions for more graceful error handling
Engine/Control/DynPLTWorker.h
Engine/Control/DynPLTWorker.cc
Removed default background value (null) from DynPLTContext constructor; a
background must now be specified when the context is created
scenes/pnrrd.cc
scenes/dynplt.cc
Reflect changes to DynPLTContext construction
Make use of new TimeSteppedParticles group
Modified: trunk/Engine/Control/DynPLTWorker.cc
==============================================================================
--- trunk/Engine/Control/DynPLTWorker.cc (original)
+++ trunk/Engine/Control/DynPLTWorker.cc Wed Jun 7 09:58:53 2006
@@ -15,6 +15,9 @@
using namespace Manta;
using namespace std;
+#include <iostream>
+using std::cerr;
+
// XXX: the exit strategy only works occasionally (no segfault) when the
queue
// isn't empty, and never when it is empty
@@ -26,9 +29,6 @@
queue(queue), scene(scene), ngroups(ngroups), nsamples(nsamples),
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;
Modified: trunk/Engine/Control/DynPLTWorker.h
==============================================================================
--- trunk/Engine/Control/DynPLTWorker.h (original)
+++ trunk/Engine/Control/DynPLTWorker.h Wed Jun 7 09:58:53 2006
@@ -25,7 +25,7 @@
DynPLTContext(SCIRun::Mailbox<DynPLTMessage>* queue, Scene* scene,
unsigned int ngroups, unsigned int nsamples,
unsigned int max_depth, bool dilate,
- Background* background=0, Real Kd=0.6, Real Ka=0.4);
+ Background* background, Real Kd=0.6, Real Ka=0.4);
~DynPLTContext(void) { }
// DynPLT work queue
@@ -71,6 +71,7 @@
MT_RNG rng;
SCIRun::Array1<SCIRun::Array1<Vector2D> > sample_groups;
int* hidx;
+ Background* background;
SCIRun::Semaphore* exitSem;
};
}
Modified: trunk/Model/Groups/CMakeLists.txt
==============================================================================
--- trunk/Model/Groups/CMakeLists.txt (original)
+++ trunk/Model/Groups/CMakeLists.txt Wed Jun 7 09:58:53 2006
@@ -28,6 +28,8 @@
Groups/PsiGammaTable.h
Groups/RealisticBvh.cc
Groups/RealisticBvh.h
+ Groups/TimeSteppedParticles.cc
+ Groups/TimeSteppedParticles.h
Groups/TransparentKDTree.cc
Groups/TransparentKDTree.h
Groups/VolumeGrid.h
Added: trunk/Model/Groups/TimeSteppedParticles.cc
==============================================================================
--- (empty file)
+++ trunk/Model/Groups/TimeSteppedParticles.cc Wed Jun 7 09:58:53 2006
@@ -0,0 +1,95 @@
+
+#include <Core/Exceptions/InputError.h>
+#include <Core/Exceptions/OutputError.h>
+#include <Model/Groups/TimeSteppedParticles.h>
+#include <Model/Primitives/GridSpheres.h>
+#include <Model/Readers/ParticleNRRD.h>
+
+#include <fstream>
+using std::ifstream;
+
+using namespace Manta;
+
+#include <iostream>
+using std::cerr;
+
+TimeSteppedParticles::TimeSteppedParticles(const string& filename, int
ncells,
+ int depth, Real radius, int ridx,
+ RegularColorMap* cmap, int cidx,
+ SCIRun::Mailbox<DynPLTMessage>*
queue,
+ int min, int max) :
+ tstep(0)
+{
+ // Check for a single timestep
+ string::size_type pos=filename.find(".nrrd", 0);
+ if (pos != string::npos) {
+ ParticleNRRD pnrrd(filename);
+ if (queue) {
+ add(new DynPLTGridSpheres(queue, pnrrd.getParticleData(),
+ pnrrd.getNParticles(), pnrrd.getNVars(),
ncells,
+ depth, radius, ridx, cmap, cidx));
+ } else {
+ add(new GridSpheres(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);
+ if (queue) {
+ add(new DynPLTGridSpheres(queue, pnrrd.getParticleData(),
+ pnrrd.getNParticles(), pnrrd.getNVars(),
ncells,
+ depth, radius, ridx, cmap, cidx));
+ } else {
+ add(new GridSpheres(pnrrd.getParticleData(), pnrrd.getNParticles(),
+ pnrrd.getNVars(), ncells, depth, radius, ridx,
cmap,
+ cidx));
+ }
+
+ ++nloaded;
+ }
+
+ in.close();
+}
+
+TimeSteppedParticles::~TimeSteppedParticles(void)
+{
+ // Do nothing
+}
+
+void TimeSteppedParticles::intersect(const RenderContext& context,
+ RayPacket& rays) const
+{
+ // Fetch the current timestep
+ const Object* obj=get(tstep);
+ obj->intersect(context, rays);
+}
+
+void TimeSteppedParticles::computeBounds(const PreprocessContext& context,
+ BBox& bbox) const
+{
+ // Fetch the current timestep
+ const Object* obj=get(tstep);
+ obj->computeBounds(context, bbox);
+}
Added: trunk/Model/Groups/TimeSteppedParticles.h
==============================================================================
--- (empty file)
+++ trunk/Model/Groups/TimeSteppedParticles.h Wed Jun 7 09:58:53 2006
@@ -0,0 +1,40 @@
+
+#ifndef Manta_Model_TimeSteppedParticles_h
+#define Manta_Model_TimeSteppedParticles_h
+
+#include <MantaTypes.h>
+#include <Model/Groups/Group.h>
+#include <Model/Primitives/DynPLTGridSpheres.h>
+#include <SCIRun/Core/Thread/Mailbox.h>
+
+#include <string>
+using std::string;
+
+#include <limits.h>
+
+namespace Manta
+{
+ class RegularColorMap;
+
+ class TimeSteppedParticles : public Group
+ {
+ public:
+ TimeSteppedParticles(const string& filename, int ncells, int depth,
+ Real radius, int ridx, RegularColorMap* cmap, int
cidx,
+ SCIRun::Mailbox<DynPLTMessage>* queue=0, int min=0,
+ int max=INT_MAX);
+ ~TimeSteppedParticles(void);
+
+ void intersect(const RenderContext& context, RayPacket& rays) const;
+ void computeBounds(const PreprocessContext& context, BBox& bbox) const;
+
+ // GUI interface
+ void next(void) { tstep=(tstep + 1)%getSize(); }
+ void previous(void) { tstep=(tstep + getSize() - 1)%getSize(); }
+
+ private:
+ int tstep;
+ };
+}
+
+#endif // Manta_Model_TimeSteppedParticles_h
Modified: trunk/Model/Readers/ParticleNRRD.cc
==============================================================================
--- trunk/Model/Readers/ParticleNRRD.cc (original)
+++ trunk/Model/Readers/ParticleNRRD.cc Wed Jun 7 09:58:53 2006
@@ -1,3 +1,5 @@
+
+#include <Core/Exceptions/InputError.h>
#include <Model/Readers/ParticleNRRD.h>
#include <teem/nrrd.h>
@@ -15,13 +17,10 @@
// Do nothing
}
-ParticleNRRD::ParticleNRRD(string const fname, bool nuke) :
+ParticleNRRD::ParticleNRRD(string const& filename, bool nuke) :
pdata(0), nvars(0), nparticles(0), nuke(nuke)
{
- if (!readFile(fname)) {
- cerr<<"ParticleNRRD::ParticleNRRD: fatal error\n";
- exit(-1);
- }
+ readFile(filename);
}
ParticleNRRD::~ParticleNRRD(void)
@@ -30,16 +29,13 @@
delete pdata;
}
-bool ParticleNRRD::readFile(string const fname)
+void ParticleNRRD::readFile(string const& filename)
{
// Load particle data
Nrrd* pnrrd=nrrdNew();
- if (nrrdLoad(pnrrd, fname.c_str(), 0)) {
- char* err=biffGet(NRRD);
- cerr<<"Error loading particle data: "<<err<<'\n';
- free(err);
- biffDone(NRRD);
- return false;
+ if (nrrdLoad(pnrrd, filename.c_str(), 0)) {
+ char* err=biffGetDone(NRRD);
+ throw InputError("Failed to open \"" + filename + "\": " + string(err));
}
// Initialize variables
@@ -48,9 +44,7 @@
nparticles=pnrrd->axis[1].size;
cout<<"Loading "<<nparticles<<" particles ("<<nvars
- <<" data values/particles) from \""<<fname<<"\"\n";
+ <<" data values/particles) from \""<<filename<<"\"\n";
pnrrd=nrrdNix(pnrrd);
-
- return true;
}
Modified: trunk/Model/Readers/ParticleNRRD.h
==============================================================================
--- trunk/Model/Readers/ParticleNRRD.h (original)
+++ trunk/Model/Readers/ParticleNRRD.h Wed Jun 7 09:58:53 2006
@@ -9,7 +9,7 @@
class ParticleNRRD {
public:
ParticleNRRD(bool nuke=false);
- ParticleNRRD(string const fname, bool nuke=false);
+ ParticleNRRD(string const& filename, bool nuke=false);
~ParticleNRRD(void);
unsigned int getNVars(void) const { return nvars; }
@@ -17,7 +17,7 @@
float* getParticleData(void) const { return pdata; }
float* getParticleData(void) { return pdata; }
- bool readFile(string const fname);
+ void readFile(string const& filename);
private:
unsigned int nvars;
Modified: trunk/scenes/dynplt.cc
==============================================================================
--- trunk/scenes/dynplt.cc (original)
+++ trunk/scenes/dynplt.cc Wed Jun 7 09:58:53 2006
@@ -10,7 +10,7 @@
#include <Model/AmbientLights/ConstantAmbient.h>
#include <Model/Backgrounds/ConstantBackground.h>
#include <Model/Backgrounds/EnvMapBackground.h>
-#include <Model/Groups/Group.h>
+#include <Model/Groups/TimeSteppedParticles.h>
#include <Model/Lights/PointLight.h>
#include <Model/Materials/DynPLTMaterial.h>
#include <Model/Primitives/DynPLTGridSpheres.h>
@@ -143,9 +143,11 @@
nthreads*qsize);
// Create DynPLTContext
- Background* bg;
+ Background* bg=0;
if (env_fname != "")
bg=new EnvMapBackground(env_fname);
+ else
+ bg=new ConstantBackground(Color(RGB(0, 0, 0)));
DynPLTContext* dpltctx=new DynPLTContext(queue, scene, ngroups, nsamples,
max_depth, dilate, bg /*, kd,
ka*/);
@@ -169,21 +171,16 @@
RegularColorMap* cmap=new RegularColorMap(type);
// Load particle data, add particles to group
- ParticleNRRD pnrrd(fname);
- DynPLTGridSpheres* spheres=new DynPLTGridSpheres(queue,
- pnrrd.getParticleData(),
- pnrrd.getNParticles(),
- pnrrd.getNVars(),
- ncells, depth, radius,
ridx,
- cmap, cidx);
- world->add(spheres);
+ TimeSteppedParticles* tsteps=new TimeSteppedParticles(fname, ncells, depth,
+ radius, ridx, cmap,
cidx,
+ queue);
// Initialize the scene
- if (bg && use_envmap)
- scene->setBackground(new EnvMapBackground(env_fname));
+ if (env_fname != "" && use_envmap)
+ scene->setBackground(bg);
else
scene->setBackground(new ConstantBackground(Color(RGB(0, 0, 0))));
- scene->setObject(world);
+ scene->setObject(tsteps);
// Add lights
LightSet* lights=new LightSet();
Modified: trunk/scenes/pnrrd.cc
==============================================================================
--- trunk/scenes/pnrrd.cc (original)
+++ trunk/scenes/pnrrd.cc Wed Jun 7 09:58:53 2006
@@ -9,7 +9,7 @@
#include <Model/AmbientLights/ConstantAmbient.h>
#include <Model/Backgrounds/ConstantBackground.h>
#include <Model/Backgrounds/EnvMapBackground.h>
-#include <Model/Groups/Group.h>
+#include <Model/Groups/TimeSteppedParticles.h>
#include <Model/Lights/PointLight.h>
#include <Model/Materials/Lambertian.h>
#include <Model/Primitives/GridSpheres.h>
@@ -88,12 +88,9 @@
RegularColorMap* cmap=new RegularColorMap(type);
// Load particle data, add particles to group
- ParticleNRRD pnrrd(fname);
- GridSpheres* spheres=new GridSpheres(pnrrd.getParticleData(),
- pnrrd.getNParticles(),
pnrrd.getNVars(),
- ncells, depth, radius, ridx, cmap,
- cidx);
- world->add(spheres);
+ TimeSteppedParticles* tsteps=new TimeSteppedParticles(fname, ncells, depth,
+ radius, ridx, cmap,
+ cidx);
// Create scene
Scene* scene=new Scene();
@@ -101,7 +98,7 @@
scene->setBackground(new EnvMapBackground(env_fname));
else
scene->setBackground(new ConstantBackground(Color(RGB(0, 0, 0))));
- scene->setObject(world);
+ scene->setObject(tsteps);
LightSet* lights=new LightSet();
lights->add(new PointLight(Vector(1, 1, 1), Color(RGB(1, 1, 1))));
- [MANTA] r1100 - in trunk: Engine/Control Model/Groups Model/Readers scenes, cgribble, 06/07/2006
Archive powered by MHonArc 2.6.16.