00001 /**************************************************************************** 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: Path 1029 2004-02-11 20:45:54Z jungd $ 00019 $Revision: 1.6 $ 00020 $Date: 2004-02-11 15:45:54 -0500 (Wed, 11 Feb 2004) $ 00021 $Author: jungd $ 00022 00023 ****************************************************************************/ 00024 00025 #ifndef _BASE_PATH_ 00026 #define _BASE_PATH_ 00027 00028 #include <base/base> 00029 #include <base/Serializable> 00030 #include <base/Externalizable> 00031 #include <base/Point3> 00032 #include <base/Orient> 00033 #include <base/Vector> 00034 #include <base/Expression> 00035 00036 #include <base/PathRep> 00037 #include <base/LineSegPathRep> 00038 #include <base/WaypointPathRep> 00039 00040 00041 namespace base { 00042 00043 00044 /** 00045 * A Path specifies a bounded inifinite number of continous 00046 * points in 6-space (cartesian position via Point3 and 00047 * orientation via Orient). The points are expressed 00048 * parametrically in terms of s:[0..1] over the path length. 00049 */ 00050 class Path : public Serializable, public Externalizable 00051 { 00052 public: 00053 /// default path - all points are 0 00054 Path(); 00055 00056 /// copy path p 00057 Path(const Path& p); 00058 00059 /// simple line segment start[position|orientation] - end[position|orientation] 00060 Path(const Point3& sp, const Orient& so, const Point3& ep, const Orient& eo); 00061 00062 /// a set of 'waypoints' - actually points and their corresponding orientations. 00063 /// if deltas is true, the arrays are considered to specify the inter-waypoint deltas instead 00064 /// (with the first point/orient being 0) 00065 Path(const array<Point3>& points, const array<Orient>& orients = array<Orient>(), bool deltas=false); 00066 00067 /// a set of 'waypoints'. If vector dim is 3, specifies position only; dim 6, specifies 00068 /// position and orientation using the EulerRPY (roll, pitch, yaw) convention; dim 7 00069 /// specifies position and orientation as a quaternion qx,qy,qz,qw. 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 Path(const array<Vector>& points, bool deltas=false); 00073 00074 /// arbitrary path defined by symbolic expressions for x,y,z,qx,qy,qz,qw in terms of s 00075 Path(const ExpressionVector& p); 00076 00077 00078 virtual String className() const { return String("Path"); } 00079 00080 /// get cartesian position at s:[0..1] 00081 Point3 position(Real s) const { return rep->position(s); } 00082 00083 /// get orientation at s:[0..1] 00084 Orient orientation(Real s) const { return rep->orientation(s); } 00085 00086 /// discard distinguished points and replace them by 'samples' distingushed points over s=[0..1] 00087 void resample(Int samples=100); 00088 00089 /// add distinguished points as necessary to ensure that distance between the positions of any pair of distinguished points is <= dxmax 00090 void resample(const Real dxmax); 00091 00092 /// get application defined coordinate frame specifier. 00093 /// Some means of creating a Path provide a coordinate frame specifier. e.g. xml externalization 00094 /// this returns that string (or whatever was set via setCoordFrame() - defaults to the empty String) 00095 const String& getCoordFrame() const { return frame; } 00096 00097 /// set application defined coordinate frame specifier. 00098 void setCoordFrame(const String& coordFrame) { frame=coordFrame; } 00099 00100 00101 /// get application defined unit specifier. 00102 /// Some means of creating a Path provide unit specifier. e.g. xml externalization 00103 /// this returns that string (or whatever was set via setUnits() - defaults to the empty String) 00104 const String& getUnits() const { return units; } 00105 00106 /// set application defined unit specifier. 00107 void setUnits(const String& unitSpecifier) { units = unitSpecifier; } 00108 00109 00110 /// some values of s may correspond to distinguished points along a path. 00111 /// the values s=0 and s=1 are always distinguished values. For example, 00112 /// if the path was specified using waypoints, then there will be a 00113 /// distinguished value of s for each waypoint. 0 <= i < numDistinguishedValues() 00114 Real distinguishedValue(Int i) const { return rep->distinguishedValue(i); } 00115 00116 Int numDistinguishedValues() const ///< number of distinguished s values 00117 { return rep->numDistinguishedValues(); } 00118 00119 /// translate the path position by t 00120 void translate(const Vector3& t) { rep->translate(t); } 00121 00122 /// rotate the path orientation by r 00123 void rotate(const Quat4& r) { rep->rotate(r); } 00124 00125 /// transform the path by m 00126 void transform(const Matrix4& m) { rep->transform(m); } 00127 00128 /// scale position coords. by s 00129 void scalePosition(Real s) { rep->scalePosition(s); } 00130 00131 00132 virtual void serialize(Serializer& s); ///< read or write object state to Serializer 00133 00134 virtual bool formatSupported(String format, Real version = 1.0, ExternalizationType type = IO) const; ///< query if specific format is supported (for input, output or both) 00135 virtual void externalize(Externalizer& e, String format = "", Real version = 1.0); ///< read or write object state to Externalizer 00136 00137 protected: 00138 // virtual initialization methods called by constructors 00139 virtual void create(); 00140 virtual void create(const Path& p); 00141 virtual void create(const Point3& sp, const Orient& so, const Point3& ep, const Orient& eo); 00142 virtual void create(const array<Point3>& points, const array<Orient>& orients, bool deltas); 00143 virtual void create(const array<Vector>& points, bool deltas); 00144 virtual void create(const ExpressionVector& p); 00145 00146 ref<PathRep> rep; ///< representation 00147 String frame; ///< application defined coord. frame specifier 00148 String units; ///< application defined unit specifier 00149 00150 void init(const array<Point3>& points, const array<Orient>& orients, bool deltas); // waypoints init 00151 00152 // Serialization helpers 00153 Serializable::SerializableDerivedInstantiator<LineSegPathRep> lineSegPathRepInstantiator; 00154 Serializable::SerializableDerivedInstantiator<WaypointPathRep> waypointPathRepInstantiator; 00155 00156 friend class Trajectory; 00157 }; 00158 00159 00160 // Operations 00161 00162 inline std::ostream& operator<<(std::ostream& out, const Path& p) // Output 00163 { return out; } 00164 00165 00166 } // base 00167 00168 #endif