Text archives Help
- From: "Thiago Ize" <thiago@sci.utah.edu>
- To: manta@sci.utah.edu
- Subject: [Manta] r2267 - in trunk: Core/Geometry Engine/Factory Model/Cameras Model/Groups Model/Materials scenes scenes/csafe/src
- Date: Sat, 24 May 2008 18:04:47 -0600 (MDT)
Author: thiago
Date: Sat May 24 18:04:45 2008
New Revision: 2267
Modified:
trunk/Core/Geometry/BBox.h
trunk/Engine/Factory/RegisterKnownComponents.cc
trunk/Model/Cameras/FisheyeCamera.cc
trunk/Model/Groups/RecursiveGrid.cc
trunk/Model/Groups/RecursiveGrid.h
trunk/Model/Materials/CMakeLists.txt
trunk/Model/Materials/Volume.h
trunk/scenes/csafe/src/CDTest.h
trunk/scenes/volumeTest.cc
Log:
scenes/csafe/src/CDTest.h:
-updated to use the modified Volume constructor.
-automatically removed tabs.
scenes/volumeTest.cc:
-updated to use the modified Volume constructor.
Core/Geometry/BBox.h:
-Added a bool contains(point) function.
Model/Groups/RecursiveGrid:
-fixed a possible race condition.
-Modified constructor to also take a mesh.
Model/Materials/CMakeLists.txt:
-Volume does not need sse and teem.
Model/Materials/Volume.h:
-Code cleanup. Removed unused data members and variables. Removed
code that is already done by other classes (i.e. no need to compute
the bbox diagonal, just use the bbox's diagonal function).
-Fixed some hangs and segfault bugs. So far it now looks to be
solid (or at least more solid).
-Volume is now rendered if you are inside the volume. Of course,
this requires that the ray hit the primitive containing the
volume. This might not happen if there's geometry inside the
volume.
Model/Cameras/FisheyeCamera.cc:
-You can now create a fisheye camera that doesn't take any
parameters. This means you can use this to set up an initial camera
bookmark.
Engine/Factory/RegisterKnownComponents.cc
-FisheyeCamera and EnvironmentCamera were disabled for some
reason. I'm reenabling them until someone can tell me why they
should be disabled.
Modified: trunk/Core/Geometry/BBox.h
==============================================================================
--- trunk/Core/Geometry/BBox.h (original)
+++ trunk/Core/Geometry/BBox.h Sat May 24 18:04:45 2008
@@ -126,6 +126,13 @@
return d.y() > d.z() ? 1 : 2;
}
+ bool contains(const Vector &p) const {
+ return
+ (p[0] >= bounds[0][0] && p[0] <= bounds[1][0]) &&
+ (p[1] >= bounds[0][1] && p[1] <= bounds[1][1]) &&
+ (p[2] >= bounds[0][2] && p[2] <= bounds[1][2]);
+ }
+
#ifndef SWIG
inline Vector &operator[] (int i) { return bounds[i]; }
inline const Vector &operator[] (int i) const { return bounds[i]; }
Modified: trunk/Engine/Factory/RegisterKnownComponents.cc
==============================================================================
--- trunk/Engine/Factory/RegisterKnownComponents.cc (original)
+++ trunk/Engine/Factory/RegisterKnownComponents.cc Sat May 24 18:04:45
2008
@@ -134,11 +134,11 @@
engine->registerComponent("edges", &NPREdges::create);
// Register cameras
- //engine->registerComponent("environment", &EnvironmentCamera::create);
+ engine->registerComponent("environment", &EnvironmentCamera::create);
engine->registerComponent("pinhole", &PinholeCamera::create);
engine->registerComponent("orthogonal", &OrthogonalCamera::create);
engine->registerComponent("thinlens", &ThinLensCamera::create);
- //engine->registerComponent("fisheye", &FisheyeCamera::create);
+ engine->registerComponent("fisheye", &FisheyeCamera::create);
// Register shadow algorithms
engine->registerComponent("noshadows", &NoShadows::create);
Modified: trunk/Model/Cameras/FisheyeCamera.cc
==============================================================================
--- trunk/Model/Cameras/FisheyeCamera.cc (original)
+++ trunk/Model/Cameras/FisheyeCamera.cc Sat May 24 18:04:45 2008
@@ -24,62 +24,47 @@
{
haveCamera = true;
setup();
- // NOTE(boulos): Someone (Andrew?) should mention why this division
- // by 90 is being done.
- hfov = hfov / 90;
- vfov = vfov / 90;
}
FisheyeCamera::FisheyeCamera(const vector<string>& args)
{
haveCamera = false;
- bool gotEye = false;
- bool gotLookat = false;
- bool gotFov = false;
- bool gotUp = false;
+ eye = Vector ( 3, 3, 2 );
+ lookat = Vector ( 0, 0, (Real)0.3 );
+ up = Vector( 0, 0, 1 );
+ vfov = hfov = 60;
for(size_t i=0; i< args.size(); i++){
string arg = args[i];
if(arg == "-eye"){
if(!getVectorArg(i, args, eye))
throw IllegalArgument("FisheyeCamera -eye", i, args);
- gotEye = true;
haveCamera = true;
} else if(arg == "-lookat"){
if(!getVectorArg(i, args, lookat))
throw IllegalArgument("FisheyeCamera -lookat", i, args);
- gotLookat = true;
haveCamera = true;
} else if(arg == "-up"){
if(!getVectorArg(i, args, up))
throw IllegalArgument("FisheyeCamera -up", i, args);
- gotUp = true;
haveCamera = true;
} else if(arg == "-fov"){
if(!getArg<Real>(i, args, hfov))
throw IllegalArgument("FisheyeCamera -fov", i, args);
vfov = hfov;
- gotFov = true;
haveCamera = true;
} else if(arg == "-hfov"){
if(!getArg<Real>(i, args, hfov))
throw IllegalArgument("FisheyeCamera -hfov", i, args);
- gotFov = true;
haveCamera = true;
} else if(arg == "-vfov"){
if(!getArg<Real>(i, args, vfov))
throw IllegalArgument("FisheyeCamera -vfov", i, args);
- gotFov = true;
haveCamera = true;
} else {
throw IllegalArgument("FisheyeCamera", i, args);
}
}
- // TODO(boulos): Separate the gotFov into gotVfov and gotHfov
- if(!gotEye || !gotLookat || !gotUp || !gotFov)
- throw IllegalArgument("FisheyeCamera needs -eye -lookat -up and -fov",
0, args);
setup();
- hfov /= 90;
- vfov /= 90;
}
FisheyeCamera::~FisheyeCamera()
@@ -119,7 +104,7 @@
Real imageY = rays.getImageCoordinates(i, 1);
Real z = Sqrt( 2 - imageX * imageX - imageY * imageY );
Real theta = Atan2( imageY, imageX );
- Real phi = Acos( z * (Real)M_SQRT1_2 ) * hfov;
+ Real phi = Acos( z * (Real)(M_SQRT1_2) ) * hfov *
(Real)0.0111111111111111;
Real x = Cos( theta ) * Sin( phi );
Real y = Sin( theta ) * Sin( phi );
z = Cos( phi );
@@ -130,7 +115,7 @@
void FisheyeCamera::scaleFOV(Real scale)
{
Real fov_min = 0;
- Real fov_max = 4;
+ Real fov_max = 360;
hfov = scale*hfov;
hfov = Clamp(hfov, fov_min, fov_max);
vfov = scale*vfov;
@@ -190,7 +175,7 @@
Real w=diag.length();
Vector lookdir(eye-lookat);
lookdir.normalize();
- Real scale = 1/(2*tan(DtoR(hfov*45)));
+ Real scale = 1/(2*tan(DtoR(hfov*.5)));
Real length = w*scale;
lookat = bbox.center();
eye = lookat+lookdir*length;
@@ -201,8 +186,8 @@
os << "fisheye( -eye " << eye
<< " -lookat " << lookat
<< " -up " << up
- << " -hfov " << hfov*90
- << " -vfov " << vfov*90
+ << " -hfov " << hfov
+ << " -vfov " << vfov
<< ")"
<< std::endl;
}
@@ -248,7 +233,9 @@
setBasicCameraData(*bookmark);
haveCamera = true;
} else {
+ cout <<hfov<<" ";
hfov = 90;
+ cout <<hfov<<"\n";
BBox bbox;
scene->getObject()->computeBounds(context, bbox);
autoview(bbox);
Modified: trunk/Model/Groups/RecursiveGrid.cc
==============================================================================
--- trunk/Model/Groups/RecursiveGrid.cc (original)
+++ trunk/Model/Groups/RecursiveGrid.cc Sat May 24 18:04:45 2008
@@ -26,8 +26,8 @@
double RecursiveGrid::nFilledCells=0;
double RecursiveGrid::nTriRefs=0;
-RecursiveGrid::RecursiveGrid(int numLevels) :
- lists(NULL), currGroup(NULL), mesh(NULL), numLevels(numLevels)
+RecursiveGrid::RecursiveGrid(int numLevels, Mesh *mesh) :
+ lists(NULL), currGroup(NULL), mesh(mesh), numLevels(numLevels)
{
}
@@ -69,7 +69,6 @@
context.manta_interface->registerSerialPreRenderCallback(
Callback::create(this, &RecursiveGrid::update));
#endif
-
}
void RecursiveGrid::setGroup(Group* new_group)
@@ -91,8 +90,10 @@
mutex.lock();
//We only support serial builds right now.
- if (proc != 0)
+ if (proc != 0) {
+ mutex.unlock();
return;
+ }
bounds.reset();
@@ -118,6 +119,8 @@
printf("Recursive Grid built in %f seconds for a %d object scene\n", dt,
(int)currGroup->size());
printf("There are %ld, %ld, %ld, %ld grids per level for a total of %ld
cells\n",
nGrids[0], nGrids[1], nGrids[2], nGrids[3], nCells);
+ printf("%d x %d x %d\n", cells.getNx(), cells.getNy(), cells.getNz());
+
mutex.unlock();
}
@@ -358,7 +361,7 @@
// cout <<"diag: " <<diag << endl;
// }
if (m > 1e20) {
- printf("m > 1e20");
+ printf("m > 1e20. %lf", vol3 );
break;//exit(1);
}
}
@@ -460,8 +463,7 @@
}
cellBounds.intersection(objBounds);
- RecursiveGrid *gg = new RecursiveGrid(numLevels);
- gg->mesh = mesh;
+ RecursiveGrid *gg = new RecursiveGrid(numLevels, mesh);
gg->build(context, cell_objects(x,y,z), cellBounds, depth+1,
totalObjects);
int start = cells(x, y, z);
lists[start] = gg;
Modified: trunk/Model/Groups/RecursiveGrid.h
==============================================================================
--- trunk/Model/Groups/RecursiveGrid.h (original)
+++ trunk/Model/Groups/RecursiveGrid.h Sat May 24 18:04:45 2008
@@ -14,7 +14,7 @@
namespace Manta {
class RecursiveGrid : public AccelerationStructure {
public:
- RecursiveGrid(int numLevels = 3);
+ RecursiveGrid(int numLevels = 3, Mesh *mesh=NULL);
virtual ~RecursiveGrid();
void setGroup(Group* new_group);
@@ -35,15 +35,18 @@
bbox.extendByBox(bounds);
}
- private:
+ //These two functions are supposed to be protected...
+ virtual void build(const PreprocessContext &context, const
vector<Object*> &objs,
+ const BBox &bounds, const int depth, int
totalObjects);
+ virtual void intersectRay( const RenderContext &context, RayPacket &rays
) const;
+
+ protected:
void clearGrid();
RecursiveGrid(const RecursiveGrid&);
RecursiveGrid& operator=(const RecursiveGrid&);
- void build(const PreprocessContext &context, const vector<Object*> &objs,
- const BBox &bounds, const int depth, int totalObjects);
- void intersectRay( const RenderContext &context, RayPacket &rays ) const;
+
//for performance measurements. Can be removed.
// #define COLLECT_STATS
Modified: trunk/Model/Materials/CMakeLists.txt
==============================================================================
--- trunk/Model/Materials/CMakeLists.txt (original)
+++ trunk/Model/Materials/CMakeLists.txt Sat May 24 18:04:45 2008
@@ -33,17 +33,5 @@
Materials/ThinDielectric.cc
Materials/Transparent.cc
Materials/Transparent.h
- )
-
-IF(MANTA_SSE AND FOUND_TEEM_BIN)
-
- # Needed by Readers/VolumeNRRD.h a dependency of Volume.h
- INCLUDE_DIRECTORIES(${TEEM_INCLUDE_DIRS})
-
- SET (Manta_Materials_SRCS
- ${Manta_Materials_SRCS}
- Materials/Volume.h
- Materials/Volume.cc
- )
-ENDIF(MANTA_SSE AND FOUND_TEEM_BIN)
-
+ Materials/Volume
+ )
Modified: trunk/Model/Materials/Volume.h
==============================================================================
--- trunk/Model/Materials/Volume.h (original)
+++ trunk/Model/Materials/Volume.h Sat May 24 18:04:45 2008
@@ -12,11 +12,6 @@
#include <Core/Containers/GridArray3.h>
#include <Core/Geometry/BBox.h>
#include <Core/Geometry/Vector.h>
-#include <Core/Thread/Barrier.h>
-#include <Core/Thread/Mutex.h>
-#include <Core/Thread/Thread.h>
-#include <Core/Thread/Time.h>
-#include <Core/Util/AlignedAllocator.h>
#include <Interface/Context.h>
#include <Interface/Material.h>
@@ -24,15 +19,11 @@
#include <Interface/RayPacket.h>
#include <Interface/SampleGenerator.h>
#include <Interface/Scene.h>
-#include <Model/Readers/ParticleNRRD.h>
-#include <Model/Materials/OpaqueShadower.h>
#include <cassert>
#include <float.h>
#include <vector>
-
-#include <assert.h>
-//#include "SIMD.hxx"
+#include <iostream>
using namespace std;
namespace Manta
@@ -102,16 +93,6 @@
float _min, _max, _invRange;
};
- struct MANTA_ALIGN(16) Box4: public AlignedAllocator<Box4>
- {
- sse_t min, max;
- sse_t diameter() const { return sub4(max,min); }
- };
- //std::ostream &operator<< (std::ostream &o, const Box4 &v) {
- // o << "(" << v.min << ".." << v.max << ")";
- // return o;
- //}
-
struct VMCell
{
// Need to make sure we have a 64 bit thing
@@ -163,107 +144,58 @@
VMCell cell;
};
- const int packetSize = 32; //TODO: look this up
- const int numPacklets = 32/4;
- struct RayPacketInfo {
- sse_union minTs[numPacklets];
- sse_union maxTs[numPacklets];
- sse_union currTs[numPacklets];
- sse_union alphas[numPacklets];
- Color accumColors[numPacklets][4];
- Color bgColor[numPacklets][4];
- sse_union latticePositions_x[numPacklets];
- sse_union latticePositions_y[numPacklets];
- sse_union latticePositions_z[numPacklets];
- sse_union steps_x[numPacklets]; //lattice steps per sample
- sse_union steps_y[numPacklets];
- sse_union steps_z[numPacklets];
- sse_union dir_x[numPacklets];
- sse_union dir_y[numPacklets];
- sse_union dir_z[numPacklets];
- sse_t steps_kt[numPacklets]; // stepping t values along slices
-
- };
-
template<class T>
- class Volume : public Material, public AlignedAllocator<Volume<T> >
- {
- protected:
- class HVIsectContext {
- public:
- // These parameters could be modified and hold accumulating state
- Color total;
- float alpha;
- // These parameters should not change
- int dix_dx, diy_dy, diz_dz;
- VMCell transfunct;
- double t_inc;
- double t_min;
- double t_max;
- double t_inc_inv;
- Ray ray;
- //RenderContext *cx;
- };
+ class Volume : public Material
+ {
+ protected:
+ class HVIsectContext {
public:
- Box4 bounds;
- sse_t sse_M, sse_N;
- sse_t sse_one_over_N;
- sse_t diam, // diameter of grid
- scale, // 1 / diam
- scaleM, // scale * M
- scaleN; // scale * N == N / diam == number of cells per unit
distance
- //length of cell in k direction divided by u or v direction cell
length.
- sse_t pcDuStretch[3];
- sse_t pcDvStretch[3];
-
- int N[3]; // grid resolution
- int M[3]; //N - 1
- int oldN[3];
-
- int N_mc[3]; // grid resolution
- int M_mc[3]; //N - 1
-
- static float resolutionFactor;
-
- float splitLength; //above this length we split packets.
-
- vector <CellData> cellVector;
-
- static void newFrame();
- typedef unsigned long long mcT;
- vector<mcT> cellVector_mc; // color hashes
-
- // float cellStepSize, float metersPerUnit);
- Volume(GridArray3<T>* data, RGBAColorMap* colorMap, const Vector&
minBound, const Vector& maxBound, double cellStepSize, double metersPerUnit,
int depth, double forceDataMin = -FLT_MAX, double forceDataMax = -FLT_MAX);
- virtual ~Volume();
- void setColorMap(RGBAColorMap* map) { _colorMap = map; }
- void getMinMax(double* min, double* max){ *min = _dataMin; *max =
_dataMax; }
- void computeHistogram(int numBuckets, int* histValues);
- virtual void preprocess(const PreprocessContext& context);
- virtual void shade(const RenderContext & context, RayPacket& rays)
const;
- virtual void attenuateShadows(const RenderContext& context, RayPacket&
shadowRays) const;
- GridArray3<T>* _data;
- float getValue(int x, int y, int z);
- GridArray3<VMCell>* macrocells;
- void calc_mcell(int depth, int ix, int iy, int iz, VMCell& mcell);
- void parallel_calc_mcell(int cell);
- void isect(int depth, double t_sample,
- double dtdx, double dtdy, double dtdz,
- double next_x, double next_y, double next_z,
- int ix, int iy, int iz,
- int startx, int starty, int startz,
- const Vector& cellcorner, const Vector& celldir,
- HVIsectContext &isctx) const;
- inline void SamplePacklet(RayPacketInfo& packetInfo, int packlet,
sse_t maxTs) const;
- Vector diag;
- Vector inv_diag;
- protected:
+ // These parameters could be modified and hold accumulating state
+ Color total;
+ float alpha;
+ // These parameters should not change
+ int dix_dx, diy_dy, diz_dz;
+ VMCell transfunct;
+ double t_inc;
+ double t_min;
+ double t_max;
+ double t_inc_inv;
+ Ray ray;
+ //RenderContext *cx;
+ };
+ public:
+ static void newFrame();
+ typedef unsigned long long mcT;
+ vector<mcT> cellVector_mc; // color hashes
+
+ Volume(GridArray3<T>* data, RGBAColorMap* colorMap, const BBox& bounds,
+ double cellStepSize, int depth,
+ double forceDataMin = -FLT_MAX, double forceDataMax = -FLT_MAX);
+ virtual ~Volume();
+ void setColorMap(RGBAColorMap* map) { _colorMap = map; }
+ void getMinMax(double* min, double* max){ *min = _dataMin; *max =
_dataMax; }
+ void computeHistogram(int numBuckets, int* histValues);
+ virtual void preprocess(const PreprocessContext& context);
+ virtual void shade(const RenderContext & context, RayPacket& rays) const;
+ virtual void attenuateShadows(const RenderContext& context, RayPacket&
shadowRays) const;
+ GridArray3<T>* _data;
+ float getValue(int x, int y, int z);
+ GridArray3<VMCell>* macrocells;
+ void calc_mcell(int depth, int ix, int iy, int iz, VMCell& mcell);
+ void parallel_calc_mcell(int cell);
+ void isect(const int depth, double t_sample,
+ const double dtdx, const double dtdy, const double dtdz,
+ double next_x, double next_y, double next_z,
+ int ix, int iy, int iz,
+ const int startx, const int starty, const int startz,
+ const Vector& cellcorner, const Vector& celldir,
+ HVIsectContext &isctx) const;
+ Vector diag;
+ Vector inv_diag;
+ protected:
int _nx,_ny,_nz;
- double* data;
- int Nx, Ny, Nz; // dimensions
RGBAColorMap* _colorMap;
- Vector _minBound;
- Vector _maxBound;
+ BBox _bounds;
Vector _datadiag;
Vector _sdiag;
Vector _hierdiag;
@@ -271,26 +203,25 @@
int _depth;
int* _xsize,*_ysize,*_zsize;
double* _ixsize, *_iysize, *_izsize;
- float _metersPerUnit;
Vector _cellSize;
float _stepSize;
float _dataMin;
float _dataMax;
float _colorScalar;
float _maxDistance;
-
- int done_count;
};
template<class T>
- Volume<T>::Volume(GridArray3<T>* dataNrrd, RGBAColorMap* colorMap, const
Vector& minBound, const Vector& maxBound, double cellStepSize, double
metersPerUnit, int depth, double forceDataMin, double forceDataMax)
- :_colorMap(colorMap)
- {
- _data = dataNrrd;
- _minBound = minBound;
- _maxBound = maxBound;
-
- Vector diag = maxBound - minBound;
+ Volume<T>::Volume(GridArray3<T>* data, RGBAColorMap* colorMap,
+ const BBox& bounds, double cellStepSize,
+ int depth, double forceDataMin, double forceDataMax)
+ : _data(data), _colorMap(colorMap)
+ {
+ //slightly expand the bounds.
+ _bounds[0] = bounds[0] - Vector(T_EPSILON, T_EPSILON, T_EPSILON);
+ _bounds[1] = bounds[1] + Vector(T_EPSILON, T_EPSILON, T_EPSILON);
+
+ Vector diag = _bounds.diagonal();
_cellSize = diag*Vector( 1.0 / (double)(_data->getNx()-1),
1.0 / (double)(_data->getNy()-1),
@@ -299,9 +230,7 @@
//_stepSize = cellStepSize*_cellSize.length()/sqrt(3.0);
_stepSize = cellStepSize;
- _metersPerUnit = metersPerUnit;
- _maxDistance = (_maxBound - _minBound).length();
-
+ _maxDistance = diag.length();
float min = 0,max = 0;
//_data->getMinMax(&min, &max);
@@ -332,8 +261,7 @@
_ny = _data->getNy();
_nz = _data->getNz();
_sdiag = _datadiag/Vector(_nx-1,_ny-1,_nz-1);
- diag = (_maxBound - _minBound);
- inv_diag = Vector(1.0f/diag.x(), 1.0f/diag.y(), 1.0f/diag.z());
+ inv_diag = diag.inverse();
// Compute all the grid stuff
_xsize=new int[depth];
@@ -397,7 +325,7 @@
exit(1);
}
_hierdiag=_datadiag*Vector(tx,ty,tz)/Vector(_nx-1,_ny-1,_nz-1);
- _ihierdiag=Vector(1.,1.,1.)/_hierdiag;
+ _ihierdiag=_hierdiag.inverse();
if(depth==1){
macrocells=0;
@@ -426,13 +354,15 @@
template<class T>
Volume<T>::~Volume()
{
-
+ delete[] macrocells;
+ delete[] _xsize;
+ delete[] _ysize;
+ delete[] _zsize;
+ delete[] _ixsize;
+ delete[] _iysize;
+ delete[] _izsize;
}
-
- template<class T>
- float Volume<T>::resolutionFactor = 5.0f;
-
template<class T>
void computeMinMax(float& min, float& max, GridArray3<T>& grid)
{
@@ -543,11 +473,11 @@
#define RAY_TERMINATION_THRESHOLD 0.9
template<class T>
- void Volume<T>::isect(int depth, double t_sample,
- double dtdx, double dtdy, double dtdz,
+ void Volume<T>::isect(const int depth, double t_sample,
+ const double dtdx, const double dtdy, const double
dtdz,
double next_x, double next_y, double next_z,
int ix, int iy, int iz,
- int startx, int starty, int startz,
+ const int startx, const int starty, const int
startz,
const Vector& cellcorner, const Vector& celldir,
HVIsectContext &isctx) const
{
@@ -731,19 +661,19 @@
double new_dtdz=dtdz*_izsize[depth-1];
const Vector dir(isctx.ray.direction());
double new_next_x;
- if(dir.x() > 0){
+ if(dir.x() >= 0){
new_next_x=next_x-dtdx+new_dtdx*(new_ix+1);
} else {
new_next_x=next_x-new_ix*new_dtdx;
}
double new_next_y;
- if(dir.y() > 0){
+ if(dir.y() >= 0){
new_next_y=next_y-dtdy+new_dtdy*(new_iy+1);
} else {
new_next_y=next_y-new_iy*new_dtdy;
}
double new_next_z;
- if(dir.z() > 0){
+ if(dir.z() >= 0){
new_next_z=next_z-dtdz+new_dtdz*(new_iz+1);
} else {
new_next_z=next_z-new_iz*new_dtdz;
@@ -826,186 +756,227 @@
}
}
- //#define CD_SSE
#define RAY_TERMINATION 0.9
template<class T>
- void Volume<T>::shade(const RenderContext & context, RayPacket& rays)
const
- {
- rays.normalizeDirections();
- float t_inc = _stepSize;
-
- RayPacketData rpData1;
- RayPacket lRays1(rpData1, RayPacket::SquarePacket, rays.begin(),
rays.end(), rays.getDepth()+1,
- RayPacket::NormalizedDirections);
- float tMins[rays.end()];
- float tMaxs[rays.end()];
- float alphas[rays.end()];
- Color totals[rays.end()];
- for(int rayIndex = rays.begin(); rayIndex < rays.end(); rayIndex++)
- {
- lRays1.setRay(rayIndex, Ray(rays.getOrigin(rayIndex)+
rays.getMinT(rayIndex)*rays.getDirection(rayIndex),
rays.getDirection(rayIndex)));
- tMins[rayIndex] = rays.getMinT(rayIndex);
- alphas[rayIndex] = 0;
- }
- lRays1.resetHits();
- context.scene->getObject()->intersect(context, lRays1);
- for(int i = rays.begin(); i < rays.end(); i++)
- {
- tMaxs[i] = lRays1.getMinT(i);
- if (lRays1.wasHit(i))
- tMaxs[i] = lRays1.getMinT(i)+ tMins[i];
- else
- tMaxs[i] = -1;
- totals[i] = Color(RGB(0,0,0));
- }
-
-
- for(int rayIndex = rays.begin(); rayIndex < rays.end(); rayIndex++)
- {
- Ray ray = rays.getRay(rayIndex);
- float t_min = tMins[rayIndex];
- float t_max = tMaxs[rayIndex];
-
- const Vector dir(ray.direction());
- const Vector orig(ray.origin());
- int dix_dx;
- int ddx;
- if(dir.x() > 0){
- dix_dx=1;
- ddx=1;
- } else {
- dix_dx=-1;
- ddx=0;
- }
- int diy_dy;
- int ddy;
- if(dir.y() > 0){
- diy_dy=1;
- ddy=1;
- } else {
- diy_dy=-1;
- ddy=0;
- }
- int diz_dz;
- int ddz;
- if(dir.z() > 0){
- diz_dz=1;
- ddz=1;
- } else {
- diz_dz=-1;
- ddz=0;
- }
+ void Volume<T>::shade(const RenderContext & context, RayPacket& rays) const
+ {
+ rays.normalizeDirections();
+ rays.computeHitPositions();
- Vector start_p(orig+dir*t_min);
- Vector s((start_p-_minBound)*_ihierdiag);
- int cx=_xsize[_depth-1];
- int cy=_ysize[_depth-1];
- int cz=_zsize[_depth-1];
- int ix=(int)(s.x()*cx);
- int iy=(int)(s.y()*cy);
- int iz=(int)(s.z()*cz);
- if(ix>=cx)
- ix--;
- if(iy>=cy)
- iy--;
- if(iz>=cz)
- iz--;
- if(ix<0)
- ix++;
- if(iy<0)
- iy++;
- if(iz<0)
- iz++;
-
- double next_x, next_y, next_z;
- double dtdx, dtdy, dtdz;
-
- double icx=_ixsize[_depth-1];
- double x=_minBound.x()+_hierdiag.x()*double(ix+ddx)*icx;
- double xinv_dir=1./dir.x();
- next_x=(x-orig.x())*xinv_dir;
- dtdx=dix_dx*_hierdiag.x()*icx*xinv_dir;
-
- double icy=_iysize[_depth-1];
- double y=_minBound.y()+_hierdiag.y()*double(iy+ddy)*icy;
- double yinv_dir=1./dir.y();
- next_y=(y-orig.y())*yinv_dir;
- dtdy=diy_dy*_hierdiag.y()*icy*yinv_dir;
-
- double icz=_izsize[_depth-1];
- double z=_minBound.z()+_hierdiag.z()*double(iz+ddz)*icz;
- double zinv_dir=1./dir.z();
- next_z=(z-orig.z())*zinv_dir;
- dtdz=diz_dz*_hierdiag.z()*icz*zinv_dir;
-
- Vector cellsize(cx,cy,cz);
- // cellcorner and celldir can be used to get the location in
terms
- // of the metacell in index space.
- //
- // For example if you wanted to get the location at time t
(world
- // space units) in terms of indexspace you would do the
following
- // computation:
- //
- // Vector pos = cellcorner + celldir * t + Vector(startx,
starty, startz);
- //
- // If you wanted to get how far you are inside a given cell you
- // could use the following code:
- //
- // Vector weights = cellcorner + celldir * t - Vector(ix, iy,
iz);
- Vector cellcorner((orig-_minBound)*_ihierdiag*cellsize);
- Vector celldir(dir*_ihierdiag*cellsize);
-
- HVIsectContext isctx;
- isctx.total = totals[rayIndex];
- isctx.alpha = alphas[rayIndex];
- isctx.dix_dx = dix_dx;
- isctx.diy_dy = diy_dy;
- isctx.diz_dz = diz_dz;
- isctx.transfunct.course_hash = _colorMap->course_hash;
- isctx.t_inc = t_inc;
- isctx.t_min = t_min;
- isctx.t_max = t_max;
- isctx.t_inc_inv = 1/isctx.t_inc;
- isctx.ray = ray;
-
- isect(_depth-1, t_min, dtdx, dtdy, dtdz, next_x, next_y,
next_z,
- ix, iy, iz, 0, 0, 0,
- cellcorner, celldir,
- isctx);
+ float t_inc = _stepSize;
- alphas[rayIndex] = isctx.alpha;
- totals[rayIndex] = isctx.total;
- }
+ RayPacketData rpData1;
+ RayPacket lRays1(rpData1, RayPacket::UnknownShape, rays.begin(),
rays.end(), rays.getDepth()+1,
+ RayPacket::NormalizedDirections);
+ float tMins[rays.end()]; //rays.ray start of volume
+ float tMaxs[rays.end()]; //rays.ray end of volume or hit something in
volume
+ float alphas[rays.end()];
+ Color totals[rays.end()];
+
+ for(int rayIndex = rays.begin(); rayIndex < rays.end(); rayIndex++) {
+ Vector origin = rays.getOrigin(rayIndex);
+ if (_bounds.contains(origin)) {
+ //we are inside the volume.
+ tMins[rayIndex] = 0;
+ }
+ else {
+ //we hit the volume from the outside so need to move the ray
+ //origin to the volume hitpoint.
+ origin = rays.getHitPosition(rayIndex);
+ tMins[rayIndex] = rays.getMinT(rayIndex);
+ }
+ lRays1.setRay(rayIndex, origin, rays.getDirection(rayIndex));
+
+ alphas[rayIndex] = 0;
+ }
+ lRays1.resetHits();
+ context.scene->getObject()->intersect(context, lRays1);
+ lRays1.computeHitPositions();
+ for(int i = rays.begin(); i < rays.end(); i++) {
+ //did we hit something, and if so, was it inside the volume.
+ if (lRays1.wasHit(i) && _bounds.contains(lRays1.getHitPosition(i)))
+ tMaxs[i] = lRays1.getMinT(i) + tMins[i];
+ else {
+ //it's possible that we hit a corner of the volume on entry
+ //and due to precision issues we can't hit the exit part of
+ //the volume. These are rare, but they do happen. Note that
+ //just checking wasHit won't work if there's geometry outside
+ //the volume.
+ tMaxs[i] = -1;
+ }
+ totals[i] = Color(RGB(0,0,0));
+ }
+
+ for(int rayIndex = rays.begin(); rayIndex < rays.end(); rayIndex++) {
+ Ray ray = rays.getRay(rayIndex);
+ float t_min = tMins[rayIndex];
+ float t_max = tMaxs[rayIndex];
+
+ const Vector dir(ray.direction());
+ const Vector orig(ray.origin());
+ int dix_dx;
+ int ddx;
+ if(dir.x() >= 0){
+ dix_dx=1;
+ ddx=1;
+ } else {
+ dix_dx=-1;
+ ddx=0;
+ }
+ int diy_dy;
+ int ddy;
+ if(dir.y() >= 0){
+ diy_dy=1;
+ ddy=1;
+ } else {
+ diy_dy=-1;
+ ddy=0;
+ }
+ int diz_dz;
+ int ddz;
+ if(dir.z() >= 0){
+ diz_dz=1;
+ ddz=1;
+ } else {
+ diz_dz=-1;
+ ddz=0;
+ }
- for(int i = rays.begin(); i < rays.end(); i++)
- {
- if (alphas[i] < RAY_TERMINATION)
- {
- Ray ray;
- ray = rays.getRay(i);
- if (lRays1.getHitMaterial(i) == this || tMaxs[i] == -1)
- {
- lRays1.setRay(i, Ray(ray.origin() +
ray.direction()*tMaxs[i], ray.direction()));
- if (tMaxs[i] == -1)
- lRays1.setRay(i,
Ray(ray.origin()+ray.direction()*(tMins[i]+0.0001f), ray.direction()));
- }
- else
- lRays1.setRay(i,
Ray(ray.origin()+ray.direction()*(tMins[i]), ray.direction()));
- }
- }
- bool depth = (rays.getDepth() <
context.scene->getRenderParameters().maxDepth);
+ Vector start_p(orig+dir*t_min);
+ Vector s((start_p-_bounds.getMin())*_ihierdiag);
+ int cx=_xsize[_depth-1];
+ int cy=_ysize[_depth-1];
+ int cz=_zsize[_depth-1];
+ int ix=(int)(s.x()*cx);
+ int iy=(int)(s.y()*cy);
+ int iz=(int)(s.z()*cz);
+ if(ix>=cx)
+ ix--;
+ if(iy>=cy)
+ iy--;
+ if(iz>=cz)
+ iz--;
+ if(ix<0)
+ ix++;
+ if(iy<0)
+ iy++;
+ if(iz<0)
+ iz++;
+
+
+ double next_x, next_y, next_z;
+ double dtdx, dtdy, dtdz;
+
+ double icx=_ixsize[_depth-1];
+ double x=_bounds.getMin().x()+_hierdiag.x()*double(ix+ddx)*icx;
+ double xinv_dir=1./dir.x();
+ next_x=Abs((x-orig.x())*xinv_dir); //take Abs so we don't get -inf
+ dtdx=dix_dx*_hierdiag.x()*icx*xinv_dir; //this is +inf when dir.x == 0
+
+ double icy=_iysize[_depth-1];
+ double y=_bounds.getMin().y()+_hierdiag.y()*double(iy+ddy)*icy;
+ double yinv_dir=1./dir.y();
+ next_y=Abs((y-orig.y())*yinv_dir);
+ dtdy=diy_dy*_hierdiag.y()*icy*yinv_dir;
+
+ double icz=_izsize[_depth-1];
+ double z=_bounds.getMin().z()+_hierdiag.z()*double(iz+ddz)*icz;
+ double zinv_dir=1./dir.z();
+ next_z=Abs((z-orig.z())*zinv_dir);
+ dtdz=diz_dz*_hierdiag.z()*icz*zinv_dir;
+
+ Vector cellsize(cx,cy,cz);
+ // cellcorner and celldir can be used to get the location in terms
+ // of the metacell in index space.
+ //
+ // For example if you wanted to get the location at time t (world
+ // space units) in terms of indexspace you would do the following
+ // computation:
+ //
+ // Vector pos = cellcorner + celldir * t + Vector(startx, starty,
startz);
+ //
+ // If you wanted to get how far you are inside a given cell you
+ // could use the following code:
+ //
+ // Vector weights = cellcorner + celldir * t - Vector(ix, iy, iz);
+ Vector cellcorner((orig-_bounds.getMin())*_ihierdiag*cellsize);
+ Vector celldir(dir*_ihierdiag*cellsize);
+
+ HVIsectContext isctx;
+ isctx.total = totals[rayIndex];
+ isctx.alpha = alphas[rayIndex];
+ isctx.dix_dx = dix_dx;
+ isctx.diy_dy = diy_dy;
+ isctx.diz_dz = diz_dz;
+ isctx.transfunct.course_hash = _colorMap->course_hash;
+ isctx.t_inc = t_inc;
+ isctx.t_min = t_min;
+ isctx.t_max = t_max;
+ isctx.t_inc_inv = 1/isctx.t_inc;
+ isctx.ray = ray;
+
+ isect(_depth-1, t_min, dtdx, dtdy, dtdz, next_x, next_y, next_z,
+ ix, iy, iz, 0, 0, 0,
+ cellcorner, celldir,
+ isctx);
+
+ alphas[rayIndex] = isctx.alpha;
+ totals[rayIndex] = isctx.total;
+ }
+
+ const bool depth = (rays.getDepth() <
context.scene->getRenderParameters().maxDepth);
+ int start = -1;
+ for(int i = rays.begin(); i < rays.end(); i++) {
+ if (alphas[i] < RAY_TERMINATION) {
+ if (start < 0)
+ start = i;
+
+ const Ray ray = rays.getRay(i);
+ if (lRays1.getHitMaterial(i) == this) //did we hit the outside of
the volume?
+ lRays1.setRay(i, ray.origin() + ray.direction()*tMaxs[i],
+ ray.direction());
+ else if (tMaxs[i] == -1) //we weren't supposed to be in the volume
+ lRays1.setRay(i, ray.origin()+ray.direction()*(tMins[i]),
+ ray.direction());
+ else //we hit something else inside the volume
+ //Let's take an epsilon step back so we can hit this when we trace
a ray.
+ lRays1.setRay(i,
ray.origin()+ray.direction()*(tMaxs[i]-T_EPSILON*2),
+ ray.direction());
+ }
+ else {
+ //we don't want to trace the terminated ray.
+ if (start >= 0) {
+ //let's trace these rays
+ lRays1.resize(start, i);
context.sample_generator->setupChildPacket(context, rays, lRays1);
context.renderer->traceRays(context, lRays1);
- for(int i = rays.begin(); i < rays.end(); i++)
- {
- Color bgColor(RGB(0,0,0));
- if (depth)
- bgColor = lRays1.getColor(i);
- totals[i] += bgColor*(1.-alphas[i]);
- rays.setColor(i, totals[i]);
- }
+ for(int k = start; k < i; k++) {
+ Color bgColor(RGB(0,0,0));
+ if (depth)
+ bgColor = lRays1.getColor(k);
+ totals[k] += bgColor*(1.-alphas[k]);
+ rays.setColor(k, totals[k]);
+ }
+ start = -1;
+ }
+ rays.setColor(i, totals[i]);
+ }
+ }
+ if (start >= 0) {
+ //let's trace just these active rays
+ lRays1.resize(start, rays.end());
-}
+ context.sample_generator->setupChildPacket(context, rays, lRays1);
+ context.renderer->traceRays(context, lRays1);
+ for(int i = start; i < rays.end(); i++) {
+ Color bgColor(RGB(0,0,0));
+ if (depth)
+ bgColor = lRays1.getColor(i);
+ totals[i] += bgColor*(1.-alphas[i]);
+ rays.setColor(i, totals[i]);
+ }
+ }
+ }
template<class T>
void Volume<T>::computeHistogram(int numBuckets, int* histValues)
@@ -1054,7 +1025,7 @@
template<class T>
float Volume<T>::getValue(int x, int y, int z)
{
- return data[x + Nx*(y + Ny*z)];
+ return _data(x, y, z);
}
}//namespace manta
Modified: trunk/scenes/csafe/src/CDTest.h
==============================================================================
--- trunk/scenes/csafe/src/CDTest.h (original)
+++ trunk/scenes/csafe/src/CDTest.h Sat May 24 18:04:45 2008
@@ -56,78 +56,78 @@
Description: used for running c++ heavy code for csafe demo
*/
class CDTest
- {
- public:
- //! CDTest constructor
- /*!
- \param pass in the scene, or NULL and set it later
- \param pass in MantaInterface used for rendering
- */
- CDTest(Scene* scene, MantaInterface* interface)
- {
+ {
+ public:
+ //! CDTest constructor
+ /*!
+ \param pass in the scene, or NULL and set it later
+ \param pass in MantaInterface used for rendering
+ */
+ CDTest(Scene* scene, MantaInterface* interface)
+ {
_sphereAnimation=NULL;
_volCMap=NULL;
_volAnimation = NULL;
- _scene = scene;
- _ridx = 6;
- _cidx = 4;
- _radius = 0.0003;
- numFrames = numFrames1 = numFrames2 = 0;
- //_readContext = context;
- _manta_interface = interface;
- _forceDataMin = -FLT_MAX;
- _forceDataMax = -FLT_MAX;
- _useAO = false;
- _spheresVisible = true;
- _volVisible = true;
- }
-
- //! sets the scene object, necessary for initializing scene
and loading spheres/volume
- /*!
- \param scene to set
- */
- void setScene(Scene* scene)
- {
- _scene = scene;
- }
-
- //! initializes the scene, must do before rendering
- /*!
- */
- void initScene()
- {
- _world = new Group();
- _scene->setBackground(new
ConstantBackground(Color(RGB(.5, .5, .5))));
- _scene->setObject(_world);
-
- LightSet* lights = new LightSet();
- lights->add(new PointLight(Vector(-500, 300, -300),
Color(RGB(.8,.8,.8))));
-
- lights->setAmbientLight(new
ConstantAmbient(Color(RGB(.4,.4,.4))));
- _scene->setLights(lights);
- Group* group = new Group();
- Primitive* prim = new Cube( new
Lambertian(Color(RGBColor(1,0,0))), Vector(-0.1, -0.1, 0.4)*0, Vector(0.1,
0.1, 0.7)*0);
+ _scene = scene;
+ _ridx = 6;
+ _cidx = 4;
+ _radius = 0.0003;
+ numFrames = numFrames1 = numFrames2 = 0;
+ //_readContext = context;
+ _manta_interface = interface;
+ _forceDataMin = -FLT_MAX;
+ _forceDataMax = -FLT_MAX;
+ _useAO = false;
+ _spheresVisible = true;
+ _volVisible = true;
+ }
+
+ //! sets the scene object, necessary for initializing scene and
loading spheres/volume
+ /*!
+ \param scene to set
+ */
+ void setScene(Scene* scene)
+ {
+ _scene = scene;
+ }
+
+ //! initializes the scene, must do before rendering
+ /*!
+ */
+ void initScene()
+ {
+ _world = new Group();
+ _scene->setBackground(new ConstantBackground(Color(RGB(.5, .5,
.5))));
+ _scene->setObject(_world);
+
+ LightSet* lights = new LightSet();
+ lights->add(new PointLight(Vector(-500, 300, -300),
Color(RGB(.8,.8,.8))));
+
+ lights->setAmbientLight(new
ConstantAmbient(Color(RGB(.4,.4,.4))));
+ _scene->setLights(lights);
+ Group* group = new Group();
+ Primitive* prim = new Cube( new
Lambertian(Color(RGBColor(1,0,0))), Vector(-0.1, -0.1, 0.4)*0, Vector(0.1,
0.1, 0.7)*0);
if (_sphereAnimation)
delete _sphereAnimation;
- _sphereAnimation= new KeyFrameAnimation();
+ _sphereAnimation= new KeyFrameAnimation();
if (_volAnimation)
delete _volAnimation;
- _volAnimation = new KeyFrameAnimation();
- Primitive* prim2 = new Cube( new
Lambertian(Color(RGBColor(0,0,1))), Vector(-0.1, -0.1, 0.4), Vector(0.1, 0.1,
.7));
- group->add(prim);
- Group* group2 = new Group();
- group2->add(prim2);
- _world->add(_sphereAnimation);
- _world->add(_volAnimation);
- _sphereAnimation->setDuration(15);
- _volAnimation->setDuration(15);
- duration = 10;
- numFrames1 = numFrames2 = numFrames = 1;
-
- _minBound = Vector(-0.001, -0.101, -0.001);
- _maxBound = Vector( 0.101, 0.201, 0.101);
-
- if (!_volCMap)
+ _volAnimation = new KeyFrameAnimation();
+ Primitive* prim2 = new Cube( new
Lambertian(Color(RGBColor(0,0,1))), Vector(-0.1, -0.1, 0.4), Vector(0.1, 0.1,
.7));
+ group->add(prim);
+ Group* group2 = new Group();
+ group2->add(prim2);
+ _world->add(_sphereAnimation);
+ _world->add(_volAnimation);
+ _sphereAnimation->setDuration(15);
+ _volAnimation->setDuration(15);
+ duration = 10;
+ numFrames1 = numFrames2 = numFrames = 1;
+
+ _minBound = Vector(-0.001, -0.101, -0.001);
+ _maxBound = Vector( 0.101, 0.201, 0.101);
+
+ if (!_volCMap)
{
vector<ColorSlice> slices;
float div = 1.0/255.0;
@@ -148,296 +148,296 @@
_volCMap = new RGBAColorMap(slices, 64);
}
- //Group* cutWorld = new Group();
- //cutWorld->add(new CuttingPlane(Vector(0,0,0),
Vector(0,1,0), _world));
- //_scene->setObject(cutWorld);
- _sphereAnimationCut = new Group();
- _cuts[0] = new CuttingPlane(Vector(0,1,0),
Vector(0,1,0), _sphereAnimation);
- _cuts[1] = new CuttingPlane(Vector(0,0,0),
Vector(0,-1,0), _cuts[0]);
- _cuts[2] = new CuttingPlane(Vector(0,0,0),
Vector(-1,0,0), _cuts[1]);
- _cuts[3] = new CuttingPlane(Vector(0,0,0),
Vector(1,0,0), _cuts[2]);
- _cuts[4] = new CuttingPlane(Vector(0,0,0),
Vector(0,0,1), _cuts[3]);
- _cuts[5] = new CuttingPlane(Vector(0,0,0),
Vector(0,0,-1), _cuts[4]);
- _sphereAnimationCut->add(_cuts[0]);
- }
- Group* _sphereAnimationCut;
- CuttingPlane* _cuts[6]; //up down left right forward back
- bool _useClippingBBox, _spheresVisible, _volVisible;
- void setClippingBBox(Vector min, Vector max)
- {
- cout << "clipping min max: " << min[0] << " " << min[1]
<< " " << min[2]
- << "\n" << max[0] << " " << max[1] << " " << max[2]
<< endl;
- /*_cuts[0]->setPlanePoint(max);
- _cuts[1]->setPlanePoint(min);
- _cuts[2]->setPlanePoint(min);
- _cuts[3]->setPlanePoint(max);
- _cuts[4]->setPlanePoint(max);
- _cuts[5]->setPlanePoint(min);
- LightSet* lights = _scene->getLights();
- PreprocessContext context(_manta_interface, 0, 1,
lights);
- for(int i = 0; i < 6; i++)
- {
- _sphereAnimation->computeBounds(context,
_cuts[i]->bounds);
- }*/
- for(int i =0; i < 3; 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]);
- }
- for(int i = 0; i < int(_volPrims.size()); i++)
- {
- _volPrims[i]->setMinMax(minB, maxB);
- }
- }
- void useClippingBBox(bool st)
- {
- /* _useClippingBBox = st;
- if (st == true)
- {
- _world = new Group();
- if (_volVisible)
- _world->add(_volAnimation);
- if (_spheresVisible)
- _world->add(_sphereAnimationCut);
- _scene->setObject(_world);
- }
- else
- {
- _world = new Group();
- if (_volVisible)
- _world->add(_volAnimation);
- if (_spheresVisible)
- _world->add(_sphereAnimation);
- }*/
- }
- void setVisibility(bool spheres, bool volume)
- {
- _spheresVisible = spheres;
- _volVisible = volume;
- _world = new Group();
- if (spheres)
- {
- _world->add(_sphereAnimation);
- /*if(_useClippingBBox)
- _world->add(_sphereAnimationCut);
- else
- _world->add(_sphereAnimation);*/
- }
- if (volume)
- _world->add(_volAnimation);
- _scene->setObject(_world);
- }
-
- //! add a sphere file to be loaded
- /*!
- \param file to be loaded later
- */
- void addSphereNrrd(string file)
- {
- _nrrdFilenames.push_back(file);
- }
-
- //! clear list of sphere files
- /*!
- */
- void clearSphereNrrds()
- {
- _nrrdFilenames.clear();
- numFrames1 = 0;
- numFrames = numFrames2;
- }
-
- //! add volume nrrd file to be loaded
- /*!
- \param file to add to be loaded later
- */
- void addVolNrrd(string file)
- {
- _nrrdFilenames2.push_back(file);
- }
-
- //! clear list of volume files
- /*!
- */
- void clearVolNrrds()
- {
- _nrrdFilenames2.clear();
- numFrames2 = 0;
- numFrames = numFrames1;
- }
-
- //! load list of sphere nrrd files
- /*!
-
- */
- void loadSphereNrrds()
- {
- LightSet* lights = _scene->getLights();
- PreprocessContext context(_manta_interface, 0, 1,
lights);
- _nrrds.clear();
- for(vector<string>::iterator i =
_nrrdFilenames.begin(); i != _nrrdFilenames.end(); i++)
- {
- cout << "Loading Nrrd file: " << *i <<
"...\n";
- ParticleNRRD* pnrrd = new ParticleNRRD();
- pnrrd->readFile(*i);
- _spherePNrrds.push_back(pnrrd);
- Group* group = new Group();
- RGBAColorMap* cmap = new RGBAColorMap(1);
- CDGridSpheres* grid = new
CDGridSpheres(pnrrd->getParticleData(), pnrrd->getNParticles(),
pnrrd->getNVars(), 6, 2,_radius, _ridx, cmap , _cidx);
- //grid->setCMinMax(4, 299.50411987304688,
500.59423828125);
- //TODO: unhardcode this!
- //cout << "reprocess\n";
- //grid->preprocess(context);
- //cout << "donepreprocess\n";
- group->add(grid);
- _sphereGrids.push_back(grid);
- if (pnrrd->getNVars() > _sphereMins.size())
- {
- for(size_t j = _sphereMins.size(); j
< pnrrd->getNVars(); j++)
- {
-
_sphereMins.push_back(FLT_MAX);
-
_sphereMaxs.push_back(-FLT_MAX);
- }
- }
- for(int j = 0; j < int(_sphereMins.size());
j++)
- {
- float min,max;
- grid->getMinMax(j, min, max);
- if (_sphereMins[j] > min)
- _sphereMins[j] = min;
- if (_sphereMaxs[j] < max)
- _sphereMaxs[j] = max;
- }
- _sphereAnimation->push_back(group);
- numFrames1++;
- //Nrrd *new_nrrd = nrrdNew();
-
////////////////////////////////////////////////////////////////////////////
- // Attempt to open the nrrd
- //if (nrrdLoad( new_nrrd, i->c_str(), 0 )) {
- // char *reason = biffGetDone( NRRD );
- // std::cout << "WARNING Loading Nrrd
Failed: " << reason << std::endl;
- // exit(__LINE__);
- // }
-
- // Check to make sure the nrrd is the proper
dimensions.
- // if (new_nrrd->dim != 3) {
- // std::cout << "WARNING Nrrd must three
dimension RGB" << std::endl;
- // exit(__LINE__);
- // }
-
- //_nrrds.push_back(new_nrrd);
- cout << "Loading " << *i << " done.\n";
- }
- updateFrames();
- if (_clipFrames && _endFrame <
int(_sphereGrids.size()))
- _sphereAnimation->clipFrames(_startFrame,
_endFrame);
- }
- vector<Cube*> _volPrims;
- //! clear list of volume files
- /*!
- */
- void loadVolNrrds()
- {
- for(vector<string>::iterator i =
_nrrdFilenames2.begin(); i != _nrrdFilenames2.end(); i++)
- {
- cout << "Loading Nrrd file: " << *i <<
"...\n";
- Group* group = new Group();
- Volume<float>* mat = new
Volume<float>(loadNRRDToGrid<float>(*i), _volCMap, _minBound, _maxBound,
0.00125, 10, 3, _forceDataMin, _forceDataMax);
- Cube* vol = new Cube(mat, _minBound -
Vector(0.001, 0.001, 0.001), _maxBound + Vector(0.001, 0.001, 0.001));
- group->add(vol);
- _volAnimation->push_back(group);
- _vols.push_back(mat);
- _volPrims.push_back(vol);
- numFrames2++;
- //Nrrd *new_nrrd = nrrdNew();
-
////////////////////////////////////////////////////////////////////////////
- // Attempt to open the nrrd
- //if (nrrdLoad( new_nrrd, i->c_str(), 0 )) {
- // char *reason = biffGetDone( NRRD );
- // std::cout << "WARNING Loading Nrrd
Failed: " << reason << std::endl;
- // exit(__LINE__);
- // }
-
- // Check to make sure the nrrd is the proper
dimensions.
- // if (new_nrrd->dim != 3) {
- // std::cout << "WARNING Nrrd must three
dimension RGB" << std::endl;
- // exit(__LINE__);
- // }
- cout << "Loading " << *i << " done.\n";
- }
- updateFrames();
- if (_clipFrames && _endFrame < int(_vols.size()))
- _volAnimation->clipFrames(_startFrame,
_endFrame);
- }
- void readUDAHeader(string directory)
- {
- uda.readUDAHeader(directory);
- }
- int getUDANumVars() { return uda.getNumVariables(); }
- string getUDAVarName(int i) { return
uda.getVarHeader(i).name; }
- void loadUDA(string file, string volName)
- {
- //TODO: clear out existing data
- LightSet* lights = _scene->getLights();
- PreprocessContext context(_manta_interface, 0, 1,
lights);
- uda.readUDA(file, volName);
- for (std::vector<UDAReader::Timestep>::iterator itr =
uda.timesteps.begin(); itr != uda.timesteps.end(); itr++)
- {
- float* sdata = itr->sphereData;
+ //Group* cutWorld = new Group();
+ //cutWorld->add(new CuttingPlane(Vector(0,0,0), Vector(0,1,0),
_world));
+ //_scene->setObject(cutWorld);
+ _sphereAnimationCut = new Group();
+ _cuts[0] = new CuttingPlane(Vector(0,1,0), Vector(0,1,0),
_sphereAnimation);
+ _cuts[1] = new CuttingPlane(Vector(0,0,0), Vector(0,-1,0),
_cuts[0]);
+ _cuts[2] = new CuttingPlane(Vector(0,0,0), Vector(-1,0,0),
_cuts[1]);
+ _cuts[3] = new CuttingPlane(Vector(0,0,0), Vector(1,0,0),
_cuts[2]);
+ _cuts[4] = new CuttingPlane(Vector(0,0,0), Vector(0,0,1),
_cuts[3]);
+ _cuts[5] = new CuttingPlane(Vector(0,0,0), Vector(0,0,-1),
_cuts[4]);
+ _sphereAnimationCut->add(_cuts[0]);
+ }
+ Group* _sphereAnimationCut;
+ CuttingPlane* _cuts[6]; //up down left right forward back
+ bool _useClippingBBox, _spheresVisible, _volVisible;
+ void setClippingBBox(Vector min, Vector max)
+ {
+ cout << "clipping min max: " << min[0] << " " << min[1] << " "
<< min[2]
+ << "\n" << max[0] << " " << max[1] << " " << max[2] << endl;
+ /*_cuts[0]->setPlanePoint(max);
+ _cuts[1]->setPlanePoint(min);
+ _cuts[2]->setPlanePoint(min);
+ _cuts[3]->setPlanePoint(max);
+ _cuts[4]->setPlanePoint(max);
+ _cuts[5]->setPlanePoint(min);
+ LightSet* lights = _scene->getLights();
+ PreprocessContext context(_manta_interface, 0, 1, lights);
+ for(int i = 0; i < 6; i++)
+ {
+ _sphereAnimation->computeBounds(context, _cuts[i]->bounds);
+ }*/
+ for(int i =0; i < 3; 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]);
+ }
+ for(int i = 0; i < int(_volPrims.size()); i++)
+ {
+ _volPrims[i]->setMinMax(minB, maxB);
+ }
+ }
+ void useClippingBBox(bool st)
+ {
+ /* _useClippingBBox = st;
+ if (st == true)
+ {
+ _world = new Group();
+ if (_volVisible)
+ _world->add(_volAnimation);
+ if (_spheresVisible)
+ _world->add(_sphereAnimationCut);
+ _scene->setObject(_world);
+ }
+ else
+ {
+ _world = new Group();
+ if (_volVisible)
+ _world->add(_volAnimation);
+ if (_spheresVisible)
+ _world->add(_sphereAnimation);
+ }*/
+ }
+ void setVisibility(bool spheres, bool volume)
+ {
+ _spheresVisible = spheres;
+ _volVisible = volume;
+ _world = new Group();
+ if (spheres)
+ {
+ _world->add(_sphereAnimation);
+ /*if(_useClippingBBox)
+ _world->add(_sphereAnimationCut);
+ else
+ _world->add(_sphereAnimation);*/
+ }
+ if (volume)
+ _world->add(_volAnimation);
+ _scene->setObject(_world);
+ }
+
+ //! add a sphere file to be loaded
+ /*!
+ \param file to be loaded later
+ */
+ void addSphereNrrd(string file)
+ {
+ _nrrdFilenames.push_back(file);
+ }
+
+ //! clear list of sphere files
+ /*!
+ */
+ void clearSphereNrrds()
+ {
+ _nrrdFilenames.clear();
+ numFrames1 = 0;
+ numFrames = numFrames2;
+ }
+
+ //! add volume nrrd file to be loaded
+ /*!
+ \param file to add to be loaded later
+ */
+ void addVolNrrd(string file)
+ {
+ _nrrdFilenames2.push_back(file);
+ }
+
+ //! clear list of volume files
+ /*!
+ */
+ void clearVolNrrds()
+ {
+ _nrrdFilenames2.clear();
+ numFrames2 = 0;
+ numFrames = numFrames1;
+ }
+
+ //! load list of sphere nrrd files
+ /*!
+
+ */
+ void loadSphereNrrds()
+ {
+ LightSet* lights = _scene->getLights();
+ PreprocessContext context(_manta_interface, 0, 1, lights);
+ _nrrds.clear();
+ for(vector<string>::iterator i = _nrrdFilenames.begin(); i !=
_nrrdFilenames.end(); i++)
+ {
+ cout << "Loading Nrrd file: " << *i << "...\n";
+ ParticleNRRD* pnrrd = new ParticleNRRD();
+ pnrrd->readFile(*i);
+ _spherePNrrds.push_back(pnrrd);
+ Group* group = new Group();
+ RGBAColorMap* cmap = new RGBAColorMap(1);
+ CDGridSpheres* grid = new
CDGridSpheres(pnrrd->getParticleData(), pnrrd->getNParticles(),
pnrrd->getNVars(), 6, 2,_radius, _ridx, cmap , _cidx);
+ //grid->setCMinMax(4, 299.50411987304688, 500.59423828125);
+ //TODO: unhardcode this!
+ //cout << "reprocess\n";
+ //grid->preprocess(context);
+ //cout << "donepreprocess\n";
+ group->add(grid);
+ _sphereGrids.push_back(grid);
+ if (pnrrd->getNVars() > _sphereMins.size())
+ {
+ for(size_t j = _sphereMins.size(); j <
pnrrd->getNVars(); j++)
+ {
+ _sphereMins.push_back(FLT_MAX);
+ _sphereMaxs.push_back(-FLT_MAX);
+ }
+ }
+ for(int j = 0; j < int(_sphereMins.size()); j++)
+ {
+ float min,max;
+ grid->getMinMax(j, min, max);
+ if (_sphereMins[j] > min)
+ _sphereMins[j] = min;
+ if (_sphereMaxs[j] < max)
+ _sphereMaxs[j] = max;
+ }
+ _sphereAnimation->push_back(group);
+ numFrames1++;
+ //Nrrd *new_nrrd = nrrdNew();
+
////////////////////////////////////////////////////////////////////////////
+ // Attempt to open the nrrd
+ //if (nrrdLoad( new_nrrd, i->c_str(), 0 )) {
+ // char *reason = biffGetDone( NRRD );
+ // std::cout << "WARNING Loading Nrrd Failed: " << reason
<< std::endl;
+ // exit(__LINE__);
+ // }
+
+ // Check to make sure the nrrd is the proper dimensions.
+ // if (new_nrrd->dim != 3) {
+ // std::cout << "WARNING Nrrd must three dimension RGB" <<
std::endl;
+ // exit(__LINE__);
+ // }
+
+ //_nrrds.push_back(new_nrrd);
+ cout << "Loading " << *i << " done.\n";
+ }
+ updateFrames();
+ if (_clipFrames && _endFrame < int(_sphereGrids.size()))
+ _sphereAnimation->clipFrames(_startFrame, _endFrame);
+ }
+ vector<Cube*> _volPrims;
+ //! clear list of volume files
+ /*!
+ */
+ void loadVolNrrds()
+ {
+ for(vector<string>::iterator i = _nrrdFilenames2.begin(); i !=
_nrrdFilenames2.end(); i++)
+ {
+ cout << "Loading Nrrd file: " << *i << "...\n";
+ 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 - Vector(0.001, 0.001,
0.001), _maxBound + Vector(0.001, 0.001, 0.001));
+ group->add(vol);
+ _volAnimation->push_back(group);
+ _vols.push_back(mat);
+ _volPrims.push_back(vol);
+ numFrames2++;
+ //Nrrd *new_nrrd = nrrdNew();
+
////////////////////////////////////////////////////////////////////////////
+ // Attempt to open the nrrd
+ //if (nrrdLoad( new_nrrd, i->c_str(), 0 )) {
+ // char *reason = biffGetDone( NRRD );
+ // std::cout << "WARNING Loading Nrrd Failed: " << reason
<< std::endl;
+ // exit(__LINE__);
+ // }
+
+ // Check to make sure the nrrd is the proper dimensions.
+ // if (new_nrrd->dim != 3) {
+ // std::cout << "WARNING Nrrd must three dimension RGB" <<
std::endl;
+ // exit(__LINE__);
+ // }
+ cout << "Loading " << *i << " done.\n";
+ }
+ updateFrames();
+ if (_clipFrames && _endFrame < int(_vols.size()))
+ _volAnimation->clipFrames(_startFrame, _endFrame);
+ }
+ void readUDAHeader(string directory)
+ {
+ uda.readUDAHeader(directory);
+ }
+ int getUDANumVars() { return uda.getNumVariables(); }
+ string getUDAVarName(int i) { return uda.getVarHeader(i).name; }
+ void loadUDA(string file, string volName)
+ {
+ //TODO: clear out existing data
+ LightSet* lights = _scene->getLights();
+ PreprocessContext context(_manta_interface, 0, 1, lights);
+ uda.readUDA(file, volName);
+ for (std::vector<UDAReader::Timestep>::iterator itr =
uda.timesteps.begin(); itr != uda.timesteps.end(); itr++)
+ {
+ float* sdata = itr->sphereData;
- for (int i = 0; i < 100; i++)
- {
- cout << "sphere data: " << sdata[i] << endl;
- }
- Group* group = new Group();
- RGBAColorMap* cmap = new RGBAColorMap(1);
- int ridx = _ridx;
- if (ridx >= itr->numSphereVars)
- ridx = -1;
- int cidx = _cidx;
- if (cidx >= itr->numSphereVars)
- cidx = 0;
- CDGridSpheres* grid = new
CDGridSpheres(itr->sphereData, itr->numSpheres, itr->numSphereVars, 6,
2,_radius, ridx, cmap , cidx);
- group->add(grid);
- _sphereGrids.push_back(grid);
- if (itr->numSphereVars >
int(_sphereMins.size()))
- {
- for(int j = int(_sphereMins.size());
j < itr->numSphereVars; j++)
- {
-
_sphereMins.push_back(FLT_MAX);
-
_sphereMaxs.push_back(-FLT_MAX);
- }
- }
- for(int j = 0; j < int(_sphereMins.size());
j++)
- {
- float min,max;
- grid->getMinMax(j, min, max);
- if (_sphereMins[j] > min)
- _sphereMins[j] = min;
- if (_sphereMaxs[j] < max)
- _sphereMaxs[j] = max;
- }
- _sphereAnimation->push_back(group);
- numFrames1++;
-
- Group* group2 = new Group();
- Volume<float>* mat = new
Volume<float>(itr->volume, _volCMap, _minBound, _maxBound, 0.00125, 10, 3,
_forceDataMin, _forceDataMax);
- Primitive* 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);
- _vols.push_back(mat);
- numFrames2++;
- }
- updateFrames();
- if (_clipFrames && _endFrame < int(_vols.size()))
- _volAnimation->clipFrames(_startFrame,
_endFrame);
- if (_clipFrames && _endFrame <
int(_sphereGrids.size()))
- _sphereAnimation->clipFrames(_startFrame,
_endFrame);
- }
+ for (int i = 0; i < 100; i++)
+ {
+ cout << "sphere data: " << sdata[i] << endl;
+ }
+ Group* group = new Group();
+ RGBAColorMap* cmap = new RGBAColorMap(1);
+ int ridx = _ridx;
+ if (ridx >= itr->numSphereVars)
+ ridx = -1;
+ int cidx = _cidx;
+ if (cidx >= itr->numSphereVars)
+ cidx = 0;
+ CDGridSpheres* grid = new CDGridSpheres(itr->sphereData,
itr->numSpheres, itr->numSphereVars, 6, 2,_radius, ridx, cmap , cidx);
+ group->add(grid);
+ _sphereGrids.push_back(grid);
+ if (itr->numSphereVars > int(_sphereMins.size()))
+ {
+ for(int j = int(_sphereMins.size()); j <
itr->numSphereVars; j++)
+ {
+ _sphereMins.push_back(FLT_MAX);
+ _sphereMaxs.push_back(-FLT_MAX);
+ }
+ }
+ for(int j = 0; j < int(_sphereMins.size()); j++)
+ {
+ float min,max;
+ grid->getMinMax(j, min, max);
+ if (_sphereMins[j] > min)
+ _sphereMins[j] = min;
+ if (_sphereMaxs[j] < max)
+ _sphereMaxs[j] = max;
+ }
+ _sphereAnimation->push_back(group);
+ numFrames1++;
+
+ Group* group2 = new Group();
+ Volume<float>* mat = new Volume<float>(itr->volume,
_volCMap, BBox(_minBound, _maxBound), 0.00125, 10, 3, _forceDataMin,
_forceDataMax);
+ Primitive* 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);
+ _vols.push_back(mat);
+ numFrames2++;
+ }
+ updateFrames();
+ if (_clipFrames && _endFrame < int(_vols.size()))
+ _volAnimation->clipFrames(_startFrame, _endFrame);
+ if (_clipFrames && _endFrame < int(_sphereGrids.size()))
+ _sphereAnimation->clipFrames(_startFrame, _endFrame);
+ }
//! calls destructors on all loaded data, then reloads sphere and
volume files
/*!
@@ -460,324 +460,324 @@
}
-
- //! update the frame cieling
- /*!
- */
- void updateFrames()
- {
- numFrames = std::max(numFrames1, numFrames2);
- }
-
- //! pause animation
- /*!
- */
- void pauseAnimation() { _sphereAnimation->pauseAnimation();
_volAnimation->pauseAnimation(); }
-
- //! resume animation
- /*!
- */
- void resumeAnimation() { _sphereAnimation->resumeAnimation();
_volAnimation->resumeAnimation();}
-
- //! go to a time in animation
- /*!
- \param time to go to
- */
- void gotoTime(float time) { _sphereAnimation->setTime(time);
_volAnimation->setTime(time); }
-
- // 0-based
- void gotoFrame(int frame) {
- if (frame < 0 || frame >= numFrames)
- {
- cerr << "ERROR: frame: " << frame << " out of
bounds\n";
- return;
- }
- float step;
- if (numFrames == 0)
- step = 0;
- else
- step = duration/float(numFrames);
- _sphereAnimation->setTime( step*float(frame) +
0.0001f);
- _volAnimation->setTime(step*float(frame) + 0.0001f);
- }
-
- void lockFrames(bool st) { _sphereAnimation->lockFrames(st);
_volAnimation->lockFrames(st); }
- void loopAnimations(bool st)
{_sphereAnimation->loopAnimation(st); _volAnimation->loopAnimation(st); }
- void clipFrames(int start, int end) { _startFrame = start;
_endFrame = end; _clipFrames = true;
- if (end < numFrames1)
_sphereAnimation->clipFrames(start,end); if (end < numFrames2)
_volAnimation->clipFrames(start,end); }
- void repeatLastFrame(float time) {
_sphereAnimation->repeatLastFrameForSeconds(time);
_volAnimation->repeatLastFrameForSeconds(time); }
-
- //! skip ahead one frame
- /*!
- */
- void forwardAnimation()
- {
- float step;
- if (numFrames == 0)
- step = 0;
- else
- step = duration/float(numFrames);
- float st = _sphereAnimation->getTime();
- st = std::max(st, 0.0f);
- float vt = _volAnimation->getTime();
- vt = std::max(vt, 0.0f);
-
- _sphereAnimation->setTime(
_sphereAnimation->getTime() + step);
- _volAnimation->setTime(_volAnimation->getTime()+step);
- }
-
- //! skip back one frame
- /*!
- */
- void backAnimation()
- {
- float step;
- if (numFrames == 0)
- step = 0;
- else
- step = duration/float(numFrames);
- _sphereAnimation->setTime(
_sphereAnimation->getTime() - step);
- _volAnimation->setTime(_volAnimation->getTime()-step);
- }
-
- //! get the duration of the animation in seconds
- /*!
- \return duration in seconds of animation
- */
- float getDuration()
- {
- return duration;
- }
-
- //! set the duration of animation in seconds
- /*!
- \param number of seconds animation takes
- */
- void setDuration(float time)
- {
- duration = time;
- _sphereAnimation->setDuration(time);
- _volAnimation->setDuration(time);
- }
-
- //! computes histogram of spherefiles
- /*!
- \param index of data to compute histogram of
- \param number of buckets to compute, ie 100 bars
- \param an allocated list of ints to store the values, must
be size numBuckets
- \param will return min
- \param will return max
- */
- void getHistogram(int index, int numBuckets, int* histValues,
float* min, float* max)
- {
- for(int i = 0; i < numBuckets; i++)
- histValues[i] = 0;
- for(size_t i = 0; i < _spherePNrrds.size(); i++)
- {
- ParticleNRRD* pnrrd = _spherePNrrds[i];
- float dataMin = _sphereMins[index];
- float dataMax = _sphereMaxs[index];
- cout << "histo dataMin/Max: " << dataMin << "
" << dataMax << endl;
- float scale;
- if (dataMin != dataMax)
- scale = (numBuckets-1)/(dataMax -
dataMin);
- else
- continue;
- for(int j = 0; j <
int(pnrrd->getNParticles()); j++)
- {
- 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]++;
- }
- }
- if (int(_sphereMins.size()) > index)
- {
- *min = _sphereMins[index];
- *max = _sphereMaxs[index];
- }
- else
- {
- *min = -FLT_MAX;
- *max = FLT_MAX;
- }
- }
-
- //! compute histogram for volume data
- /*!
- \param number of buckets to compute, ie 100 bars
- \param an allocated list of ints to store the values, must
be size numBuckets
- \param will return min
- \param will return max
- */
- void getVolHistogram(int numBuckets, int* histValues, float*
min, float* max)
- {
- cout << "computing volume histogram for " <<
_vols.size() << " volumes\n";
- *min = FLT_MAX;
- *max = -FLT_MAX;
- for(int i = 0; i < numBuckets; i++)
- histValues[i] = 0;
- for (int i = 0; i < int(_vols.size()); i++)
- {
- if (_vols[i] == NULL)
- continue;
- int* histValues2 = new int[numBuckets];
- _vols[i]->computeHistogram(numBuckets,
histValues2);
- for(int j = 0; j < numBuckets; j++)
- histValues[j] += histValues2[j];
- double nmin, nmax;
- _vols[i]->getMinMax(&nmin, &nmax);
- *min= std::min(float(nmin), *min);
- *max = std::max(float(nmax), *max);
- cout << "compared min/max: " << nmin << " "
<< nmax << endl;
- }
- cout << "histogram computed: min/max: " << *min << "
" << *max << endl;
- }
-
- //! get the colormap used for the volume
- /*!
- \return colormap used for volume
- */
- RGBAColorMap* getVolCMap() { return _volCMap; }
-
- //! set the colormap for volume
- /*!
- \param colormap
- */
- void setVolCMap(RGBAColorMap* map) { _volCMap = map;
- for(vector<Volume<float>*>::iterator i =
_vols.begin(); i != _vols.end(); i++)
+
+ //! update the frame cieling
+ /*!
+ */
+ void updateFrames()
+ {
+ numFrames = std::max(numFrames1, numFrames2);
+ }
+
+ //! pause animation
+ /*!
+ */
+ void pauseAnimation() { _sphereAnimation->pauseAnimation();
_volAnimation->pauseAnimation(); }
+
+ //! resume animation
+ /*!
+ */
+ void resumeAnimation() { _sphereAnimation->resumeAnimation();
_volAnimation->resumeAnimation();}
+
+ //! go to a time in animation
+ /*!
+ \param time to go to
+ */
+ void gotoTime(float time) { _sphereAnimation->setTime(time);
_volAnimation->setTime(time); }
+
+ // 0-based
+ void gotoFrame(int frame) {
+ if (frame < 0 || frame >= numFrames)
+ {
+ cerr << "ERROR: frame: " << frame << " out of bounds\n";
+ return;
+ }
+ float step;
+ if (numFrames == 0)
+ step = 0;
+ else
+ step = duration/float(numFrames);
+ _sphereAnimation->setTime( step*float(frame) + 0.0001f);
+ _volAnimation->setTime(step*float(frame) + 0.0001f);
+ }
+
+ void lockFrames(bool st) { _sphereAnimation->lockFrames(st);
_volAnimation->lockFrames(st); }
+ void loopAnimations(bool st) {_sphereAnimation->loopAnimation(st);
_volAnimation->loopAnimation(st); }
+ void clipFrames(int start, int end) { _startFrame = start; _endFrame
= end; _clipFrames = true;
+ if (end < numFrames1) _sphereAnimation->clipFrames(start,end);
if (end < numFrames2) _volAnimation->clipFrames(start,end); }
+ void repeatLastFrame(float time) {
_sphereAnimation->repeatLastFrameForSeconds(time);
_volAnimation->repeatLastFrameForSeconds(time); }
+
+ //! skip ahead one frame
+ /*!
+ */
+ void forwardAnimation()
+ {
+ float step;
+ if (numFrames == 0)
+ step = 0;
+ else
+ step = duration/float(numFrames);
+ float st = _sphereAnimation->getTime();
+ st = std::max(st, 0.0f);
+ float vt = _volAnimation->getTime();
+ vt = std::max(vt, 0.0f);
+
+ _sphereAnimation->setTime( _sphereAnimation->getTime() + step);
+ _volAnimation->setTime(_volAnimation->getTime()+step);
+ }
+
+ //! skip back one frame
+ /*!
+ */
+ void backAnimation()
+ {
+ float step;
+ if (numFrames == 0)
+ step = 0;
+ else
+ step = duration/float(numFrames);
+ _sphereAnimation->setTime( _sphereAnimation->getTime() - step);
+ _volAnimation->setTime(_volAnimation->getTime()-step);
+ }
+
+ //! get the duration of the animation in seconds
+ /*!
+ \return duration in seconds of animation
+ */
+ float getDuration()
+ {
+ return duration;
+ }
+
+ //! set the duration of animation in seconds
+ /*!
+ \param number of seconds animation takes
+ */
+ void setDuration(float time)
+ {
+ duration = time;
+ _sphereAnimation->setDuration(time);
+ _volAnimation->setDuration(time);
+ }
+
+ //! computes histogram of spherefiles
+ /*!
+ \param index of data to compute histogram of
+ \param number of buckets to compute, ie 100 bars
+ \param an allocated list of ints to store the values, must be size
numBuckets
+ \param will return min
+ \param will return max
+ */
+ void getHistogram(int index, int numBuckets, int* histValues, float*
min, float* max)
+ {
+ for(int i = 0; i < numBuckets; i++)
+ histValues[i] = 0;
+ for(size_t i = 0; i < _spherePNrrds.size(); i++)
+ {
+ ParticleNRRD* pnrrd = _spherePNrrds[i];
+ float dataMin = _sphereMins[index];
+ float dataMax = _sphereMaxs[index];
+ cout << "histo dataMin/Max: " << dataMin << " " << dataMax
<< endl;
+ float scale;
+ if (dataMin != dataMax)
+ scale = (numBuckets-1)/(dataMax - dataMin);
+ else
+ continue;
+ for(int j = 0; j < int(pnrrd->getNParticles()); j++)
+ {
+ 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]++;
+ }
+ }
+ if (int(_sphereMins.size()) > index)
+ {
+ *min = _sphereMins[index];
+ *max = _sphereMaxs[index];
+ }
+ else
+ {
+ *min = -FLT_MAX;
+ *max = FLT_MAX;
+ }
+ }
+
+ //! compute histogram for volume data
+ /*!
+ \param number of buckets to compute, ie 100 bars
+ \param an allocated list of ints to store the values, must be size
numBuckets
+ \param will return min
+ \param will return max
+ */
+ void getVolHistogram(int numBuckets, int* histValues, float* min,
float* max)
+ {
+ cout << "computing volume histogram for " << _vols.size() << "
volumes\n";
+ *min = FLT_MAX;
+ *max = -FLT_MAX;
+ for(int i = 0; i < numBuckets; i++)
+ histValues[i] = 0;
+ for (int i = 0; i < int(_vols.size()); i++)
+ {
+ if (_vols[i] == NULL)
+ continue;
+ int* histValues2 = new int[numBuckets];
+ _vols[i]->computeHistogram(numBuckets, histValues2);
+ for(int j = 0; j < numBuckets; j++)
+ histValues[j] += histValues2[j];
+ double nmin, nmax;
+ _vols[i]->getMinMax(&nmin, &nmax);
+ *min= std::min(float(nmin), *min);
+ *max = std::max(float(nmax), *max);
+ cout << "compared min/max: " << nmin << " " << nmax << endl;
+ }
+ cout << "histogram computed: min/max: " << *min << " " << *max
<< endl;
+ }
+
+ //! get the colormap used for the volume
+ /*!
+ \return colormap used for volume
+ */
+ RGBAColorMap* getVolCMap() { return _volCMap; }
+
+ //! set the colormap for volume
+ /*!
+ \param colormap
+ */
+ void setVolCMap(RGBAColorMap* map) { _volCMap = map;
+ for(vector<Volume<float>*>::iterator i = _vols.begin(); i !=
_vols.end(); i++)
{
- (*i)->setColorMap(map);
-
- }
- }
-
- //! set the colormap for spheres
- /*!
- \param colormap
- */
- void setSphereCMap(RGBAColorMap* map) {
- for(int i =0; i < int(_sphereGrids.size()); i++)
- _sphereGrids[i]->setCMap(map);
- }
-
- //! set minimum and maximum clipping region for a specific
index into spheres
- /*!
- \param index into data
- \param min
- \param max
- */
- void setClipMinMax(int index, float min, float max)
- {
- if (index >= int(_sphereMins.size()))
- return;
- for(int i = 0; i < int(_sphereGrids.size()); i++)
- if (_sphereGrids[i])
_sphereGrids[i]->setClipMinMax(index, min, max);
- }
-
- //! set the minimum and maximum data values used for
normalizing color data
- /*!
- \param index into data
- \param min
- \param max
- */
- void setSphereCMinMax(int index, float min, float max)
//set the min max for normalizing color data
- {
- if (index >= int(_sphereGrids.size()))
- return;
- for(int i =0; i < int(_sphereGrids.size()); i++)
- _sphereGrids[i]->setCMinMax(index, min, max);
- }
-
- //! get the min and max being used for normalizing color
values
- /*!
- \param index into data
- \param returns min
- \param returns max
- */
- void getSphereCMinMax(int index, float& min, float& max)
- {
- if(index >= int(_sphereMins.size()))
- {
- min = -FLT_MAX;
- max = FLT_MAX;
- return;
- }
- for(int i =0;i<int(_sphereGrids.size());i++)
- _sphereGrids[i]->getCMinMax(index, min, max);
-
- }
-
- //! set minimum and maximum data values for volume data,
should be called before loading
- /*!
- \param min
- \param max
- */
- void setVolCMinMax(float min, float max)
- {
- _forceDataMin = min;
- _forceDataMax = max;
- }
-
- //! get the min and max data values used for normalizing
color values
- /*!
- \param returns min
- \param returns max
- */
- void getVolCMinMax(float& min, float& max)
- {
- min = FLT_MAX;
- max = -FLT_MAX;
- for(int i =0;i<int(_vols.size());i++)
- {
- if (_vols[i] == NULL)
- continue;
- double min1, max1;
- _vols[i]->getMinMax(&min1, &max1);
- min = std::min(min, float(min1));
- max = std::max(max, float(max1));
- }
- }
-
- //! sets radius index used for spheredata
- /*!
- \param radius index
- */
- void setRidx(int ridx) { _ridx = ridx; }
-
- //! get radius index
- /*!
- \return radius index
- */
- int getRidx() { return _ridx; }
-
- //! set default radius of spheres
- /*!
- \param radius
- */
- void setRadius(float radius) { _radius = radius; }
-
- //! get the default radius of spheres
- /*!
- \return default radius
- */
- float getRadius() { return _radius; }
-
- //! set color index, what index colormap uses
- /*!
- \param color index to use
- */
- void setCidx(int cidx) {
- _cidx = cidx;
- for(int i =0; i < int(_sphereGrids.size()); i++)
- _sphereGrids[i]->setCidx(cidx);
- }
-
- //! get color index
- /*!
- \return color index
- */
- int getCidx() { return _cidx; }
+ (*i)->setColorMap(map);
+
+ }
+ }
+
+ //! set the colormap for spheres
+ /*!
+ \param colormap
+ */
+ void setSphereCMap(RGBAColorMap* map) {
+ for(int i =0; i < int(_sphereGrids.size()); i++)
+ _sphereGrids[i]->setCMap(map);
+ }
+
+ //! set minimum and maximum clipping region for a specific index
into spheres
+ /*!
+ \param index into data
+ \param min
+ \param max
+ */
+ void setClipMinMax(int index, float min, float max)
+ {
+ if (index >= int(_sphereMins.size()))
+ return;
+ for(int i = 0; i < int(_sphereGrids.size()); i++)
+ if (_sphereGrids[i]) _sphereGrids[i]->setClipMinMax(index,
min, max);
+ }
+
+ //! set the minimum and maximum data values used for normalizing
color data
+ /*!
+ \param index into data
+ \param min
+ \param max
+ */
+ void setSphereCMinMax(int index, float min, float max) //set the
min max for normalizing color data
+ {
+ if (index >= int(_sphereGrids.size()))
+ return;
+ for(int i =0; i < int(_sphereGrids.size()); i++)
+ _sphereGrids[i]->setCMinMax(index, min, max);
+ }
+
+ //! get the min and max being used for normalizing color values
+ /*!
+ \param index into data
+ \param returns min
+ \param returns max
+ */
+ void getSphereCMinMax(int index, float& min, float& max)
+ {
+ if(index >= int(_sphereMins.size()))
+ {
+ min = -FLT_MAX;
+ max = FLT_MAX;
+ return;
+ }
+ for(int i =0;i<int(_sphereGrids.size());i++)
+ _sphereGrids[i]->getCMinMax(index, min, max);
+
+ }
+
+ //! set minimum and maximum data values for volume data, should be
called before loading
+ /*!
+ \param min
+ \param max
+ */
+ void setVolCMinMax(float min, float max)
+ {
+ _forceDataMin = min;
+ _forceDataMax = max;
+ }
+
+ //! get the min and max data values used for normalizing color values
+ /*!
+ \param returns min
+ \param returns max
+ */
+ void getVolCMinMax(float& min, float& max)
+ {
+ min = FLT_MAX;
+ max = -FLT_MAX;
+ for(int i =0;i<int(_vols.size());i++)
+ {
+ if (_vols[i] == NULL)
+ continue;
+ double min1, max1;
+ _vols[i]->getMinMax(&min1, &max1);
+ min = std::min(min, float(min1));
+ max = std::max(max, float(max1));
+ }
+ }
+
+ //! sets radius index used for spheredata
+ /*!
+ \param radius index
+ */
+ void setRidx(int ridx) { _ridx = ridx; }
+
+ //! get radius index
+ /*!
+ \return radius index
+ */
+ int getRidx() { return _ridx; }
+
+ //! set default radius of spheres
+ /*!
+ \param radius
+ */
+ void setRadius(float radius) { _radius = radius; }
+
+ //! get the default radius of spheres
+ /*!
+ \return default radius
+ */
+ float getRadius() { return _radius; }
+
+ //! set color index, what index colormap uses
+ /*!
+ \param color index to use
+ */
+ void setCidx(int cidx) {
+ _cidx = cidx;
+ for(int i =0; i < int(_sphereGrids.size()); i++)
+ _sphereGrids[i]->setCidx(cidx);
+ }
+
+ //! get color index
+ /*!
+ \return color index
+ */
+ int getCidx() { return _cidx; }
//! set to use ambient occlusion on spheres
void useAO(bool st)
@@ -816,38 +816,38 @@
delete *itr;
_spherePNrrdsOld.clear();
}
-
- MantaInterface* _manta_interface;
- RGBAColorMap* _volCMap;
- Vector _minBound;
- Vector _maxBound;
- float _forceDataMin;
- float _forceDataMax;
- int _cidx;
- int _ridx;
- float _radius;
- float duration; //number of seconds for animation
- int numFrames; //number of keyframes
- int numFrames1, numFrames2;
- ReadContext* _readContext;
- vector<string> _nrrdFilenames;
- vector<string> _nrrdFilenames2;
- vector<Nrrd*> _nrrds;
- vector<ParticleNRRD*> _spherePNrrds;
- vector<CDGridSpheres*> _sphereGrids;
- vector<Volume<float>*> _vols;
+
+ MantaInterface* _manta_interface;
+ RGBAColorMap* _volCMap;
+ Vector _minBound;
+ Vector _maxBound;
+ float _forceDataMin;
+ float _forceDataMax;
+ int _cidx;
+ int _ridx;
+ float _radius;
+ float duration; //number of seconds for animation
+ int numFrames; //number of keyframes
+ int numFrames1, numFrames2;
+ ReadContext* _readContext;
+ vector<string> _nrrdFilenames;
+ vector<string> _nrrdFilenames2;
+ vector<Nrrd*> _nrrds;
+ vector<ParticleNRRD*> _spherePNrrds;
+ vector<CDGridSpheres*> _sphereGrids;
+ vector<Volume<float>*> _vols;
vector<ParticleNRRD*> _spherePNrrdsOld;
- vector<CDGridSpheres*> _sphereGridsOld;
- vector<Volume<float>*> _volsOld;
- vector<float> _sphereMins;
- vector<float> _sphereMaxs;
- Group* _world;
- Scene* _scene;
- KeyFrameAnimation* _sphereAnimation;
- KeyFrameAnimation* _volAnimation;
- int _startFrame, _endFrame, _clipFrames;
- bool _useAO;
- UDAReader uda;
- };
+ vector<CDGridSpheres*> _sphereGridsOld;
+ vector<Volume<float>*> _volsOld;
+ vector<float> _sphereMins;
+ vector<float> _sphereMaxs;
+ Group* _world;
+ Scene* _scene;
+ KeyFrameAnimation* _sphereAnimation;
+ KeyFrameAnimation* _volAnimation;
+ int _startFrame, _endFrame, _clipFrames;
+ bool _useAO;
+ UDAReader uda;
+ };
#endif
Modified: trunk/scenes/volumeTest.cc
==============================================================================
--- trunk/scenes/volumeTest.cc (original)
+++ trunk/scenes/volumeTest.cc Sat May 24 18:04:45 2008
@@ -229,7 +229,7 @@
cMap->scaleAlphas(t_inc);
-Volume<float>* mat = new Volume<float>(loadNRRDToGrid<float>(volFile), cMap,
minBound, maxBound, t_inc, 10.0, depth, dataMin, dataMax);
+ Volume<float>* mat = new Volume<float>(loadNRRDToGrid<float>(volFile),
cMap, BBox(minBound, maxBound), t_inc, 10.0, depth, dataMin, dataMax);
//double min, max;
//mat->getMinMax(&min, &max);
//cmap2->setMinMax(min, max);
- [Manta] r2267 - in trunk: Core/Geometry Engine/Factory Model/Cameras Model/Groups Model/Materials scenes scenes/csafe/src, Thiago Ize, 05/24/2008
Archive powered by MHonArc 2.6.16.