00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <math.h>
00016 #include <iostream>
00017 #include <strstream>
00018 #include <assert.h>
00019 #include "streams/mystreams.h"
00020
00021
00022
00023 #include "kinematics\Configuration.h"
00024
00025 #include "Paths\PA_Points.h"
00026
00027
00028
00029
00030
00031
00032
00033 PA_Points::PA_Points ()
00034
00035
00036
00037
00038 {
00039
00040
00041 }
00042
00043
00044 PA_Points::~PA_Points()
00045 {
00046
00047
00048 }
00049
00050
00051
00052
00053 PA_Points& PA_Points::operator = (const PA_Points& right)
00054 {
00055
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 ] ;
00065
00066 points.push_back( r ) ;
00067
00068
00069
00070 }
00071 return *this ;
00072
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
00085
00086
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
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
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
00131 return points.size() ;
00132
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
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
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
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
00185
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
00193 }
00194
00195 void PA_Points::AppendPointToBeginning (const Configuration& point)
00196 {
00197
00198 points.insert( points.begin(), point ) ;
00199
00200 }
00201
00202 void PA_Points::DeleteFirstPoint()
00203 {
00204 points.erase(points.begin());
00205 }
00206
00207
00208
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
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
00247
00248
00249