Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r1060 - in trunk: Model Model/Readers scenes


Chronological Thread 
  • From: cgribble@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r1060 - in trunk: Model Model/Readers scenes
  • Date: Mon, 15 May 2006 15:44:03 -0600 (MDT)

Author: cgribble
Date: Mon May 15 15:44:00 2006
New Revision: 1060

Added:
   trunk/Model/Readers/ParticleNRRD.cc
   trunk/Model/Readers/ParticleNRRD.h
   trunk/scenes/pnrrd.cc
Modified:
   trunk/Model/CMakeLists.txt
   trunk/Model/Readers/CMakeLists.txt
   trunk/scenes/CMakeLists.txt
Log:
Model/Readers/ParticleNRRD.h
Model/Readers/ParticleNRRD.cc
Model/Readers/CMakeLists.txt
Model/CMakeLists.txt
  Added a simple reader for loading NRRD particle datasets

scenes/CMakeLists.txt
scenes/pnrrd.cc
  Added a basic scene to render NRRD particle datasets


Modified: trunk/Model/CMakeLists.txt
==============================================================================
--- trunk/Model/CMakeLists.txt  (original)
+++ trunk/Model/CMakeLists.txt  Mon May 15 15:44:00 2006
@@ -35,5 +35,13 @@
              ${Manta_Textures_SRCS}
              )
 
-TARGET_LINK_LIBRARIES(Manta_Model Manta_Interface Manta_Core)
+IF(MODEL_PARTICLENRRD)
+   TARGET_LINK_LIBRARIES(Manta_Model
+                         Manta_Interface
+                        Manta_Core
+                        ${FOUND_TEEM_LIB})
+ELSE(MODEL_PARTICLENRRD)
+   TARGET_LINK_LIBRARIES(Manta_Model Manta_Interface Manta_Core)
+ENDIF(MODEL_PARTICLENRRD)
+
 

Modified: trunk/Model/Readers/CMakeLists.txt
==============================================================================
--- trunk/Model/Readers/CMakeLists.txt  (original)
+++ trunk/Model/Readers/CMakeLists.txt  Mon May 15 15:44:00 2006
@@ -11,7 +11,6 @@
      Readers/PlyReader.cc
      Readers/V3C1.h
      Readers/V3C1.cc
-
 )
 
 
@@ -19,3 +18,14 @@
 IF (APPLE)
    INCLUDE_DIRECTORIES(/usr/include/malloc/)
 ENDIF (APPLE)
+
+# Reader for NRRD particle data
+SET(MODEL_PARTICLENRRD 0 CACHE BOOL "NRRD particle data reader")
+IF(MODEL_PARTICLENRRD)
+   SET(Manta_Readers_SRCS
+       ${Manta_Readers_SRCS}
+       Readers/ParticleNRRD.h
+       Readers/ParticleNRRD.cc
+   )
+   INCLUDE_DIRECTORIES(${FOUND_TEEM_INCLUDE})
+ENDIF(MODEL_PARTICLENRRD)

Added: trunk/Model/Readers/ParticleNRRD.cc
==============================================================================
--- (empty file)
+++ trunk/Model/Readers/ParticleNRRD.cc Mon May 15 15:44:00 2006
@@ -0,0 +1,50 @@
+#include <Model/Readers/ParticleNRRD.h>
+
+#include <teem/nrrd.h>
+
+#include <sgi_stl_warnings_off.h>
+#include <iostream>
+#include <sgi_stl_warnings_on.h>
+
+using namespace Manta;
+using namespace std;
+
+ParticleNRRD::ParticleNRRD(void) :
+  pdata(0), nvars(0), nparticles(0)
+{
+  // Do nothing
+}
+
+ParticleNRRD::ParticleNRRD(string const fname)
+{
+  readFile(fname);
+}
+
+ParticleNRRD::~ParticleNRRD(void)
+{
+  if (pdata)
+    delete pdata;
+}
+
+void ParticleNRRD::readFile(string const fname)
+{
+  // 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;
+  }
+  
+  // Initialize variables
+  pdata=static_cast<float*>(pnrrd->data);
+  nvars=pnrrd->axis[0].size;
+  nparticles=pnrrd->axis[1].size;
+
+  cout<<"Loading "<<nparticles<<" particles ("<<nvars
+      <<" data values/particles) from \""<<fname<<"\"\n";
+
+  pnrrd=nrrdNix(pnrrd);
+}

