basic/paths/PA_Points.cpp

Go to the documentation of this file.
00001 //## begin module%36FDB0E70104.cm preserve=no
00002 //        %X% %Q% %Z% %W%
00003 //## end module%36FDB0E70104.cm
00004 
00005 //## begin module%36FDB0E70104.cp preserve=no
00006 //## end module%36FDB0E70104.cp
00007 
00008 //## Module: PA_Points%36FDB0E70104; Pseudo Package body
00009 //## Source file: C:\project\mpk\code\Paths\PA_Points.cpp
00010 
00011 //## begin module%36FDB0E70104.additionalIncludes preserve=no
00012 //## end module%36FDB0E70104.additionalIncludes
00013 
00014 //## begin module%36FDB0E70104.includes preserve=yes
00015 #include <math.h>
00016 #include <iostream>
00017 #include <strstream>
00018 #include <assert.h>
00019 #include "streams/mystreams.h"
00020 //## end module%36FDB0E70104.includes
00021 
00022 // Configuration
00023 #include "kinematics\Configuration.h"
00024 // PA_Points
00025 #include "Paths\PA_Points.h"
00026 //## begin module%36FDB0E70104.additionalDeclarations preserve=yes
00027 //## end module%36FDB0E70104.additionalDeclarations
00028 
00029 
00030 // Class PA_Points 
00031 
00032 
00033 PA_Points::PA_Points ()
00034   //## begin PA_Points::PA_Points%922595690.hasinit preserve=no
00035   //## end PA_Points::PA_Points%922595690.hasinit
00036   //## begin PA_Points::PA_Points%922595690.initialization preserve=yes
00037   //## end PA_Points::PA_Points%922595690.initialization
00038 {
00039   //## begin PA_Points::PA_Points%922595690.body preserve=yes
00040   //## end PA_Points::PA_Points%922595690.body
00041 }
00042 
00043 
00044 PA_Points::~PA_Points()
00045 {
00046   //## begin PA_Points::~PA_Points%.body preserve=yes
00047   //## end PA_Points::~PA_Points%.body
00048 }
00049 
00050 
00051 
00052 //## Other Operations (implementation)
00053 PA_Points& PA_Points::operator = (const PA_Points& right)
00054 {
00055   //## begin PA_Points::operator=%923255757.body preserve=yes
00056 
00057         if( this == &right )
00058         {
00059                 return *this ;
00060         }
00061         Clear() ;
00062         for( int i = 0; i < right.Size() ; i++ )
00063         {
00064                 Configuration r = right[ i ] ;  //IMPROVE: this is supposed to be here
00065 
00066                 points.push_back( r ) ;
00067 //              points.push_back( r ) ;
00068 //              points.push_back( r ) ;
00069 //              AppendPoint( r ) ;
00070         }
00071         return *this ;
00072   //## end PA_Points::operator=%923255757.body
00073 }
00074 
00075 void PA_Points::AppendPoint (const Configuration& point)
00076 {
00077 #ifdef _DEBUG
00078     int pointsSize = points.size();
00079     if( pointsSize >= 1 )
00080     {
00081         int firstSize = points[ 0 ].Size();
00082         int thisSize = point.size();
00083         IJG_Assert( firstSize == thisSize );
00084         //this assert means that some things in the 
00085         //path aren't points in the same vector space
00086         //thats BAD
00087     }
00088 #endif
00089 
00090         points.push_back( point ) ;
00091 }
00092 
00093 void PA_Points::Clear ()
00094 {
00095         points.clear() ;
00096 }
00097 
00098 void PA_Points::Output () const
00099 {
00100   //## begin PA_Points::Output%923255763.body preserve=yes
00101         using std::cout ;
00102         using std::endl ;
00103         cout << "Path Start" << endl ;
00104         for( int i = 0; i < points.size(); i++ )
00105         {
00106                 points[ i ].Output() ;
00107                 cout << endl ;
00108         }
00109         cout << "PathEnd" << endl ;
00110   //## end PA_Points::Output%923255763.body
00111 }
00112 
00113 double PA_Points::PhysicalLength() const
00114 {
00115     double totalDistance = 0.0;
00116     int i;
00117     int size = Size() - 1;
00118     for( i = 0; i < size; ++i )
00119     {
00120         const Configuration& c0 = operator[]( i + 0 );
00121         const Configuration& c1 = operator[]( i + 1 );
00122         double distance = ( c1 - c0 ).Magnitude();
00123         totalDistance += distance;
00124     }
00125     return totalDistance;
00126 }
00127 
00128 unsigned int PA_Points::Size () const
00129 {
00130   //## begin PA_Points::Size%926550116.body preserve=yes
00131         return points.size() ;
00132   //## end PA_Points::Size%926550116.body
00133 }
00134 
00135 const Configuration& PA_Points::operator [](const unsigned int index) const
00136 {
00137         assert( index < points.size() ) ;
00138         return points[ index ] ;
00139 }
00140 
00141 Configuration& PA_Points::operator [] (const unsigned int index)
00142 {
00143         assert( index < points.size() ) ;
00144         return points[ index ] ;
00145 }
00146 
00147 Configuration PA_Points::GetConfiguration (double percent) const
00148 {
00149   //## begin PA_Points::GetConfiguration%926635235.body preserve=yes
00150         assert( percent >= 0.0 ) ;
00151         assert( percent <= 1.0 ) ;
00152         if( points.size() == 1 )
00153         {
00154                 return points[ 0 ] ;
00155         }
00156 
00157         assert( points.size() != 0 ) ;
00158         assert( points.size() >= 1 ) ;
00159         if( points.size() == 1 )
00160         {
00161                 return points[ 0 ] ;
00162         }
00163 
00164         //determine the correct index 
00165         int index1 = floor( ( points.size() - 1 ) * percent ) ;
00166         int index2 = ceil(  ( points.size() - 1 ) * percent );
00167         double remainder = ( points.size() - 1 ) * percent - ( floor( ( points.size() - 1 ) * percent ) ) ;
00168 
00169         double weight1 = ( 1 - remainder ) ;
00170         double weight2 = remainder ;
00171         return points[ index1 ] * weight1 + points[ index2 ] * weight2 ;
00172   //## end PA_Points::GetConfiguration%926635235.body
00173 }
00174 
00175 Configuration PA_Points::GetPoint(const unsigned int index) const
00176 {
00177         assert (index >= 0);
00178         assert (index < points.size() );
00179         return points[ index ];
00180 }
00181 
00182 void PA_Points::Serialize (char* str, const unsigned int size) const
00183 {
00184   //## begin PA_Points::Serialize%933360619.body preserve=yes
00185         //output the start marker
00186         using std::endl ;
00187         using std::strstream ;
00188         strstream stream( str, size, std::ios::out ) ;
00189         stream << "#PA_POINTS" << endl ;
00190         stream << *this ;       
00191 
00192   //## end PA_Points::Serialize%933360619.body
00193 }
00194 
00195 void PA_Points::AppendPointToBeginning (const Configuration& point)
00196 {
00197   //## begin PA_Points::AppendPointToBeginning%965675402.body preserve=yes
00198         points.insert( points.begin(), point ) ;
00199   //## end PA_Points::AppendPointToBeginning%965675402.body
00200 }
00201 
00202 void PA_Points::DeleteFirstPoint()
00203 {
00204         points.erase(points.begin());
00205 }
00206 
00207 // Additional Declarations
00208   //## begin PA_Points%36FDB0E70104.declarations preserve=yes
00209 //-----------------------------------------------------------------------------
00210 std::ostream & operator<<(std::ostream &os, const PA_Points& v)
00211 {
00212         using std::endl ;
00213         os << v.Size() << endl ;
00214 
00215         for( int i = 0; i < v.Size(); i++ )
00216         {
00217                 Configuration config = v[ i ]; 
00218                 os << config << endl ;
00219         }
00220 
00221         //output the terminating marker
00222         os << "#end_pa_points" << endl ;
00223         return os ;
00224 }
00225 //-----------------------------------------------------------------------------
00226 std::istream & operator>>( std::istream &is, PA_Points& v)
00227 {
00228         int size = 0 ;
00229         is >> size ;
00230 
00231         for( int i = 0; i < size; i++ )
00232         {
00233                 Configuration config  ;
00234                 is >> config ;
00235                 v.AppendPoint( config ) ;
00236         }
00237 
00238         char marker[ 300 ] = "" ;
00239         eatwhite( is ) ;
00240         is.getline( marker, 300 ) ;
00241         assert( stricmp( marker, "#end_pa_points" ) == 0 ) ;
00242 
00243         return is ;
00244 }
00245 //-----------------------------------------------------------------------------
00246   //## end PA_Points%36FDB0E70104.declarations
00247 //## begin module%36FDB0E70104.epilog preserve=yes
00248 //## end module%36FDB0E70104.epilog
00249 

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