Text archives Help
- From:
- To:
- Subject: [Manta] r2335 - in trunk: Model/MiscObjects Model/Readers SwigInterface UserInterface scenes/csafe/python scenes/csafe/src
- Date: Wed, 22 Oct 2008 10:10:57 -0600 (MDT)
Author: brownlee
Date: Wed Oct 22 10:10:53 2008
New Revision: 2335
Modified:
trunk/Model/MiscObjects/KeyFrameAnimation.cc
trunk/Model/Readers/VolumeNRRD.h
trunk/SwigInterface/MantaCameraPath.py
trunk/UserInterface/CameraPathAutomator.cc
trunk/scenes/csafe/python/SceneInfo.py
trunk/scenes/csafe/python/SceneMenus.py
trunk/scenes/csafe/python/csafe_demo.cfg
trunk/scenes/csafe/python/csafe_demo.py
trunk/scenes/csafe/src/CDGridSpheres.cc
trunk/scenes/csafe/src/CDGridSpheres.h
trunk/scenes/csafe/src/CDTest.h
Log:
changes from site visit. Volumes now have changing size throughout animation
if there are bounds specified inside the nrrd file headers.
Modified: trunk/Model/MiscObjects/KeyFrameAnimation.cc
==============================================================================
--- trunk/Model/MiscObjects/KeyFrameAnimation.cc (original)
+++ trunk/Model/MiscObjects/KeyFrameAnimation.cc Wed Oct 22 10:10:53
2008
@@ -80,6 +80,13 @@
if (paused)
startTime += Time::currentSeconds() - pauseTime;
paused = false;
+ //assume that if resume is called when the animation
+ // isn't looping that the user want's to start from
+ // the beginning
+ if (!loop && (currTime - startTime) >= duration) {
+ startTime = Time::currentSeconds();
+ updateToCurrTime = true;
+ }
}
void KeyFrameAnimation::update(Temp_Callback context)
@@ -135,9 +142,9 @@
//work backwards.
float nextFrame = 0;
if (duration > 0.0)
- nextFrame = currTime/duration*numFrames+1;
+ nextFrame = (currTime/duration)*numFrames+1;
if (numFrames > 0)
- currTime = nextFrame/numFrames*duration;
+ currTime = (nextFrame/numFrames)*duration;
else
currTime = 0;
differentFrame = numFrames > 1;
@@ -153,7 +160,7 @@
if (!loop && (context.time - startTime) >=duration) {
pauseAnimation();
}
- if (loop && repeatLastFrame > 0.0f && (context.time - startTime) >=
duration) {
+ if (repeatLastFrame > 0.0f && (context.time - startTime) >= duration) {
repeating = true;
}
}
@@ -161,6 +168,9 @@
//need to make sure proc 0 has updated the currTime.
//a barrier is a little heavy for this, but it's cleaner code (and I'm
lazy).
barrier.wait(context.numProcs);
+ if (!loop && (context.time - startTime) >=duration) {
+ return;
+ }
if (differentFrame) {
float frame = currTime/duration * numFrames;
Modified: trunk/Model/Readers/VolumeNRRD.h
==============================================================================
--- trunk/Model/Readers/VolumeNRRD.h (original)
+++ trunk/Model/Readers/VolumeNRRD.h Wed Oct 22 10:10:53 2008
@@ -13,13 +13,12 @@
#if HAVE_TEEM
#include <teem/nrrd.h>
#endif
-using namespace std;
namespace Manta
{
#if HAVE_TEEM
template<class T>
- GridArray3<T>* loadNRRDToGrid(string file)
+ GridArray3<T>* loadNRRDToGrid(std::string file,
std::vector<std::pair<std::string, std::string> >* keyValuePairs = NULL )
{
GridArray3<T>* grid = new GridArray3<T>();
cout << "READING NRRD: " << file << " ";
@@ -54,18 +53,34 @@
Vector size( new_nrrd->axis[0].size * new_nrrd->axis[0].spacing,
new_nrrd->axis[1].size * new_nrrd->axis[1].spacing,
new_nrrd->axis[2].size * new_nrrd->axis[2].spacing );
+ if (keyValuePairs != NULL) {
+ //keyValuePairs->clear();
+ std::cout << "key value pairs: \n";
+ int ki, nk;
+ char *key, *val;
+ nk = nrrdKeyValueSize(new_nrrd);
+ for(ki=0; ki<nk; ki++) {
+ nrrdKeyValueIndex(new_nrrd, &key, &val, ki);
+ printf("%s = %s\n", key, val);
+ keyValuePairs->push_back(std::pair<std::string, std::string>(key,
val));
+ free(key); free(val);
+ key = NULL; val = NULL;
+ }
+ }
+
+
size = Vector(new_nrrd->axis[0].size, new_nrrd->axis[1].size,
new_nrrd->axis[2].size);
- cout << "size: " << size.x() << " " << size.y() << " " << size.z() <<
endl;
+ std::cout << "size: " << size.x() << " " << size.y() << " " << size.z()
<< std::endl;
// Rescale.
float max_dim = max( size.x(), max( size.y(), size.z() ) );
- cout << "resizing\n";
+ std::cout << "resizing\n";
size /= max_dim;
//_minBound = -size/2.0;
//_maxBound = size/2.0;
- cout << "resizing grid\n";
+ std::cout << "resizing grid\n";
grid->resize(new_nrrd->axis[0].size, new_nrrd->axis[1].size,
new_nrrd->axis[2].size);
- cout << "copying nrrd data\n";
+ std::cout << "copying nrrd data\n";
for(int i=0; i<grid->getNz(); i++)
for(int j=0; j<grid->getNy(); j++)
for(int k=0; k<grid->getNx(); k++)
@@ -95,14 +110,14 @@
// (*grid)(k,j,i) = ((unsigned
long*)new_nrrd->data)[(int)(((i*grid->getNy() + j)*grid->getNx() + k))];
}
nrrdNuke(new_nrrd);
- cout << "done\n";
+ std::cout << "done\n";
return grid;
}
#else
template<class T>
- GridArray3<T>* loadNRRDToGrid(string file)
+ GridArray3<T>* loadNRRDToGrid(string file,
std::vector<std::pair<std::string, std::string> >* keyValuePairs = NULL)
{
- cerr << "Error: " << __FILE__ << ": please link Manta with TEEM\n";
+ std::cerr << "Error: " << __FILE__ << ": please link Manta with TEEM\n";
return new GridArray3<T>();
}
#endif
Modified: trunk/SwigInterface/MantaCameraPath.py
==============================================================================
--- trunk/SwigInterface/MantaCameraPath.py (original)
+++ trunk/SwigInterface/MantaCameraPath.py Wed Oct 22 10:10:53 2008
@@ -31,6 +31,8 @@
self.engine = engine
self.channel = channel
self.parent = parent
+ self.record_delta_t = 0.0
+ self.record_delta_time = 0.0
# Load/Create Path.
self.load_path_button = wx.Button( self, -1, "Load Path" )
Modified: trunk/UserInterface/CameraPathAutomator.cc
==============================================================================
--- trunk/UserInterface/CameraPathAutomator.cc (original)
+++ trunk/UserInterface/CameraPathAutomator.cc Wed Oct 22 10:10:53 2008
@@ -564,6 +564,7 @@
fprintf( file, "control( -eye %f %f %f ", eye[i][0], eye[i][1],
eye[i][2] );
fprintf( file, "-lookat %f %f %f ", lookat[i][0], lookat[i][1],
lookat[i][2] );
fprintf( file, "-up %f %f %f ", up[i][0], up[i][1],
up[i][2] );
+ fprintf(file, "-hfov %f -vfov %f", hfov[i], vfov[i]);
fprintf( file, ")\n");
}
Modified: trunk/scenes/csafe/python/SceneInfo.py
==============================================================================
--- trunk/scenes/csafe/python/SceneInfo.py (original)
+++ trunk/scenes/csafe/python/SceneInfo.py Wed Oct 22 10:10:53 2008
@@ -28,9 +28,12 @@
self.showSpheres = True
self.showVolume = True
self.biggify = False # make text bigger
- self.minX = self.minY = self.minZ = -0.1
- self.maxX = self.maxY = self.maxZ = 0.1
- self.maxY = 0.2
+ self.minX = -1.0
+ self.minY = -1.0
+ self.minZ = -1.0
+ self.maxX = 1.0
+ self.maxY = 1.0
+ self.maxZ = 1.0
self.histogramBuckets = 300
self.volumeMinBound = [-0.001, -0.101, -0.001]
self.volumeMaxBound = [0.101, 0.201, 0.101]
Modified: trunk/scenes/csafe/python/SceneMenus.py
==============================================================================
--- trunk/scenes/csafe/python/SceneMenus.py (original)
+++ trunk/scenes/csafe/python/SceneMenus.py Wed Oct 22 10:10:53 2008
@@ -105,9 +105,9 @@
continue
def OnClickAddParticles(self, evt):
- wildcard = "All files (*.*)|*.*" \
+ wildcard = "All files (*.*)|*.*|" \
"Nrrd File (*.nrrd)|*.nrrd|" \
- "Nrrd Header (*.nrhd)|*.nhdr|"
+ "Nrrd Header (*.nrhd)|*.nhdr"
dlg = wx.FileDialog(self, message="Choose a Particle file(s)",
defaultDir=os.getcwd(), defaultFile="",wildcard=wildcard,
style=wx.OPEN | wx.MULTIPLE | wx.CHANGE_DIR)
@@ -124,9 +124,9 @@
dlg.Destroy()
def OnClickAddVolume(self, evt):
- wildcard = "All files (*.*)|*.*" \
+ wildcard = "All files (*.*)|*.*|" \
"Nrrd File (*.nrrd)|*.nrrd|" \
- "Nrrd Header (*.nrhd)|*.nhdr|"
+ "Nrrd Header (*.nrhd)|*.nhdr"
dlg = wx.FileDialog(self, message="Choose a Volume file(s)",
defaultDir=os.getcwd(), defaultFile="",wildcard=wildcard,
@@ -198,6 +198,15 @@
self.scene.maxZ = self.maxZSP.GetValue()
min = Vector(float(self.scene.minX), float(self.scene.minY),
float(self.scene.minZ))
max = Vector(float(self.scene.maxX), float(self.scene.maxY),
float(self.scene.maxZ))
+ if (min[0]>= max[0]):
+ min[0] = max[0] - 0.0001
+ self.minXSP.SetValue(min[0])
+ if (min[1]>= max[1]):
+ min[1] = max[1] - 0.0001
+ self.minYSP.SetValue(min[1])
+ if (min[2]>= max[2]):
+ min[2] = max[2] - 0.0001
+ self.minZSP.SetValue(min[2])
self.scene.test.setClippingBBox(min, max)
self.scene.test.useClippingBBox(True)
Modified: trunk/scenes/csafe/python/csafe_demo.cfg
==============================================================================
--- trunk/scenes/csafe/python/csafe_demo.cfg (original)
+++ trunk/scenes/csafe/python/csafe_demo.cfg Wed Oct 22 10:10:53 2008
@@ -275,6 +275,8 @@
0.001
4
8
+-0.49600000000000000000 -0.49600000000000000000 -0.49600000000000000000
+0.49600000000000000000 0.49600000000000000000 0.49600000000000000000
1
/home/sci/brownlee/Data-Explosion/vol/temp_CC_M02_0002.nrrd
1
Modified: trunk/scenes/csafe/python/csafe_demo.py
==============================================================================
--- trunk/scenes/csafe/python/csafe_demo.py (original)
+++ trunk/scenes/csafe/python/csafe_demo.py Wed Oct 22 10:10:53 2008
@@ -36,7 +36,7 @@
#import wxversion
#wxversion.ensureMinimal("2.8")
import wxManta
-import getopt, sys
+import getopt, sys, re
from manta import *
import sys, os, time, traceback, types
@@ -355,7 +355,8 @@
#TODO: be able to set these in GUI
data = manta_new(BasicCameraData(eye,lookat,up,fov,fov))
engine.getCamera(0).setBasicCameraData(data)
-
scene.setBackground(manta_new(ConstantBackground(ColorDB.getNamedColor("SkyBlue3").scaled(0.5))))
+#
scene.setBackground(manta_new(ConstantBackground(ColorDB.getNamedColor("SkyBlue3").scaled(0.5))))
+
scene.setBackground(manta_new(ConstantBackground(Color(RGBColor(0,0,0)))))
engine.setShadowAlgorithm(manta_new(NoShadows()))
#engine.selectShadowAlgorithm("noshadows")
@@ -408,8 +409,6 @@
minBound = Vector(self.scene.volumeMinBound[0],
self.scene.volumeMinBound[1], self.scene.volumeMinBound[2])
maxBound = Vector(self.scene.volumeMaxBound[0],
self.scene.volumeMaxBound[1], self.scene.volumeMaxBound[2])
- print "setting min volume bound to : " +
str(self.scene.volumeMinBound)+ "\n"
- print "LLLAAAAAALLLLL\nLAAAAAAALLLL\nLLLLLAAAAAAALLLLL\n"
self.test = manta_new(CDTest(scene, engine, minBound, maxBound));
self.test.initScene();
self.test.setVolCMap(self.volCMap);
@@ -579,6 +578,7 @@
self.loadbalancer = None
self.pixelsampler = None
self.renderer = None
+ self.size = (512,512)
setup = Setup()
@@ -716,7 +716,7 @@
if (setup.num_workers == None):
setup.num_workers = 4
app = wxManta.MantaApp( initialize_scene,
- setup.num_workers, renderSize=(512,512),
begin_rendering=False)
+ setup.num_workers, renderSize=setup.size,
begin_rendering=False)
factory = Factory(app.frame.engine, True)
@@ -790,10 +790,11 @@
frame1.slider.SetRange(1, 1)
frame1.scene.mantaApp.frame.StartEngine()
- if (setup.generate == True):
- frame1.BuildScene()
frame1.scene.numThreads = setup.num_workers
frame1.scene.engine.changeNumWorkers(frame1.scene.numThreads)
+ if (setup.generate == True):
+ frame1.BuildScene()
+
###########################################################################
# Perform any additional setup
Modified: trunk/scenes/csafe/src/CDGridSpheres.cc
==============================================================================
--- trunk/scenes/csafe/src/CDGridSpheres.cc (original)
+++ trunk/scenes/csafe/src/CDGridSpheres.cc Wed Oct 22 10:10:53 2008
@@ -18,6 +18,7 @@
#include <Core/Containers/Array1.h>
#include <Core/Math/MinMax.h>
#include <Core/Util/Timer.h>
+#include <Interface/MantaInterface.h>
#include <iostream>
using std::cerr;
@@ -26,18 +27,24 @@
using namespace Manta;
+int CDGridSpheres::__numGrids = 0;
+bool* CDGridSpheres::__processedGrids = new bool[256];
+CDGridSpheres** CDGridSpheres::__grids = new CDGridSpheres*[256];
+
CDGridSpheres::CDGridSpheres(float* spheres, int nspheres, int nvars, int
ncells,
int depth, Real
radius, int ridx, RGBAColorMap* cmap,
int cidx) :
-spheres(spheres), nspheres(nspheres), nvars(nvars),
+barrier("CDGRidSpheres barrier"), mutex("CDGridSpheres mutex"),
spheres(spheres), nspheres(nspheres), nvars(nvars),
radius(radius), ridx(ridx), ncells(ncells), depth(depth),
cmap(cmap), cidx(cidx), _useAmbientOcclusion(false)
{
+ __grids[__numGrids] = this;
+ __numGrids++;
_matl = new Phong(this, this, 10, NULL);
cerr<<"Initializing GridSpheres\n";
if (radius <= 0) {
- if (ridx <= 0)
+ if (ridx < 0)
{
cerr<<"Resetting default radius to 1\n";
radius=1;
@@ -112,21 +119,75 @@
void CDGridSpheres::preprocess(const PreprocessContext& context)
{
+ // context.manta_interface->registerParallelPreRenderCallback(
+ computeBounds(context, bounds);
+
_matl->preprocess(context);
// Preprocess material
LitMaterial::preprocess(context);
+
+ _ao = new AmbientOcclusion(Color(RGB(1,1,1)), 0.01f, 10);
+ _ao->preprocess(context);
+
context.manta_interface->addOneShotCallback(MantaInterface::Relative, 0,
+ Callback::create(this, &CDGridSpheres::update));
+ for (int i = 0; i < __numGrids;i++)
+ __processedGrids[i] = false;
+ }
+
+
+void CDGridSpheres::updateStatic(int proc, int numProcs)
+{
+ static Mutex static_mutex("CDGridSpheres static Mutex");
+ for(int index = 0; index < __numGrids; index++) {
+ bool updateGrid = false;
+ static_mutex.lock();
+ if (!__processedGrids[index])
+ {
+ __processedGrids[index] = true;
+ updateGrid = true;
+ }
+ static_mutex.unlock();
+ if (updateGrid) {
+ cout << "updating grid : " << index << endl;
+ __grids[index]->update(0, 1);
+ cout << "updating grid " << index << " complete\n";
+ }
+ }
+}
+
+ void CDGridSpheres::update(int proc, int numProcs)
+ {
+ //int proc, numProcs;
+ proc = 0; numProcs = 1;
+ //barrier.wait(numProcs);
+ //mutex.lock();
+ // cout << "update numProcs, proc: " << numProcs
+ // << " " << proc << endl;
+ //mutex.unlock();
+
+ // cout << "numProcs: " << numProcs << endl;
+ // cout << "context proc: " << proc << endl;
+ int procRange = totalcells/numProcs;
+ int procStart = proc*procRange;
+ int procEnd = procStart+procRange;
+ float max_radius;
+ WallClockTimer timer;
+ int* map;
+ size_t totalsize;
+ Real stime;
+ // if (proc == 0){
+
+
// Build grid
cerr<<"Building GridSpheres\n";
- WallClockTimer timer;
timer.start();
cerr<<" min: ("<<min[0]<<", "<<min[1]<<", "<<min[2]<<")\n";
cerr<<" max: ("<<max[0]<<", "<<max[1]<<", "<<max[2]<<")\n";
// Determine the maximum radius
- float max_radius;
if (ridx>0) {
cerr<<" GridSpheres::preprocess - ridx="<<ridx<<'\n';
max_radius=max[ridx];
@@ -140,7 +201,7 @@
max_radius=radius;
// Bound the spheres
- computeBounds(context, bounds);
+ // computeBounds(context, bounds);
diagonal=bounds.diagonal();
inv_diagonal=Vector(1/diagonal.x(), 1/diagonal.y(), 1/diagonal.z());
@@ -149,7 +210,7 @@
for (int i=0; i<=depth; ++i)
totalcells *= ncells;
- int totalsize=totalcells*totalcells*totalcells;
+ totalsize=totalcells*totalcells*totalcells;
cerr<<" Computing "<<totalcells<<'x'<<totalcells<<'x'<<totalcells
<<" grid ("<<totalsize<<" cells total)\n";
@@ -165,9 +226,8 @@
bzero(counts, 2*totalsize*sizeof(int));
cerr<<" 0/6: Allocation took "<<timer.time()<<" seconds\n";
-
// Generate map
- int* map=new int[totalsize];
+ map=new int[totalsize];
int idx=0;
for (int x=0; x<totalcells; ++x) {
for (int y=0; y<totalcells; ++y) {
@@ -177,13 +237,26 @@
}
}
- Real stime=timer.time();
- cerr<<" 1/6: Generating map took "<<stime<<" seconds\n";
-
+
+ cerr << "1/6: Generating map took "<<stime<<" seconds\n";
+ stime=timer.time();
+ // } // if proc == 0
+ // barrier.wait(numProcs);
+ // int* countsTemp = new int[2*totalsize];
+ // bzero(countsTemp, 2*totalsize*sizeof(int));
+
+ procRange = nspheres/numProcs;
+ procStart = proc*procRange;
+ procEnd = procStart+procRange;
+ // mutex.lock();
+ // cout << "proc, procRange, procStart, procEnd: "
+ // << proc<< " " << procRange << " " << procStart
+ // << " " << procEnd << endl;
+ //mutex.unlock();
// Compute cell counts
- float* data=spheres;
+ float* data=spheres + procStart*nvars;
int tc2=totalcells*totalcells;
- for (int i=0; i<nspheres; ++i) {
+ for (int i=procStart; i<procEnd; ++i) {
Real ctime=timer.time();
if (ctime - stime>5.0) {
cerr<<i<<"/"<<nspheres<<'\n';
@@ -215,16 +288,23 @@
idx_y += totalcells;
for (int z=sz; z<=ez; ++z) {
int aidx=map[idx++];
- counts[2*aidx + 1]++;
+ //mutex.lock();
+ // countsTemp[2*aidx + 1]++;
+ counts[2*aidx+1]++;
+ //mutex.unlock();
}
}
}
data += nvars;
}
-
+ // mutex.lock();
+ // for(int i = 0; i < 2*totalsize; i++)
+ // counts[i] += countsTemp[i];
+ // mutex.unlock();
+ // barrier.wait(numProcs);
+ // if (proc == 0) {
cerr<<" 2/6: Counting cells took "<<timer.time()<<" seconds\n";
-
int total=0;
for (int i=0; i<totalsize; ++i) {
int count=counts[2*i + 1];
@@ -350,9 +430,8 @@
}
cerr<<"Done building GridSpheres\n";
-
- _ao = new AmbientOcclusion(Color(RGB(1,1,1)), 0.01f, 10);
- _ao->preprocess(context);
+
+ //}
}
void CDGridSpheres::computeBounds(const PreprocessContext& context,
@@ -546,25 +625,26 @@
}
void CDGridSpheres::computeNormal(const RenderContext& context,
- RayPacket&
rays) const
+ RayPacket& rays) const
{
- rays.computeHitPositions();
- for (int i=int(rays.begin()); i<int(rays.end()); ++i) {
- float* data=spheres + rays.scratchpad<int>(i);
- Vector n=rays.getHitPosition(i) - Vector(data[0], data[1],
data[2]);
-
- if (ridx>0) {
- if (data[ridx] <= 0)
- n *= inv_radius;
- else
- n.normalize();
- } else {
- n *= inv_radius;
- }
- rays.setNormal(i, n);
- }
+ rays.computeHitPositions();
+ for (int i=int(rays.begin()); i<int(rays.end()); ++i) {
+ float* data=spheres + rays.scratchpad<int>(i);
+ Vector n=rays.getHitPosition(i) - Vector(data[0], data[1], data[2]);
+
+/*if (ridx>0) {
+ if (data[ridx] <= 0.0)
+ n *= inv_radius;
+ else
+ n.normalize();
+ } else {
+ n *= inv_radius;
+ }*/
+n.normalize();
+ rays.setNormal(i, n);
+ }
- rays.setFlag(RayPacket::HaveUnitNormals);
+ rays.setFlag(RayPacket::HaveUnitNormals);
}
void CDGridSpheres::shade(const RenderContext& context, RayPacket& rays)
const
@@ -652,17 +732,12 @@
{
float dataMin = min[index];
float dataMax = max[index];
- cout << "histogram dataMin/max: " << dataMin << " " << dataMax <<
endl;
float scale = (numBuckets-1)/(dataMax - dataMin);
for(int i = 0; i < numBuckets; i++)
histValues[i] = 0;
- cout << "nspheres: " << nspheres << endl;
for(int i = 0; i < nspheres; i++)
{
float val = *(spheres + i*nvars + index);
- static int count = 0;
- if (count++ < 100)
- cout << "val: " << val << endl;
int bucket = int((val-dataMin)*scale);
histValues[bucket]++;
}
Modified: trunk/scenes/csafe/src/CDGridSpheres.h
==============================================================================
--- trunk/scenes/csafe/src/CDGridSpheres.h (original)
+++ trunk/scenes/csafe/src/CDGridSpheres.h Wed Oct 22 10:10:53 2008
@@ -1,7 +1,7 @@
//! Filename: CDGridSpheres.h
/*!
- same as Gridspheres, but with small changes to incorporate csafe demo.
TODO: incorporate changes into main Gridspheres file
- */
+ same as Gridspheres, but with small changes to incorporate csafe demo.
TODO: incorporate changes into main Gridspheres file
+*/
#ifndef Manta_Model_CDGridSpheres_h
#define Manta_Model_CDGridSpheres_h
@@ -15,6 +15,8 @@
#include <Model/Materials/LitMaterial.h>
#include <Model/Materials/AmbientOcclusion.h>
#include <Model/Materials/Volume.h>
+#include <Core/Thread/Barrier.h>
+#include <Core/Thread/Mutex.h>
#include <iostream>
@@ -22,135 +24,144 @@
#define USE_OPTIMIZED_FCNS
namespace Manta {
- class RegularColorMap;
+ class RegularColorMap;
- class CDGridSpheres : public PrimitiveCommon, public LitMaterial,
- public TexCoordMapper, public Texture<Color>
- {
- public:
- CDGridSpheres(float* spheres, int nspheres, int nvars, int
ncells, int depth,
- Real radius, int ridx,
RGBAColorMap* cmap, int cidx);
- ~CDGridSpheres(void);
-
- void preprocess(const PreprocessContext&);
-
- void computeBounds(const PreprocessContext& context,
- BBox& bbox) const;
- void intersect(const RenderContext& context, RayPacket& rays)
const;
- void computeNormal(const RenderContext& context, RayPacket&
rays) const;
-
- virtual void shade(const RenderContext& context, RayPacket&
rays) const;
-
- void computeTexCoords2(const RenderContext& context,
- RayPacket& rays)
const;
- void computeTexCoords3(const RenderContext& context,
- RayPacket& rays)
const;
- void setCMinMax(int index, float min, float max) {
cmin[index] = min; cmax[index] = max; }
- void getCMinMax(int index, float& min, float& max) { min =
cmin[index]; max = cmax[index]; }
- void computeHistogram(int index, int numBuckets, int*
histValues); //index is data index to use. histValues should be of size
numBuckets
- void getMinMax(int index, float& dmin, float&dmax)
- {
- dmin = min[index];
- dmax = max[index];
- }
- void setCidx(int cidx) { this->cidx = cidx; }
- void setCMap(RGBAColorMap* map) { cmap = map; }
- bool clip(int s) const;
- void setClipMinMax(int index, float clipMin, float clipMax)
- {
- std::cout << "setting clipmin/max: " << clipMin << " " <<
clipMax << std::endl;
- clipMins[index] = clipMin;
- clipMaxs[index] = clipMax;
- }
- void useAmbientOcclusion(bool st) { _useAmbientOcclusion = st; }
- void setAmbientOcclusionVariables(float cutoff, int numDirs) { if
(_ao) { _ao->setCutoffDistance(cutoff); _ao->setNumRays(numDirs); } }
+ class CDGridSpheres : public PrimitiveCommon, public LitMaterial,
+ public TexCoordMapper, public Texture<Color>
+ {
+ public:
+ CDGridSpheres(float* spheres, int nspheres, int nvars, int ncells, int
depth,
+ Real radius, int ridx, RGBAColorMap* cmap, int cidx);
+ ~CDGridSpheres(void);
+
+ void preprocess(const PreprocessContext&);
+
+ void computeBounds(const PreprocessContext& context,
+ BBox& bbox) const;
+ void intersect(const RenderContext& context, RayPacket& rays) const;
+ void computeNormal(const RenderContext& context, RayPacket& rays)
const;
+
+ virtual void shade(const RenderContext& context, RayPacket& rays)
const;
+
+ void computeTexCoords2(const RenderContext& context,
+ RayPacket& rays) const;
+ void computeTexCoords3(const RenderContext& context,
+ RayPacket& rays) const;
+ void setCMinMax(int index, float min, float max) { cmin[index] = min;
cmax[index] = max; }
+ void getCMinMax(int index, float& min, float& max) { min =
cmin[index]; max = cmax[index]; }
+ void computeHistogram(int index, int numBuckets, int* histValues);
//index is data index to use. histValues should be of size numBuckets
+ void getMinMax(int index, float& dmin, float&dmax)
+ {
+ dmin = min[index];
+ dmax = max[index];
+ }
+ void setCidx(int cidx) { this->cidx = cidx; }
+ void setCMap(RGBAColorMap* map) { cmap = map; }
+ bool clip(int s) const;
+ void setClipMinMax(int index, float clipMin, float clipMax)
+ {
+ clipMins[index] = clipMin;
+ clipMaxs[index] = clipMax;
+ }
+ void useAmbientOcclusion(bool st) { _useAmbientOcclusion = st; }
+ void setAmbientOcclusionVariables(float cutoff, int numDirs) { if
(_ao) { _ao->setCutoffDistance(cutoff); _ao->setNumRays(numDirs); } }
- protected:
+ protected:
#ifdef USE_OPTIMIZED_FCNS
- typedef void (CDGridSpheres::*SphereIntersectFcn)(RayPacket&,
int, int,
-
const Vector&, float) const;
+ typedef void (CDGridSpheres::*SphereIntersectFcn)(RayPacket&, int, int,
+ const Vector&,
float) const;
#endif
- struct MCell {
- int nspheres;
- float* max;
- float* min;
- };
-
- void traverse(int i, RayPacket& rays, int depth,
- Real tnear,
- int ix, int iy, int iz,
- int idx,
- Real dt_dx, Real dt_dy, Real dt_dz,
- Real tnext_x, Real tnext_y, Real
tnext_z,
- const Vector& corner, const Vector&
celldir,
- int di_dx, int di_dy, int di_dz,
- int didx_dx, int didx_dy,
+ struct MCell {
+ int nspheres;
+ float* max;
+ float* min;
+ };
+
+ void traverse(int i, RayPacket& rays, int depth,
+ Real tnear,
+ int ix, int iy, int iz,
+ int idx,
+ Real dt_dx, Real dt_dy, Real dt_dz,
+ Real tnext_x, Real tnext_y, Real tnext_z,
+ const Vector& corner, const Vector& celldir,
+ int di_dx, int di_dy, int di_dz,
+ int didx_dx, int didx_dy,
#ifdef USE_OPTIMIZED_FCNS
- int didx_dz, int stop_x, int
stop_y, int stop_z,
- SphereIntersectFcn intersectSphere)
const;
+ int didx_dz, int stop_x, int stop_y, int stop_z,
+ SphereIntersectFcn intersectSphere) const;
#else
- int didx_dz, int stop_x, int stop_y, int stop_z) const;
+ int didx_dz, int stop_x, int stop_y, int stop_z) const;
#endif // USE_OPTIMIZED_FCNS
- void transformToLattice(const BBox& box, int& sx, int& sy,
int& sz,
- int& ex, int&
ey, int& ez) const;
- int mapIdx(int ix, int iy, int iz, int depth);
- void fillMCell(MCell& mcell, int depth, int startidx) const;
- void mapDiffuseColors(Packet<Color>& diffuse, RayPacket&
rays) const;
+ void transformToLattice(const BBox& box, int& sx, int& sy, int& sz,
+ int& ex, int& ey, int& ez) const;
+ int mapIdx(int ix, int iy, int iz, int depth);
+ void fillMCell(MCell& mcell, int depth, int startidx) const;
+ void mapDiffuseColors(Packet<Color>& diffuse, RayPacket& rays) const;
#ifdef USE_OPTIMIZED_FCNS
- // Sphere intersection functions
- void intersectSphereCOND(RayPacket& rays, int ray_idx, int
idx,
- const
Vector& center, float radius2) const;
- void intersectSphereCO(RayPacket& rays, int ray_idx, int idx,
- const Vector&
center, float radius2) const;
- void intersectSphereND(RayPacket& rays, int ray_idx, int idx,
- const Vector&
center, float radius2) const;
+ // Sphere intersection functions
+ void intersectSphereCOND(RayPacket& rays, int ray_idx, int idx,
+ const Vector& center, float radius2) const;
+ void intersectSphereCO(RayPacket& rays, int ray_idx, int idx,
+ const Vector& center, float radius2) const;
+ void intersectSphereND(RayPacket& rays, int ray_idx, int idx,
+ const Vector& center, float radius2) const;
#endif // USE_OPTIMIZED_FCNS
- void intersectSphereDefault(RayPacket& rays, int ray_idx, int
idx,
- const
Vector& center, float radius2) const;
+ void intersectSphereDefault(RayPacket& rays, int ray_idx, int idx,
+ const Vector& center, float radius2) const;
- void lambertianShade(const RenderContext& context, RayPacket&
rays,
- ColorArray&
totalLight) const;
-void mapValues(Packet<Color>& results,
- const RenderContext&,
- RayPacket& rays) const;
+ void lambertianShade(const RenderContext& context, RayPacket& rays,
+ ColorArray& totalLight) const;
+ void mapValues(Packet<Color>& results,
+ const RenderContext&,
+ RayPacket& rays) const;
+
+ void update(int, int);
+ void updateStatic(int, int);
-protected:
- float* spheres;
- int nspheres;
- int nvars;
- Real radius;
- Real inv_radius;
- int ridx;
-
- Vector diagonal;
- Vector inv_diagonal;
- int totalcells;
-
- int* counts;
- int* cells;
- float* min;
- float* max;
- float* cmin; //specified min/max values to override actual
ones(used for coloring)
- float* cmax;
- float* clipMins; //clip data by these values (array of nvars
size)
- float* clipMaxs;
- BBox bounds;
-
- int ncells;
- int depth;
- Real inv_ncells;
-
- MCell** macrocells;
-
- RGBAColorMap* cmap;
- int cidx;
- AmbientOcclusion* _ao;
- bool _useAmbientOcclusion;
- Material* _matl;
- };
+ protected:
+ mutable Barrier barrier;
+ mutable Mutex mutex;
+ float* spheres;
+ int nspheres;
+ int nvars;
+ Real radius;
+ Real inv_radius;
+ int ridx;
+
+ Vector diagonal;
+ Vector inv_diagonal;
+ int totalcells;
+
+ int* counts;
+ int* cells;
+ float* min;
+ float* max;
+ float* cmin; //specified min/max values to override actual ones(used for
coloring)
+ float* cmax;
+ float* clipMins; //clip data by these values (array of nvars size)
+ float* clipMaxs;
+ BBox bounds;
+
+ int ncells;
+ int depth;
+ Real inv_ncells;
+
+ MCell** macrocells;
+
+ RGBAColorMap* cmap;
+ int cidx;
+ AmbientOcclusion* _ao;
+ bool _useAmbientOcclusion;
+ Material* _matl;
+
+ static CDGridSpheres** __grids;
+ static int __numGrids;
+ static bool* __processedGrids;
+
+};
}
#endif
Modified: trunk/scenes/csafe/src/CDTest.h
==============================================================================
--- trunk/scenes/csafe/src/CDTest.h (original)
+++ trunk/scenes/csafe/src/CDTest.h Wed Oct 22 10:10:53 2008
@@ -211,20 +211,37 @@
Vector size = max - min;
setVolumePositionSize(pos,size);
}
+ Vector tempMin, tempMax;
void setClippingBBox(Vector min, Vector max)
{
+ tempMin = min; tempMax = max;
+ _manta_interface->addOneShotCallback(MantaInterface::Relative, 1,
Callback::create(this, &CDTest::setClippingBBoxHelper));
+ }
+ void setClippingBBoxHelper(int, int)
+ {
+ Vector min = tempMin;
+ Vector max = tempMax;
for(int i =0; i < 3; i++)
- setClipMinMax(i, min[i], max[i]);
+ setClipMinMax(i, min[i], max[i]);
Vector minB(_minBound);
Vector maxB(_maxBound);
for(int i=0;i<3;i++)
{
minB[i] = std::max(min[i], minB[i]);
maxB[i] = std::min(max[i], maxB[i]);
+ if (minB[i] >= maxB[i])
+ minB[i] = maxB[i] - T_EPSILON;
}
for(int i = 0; i < int(_volPrims.size()); i++)
{
- _volPrims[i]->setMinMax(minB, maxB);
+ BBox bounds = _vols[i]->getBounds();
+ Vector tmin = minB;
+ Vector tmax = maxB;
+ for(int j = 0; j < 3; j++){
+ tmin[j] = std::max(minB[j], bounds[0][j]) + T_EPSILON;
+ tmax[j] = std::min(maxB[j], bounds[1][j]) - T_EPSILON;
+ }
+ _volPrims[i]->setMinMax(tmin, tmax);
}
}
void useClippingBBox(bool st)
@@ -339,7 +356,7 @@
#if USE_GRIDSPHERES
RGBAColorMap* cmap = new RGBAColorMap(1);
- CDGridSpheres* grid = new CDGridSpheres(pnrrd->getParticleData(),
pnrrd->getNParticles(), pnrrd->getNVars(), 6, 2,_radius, _ridx, cmap ,
_cidx);
+ CDGridSpheres* grid = new CDGridSpheres(pnrrd->getParticleData(),
pnrrd->getNParticles(), pnrrd->getNVars(), 4, 2,_radius, _ridx, cmap ,
_cidx);
//grid->setCMinMax(4, 299.50411987304688, 500.59423828125);
//Material* matl = new Phong(Color(RGB(1,0,0)), Color(RGB(1,0,0)),
10);
//Material* matl = new AmbientOcclusion(colormap, 0.01, 10);
@@ -434,9 +451,24 @@
{
cout << "Loading Nrrd file: " << *i << "..." << endl;
Group* group = new Group();
- Volume<float>* mat = new Volume<float>(loadNRRDToGrid<float>(*i),
_volCMap, BBox(_minBound, _maxBound), 0.00125, 3, _forceDataMin,
_forceDataMax);
- Cube* vol = new Cube(mat, _minBound, _maxBound);
- group->add(vol);
+ vector<pair<string, string> > keyValuePairs;
+ Vector min = _minBound;
+ Vector max = _maxBound;
+ GridArray3<float>* grid = loadNRRDToGrid<float>(*i,
&keyValuePairs);
+ for(vector<pair<string, string> >::iterator itr =
keyValuePairs.begin(); itr != keyValuePairs.end(); itr++) {
+ if (itr->first == "extents") {
+ cout << "parsing keyvalue: \"" << itr->first << "\" \"" <<
itr->second
+ << "\"\n";
+ sscanf(itr->second.c_str(), "[%f %f %f]..[%f %f %f]",
+ &min[0], &min[1], &min[2], &max[0], &max[1], &max[2]);
+ printf("\nfound extent: %f %f %f .. %f %f %f\n", min[0],
min[1],
+ min[2], max[0], max[1], max[2]);
+ }
+ }
+ Volume<float>* mat = new Volume<float>(grid, _volCMap, BBox(min,
max), 0.00125, 3, NULL, _forceDataMin, _forceDataMax);
+ Cube* vol = new Cube(mat, min, max);
+ group->add(vol);
+ //# group->add(vol);
_volAnimation->push_back(group);
_vols.push_back(mat);
_volPrims.push_back(vol);
@@ -446,6 +478,7 @@
updateFrames();
if (_clipFrames && _endFrame < int(_vols.size()))
_volAnimation->clipFrames(_startFrame, _endFrame);
+ setClippingBBox(Vector(-1,-1,-1), Vector(1,1,1));
}
void readUDAHeader(string directory)
{
@@ -501,7 +534,7 @@
numFrames1++;
Group* group2 = new Group();
- Volume<float>* mat = new Volume<float>(itr->volume, _volCMap,
BBox(_minBound, _maxBound), 0.00125, 3, _forceDataMin, _forceDataMax);
+ Volume<float>* mat = new Volume<float>(itr->volume, _volCMap,
BBox(_minBound, _maxBound), 0.00125, 3, NULL, _forceDataMin, _forceDataMax);
Cube* vol = new Cube(mat, _minBound - Vector(0.001, 0.001, 0.001),
_maxBound + Vector(0.001, 0.001, 0.001));
group2->add(vol);
_volAnimation->push_back(group2);
@@ -664,7 +697,6 @@
{
float val = *(pnrrd->getParticleData() + j*pnrrd->getNVars() +
index);
int bucket = int((val-dataMin)*scale);
- static int count = 0; if (val > 0.06 && count++ < 20) cout <<
"val: " << val << " " << bucket << endl;
histValues[bucket]++;
}
}
@@ -987,13 +1019,13 @@
}
void setVolumePositionSizeHelper(int, int)
{
- BBox bounds(_volPosition - _volSize/2.0, _volPosition + _volSize/2.0);
+ /* BBox bounds(_volPosition - _volSize/2.0, _volPosition +
_volSize/2.0);
for(vector<Volume<float>*>::iterator itr = _vols.begin(); itr !=
_vols.end(); itr++) {
(*itr)->setBounds(bounds);
}
for(vector<Cube*>::iterator itr = _volPrims.begin(); itr !=
_volPrims.end(); itr++) {
(*itr)->setMinMax(bounds.getMin(), bounds.getMax());
- }
+ }*/
}
MantaInterface* _manta_interface;
- [Manta] r2335 - in trunk: Model/MiscObjects Model/Readers SwigInterface UserInterface scenes/csafe/python scenes/csafe/src, brownlee, 10/22/2008
Archive powered by MHonArc 2.6.16.