Added: trunk/Model/Readers/ParticleNRRD.h
==============================================================================
--- (empty file)
+++ trunk/Model/Readers/ParticleNRRD.h  Mon May 15 15:44:00 2006
@@ -0,0 +1,29 @@
+#ifndef Manta_Model_ParticleNRRD_h
+#define Manta_Model_ParticleNRRD_h
+
+#include <string>
+
+using namespace std;
+
+namespace Manta {
+  class ParticleNRRD {
+  public:
+    ParticleNRRD(void);
+    ParticleNRRD(string const fname);
+    ~ParticleNRRD(void);
+
+    unsigned int getNVars(void) const { return nvars; }
+    unsigned int getNParticles(void) const { return nparticles; }
+    float* getParticleData(void) const { return pdata; }
+    float* getParticleData(void) { return pdata; }
+
+    void readFile(string const fname);
+
+  private:
+    unsigned int nvars;
+    unsigned int nparticles;
+    float* pdata;
+  };
+}
+
+#endif // Manta_Model_ParticleNRRD_h

Modified: trunk/scenes/CMakeLists.txt
==============================================================================
--- trunk/scenes/CMakeLists.txt (original)
+++ trunk/scenes/CMakeLists.txt Mon May 15 15:44:00 2006
@@ -82,4 +82,11 @@
 IF(SCENE_PERF)
    ADD_LIBRARY(scene_perf perf.cc)
    TARGET_LINK_LIBRARIES(scene_perf ${MANTA_SCENE_LINK})
-ENDIF(SCENE_PERF)
\ No newline at end of file
+ENDIF(SCENE_PERF)
+
+# Viewer for NRRD particle datasets
+SET(SCENE_PARTICLEREADER 0 CACHE BOOL "NRRD particle data viewer")
+IF(SCENE_PARTICLEREADER)
+   ADD_LIBRARY(scene_pnrrd pnrrd.cc)
+   TARGET_LINK_LIBRARIES(scene_pnrrd ${MANTA_SCENE_LINK})
+ENDIF(SCENE_PARTICLEREADER)

Added: trunk/scenes/pnrrd.cc
==============================================================================
--- (empty file)
+++ trunk/scenes/pnrrd.cc       Mon May 15 15:44:00 2006
@@ -0,0 +1,87 @@
+#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/Groups/Group.h>
+#include <Model/Lights/PointLight.h>
+#include <Model/Materials/Lambertian.h>
+#include <Model/Primitives/Sphere.h>
+#include <Model/Readers/ParticleNRRD.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());
+  string fname="";
+  double radius=1.;
+  int ridx=-1;
+  Group* world=0;
+  for(int i=0; i<argc; ++i) {
+    string arg=args[i];
+    if (arg=="-bv") {
+      string s;
+      if (!getStringArg(i, args, s))
+        throw IllegalArgument("scene pnrrd -bv", i, args);
+      world=context.manta_interface->makeGroup(s);
+    } else if (arg=="-i") {
+      if (!getStringArg(i, args, fname))
+        throw IllegalArgument("scene pnrrd -i", i, args);
+    } else if (arg=="-radius") {
+      if (!getDoubleArg(i, args, radius))
+        throw IllegalArgument("scene pnrrd -radius", i, args);
+    } else if (arg=="-ridx") {
+      if (!getIntArg(i, args, ridx))
+        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<<"  -i <string>       filename\n";
+      cerr<<"  -radius <float>   particle radius\n";
+      cerr<<"  -ridx <int>       radius index\n";
+      throw IllegalArgument("scene pnrrd", i, args);
+    }
+  }
+
+  if (!world)
+    world=new Group();
+
+  // Load particle data, add particles to group
+  ParticleNRRD pnrrd(fname);
+  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));
+  }
+
+  // Create scene
+  Scene* scene=new Scene();
+  scene->setBackground(new ConstantBackground(Color(RGB(0, 0, 0))));
+  scene->setObject(world);
+
+  LightSet* lights=new LightSet();
+  lights->add(new PointLight(Vector(1, 1, 1), Color(RGB(1, 1, 1))));
+  lights->setAmbientLight(new ConstantAmbient(Color(RGB(0.4, 0.4, 0.4))));
+  scene->setLights(lights);
+
+  return scene;
+}




  • [MANTA] r1060 - in trunk: Model Model/Readers scenes, cgribble, 05/15/2006

Archive powered by MHonArc 2.6.16.

Top of page