ISeeML  1.0
CompoundPath.hpp
1 //
2 // Definition of iSeeML::rob::CompoundPath, superclass of every
3 // other ISeeML compound/complex/composed robotic paths' class.
4 //
5 
6 // To only include this definition once
7 #ifndef ISEEML_COMP_PATH_HH
8 #define ISEEML_COMP_PATH_HH
9 
10 
11 // This class needs the definition of iSeeML::rob::CurvConfig.
12 #include <iSeeML/rob/CurvConfig.hpp>
13 // This class needs the definition of iSeeML::rob::BasicPath.
14 #include <iSeeML/rob/BasicPath.hpp>
15 
29  // === Object's Fields ==========================================
30 
31  // The set of basic paths is defined in sub-class, and is
32  // manipulated through piece and replace virtual methods, as well
33  // as through copy operator.
34 
39  static const string ClassName;
40 
41 
42  // === Constructors and Destructors =============================
43 
44  // None, this is an abstract class with no object's fields.
45 
46 public:
47  // === Description Methods ======================================
48 
54 #define ISEEML_ROB_COMPATH_forall_pieces(i) \
55  int i; for(i = 1; i <= nbPieces(); i++)
56 
67  void writeTo(ostream& O) const {
68  O << '{'; ISEEML_ROB_COMPATH_forall_pieces(i)
69  O << piece(i) << (i == nbPieces() ? "}" : ", "); }
70 
71 
79  const iSeeML::rob::OrPtConfig& start() const { return piece(1).start(); }
80 
88  const iSeeML::rob::OrPtConfig& end() const
89  { return piece( nbPieces() ).end(); }
90 
91 
114  const iSeeML::rob::BasicPath& piece(const int index) const {
115  // cout << this << "->CP::piece(" << index << ") const" << endl;
116  return getPiece(index); }
117 
118 
126  double length() const {
127  double res = 0; ISEEML_ROB_COMPATH_forall_pieces(i)
128  res += piece(i).length(); return res; }
129 
137  double deflection() const {
138  double res = 0; ISEEML_ROB_COMPATH_forall_pieces(i)
139  res += piece(i).deflection(); return res; }
140 
145  virtual int nbPieces() const = 0;
146 
147  // === Modification Methods =====================================
148 
166  iSeeML::rob::BasicPath& piece(const int index) {
167  // cout << this << "->CP::piece(" << index << ")" << endl;
168  return getPiece(index); }
169 
170 
171  // === Operators ================================================
172 
191  iSeeML::rob::CurvConfig operator[](const double& s) const {
192  int pieceNb = 1; // Start from the first piece
193  double arcLength = s, l = piece(pieceNb).length();
194 #ifdef ISEEML_CHECK_COMP_PATH_PRECOND
195  if (s < 0) cerr << ClassName << "::operator[]:"
196  << " negative arc length " << s << endl;
197 #endif
198  // Search the piece corresponding to the arc length
199  while (arcLength > l)
200 #ifdef ISEEML_CHECK_COMP_PATH_PRECOND
201  if ( pieceNb == nbPieces() )
202  cerr << ClassName << "::operator[]:"
203  << " arc length " << s << endl
204  << " bigger than length " << length() << endl;
205  else
206 #endif
207  { arcLength -= l;
208 #ifdef ISEEML_CHECK_ARRAY_ELEMT
209  if ( pieceNb == nbPieces() ) l = arcLength; // stop
210  else
211 #endif
212  l = piece(++pieceNb).length(); }
213  // Return the configuration in the selected piece
214  return( piece(pieceNb)[arcLength] ); } // end of operator[]
215 
216 protected:
217  // === Various Methods ==========================================
218 
237  iSeeML::rob::BasicPath& getPiece(const int index) const {
238  // cout << this << "->CP::getPiece(" << index << ")" << endl;
239 #ifdef ISEEML_CHECK_COMP_PATH_PRECOND
240  if ( !nbPieces() )
241  cerr << ClassName << "::piece: no pieces!!!" << endl;
242  else if ( (index < 1) || ( index > nbPieces() ) )
243  cerr << ClassName << "::piece: abnormal index "
244  << index << ", not in 1.." << nbPieces() << endl;
245 #endif
246  const int nb =
247 #ifdef ISEEML_CHECK_ARRAY_ELEMT
248  index < 2 ? 1 : index >= nbPieces() ? nbPieces() :
249 #endif
250  index; return _piece(nb); }
251 
263  virtual iSeeML::rob::BasicPath& _piece(const int index) const = 0;
264 
265 }; // end of class iSeeML::rob::CompoundPath
266 
267 #endif // end of definition
268 
void writeTo(ostream &O) const
Description method, writing a description of the path in a given output stream (the array of pieces i...
Definition: CompoundPath.hpp:67
virtual double deflection() const =0
Description method, giving the path&#39;s deflection (change of orientation).
This class defines compound (or complex, or composed) paths, which are made of a set of basic paths...
Definition: CompoundPath.hpp:28
This class defines superclass of basic paths, from which compound paths can be built.
Definition: BasicPath.hpp:21
const iSeeML::rob::OrPtConfig & end() const
Description method, giving the path&#39;s final configuration (last piece&#39;s starting configuration).
Definition: CompoundPath.hpp:88
const iSeeML::rob::OrPtConfig & start() const
Description method, giving the path&#39;s starting configuration (first piece&#39;s starting configuration)...
Definition: CompoundPath.hpp:79
double deflection() const
Description method, giving the path&#39;s deflection (sum of the pieces&#39; deflection). ...
Definition: CompoundPath.hpp:137
virtual double length() const =0
Description method, giving the path&#39;s length.
This class defines a standard robotic configuration, containing the position of a reference point and...
Definition: OrPtConfig.hpp:45
iSeeML::rob::BasicPath & piece(const int index)
Modification method, returning (for modification) the basic path of given index in the list of which ...
Definition: CompoundPath.hpp:166
iSeeML::rob::CurvConfig operator[](const double &s) const
Description method, giving a configuration at a given arc length along the path.
Definition: CompoundPath.hpp:191
double length() const
Description method, giving the path&#39;s length (sum of the pieces&#39; length).
Definition: CompoundPath.hpp:126
virtual const iSeeML::rob::OrPtConfig & start() const =0
Description method, giving the path&#39;s starting configuration.
virtual iSeeML::rob::BasicPath & _piece(const int index) const =0
Virtual method returning the basic path of given index in the list of which this compound path is mad...
virtual int nbPieces() const =0
Description method, giving the number of pieces of the path.
This class is the base class of all robotic paths in ISeeML.
Definition: Path.hpp:51
iSeeML::rob::BasicPath & getPiece(const int index) const
Method returning the basic path of given index in the list of which this compound path is made...
Definition: CompoundPath.hpp:237
This class defines a more precise configuration than classical ones for mobile robots.
Definition: CurvConfig.hpp:30
virtual const iSeeML::rob::OrPtConfig & end() const =0
Description method, giving the path&#39;s final configuration.
const iSeeML::rob::BasicPath & piece(const int index) const
Description method, returning the (constant) basic path of given index in the list of which this comp...
Definition: CompoundPath.hpp:114