Text archives Help
- From: aek@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r569 - in trunk: Model/Primitives scenes
- Date: Mon, 26 Sep 2005 15:38:51 -0600 (MDT)
Author: aek
Date: Mon Sep 26 15:38:50 2005
New Revision: 569
Modified:
trunk/Model/Primitives/ParticleBVH.cc
trunk/Model/Primitives/ParticleBVH.h
trunk/scenes/ParticleBVHTest.cc
Log:
Fixed crash in ParticleBVH. It now works, but needs performance tweaking.
Modified: trunk/Model/Primitives/ParticleBVH.cc
==============================================================================
--- trunk/Model/Primitives/ParticleBVH.cc (original)
+++ trunk/Model/Primitives/ParticleBVH.cc Mon Sep 26 15:38:50 2005
@@ -9,7 +9,7 @@
ParticleBVH::ParticleBVH(
Material *material,
int const number_of_particles )
- : PrimitiveCommon( material, this ),
+ : PrimitiveCommon( material ),
number_of_particles( number_of_particles ),
particles( new Particle[ number_of_particles ] ),
nodes( new Node[ number_of_particles * 2 ] )
@@ -32,7 +32,7 @@
particles[ which_one ].inverse_radius = 1.0 / radius;
}
-int ParticleBVH::partition(
+inline int ParticleBVH::partition(
int first,
int last,
int const axis,
@@ -63,7 +63,7 @@
node.bound.reset();
for ( int current = first; current < last; ++current )
node.bound.extendBySphere( particles[ current ].center, particles[
current ].radius );
- if ( last - first < maximum_objects_per_leaf ) {
+ if ( last - first <= maximum_objects_per_leaf ) {
node.index = first;
node.length = last - first;
node.axis = 0;
@@ -92,6 +92,7 @@
void ParticleBVH::preprocess(
PreprocessContext const &context )
{
+ PrimitiveCommon::preprocess( context );
build( 0, 0, number_of_particles, 1 );
}
@@ -103,7 +104,7 @@
box.extendBySphere( particles[ current ].center, particles[ current
].radius );
}
-bool ParticleBVH::testBox(
+inline bool ParticleBVH::testBox(
RayPacket &rays,
BBox const &box ) const
{
@@ -142,18 +143,19 @@
return false;
}
-bool ParticleBVH::intersectParticles(
+inline bool ParticleBVH::intersectParticles(
RayPacket &rays,
int const first,
int const last ) const
{
for ( int current = first; current < last; ++current ) {
Particle &particle( particles[ current ] );
+ double radius_squared = particle.radius * particle.radius;
for ( int ray = 0; ray < rays.getSize(); ray++ ) {
RayPacket::Element &element( rays.get( ray ) );
Vector offset( element.ray.origin() - particle.center );
double B = Dot( offset, element.ray.direction() );
- double C = Dot( offset, offset ) - particle.radius * particle.radius;
+ double C = Dot( offset, offset ) - radius_squared;
double discriminant = B * B - C;
if ( discriminant >= 0.0 ) {
double r = sqrt( discriminant );
@@ -163,8 +165,7 @@
element.hitInfo.scratchpad< ParticleHit >().particle = current;
} else {
double t1 = r - B;
- element.hitInfo.hit( t1, material, this, tex );
- if ( element.hitInfo.hit( t0, material, this, tex ) )
+ if ( element.hitInfo.hit( t1, material, this, tex ) )
element.hitInfo.scratchpad< ParticleHit >().particle = current;
}
}
@@ -186,7 +187,7 @@
for ( ; ; ) {
Node &node( nodes[ current ] );
if ( testBox( rays, node.bound ) ) {
- if ( node.leaf )
+ if ( node.leaf )
intersectParticles( rays, node.index, node.index + node.length );
else {
stack[ stack_position++ ] = node.index + 1 - element_0.sign[
node.axis ];
@@ -194,7 +195,7 @@
continue;
}
}
- if ( --stack_position < 0 )
+ if ( stack_position-- < 1 )
break;
current = stack[ stack_position ];
}
@@ -211,38 +212,4 @@
element.normal = ( element.hitPosition - particle.center ) *
particle.inverse_radius;
}
rays.setFlag( RayPacket::HaveUnitNormals );
-}
-
-void ParticleBVH::computeTexCoords2(
- RenderContext const &/*context*/,
- RayPacket &rays ) const
-{
- rays.computeHitPositions();
- for ( int ray = 0; ray < rays.getSize(); ++ray ) {
- RayPacket::Element &element( rays.get( ray ) );
- Particle &particle( particles[ element.hitInfo.scratchpad< ParticleHit
>
().particle ] );
- Vector n = ( element.hitPosition - particle.center ) *
particle.inverse_radius;
- double angle = Clamp( n.z(), -1.0, 1.0 );
- double theta = acos( angle );
- double phi = atan2( n.x(), n.y() );
- element.texCoords = Point( ( phi + M_PI ) * ( 1.0 / ( 2.0 * M_PI ) ),
theta * ( 1.0 / M_PI ), 0.0 );
- }
- rays.setFlag( RayPacket::HaveTexture2 | RayPacket::HaveTexture3 );
-}
-
-void ParticleBVH::computeTexCoords3(
- const RenderContext &/*context*/,
- RayPacket &rays ) const
-{
- rays.computeHitPositions();
- for ( int ray = 0; ray < rays.getSize(); ++ray ) {
- RayPacket::Element &element( rays.get( ray ) );
- Particle &particle( particles[ element.hitInfo.scratchpad< ParticleHit
>
().particle ] );
- Vector n = ( element.hitPosition - particle.center ) *
particle.inverse_radius;
- double angle = Clamp( n.z(), -1.0, 1.0 );
- double theta = acos( angle );
- double phi = atan2( n.x(), n.y() );
- element.texCoords = Point( ( phi + M_PI ) * ( 1.0 / ( 2.0 * M_PI ) ),
theta * ( 1.0 / M_PI ), 0.0 );
- }
- rays.setFlag( RayPacket::HaveTexture2 | RayPacket::HaveTexture3 );
}
Modified: trunk/Model/Primitives/ParticleBVH.h
==============================================================================
--- trunk/Model/Primitives/ParticleBVH.h (original)
+++ trunk/Model/Primitives/ParticleBVH.h Mon Sep 26 15:38:50 2005
@@ -2,12 +2,11 @@
#define Manta_Particle_BVH_h
#include <Model/Primitives/PrimitiveCommon.h>
-#include <Interface/TexCoordMapper.h>
#include <Core/Geometry/PointVector.h>
#include <Core/Geometry/BBox.h>
namespace Manta {
- class ParticleBVH : public PrimitiveCommon, public TexCoordMapper {
+ class ParticleBVH : public PrimitiveCommon {
public:
ParticleBVH( Material *material, int const number_of_particles );
@@ -18,11 +17,9 @@
virtual void computeBounds( PreprocessContext const &context, BBox &box
) const;
virtual void intersect( RenderContext const &context, RayPacket &rays )
const;
virtual void computeNormal( RenderContext const &context, RayPacket
&rays ) const;
- virtual void computeTexCoords2( RenderContext const &context, RayPacket
&rays ) const;
- virtual void computeTexCoords3( RenderContext const &context, RayPacket
&rays ) const;
protected:
- static const int maximum_objects_per_leaf = 4;
+ static const int maximum_objects_per_leaf = 2;
static const int maximum_depth = 128;
int number_of_particles;
Modified: trunk/scenes/ParticleBVHTest.cc
==============================================================================
--- trunk/scenes/ParticleBVHTest.cc (original)
+++ trunk/scenes/ParticleBVHTest.cc Mon Sep 26 15:38:50 2005
@@ -27,16 +27,21 @@
const ReadContext &context,
const vector< string > &args )
{
- string model_name = "/usr/sci/data/Geometry/particle/sd022-crop.mpm";
+ string model_name = "/usr/sci/data/Geometry/particle/sd173-crop.mpm";
+ int maximum_particles = 0;
int argc = static_cast< int >( args.size() );
for ( int i = 0; i < argc; i++ ) {
string arg = args[ i ];
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 {
cerr << "Valid options for scene particlebvhtest:" << endl
- << " -model file - MPM particle set model to show" << endl;
+ << " -model file - MPM particle set model to show" << endl
+ << " -max number - Maximum number of particles to show" << endl;
throw IllegalArgument( "scene particlebvhtest", i, args );
}
}
@@ -47,6 +52,8 @@
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 );
ParticleBVH *bvh = new ParticleBVH( material, number_of_particles );
float data[ number_of_variables ];
for ( int particle = 0; particle < number_of_particles; ++particle ) {
@@ -54,7 +61,7 @@
in >> data[ variable ];
bvh->setParticle( particle,
Point( data[ 0 ], data[ 1 ], data[ 2 ] ),
- radius_index > 0 ? data[ radius_index ] : 1.0 );
+ radius_index > 0 ? data[ radius_index ] : 0.0005 );
}
Scene *scene = new Scene();
scene->setBackground( new LinearBackground( Color( RGB( 0.2, 0.4, 0.9 ) ),
- [MANTA] r569 - in trunk: Model/Primitives scenes, aek, 09/26/2005
Archive powered by MHonArc 2.6.16.