path_composite.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include "path_composite.hpp"
00044 #include "utilities/error.h"
00045 #include <memory>
00046
00047 namespace KDL {
00048
00049
00050
00051
00052
00053
00054 double Path_Composite::Lookup(double s) const
00055 {
00056
00057 if ( (cached_starts <=s) && ( s <= cached_ends) ) {
00058 return s - cached_starts;
00059 }
00060 double previous_s=0;
00061 for (unsigned int i=0;i<dv.size();++i) {
00062 if ((s <= dv[i])||(i == (dv.size()-1) )) {
00063 cached_index = i;
00064 cached_starts = previous_s;
00065 cached_ends = dv[i];
00066 return s - previous_s;
00067 }
00068 previous_s = dv[i];
00069 }
00070 return 0;
00071 }
00072
00073 Path_Composite::Path_Composite() {
00074 pathlength = 0;
00075 cached_starts = 0;
00076 cached_ends = 0;
00077 cached_index = 0;
00078 }
00079
00080 void Path_Composite::Add(Path* geom, bool aggregate ) {
00081 pathlength += geom->PathLength();
00082 dv.insert(dv.end(),pathlength);
00083 gv.insert( gv.end(),std::make_pair(geom,aggregate) );
00084 }
00085
00086 double Path_Composite::LengthToS(double length) {
00087 throw Error_MotionPlanning_Not_Applicable();
00088 return 0;
00089 }
00090
00091 double Path_Composite::PathLength() {
00092 return pathlength;
00093 }
00094
00095 Frame Path_Composite::Pos(double s) const {
00096 s = Lookup(s);
00097 return gv[cached_index].first->Pos(s);
00098 }
00099
00100 Twist Path_Composite::Vel(double s,double sd) const {
00101 s = Lookup(s);
00102 return gv[cached_index].first->Vel(s,sd);
00103 }
00104
00105 Twist Path_Composite::Acc(double s,double sd,double sdd) const {
00106 s = Lookup(s);
00107 return gv[cached_index].first->Acc(s,sd,sdd);
00108 }
00109
00110 Path* Path_Composite::Clone() {
00111 std::auto_ptr<Path_Composite> comp( new Path_Composite() );
00112 for (unsigned int i = 0; i < dv.size(); ++i) {
00113 comp->Add(gv[i].first->Clone(), gv[i].second);
00114 }
00115 return comp.release();
00116 }
00117
00118 void Path_Composite::Write(std::ostream& os) {
00119 os << "COMPOSITE[ " << std::endl;
00120 os << " " << dv.size() << std::endl;
00121 for (unsigned int i=0;i<dv.size();i++) {
00122 gv[i].first->Write(os);
00123 }
00124 os << "]" << std::endl;
00125 }
00126
00127 Path_Composite::~Path_Composite() {
00128 PathVector::iterator it;
00129 for (it=gv.begin();it!=gv.end();++it) {
00130 if (it->second)
00131 delete it->first;
00132 }
00133 }
00134
00135 }