collisiondetectors/CD_Linear.cpp

Go to the documentation of this file.
00001 #include "CollisionDetectors\CD_Linear.h"
00002 #include "Universe\Universe.h"
00003 
00004 
00005 CD_Linear::CD_Linear (const CD_Linear& right)
00006   :     
00007         CollisionDetectorBase( right ),
00008         CD_Bool( right ),
00009         m_StatNumberOfLinearCalls( 0 )
00010 {
00011         // Copy Constructor
00012         useWrapping = right.useWrapping;
00013 }
00014 
00015 CD_Linear::CD_Linear( const Universe& universe )
00016 :       
00017         CollisionDetectorBase( universe ),
00018         CD_Bool( universe ),
00019         m_StatNumberOfLinearCalls( 0 )
00020 {
00021         // Default:  Do not use wrapping joints.
00022     useWrapping = false;
00023 }
00024 
00025 CD_Linear::~CD_Linear()
00026 {
00027 }
00028 
00029 Configuration CD_Linear::GetLastIntersection () const
00030 {
00031         return lastIntersection ;
00032 }
00033 
00034 Configuration CD_Linear::GetLastValid () const
00035 {
00036         return lastValid ;
00037 }
00038 
00039 //=============================================================================
00040 // LinearTest
00041 //
00042 // Description: tests the linear path in CSpace and returns the status
00043 //=============================================================================
00044 CD_RESULT CD_Linear::LinearTest( const Configuration& c1, const Configuration& c2 )
00045 {
00046     bool completelyFree = true;
00047     bool completelyObstacle = true;
00048     unsigned int steps = 32;
00049     int i;
00050     for( i = 0; i <= steps; ++i )
00051     {
00052         double percent = static_cast< double >( i ) / static_cast< double >( steps );
00053         Configuration current = c1 * percent + c2 * ( 1.0 - percent );
00054         bool collision = IsInterfering( current );
00055         if( collision )
00056         {
00057             completelyFree = false;
00058         }
00059         else
00060         {
00061             completelyObstacle = false;
00062         }
00063 
00064         if( ( !completelyFree ) && (!completelyObstacle ) )
00065         {
00066             return CD_PARTIAL;
00067         }
00068     }
00069 
00070     if( completelyFree )
00071     {
00072         return CD_FREE;
00073     }
00074     return CD_OBSTACLE;
00075 }
00076 
00077 //=============================================================================
00078 // IncrementLinearStat
00079 //
00080 // Description: gets the stat of how many times this has been called
00081 //=============================================================================
00082 int CD_Linear::GetNumberOfTimesCalledLinear()
00083 {
00084         return this->m_StatNumberOfLinearCalls;
00085 }
00086 
00087 //=============================================================================
00088 // IncrementLinearStat
00089 //
00090 // Description: increments the stats of how many times this collision detector 
00091 // has been called
00092 //=============================================================================
00093 void CD_Linear::IncrementLinearStat()
00094 {
00095         m_StatNumberOfLinearCalls++;
00096 }
00097 
00098 //resets the stats for counting number of times called
00099 void CD_Linear::ResetStats()
00100 {
00101         CD_Bool::ResetStats();
00102         m_StatNumberOfLinearCalls = 0;
00103 }
00104 
00105 
00106 void CD_Linear::SetUseWrapping( bool wrapping )
00107 {
00108         useWrapping = wrapping;
00109 }

Generated on Sat Apr 1 21:30:36 2006 for Motion Planning Kernel by  doxygen 1.4.6-NO