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

base/Trajectory

Go to the documentation of this file.
00001 /* **-*-c++-*-**************************************************************
00002   Copyright (C)2002 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: Trajectory 1029 2004-02-11 20:45:54Z jungd $
00019   $Revision: 1.5 $
00020   $Date: 2004-02-11 15:45:54 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
00022  
00023 ****************************************************************************/
00024 
00025 #ifndef _BASE_TRAJECTORY_
00026 #define _BASE_TRAJECTORY_
00027 
00028 #include <base/base>
00029 
00030 #include <base/Path>
00031 #include <base/Time>
00032 
00033 #include <base/TrajectoryTimeRep>
00034 #include <base/LineSegTrajectoryRep>
00035 #include <base/WaypointTrajectoryRep>
00036 #include <base/ParametricTrajectoryRep>
00037 
00038 
00039 namespace base {
00040 
00041 
00042 /**
00043  *  A Trajectory specifies a space-time curve.  It is a Path
00044  *   through 6-space (position & orientation) where each point
00045  *   occurs at a specific time. @see base::Path.  Note that unlike
00046  *   Path for which the parameter s varies over the path length, 
00047  *   instead s:[0..1] varies proportionally over 
00048  *   time t:[start-time, end-time]. 
00049  */
00050 class Trajectory : public Path
00051 {
00052 public:
00053   /// default trajectory - all points & times range over [0..1] secs.
00054   Trajectory();
00055 
00056   /// copy trajectory t
00057   Trajectory(const Trajectory& t);
00058 
00059   /// copy Path p (times will be in range [0..1] secs)
00060   /// If p has >2 distinguished points, then the trajectory is created by sampling the path
00061   ///  at those points, otherwise it is created by dividing the range s:[0..1] into the no. of
00062   //// samples specified.
00063   Trajectory(const Path& p, Int samples = 100);
00064 
00065   /// simple line segment start[position|orientation|time] - end[position|orientation|time]
00066   Trajectory(const Point3& sp, const Orient& so, const Time& st, 
00067              const Point3& ep, const Orient& eo, const Time& et);
00068 
00069   /// a set of 'waypoints' - actually points and their corresponding orientations & times.
00070   /// if deltas is true, the arrays are considered to specify the inter-waypoint deltas instead
00071   ///  (with the first point/orient being 0)
00072   Trajectory(const array<Point3>& points, const array<Orient>& orients = array<Orient>(), const array<Time>& times = array<Time>(), bool deltas=false);
00073 
00074   /// a set of 'waypoints'.  If vector dim is 4, specifies position & time only; dim 7, specifies
00075   ///  position and orientation using the EulerRPY (roll, pitch, yaw) convention & time; dim 8
00076   ///  specifies position and orientation as a quaternion qx,qy,qz,qw & time (secs).
00077   /// if deltas is true, the array is considered to specify the inter-waypoint deltas instead
00078   ///  (with the first point/orient/time being 0)
00079   Trajectory(const array<Vector>& points, bool deltas=false);
00080 
00081   /// arbitrary path defined by symbolic expressions for x,y,z,qx,qy,qz,qw,t in terms of s
00082   Trajectory(const ExpressionVector& p);
00083 
00084 
00085   virtual String className() const { return String("Trajectory"); }
00086 
00087   /// get cartesian position at time t
00088   Point3 position(const Time& t) const { return Path::position(trep->gets(t)); }
00089 
00090   /// get orientation at time t
00091   Orient orientation(const Time& t) const { return Path::orientation(trep->gets(t)); }
00092 
00093   /// get time at s:[0..1]
00094   Time time(Real s) const { return trep->time(s); }
00095 
00096   /// discard distinguished points and replace them by 'samples' distingushed points over s=[0..1]
00097   void resample(Int samples=100);
00098   
00099   /// add distinguished points as necessary to ensure that distance between the positions of any pair of distinguished points is <= dxmax
00100   void resample(const Real dxmax);
00101 
00102   /// shift time by dt
00103   void shiftTime(const Time& dt) { trep->shiftTime(dt); }
00104 
00105   /// scale time by s
00106   void scaleTime(Real s) { trep->scaleTime(s); }
00107 
00108   /// convert to a Path by discarding time information
00109   Path toPath() const;
00110 
00111   virtual void serialize(Serializer& s); ///< read or write object state to Serializer
00112 
00113   virtual bool formatSupported(String format, Real version = 1.0, ExternalizationType type = IO) const; ///< query if specific format is supported (for input, output or both)
00114   virtual void externalize(Externalizer& e, String format = "", Real version = 1.0); ///< read or write object state to Externalizer
00115 
00116 protected:
00117   // virtual initialization methods called by constructors
00118   virtual void create();
00119   virtual void create(const Trajectory& t);
00120   virtual void create(const Point3& sp, const Orient& so, const Point3& ep, const Orient& eo);
00121   virtual void create(const Point3& sp, const Orient& so, const Time& st, 
00122                       const Point3& ep, const Orient& eo, const Time& et);
00123   virtual void create(const array<Point3>& points, const array<Orient>& orients, bool deltas);
00124   virtual void create(const array<Point3>& points, const array<Orient>& orients, const array<Time>& times, bool deltas);
00125   virtual void create(const array<Vector>& points, bool deltas);
00126   virtual void create(const ExpressionVector& p);
00127 
00128 
00129   ref<TrajectoryTimeRep> trep; ///< representation
00130 
00131   void init(const array<Point3>& points, const array<Orient>& orients, const array<Time>& times, bool deltas); // waypoints init
00132 
00133   // Serialization helpers
00134   Serializable::SerializableDerivedInstantiator<LineSegTrajectoryRep> lineSegTrajectoryRepInstantiator;
00135   Serializable::SerializableDerivedInstantiator<WaypointTrajectoryRep> waypointTrajectoryRepInstantiator;
00136   Serializable::SerializableDerivedInstantiator<ParametricTrajectoryRep> parametricTrajectoryRepInstantiator;
00137 
00138 };
00139 
00140 
00141 // Operations
00142 
00143 inline std::ostream& operator<<(std::ostream& out, const Trajectory& t) // Output
00144 { return out; }
00145 
00146 
00147 } // base
00148 
00149 #endif

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