openrave.org

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
trajectory.h
Go to the documentation of this file.
1 // -*- coding: utf-8 -*-
2 // Copyright (C) 2006-2011 Rosen Diankov (rosen.diankov@gmail.com)
3 //
4 // This file is part of OpenRAVE.
5 // OpenRAVE is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef OPENRAVE_TRAJECTORY_H
23 #define OPENRAVE_TRAJECTORY_H
24 
25 namespace OpenRAVE {
26 
31 {
32 public:
34  virtual ~TrajectoryBase() {
35  }
36 
38  static inline InterfaceType GetInterfaceTypeStatic() {
39  return PT_Trajectory;
40  }
41 
42  virtual void Init(const ConfigurationSpecification& spec) = 0;
43 
50  virtual void Insert(size_t index, const std::vector<dReal>& data, bool bOverwrite=false) = 0;
51 
59  virtual void Insert(size_t index, const std::vector<dReal>& data, const ConfigurationSpecification& spec, bool bOverwrite=false) = 0;
60 
62  virtual void Remove(size_t startindex, size_t endindex) = 0;
63 
69  virtual void Sample(std::vector<dReal>& data, dReal time) const = 0;
70 
78  virtual void Sample(std::vector<dReal>& data, dReal time, const ConfigurationSpecification& spec) const;
79 
80  virtual const ConfigurationSpecification& GetConfigurationSpecification() const = 0;
81 
83  virtual size_t GetNumWaypoints() const = 0;
84 
91  virtual void GetWaypoints(size_t startindex, size_t endindex, std::vector<dReal>& data) const = 0;
92 
101  virtual void GetWaypoints(size_t startindex, size_t endindex, std::vector<dReal>& data, const ConfigurationSpecification& spec) const;
102 
108  inline void GetWaypoint(int index, std::vector<dReal>& data) const
109  {
110  int numpoints = GetNumWaypoints();
111  BOOST_ASSERT(index >= -numpoints && index < numpoints);
112  if( index < 0 ) {
113  index += numpoints;
114  }
115  GetWaypoints(index,index+1,data);
116  }
117 
123  inline void GetWaypoint(int index, std::vector<dReal>& data, const ConfigurationSpecification& spec) const
124  {
125  int numpoints = GetNumWaypoints();
126  BOOST_ASSERT(index >= -numpoints && index < numpoints);
127  if( index < 0 ) {
128  index += numpoints;
129  }
130  GetWaypoints(index,index+1,data,spec);
131  }
132 
134  virtual dReal GetDuration() const = 0;
135 
137  virtual void serialize(std::ostream& O, int options=0) const;
138 
140  virtual InterfaceBasePtr deserialize(std::istream& I);
141 
142  virtual void Clone(InterfaceBaseConstPtr preference, int cloningoptions);
143 
144  // Old Trajectory API
145 
147  class Point
148  {
149 public:
150  Point() : time(0) {
151  }
152  Point(const std::vector<dReal>& newq, dReal newtime) : time(newtime) {
153  q = newq;
154  }
155  Point(const std::vector<dReal>& newq, const Transform& newtrans, dReal newtime) : time(newtime) {
156  q=newq;
157  trans=newtrans;
158  }
160  std::vector<dReal> q, qdot, qtorque;
162  Vector linearvel, angularvel;
163  };
164 
166  typedef Point TPOINT RAVE_DEPRECATED;
167 
169  virtual bool SampleTrajectory(dReal time, Point& tp) const RAVE_DEPRECATED;
170 
172  virtual const std::vector<Point>& GetPoints() const RAVE_DEPRECATED;
173 
175  inline int GetDOF() const RAVE_DEPRECATED {
176  return GetConfigurationSpecification().GetDOF();
177  }
178 
180  virtual dReal GetTotalDuration() const RAVE_DEPRECATED
181  {
182  return GetDuration();
183  }
184 
186  virtual bool Write(std::ostream& O, int options) const RAVE_DEPRECATED {
187  serialize(O,options);
188  return true;
189  }
190 
192  virtual bool Read(std::istream& I, RobotBaseConstPtr) RAVE_DEPRECATED {
193  deserialize(I);
194  return true;
195  }
196 
198  virtual int GetInterpMethod() const RAVE_DEPRECATED {
199  return 0;
200  }
201 
203  virtual bool CalcTrajTiming(RobotBasePtr probot, int interp, bool autocalc, bool activedof, dReal fmaxvelmult=1) RAVE_DEPRECATED;
204 
206  virtual void Clear() RAVE_DEPRECATED
207  {
208  Remove(0,GetNumWaypoints());
209  }
210 
212  virtual void AddPoint(const Point& p) RAVE_DEPRECATED;
213 
215  virtual void Reset(int dof) RAVE_DEPRECATED
216  {
217  Remove(0,GetNumWaypoints());
218  }
219 
221  static const int TO_OneLine RAVE_DEPRECATED = 1;
222  static const int TO_NoHeader RAVE_DEPRECATED = 2;
223  static const int TO_IncludeTimestamps RAVE_DEPRECATED = 4;
224  static const int TO_IncludeBaseTransformation RAVE_DEPRECATED = 8;
225  static const int TO_IncludeVelocities RAVE_DEPRECATED = 0x10;
226  static const int TO_IncludeTorques RAVE_DEPRECATED = 0x20;
227  static const int TO_InterpolationMask RAVE_DEPRECATED = 0x1c0;
228  static const int NONE RAVE_DEPRECATED = 0;
229  static const int LINEAR RAVE_DEPRECATED = 1;
230  static const int LINEAR_BLEND RAVE_DEPRECATED = 2;
231  static const int CUBIC RAVE_DEPRECATED = 3;
232  static const int QUINTIC RAVE_DEPRECATED = 4;
233  static const int NUM_METHODS RAVE_DEPRECATED = 5;
234 
235 protected:
237  return boost::static_pointer_cast<TrajectoryBase>(shared_from_this());
238  }
240  return boost::static_pointer_cast<TrajectoryBase const>(shared_from_this());
241  }
242 
243 private:
244  virtual const char* GetHash() const {
246  }
247 
249  mutable std::vector<Point> __vdeprecatedpoints;
250 };
251 
253 typedef TrajectoryBase Trajectory RAVE_DEPRECATED;
254 
255 } // end namespace OpenRAVE
256 
257 #endif // TRAJECTORY_H