Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Examples  

gadget::LinearSigmoidPositionFilter Class Reference

A pos filter class that uses a linear sigmoid. More...

#include <LinearSigmoidPositionFilter.h>

Inheritance diagram for gadget::LinearSigmoidPositionFilter:

Inheritance graph
[legend]
Collaboration diagram for gadget::LinearSigmoidPositionFilter:

Collaboration graph
[legend]
List of all members.

Public Methods

 LinearSigmoidPositionFilter ()
gmtl::Matrix44f getPos (const gmtl::Matrix44f newPos)
 Gets the position to use>. More...

float getScaleFactor (const float distance)
 Given a distance, return the scale factor based upon the minDist and maxDist values. More...

void setMinDist (float val)
float minDist ()
void setMaxDist (float val)
float maxDist ()
void setMaxThreshold (float val)
float maxTheshold ()

Detailed Description

A pos filter class that uses a linear sigmoid.

Definition at line 45 of file LinearSigmoidPositionFilter.h.


Constructor & Destructor Documentation

gadget::LinearSigmoidPositionFilter::LinearSigmoidPositionFilter   [inline]
 

Definition at line 48 of file LinearSigmoidPositionFilter.h.

00049    {
00050       mMinDist = 0.0f;
00051       mMaxDist = 0.05f;
00052       mMaxThreshold = 10000000.0f;        // Just set to some huge number
00053    }


Member Function Documentation

gmtl::Matrix44f gadget::LinearSigmoidPositionFilter::getPos const gmtl::Matrix44f    newPos
 

Gets the position to use>.

Parameters:
newPos  The new postion this frame of the physical device.

Definition at line 67 of file LinearSigmoidPositionFilter.cpp.

References getScaleFactor.

00068 {
00069    // If value is the same, then return immediately
00070    if(newPos == mLastReturnedPos)
00071    { return mLastReturnedPos; }
00072 
00073    const float eps(0.001);         // An epsilon value because of numerical precision as we approach zero difference
00074    float scale_factor(0.0f);
00075    float dist;
00076    gmtl::Vec3f last_returned_trans;
00077    gmtl::Vec3f new_trans;
00078    gmtl::Vec3f trans_diff;
00079 
00080    // Get difference in translation
00081    last_returned_trans = gmtl::makeTrans<gmtl::Vec3f>(mLastReturnedPos);
00082    new_trans = gmtl::makeTrans<gmtl::Vec3f>(newPos);
00083    trans_diff = new_trans-last_returned_trans;
00084    dist = gmtl::length(trans_diff);
00085 
00086    vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL)
00087       << "sigmoid: dist: " << dist << std::endl << vprDEBUG_FLUSH;
00088 
00089    // Check max threshold
00090    if(dist > mMaxThreshold)
00091    {
00092       return mLastReturnedPos;      // If outside of threshold, just return old data
00093    }
00094 
00095    // Get scale factor
00096    scale_factor = getScaleFactor(dist);
00097 
00098    if(scale_factor <= eps)
00099    { return mLastReturnedPos; }
00100    else if(scale_factor >= (1.0f-eps))
00101    {
00102       mLastReturnedPos = newPos;
00103       return newPos;
00104    }
00105    else
00106    {
00107       vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL)
00108          << "sigmoid: scale_factor: " << scale_factor << std::endl
00109          << vprDEBUG_FLUSH;
00110 
00111       vprASSERT((scale_factor > eps) && (scale_factor < (1.0f-eps)));
00112 
00113       gmtl::Vec3f ret_trans;
00114       gmtl::Matrix44f ret_val;
00115 
00116       ret_trans = last_returned_trans + (trans_diff * scale_factor);
00117 
00118       /*
00119       vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL)
00120          << "\tret_trans = last_returned_trans + (trans_diff * scale_factor) -->"
00121          << ret_trans << " = " << last_returned_trans << " + (" << trans_diff
00122          << " * " << scale_factor << " )\n" << vprDEBUG_FLUSH;
00123       */
00124 
00125       // Compute scaled rotation
00126       gmtl::Quatf source_rot, goal_rot, slerp_rot;
00127       gmtl::set( source_rot, mLastReturnedPos );
00128       gmtl::set( goal_rot, newPos );
00129 
00130       // ASSERT: We don't have two identical matrices
00131       gmtl::slerp( slerp_rot, scale_factor, source_rot, goal_rot );
00132       //slerp_rot.slerp( scale_factor,source_rot,goal_rot );    // Transform part way there
00133       gmtl::set( ret_val, slerp_rot );
00134       //ret_val.makeQuaternion( slerp_rot );            // Create the transform matrix to use
00135       //ret_val.setTrans(ret_trans);
00136       gmtl::setTrans(ret_val, ret_trans );
00137 
00138       mLastReturnedPos = ret_val;
00139       return mLastReturnedPos;
00140    }
00141 }

float gadget::LinearSigmoidPositionFilter::getScaleFactor const float    distance
 

Given a distance, return the scale factor based upon the minDist and maxDist values.

Definition at line 143 of file LinearSigmoidPositionFilter.cpp.

Referenced by getPos.

00144 {
00145    if(distance < mMinDist)
00146    {
00147       return 0.0f;
00148    }
00149    else if(distance > mMaxDist)
00150    {
00151       return 1.0f;
00152    }
00153    else
00154    {
00155       vprASSERT(mMaxDist >= mMinDist);
00156       float range = mMaxDist - mMinDist;
00157       float scale_factor = (distance-mMinDist)/range;
00158       return scale_factor;
00159    }
00160 }

void gadget::LinearSigmoidPositionFilter::setMinDist float    val [inline]
 

Definition at line 67 of file LinearSigmoidPositionFilter.h.

00067 { mMinDist = val;}

float gadget::LinearSigmoidPositionFilter::minDist   [inline]
 

Definition at line 68 of file LinearSigmoidPositionFilter.h.

00068 { return mMinDist;}

void gadget::LinearSigmoidPositionFilter::setMaxDist float    val [inline]
 

Definition at line 70 of file LinearSigmoidPositionFilter.h.

00070 { mMaxDist = val;}

float gadget::LinearSigmoidPositionFilter::maxDist   [inline]
 

Definition at line 71 of file LinearSigmoidPositionFilter.h.

00071 { return mMaxDist;}

void gadget::LinearSigmoidPositionFilter::setMaxThreshold float    val [inline]
 

Definition at line 73 of file LinearSigmoidPositionFilter.h.

00073 { mMaxThreshold = val; }

float gadget::LinearSigmoidPositionFilter::maxTheshold   [inline]
 

Definition at line 74 of file LinearSigmoidPositionFilter.h.

00074 { return mMaxThreshold; }


The documentation for this class was generated from the following files:
Generated on Sun May 2 14:27:01 2004 for Gadgeteer by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002