Text archives Help
- From: aek@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r573 - trunk/scenes
- Date: Mon, 26 Sep 2005 20:22:47 -0600 (MDT)
Author: aek
Date: Mon Sep 26 20:22:46 2005
New Revision: 573
Modified:
trunk/scenes/ParticleBVHTest.cc
Log:
Update ParticleBVHTest to apply a colour map to an arbitrary channel of the
data sets.
Modified: trunk/scenes/ParticleBVHTest.cc
==============================================================================
--- trunk/scenes/ParticleBVHTest.cc (original)
+++ trunk/scenes/ParticleBVHTest.cc Mon Sep 26 20:22:46 2005
@@ -1,6 +1,7 @@
#include <Core/Exceptions/IllegalArgument.h>
#include <Core/Util/Args.h>
+#include <Core/Math/MiscMath.h>
#include <Interface/Context.h>
#include <Interface/LightSet.h>
#include <Interface/RTRTInterface.h>
@@ -17,9 +18,11 @@
#include <vector>
#include <iostream>
#include <fstream>
+#include <limits>
#include <sgi_stl_warnings_on.h>
using namespace Manta;
+using namespace SCIRun;
using namespace std;
extern "C"
@@ -27,8 +30,20 @@
const ReadContext &context,
const vector< string > &args )
{
+ Color color_map[] = { Color( RGB( 0.0, 0.0, 1.0 ) ),
+ Color( RGB( 0.0, 0.4, 1.0 ) ),
+ Color( RGB( 0.0, 0.8, 1.0 ) ),
+ Color( RGB( 0.0, 1.0, 0.8 ) ),
+ Color( RGB( 0.0, 1.0, 0.4 ) ),
+ Color( RGB( 0.0, 1.0, 0.0 ) ),
+ Color( RGB( 0.4, 1.0, 0.0 ) ),
+ Color( RGB( 0.8, 1.0, 0.0 ) ),
+ Color( RGB( 1.0, 0.9, 0.0 ) ),
+ Color( RGB( 1.0, 0.8, 0.0 ) ),
+ Color( RGB( 1.0, 0.4, 0.0 ) ),
+ Color( RGB( 1.0, 0.0, 0.0 ) ) };
string model_name = "/usr/sci/data/Geometry/particle/sd173-crop.mpm";
- int maximum_particles = 0;
+ int map_channel = 0;
double default_radius = 0.0005;
int argc = static_cast< int >( args.size() );
for ( int i = 0; i < argc; i++ ) {
@@ -36,40 +51,54 @@
if ( arg == "-model" ) {
if ( !getStringArg( i, args, model_name ) )
throw IllegalArgument( "scene particlebvhtest -model", i, args );
- } else if ( arg == "-max" ) {
- if ( !getIntArg( i, args, maximum_particles ) )
- throw IllegalArgument( "scene particlebvhtest -max", i, args );
+ } else if ( arg == "-mapchannel" ) {
+ if ( !getIntArg( i, args, map_channel ) )
+ throw IllegalArgument( "scene particlebvhtest -mapchannel", i, args
);
} else if ( arg == "-radius" ) {
if ( !getDoubleArg( i, args, default_radius ) )
throw IllegalArgument( "scene particlebvhtest -radius", i, args );
} else {
cerr << "Valid options for scene particlebvhtest:" << endl
<< " -model file - MPM particle set model to show" << endl
- << " -max number - Maximum number of particles to show" << endl
+ << " -mapchannel number - Index of data field to use for color
map" << endl
<< " -radius number - Default radius if none given in file" <<
endl;
throw IllegalArgument( "scene particlebvhtest", i, args );
}
}
- ifstream in( model_name.c_str() );
- if ( !in.is_open() )
+ ifstream in1( model_name.c_str() );
+ if ( !in1.is_open() )
throw IllegalArgument( "Couldn't load model: " + model_name, 0, args );
int number_of_particles, number_of_variables, radius_index;
- in >> number_of_particles >> number_of_variables >> radius_index;
- if ( maximum_particles > 0 )
- number_of_particles = min( number_of_particles, maximum_particles );
+ in1 >> number_of_particles >> number_of_variables >> radius_index;
+ double data[ number_of_variables ];
+ double min_value = numeric_limits< double >::max();
+ double max_value = -numeric_limits< double >::max();
+ if ( min_value == max_value )
+ max_value += 1.0;
+ for ( int particle = 0; particle < number_of_particles; ++particle ) {
+ for ( int variable = 0; variable < number_of_variables; ++variable )
+ in1 >> data[ variable ];
+ if ( data[ map_channel ] < min_value )
+ min_value = data[ map_channel ];
+ if ( data[ map_channel ] > max_value )
+ max_value = data[ map_channel ];
+ }
+ ifstream in2( model_name.c_str() );
+ if ( !in2.is_open() )
+ throw IllegalArgument( "Couldn't load model: " + model_name, 0, args );
+ in2 >> number_of_particles >> number_of_variables >> radius_index;
ParticleBVH::ParticleTexture *texture = new ParticleBVH::ParticleTexture();
Material *material = new Lambertian( texture );
ParticleBVH *bvh = new ParticleBVH( material, number_of_particles );
texture->setParticleBVH( bvh );
- float data[ number_of_variables ];
for ( int particle = 0; particle < number_of_particles; ++particle ) {
for ( int variable = 0; variable < number_of_variables; ++variable )
- in >> data[ variable ];
- float angle = particle * 2 * M_PI / number_of_particles;
+ in2 >> data[ variable ];
+ double map_value = ( data[ map_channel ] - min_value ) / ( max_value -
min_value ) * 11;
bvh->setParticle( particle,
- Color( RGB( sin( angle ) * 0.4 + 0.5,
- sin( angle + M_PI * 2 / 3 ) * 0.4 + 0.5,
- sin( angle + M_PI * 4 / 3 ) * 0.4 + 0.5 )
),
+ Interpolate( color_map[ Floor( map_value ) ],
+ color_map[ Ceil( map_value ) ],
+ Fraction( map_value ) ),
Point( data[ 0 ], data[ 1 ], data[ 2 ] ),
radius_index > 0 ? data[ radius_index ] :
default_radius );
}
- [MANTA] r573 - trunk/scenes, aek, 09/26/2005
Archive powered by MHonArc 2.6.16.