Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

base/WaypointTrajectoryRep.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002   Copyright (C)2003 David Jung <opensim@pobox.com>
00003 
00004   This program/file is free software; you can redistribute it and/or modify
00005   it under the terms of the GNU General Public License as published by
00006   the Free Software Foundation; either version 2 of the License, or
00007   (at your option) any later version.
00008   
00009   This program is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012   GNU General Public License for more details. (http://www.gnu.org)
00013   
00014   You should have received a copy of the GNU General Public License
00015   along with this program; if not, write to the Free Software
00016   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017   
00018   $Id: WaypointTrajectoryRep.cpp 1029 2004-02-11 20:45:54Z jungd $
00019   $Revision: 1.2 $
00020   $Date: 2004-02-11 15:45:54 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
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   // ensure at least two points
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   // s's map [0..1] to the range [start-time..end-time]
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 }

Generated on Thu Jul 29 15:56:17 2004 for OpenSim by doxygen 1.3.6