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 #include <base/WaypointTrajectoryRep>
00026
00027 #include <base/Serializer>
00028
00029 using base::WaypointTrajectoryRep;
00030
00031 using base::Time;
00032
00033
00034 Time WaypointTrajectoryRep::time(Real s) const
00035 {
00036 Math::bound<Real>(s,0,1);
00037 return Time( times[0].seconds() + ( (times[times.size()-1] - times[0]).seconds() * s ) );
00038 }
00039
00040
00041 void WaypointTrajectoryRep::shiftTime(const Time& dt)
00042 {
00043 for(Int i=0; i<times.size(); i++)
00044 times[i] += dt;
00045 }
00046
00047
00048 void WaypointTrajectoryRep::scaleTime(Real s)
00049 {
00050 for(Int i=0; i<times.size(); i++)
00051 times[i] *= s;
00052 }
00053
00054
00055 Real WaypointTrajectoryRep::gets(const Time& t) const
00056 {
00057 const Time& st(times[0]);
00058 const Time& et(times[times.size()-1]);
00059 Time bt(t);
00060 Math::bound<Time>(bt,st,et);
00061 return (bt-st).seconds() / (et-st).seconds();
00062 }
00063
00064 void WaypointTrajectoryRep::serialize(Serializer& s)
00065 {
00066 WaypointPathRep::serialize(s);
00067 s(times,"times");
00068 }
00069
00070
00071 void WaypointTrajectoryRep::computeSis()
00072 {
00073
00074 if (points.size() == 0) { points.at(0) = points.at(1) = Point3(); }
00075 if (orients.size() == 0) { orients.at(0) = orients.at(1) = Orient(); }
00076 if (times.size() == 0) { times.at(0) = 0; times.at(1) = 1; }
00077
00078 Assert(points.size() == orients.size());
00079 Assert(points.size() == times.size());
00080
00081
00082 Real T = (times[times.size()-1] - times[0]).seconds();
00083 Int i = 1;
00084 si.resize(points.size());
00085 si[0] = 0;
00086 while (i<points.size()) {
00087 if (!(times[i-1] < times[i]))
00088 throw std::invalid_argument(Exception("times must be monotonically increasing"));
00089 si[i] = (times[i] - times[0]).seconds() / T;
00090 i++;
00091 }
00092
00093 }