Text archives Help
- From: aek@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r792 - trunk/Model/Primitives
- Date: Thu, 15 Dec 2005 17:28:05 -0700 (MST)
Author: aek
Date: Thu Dec 15 17:28:04 2005
New Revision: 792
Modified:
trunk/Model/Primitives/SuperEllipsoid.cc
trunk/Model/Primitives/SuperEllipsoid.h
Log:
Fixed SuperEllipsoid breakage from the merge. Works again but needs
parameter tuning.
Modified: trunk/Model/Primitives/SuperEllipsoid.cc
==============================================================================
--- trunk/Model/Primitives/SuperEllipsoid.cc (original)
+++ trunk/Model/Primitives/SuperEllipsoid.cc Thu Dec 15 17:28:04 2005
@@ -11,9 +11,9 @@
using namespace SCIRun;
using namespace Manta;
-#define GOLDENMEAN (Real)0.61803398874989484820
-#define BRACKETWIDTH (Real)1.e-3
-#define MAXNEWTONITER 10
+static const float golden_mean = static_cast< Real >( 0.61803398874989484820
);
+static const float bracket_width = static_cast< Real >( 1.e-3 );
+static const int max_newton_iter = 10;
SuperEllipsoid::SuperEllipsoid(
Material *material,
@@ -22,14 +22,13 @@
Real alpha,
Real beta )
: PrimitiveCommon( material, this ),
- two_over_alpha( 2. / alpha ),
- two_over_beta( 2. / beta ),
+ center( center ),
+ radius( radius ),
+ inv_radius( 1 / radius ),
+ two_over_alpha( 2 / alpha ),
+ two_over_beta( 2 / beta ),
alpha_over_beta( alpha / beta )
{
- inv_radius = 1 / radius;
- two_over_alpha = 2 / alpha;
- two_over_beta = 2 / beta;
- alpha_over_beta = alpha / beta;
}
SuperEllipsoid::~SuperEllipsoid()
@@ -37,22 +36,22 @@
}
inline Real SuperEllipsoid::functionValue(
- Point const &location ) const
+ Vector const &location ) const
{
Real x_power = SCIRun::Pow( SCIRun::Abs( location.x() ), two_over_alpha );
Real y_power = SCIRun::Pow( SCIRun::Abs( location.y() ), two_over_alpha );
Real z_power = SCIRun::Pow( SCIRun::Abs( location.z() ), two_over_beta );
- return pow( x_power + y_power, alpha_over_beta ) + z_power - 1;
+ return SCIRun::Pow( x_power + y_power, alpha_over_beta ) + z_power - 1;
}
inline Vector SuperEllipsoid::functionGradient(
- Point const &location,
+ Vector const &location,
Real &value ) const
{
Real x_power = SCIRun::Pow( SCIRun::Abs(location.x() ), two_over_alpha );
Real y_power = SCIRun::Pow( SCIRun::Abs(location.y() ), two_over_alpha );
Real z_power = SCIRun::Pow( SCIRun::Abs(location.z() ), two_over_beta );
- Real x_and_y_power = pow( x_power + y_power, alpha_over_beta - 1 );
+ Real x_and_y_power = SCIRun::Pow( x_power + y_power, alpha_over_beta - 1 );
value = x_and_y_power * ( x_power + y_power ) + z_power - 1;
return Vector( two_over_beta * x_and_y_power * x_power / location.x(),
two_over_beta * x_and_y_power * y_power / location.y(),
@@ -60,18 +59,17 @@
}
inline Vector SuperEllipsoid::logarithmFunctionGradient(
- Point const &location,
+ Vector const &location,
Real &value ) const
{
Real x_power = SCIRun::Pow( SCIRun::Abs(location.x() ), two_over_alpha );
Real y_power = SCIRun::Pow( SCIRun::Abs(location.y() ), two_over_alpha );
Real z_power = SCIRun::Pow( SCIRun::Abs(location.z() ), two_over_beta );
- Real x_and_y_power = (SCIRun::Pow( x_power + y_power, 1 - alpha_over_beta )
- * z_power + x_power + y_power);
- value = log( pow( x_power + y_power, alpha_over_beta ) + z_power );
+ Real x_and_y_power = ( SCIRun::Pow( x_power + y_power, 1 - alpha_over_beta
) * z_power + x_power + y_power );
+ value = log( SCIRun::Pow( x_power + y_power, alpha_over_beta ) + z_power );
return Vector( two_over_beta * x_power / ( location.x() * x_and_y_power ),
two_over_beta * y_power / ( location.y() * x_and_y_power ),
- two_over_beta / ( location.z() * ( 1 + pow( x_power +
y_power, alpha_over_beta ) / z_power ) ) );
+ two_over_beta / ( location.z() * ( 1 + SCIRun::Pow( x_power
+ y_power, alpha_over_beta ) / z_power ) ) );
}
void SuperEllipsoid::computeBounds(
@@ -88,7 +86,10 @@
rays.computeInverseDirections();
for( int i = 0; i < rays.getSize(); ++i ) {
RayPacket::Element& e( rays.get(i) );
- Vector offset_center = e.ray.origin() - center;
+
+ Vector offset_center( e.ray.origin() - center );
+ //float radius = 1.01;
+ //float inv_radius = 1.0;
// First check if the ray hits the bounding box and whether it could
// remotely produce a hit of interest.
@@ -130,11 +131,11 @@
// A few preliminary early exit tests...
Real near_value, far_value;
Real near_deriv = Dot( functionGradient(
- ( e.ray.origin() + tnear *
e.ray.direction() ),
+ ( offset_center + tnear * e.ray.direction()
) * inv_radius,
near_value ),
e.ray.direction() );
Real far_deriv = Dot( functionGradient(
- ( e.ray.origin() + tfar * e.ray.direction()
),
+ ( offset_center + tfar * e.ray.direction() )
* inv_radius,
far_value ),
e.ray.direction() );
if ( ( near_value < (Real)T_EPSILON && far_value < (Real)T_EPSILON ) ||
@@ -146,25 +147,25 @@
if ( near_deriv * far_deriv <= 0 ) {
Real a_bracket = tnear;
Real b_bracket = tfar;
- Real left = GOLDENMEAN * a_bracket + ( 1 - GOLDENMEAN ) * b_bracket;
+ Real left = golden_mean * a_bracket + ( 1 - golden_mean ) * b_bracket;
Real left_value = functionValue(
- Point( (offset_center + left * e.ray.direction() ) * inv_radius ));
- Real right = ( 1 - GOLDENMEAN ) * a_bracket + GOLDENMEAN * b_bracket;
+ ( offset_center + left * e.ray.direction() ) * inv_radius );
+ Real right = ( 1 - golden_mean ) * a_bracket + golden_mean * b_bracket;
Real right_value = functionValue(
- Point( (offset_center + right * e.ray.direction() ) * inv_radius ));
- while( SCIRun::Abs( b_bracket - a_bracket ) > BRACKETWIDTH ) {
+ ( offset_center + right * e.ray.direction() ) * inv_radius );
+ while( SCIRun::Abs( b_bracket - a_bracket ) > bracket_width ) {
if ( left_value < right_value ) {
b_bracket = right;
right = left;
right_value = left_value;
- left = GOLDENMEAN * a_bracket + ( 1 - GOLDENMEAN ) * b_bracket;
- left_value = functionValue( e.ray.origin() + left *
e.ray.direction() );
+ left = golden_mean * a_bracket + ( 1 - golden_mean ) * b_bracket;
+ left_value = functionValue( ( offset_center + left *
e.ray.direction() ) * inv_radius );
} else {
a_bracket = left;
left = right;
left_value = right_value;
- right = ( 1 - GOLDENMEAN ) * a_bracket + GOLDENMEAN * b_bracket;
- right_value = functionValue( e.ray.origin() + right *
e.ray.direction() );
+ right = ( 1 - golden_mean ) * a_bracket + golden_mean * b_bracket;
+ right_value = functionValue( ( offset_center + right *
e.ray.direction() ) * inv_radius );
}
}
@@ -193,13 +194,13 @@
Real troot = ( tnear + tfar ) * (Real)0.5;
Real root_value;
Real root_deriv = Dot( logarithmFunctionGradient(
- e.ray.origin() + troot * e.ray.direction(),
+ ( offset_center + troot * e.ray.direction()
) * inv_radius,
root_value ),
e.ray.direction() );
int iterations = 0;
while ( SCIRun::Abs( tfar - tnear ) >= (Real)T_EPSILON &&
SCIRun::Abs( root_value ) >= (Real)T_EPSILON &&
- ++iterations < MAXNEWTONITER ) {
+ ++iterations < max_newton_iter ) {
if ( root_value * near_value < 0 ) {
tfar = troot;
far_value = root_value;
@@ -211,7 +212,7 @@
if ( troot <= tnear || troot >= tfar )
troot = ( tnear + tfar ) * (Real)0.5;
root_deriv = Dot( logarithmFunctionGradient(
- e.ray.origin() + troot * e.ray.direction(),
+ ( offset_center + troot * e.ray.direction() ) *
inv_radius,
root_value ),
e.ray.direction() );
}
@@ -231,7 +232,7 @@
rays.computeHitPositions();
for( int i = 0; i < rays.getSize(); i++ ) {
RayPacket::Element &e( rays.get( i ) );
- e.normal = functionGradient( e.hitPosition, ignored );
+ e.normal = functionGradient( Vector( e.hitPosition ), ignored );
e.normal.normalize();
}
rays.setFlag(RayPacket::HaveNormals | RayPacket::HaveUnitNormals);
@@ -272,4 +273,3 @@
}
rays.setFlag( RayPacket::HaveTexture2 | RayPacket::HaveTexture3 );
}
-
Modified: trunk/Model/Primitives/SuperEllipsoid.h
==============================================================================
--- trunk/Model/Primitives/SuperEllipsoid.h (original)
+++ trunk/Model/Primitives/SuperEllipsoid.h Thu Dec 15 17:28:04 2005
@@ -22,9 +22,9 @@
virtual void computeTexCoords3(const RenderContext& context,
RayPacket& rays) const;
private:
- Real functionValue(const Point& location) const;
- inline Vector functionGradient(const Point& location, Real& value )
const;
- inline Vector logarithmFunctionGradient(const Point& location, Real&
value ) const;
+ Real functionValue(const Vector& location) const;
+ inline Vector functionGradient(const Vector& location, Real& value )
const;
+ inline Vector logarithmFunctionGradient(const Vector& location, Real&
value ) const;
Point center;
Real radius;
Real inv_radius;
- [MANTA] r792 - trunk/Model/Primitives, aek, 12/15/2005
Archive powered by MHonArc 2.6.16.