Author: cgribble
Date: Thu Jul 19 11:40:32 2007
New Revision: 1510
Added:
trunk/scenes/pcgt.cc
Modified:
trunk/scenes/CMakeLists.txt
Log:
Added scene for using Particle CGT algorithm with particle NRRDs; more general than particleCGTTest.cc, will eventually support the same features as pnrrd.cc (using PCGT rather than GridSpheres)
Modified: trunk/scenes/CMakeLists.txt
====================================================================== ========
--- trunk/scenes/CMakeLists.txt (original)
+++ trunk/scenes/CMakeLists.txt Thu Jul 19 11:40:32 2007
@@ -54,6 +54,12 @@
TARGET_LINK_LIBRARIES(scene_ParticleBVHTest ${MANTA_SCENE_LINK})
ENDIF(SCENE_PARTICLEBVHTEST)
+SET(SCENE_PARTICLECGTTEST 0 CACHE BOOL "Particle Coherent Grid Traversal Test")
+IF(SCENE_PARTICLECGTTEST)
+ ADD_LIBRARY(scene_particleCGTTest particleCGTTest.cc)
+ TARGET_LINK_LIBRARIES(scene_particleCGTTest ${MANTA_SCENE_LINK})
+ENDIF(SCENE_PARTICLECGTTEST)
+
# Boeing 777 Test Scene.
SET(SCENE_BOEING777 0 CACHE BOOL "Boeing 777 Test Scene")
IF(SCENE_BOEING777)
@@ -114,19 +120,17 @@
TARGET_LINK_LIBRARIES(scene_pnrrd ${MANTA_SCENE_LINK})
ENDIF(BUILD_NRRDPARTICLES)
+# Viewer for NRRD particle datasets using PCGT algorithm
+IF(BUILD_NRRDPARTICLES)
+ ADD_LIBRARY(scene_pcgt pcgt.cc)
+ TARGET_LINK_LIBRARIES(scene_pcgt ${MANTA_SCENE_LINK})
+ENDIF(BUILD_NRRDPARTICLES)
+
# Lazily evaluated LTs for NRRD particle datasets
IF(BUILD_DYNLT)
ADD_LIBRARY(scene_dynlt dynlt.cc)
TARGET_LINK_LIBRARIES(scene_dynlt Manta_DynLT ${MANTA_SCENE_LINK})
ENDIF(BUILD_DYNLT)
-
-# Test different primitives.
-SET(SCENE_PARTICLE_CGT 0 CACHE BOOL "Test scene for particle Coherent Grid Traversal")
-IF(SCENE_PARTICLE_CGT)
- ADD_LIBRARY(scene_particleCGTTest particleCGTTest.cc)
- TARGET_LINK_LIBRARIES(scene_particleCGTTest ${MANTA_SCENE_LINK})
-ENDIF(SCENE_PARTICLE_CGT)
-
# Recurse into galileo directory
SUBDIRS(galileo)
Added: trunk/scenes/pcgt.cc
====================================================================== ========
--- (empty file)
+++ trunk/scenes/pcgt.cc Thu Jul 19 11:40:32 2007
@@ -0,0 +1,126 @@
+
+#include <Core/Color/RegularColorMap.h>
+#include <Core/Exceptions/IllegalArgument.h>
+#include <Core/Geometry/Vector.h>
+#include <Core/Util/Args.h>
+#include <Interface/Context.h>
+#include <Interface/LightSet.h>
+#include <Interface/MantaInterface.h>
+#include <Interface/Scene.h>
+#include <Model/AmbientLights/ConstantAmbient.h>
+#include <Model/Backgrounds/ConstantBackground.h>
+#include <Model/Backgrounds/EnvMapBackground.h>
+#include <Model/Groups/TimeSteppedParticles.h>
+#include <Model/Lights/PointLight.h>
+#include <Model/Materials/Lambertian.h>
+#include <Model/Primitives/GridSpheres.h>
+#include <Model/Primitives/Sphere.h>
+#include <Model/Readers/ParticleNRRD.h>
+#include <Model/Groups/private/ParticleCGT.h>
+
+#include <sgi_stl_warnings_off.h>
+#include <iostream>
+#include <sgi_stl_warnings_on.h>
+
+using namespace Manta;
+using namespace std;
+
+extern "C"
+Scene* make_scene(ReadContext const& context, vector<string> const& args)
+{
+ int argc = static_cast<int>(args.size());
+ int cidx = 0;
+ string env_fname = "";
+ string fname = "";
+ double radius = 1.;
+ int ridx = -1;
+ double lx = 10.;
+ double ly = 10.;
+ double lz = 10.;
+
+ for(int i = 0; i < argc; ++i) {
+ string arg = args[i];
+ if (arg == "-cidx") {
+ if (!getIntArg(i, args, cidx))
+ throw IllegalArgument("scene pcgt -cidx", i, args);
+ } else if (arg == "-envmap") {
+ if (!getStringArg(i, args, env_fname))
+ throw IllegalArgument("scene pcgt -envmap", i, args);
+ } else if (arg == "-i") {
+ if (!getStringArg(i, args, fname))
+ throw IllegalArgument("scene pcgt -i", i, args);
+ } else if (arg == "-light") {
+ if (!getDoubleArg(i, args, lx))
+ throw IllegalArgument("scene pcgt -light", i, args);
+ if (!getDoubleArg(i, args, ly))
+ throw IllegalArgument("scene pcgt -light", i, args);
+ if (!getDoubleArg(i, args, lz))
+ throw IllegalArgument("scene pcgt -light", i, args);
+ } else if (arg == "-radius") {
+ if (!getDoubleArg(i, args, radius))
+ throw IllegalArgument("scene pcgt -radius", i, args);
+ } else if (arg == "-ridx") {
+ if (!getIntArg(i, args, ridx))
+ throw IllegalArgument("scene pcgt -ridx", i, args);
+ } else {
+ cerr<<"Valid options for scene pcgt:\n";
+ cerr<<" -cidx <int> data value index for color mapping\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 pcgt", i, args);
+ }
+ }
+
+ // Create scene
+ Scene* scene = new Scene();
+
+ // Create color map
+ unsigned int type = RegularColorMap::parseType("InvRainbowIso");
+ RegularColorMap* cmap = new RegularColorMap(type);
+
+ // XXX(cpg) - There are some problems here:
+ // 1. Get bus error without the random, manually added sphere at (0, 0, 0)
+ // 2. I don't understand the scene <- world <- particles <- data mapping.
+ // Why so many layers of groups? It seems to me that ParticleGrid should
+ // be the scene's primary object, unless we're loading multiple time steps
+ // (see pnrrd.cc).
+ // 3. Doesn't support variable radii
+ // 3. Doesn't support run time color mapping
+
+ // ***** begin copy (more or less) from ParticleCGTTest.cc *****
+ Group* world = new Group;
+ Group* particles = new Group;
+
+ Material* material = new Lambertian(Color(RGB(1, 0, 0)));
+ ParticleNRRD pnrrd(fname);
+ unsigned int nvars = pnrrd.getNVars();
+ for (unsigned int i = 0; i < pnrrd.getNParticles(); i++) {
+ float* data = pnrrd.getParticleData() + i*nvars;
+ Vector position(data[0], data[1], data[2]);
+ particles->add(new Sphere(material, position, radius));
+ }
+
+ ParticleGrid* grid = new ParticleGrid;
+ grid->rebuild(particles);
+ world->add(grid);
+ world->add(new Sphere(material, Vector(0,0,0), radius));
+ scene->setObject(world);
+ // ***** end copy *****
+
+ // Set background
+ if (env_fname != "")
+ scene->setBackground(new EnvMapBackground(env_fname));
+ else
+ scene->setBackground(new ConstantBackground(Color(RGB(0, 0, 0))));
+
+ // Add lights
+ LightSet* lights=new LightSet();
+ lights->add(new PointLight(Vector(lx, ly, lz), Color(RGB(1, 1, 1))));
+ lights->setAmbientLight(new ConstantAmbient(Color(RGB(0.4, 0.4, 0.4))));
+ scene->setLights(lights);
+
+ return scene;
+}
Archive powered by MHonArc 2.6.16.