Main MRPT website > C++ reference for MRPT 1.9.9
CPoseInterpolatorBase.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
11 #include <mrpt/system/datetime.h>
12 #include <mrpt/utils/TEnumType.h>
13 #include <mrpt/poses/SE_traits.h>
15 #include <mrpt/poses/poses_frwds.h>
16 
17 namespace mrpt
18 {
19 namespace poses
20 {
21 /** Type to select the interpolation method in CPoseInterpolatorBase derived
22  * classes.
23  * - imSpline: Spline interpolation using 4 points (2 before + 2 after the
24  * query point).
25  * - imLinear2Neig: Linear interpolation between the previous and next
26  * neightbour.
27  * - imLinear4Neig: Linear interpolation using the linear fit of the 4 closer
28  * points (2 before + 2 after the query point).
29  * - imSSLLLL : Use Spline for X and Y, and Linear Least squares for Z, yaw,
30  * pitch and roll.
31  * - imSSLSLL : Use Spline for X, Y and yaw, and Linear Lesat squares for Z,
32  * pitch and roll.
33  * - imLinearSlerp: Linear for X,Y,Z, Slerp for 3D angles.
34  * - imSplineSlerp: Spline for X,Y,Z, Slerp for 3D angles.
35  * \ingroup interpolation_grp poses_grp
36  */
38 {
39  imSpline = 0,
46 };
47 
48 /** Base class for SE(2)/SE(3) interpolators. See docs for derived classes.
49 * \ingroup interpolation_grp poses_grp
50 */
51 template <int DIM>
53 {
54  public:
55  /** Default ctor: empty sequence of poses */
57 
58  /** @name Type definitions and STL-like container interface
59  * @{ */
60 
61  /** TPose2D or TPose3D */
63  /** CPose2D or CPose3D */
65  /** TPoint2D or TPoint3D */
67 
68  typedef std::pair<mrpt::system::TTimeStamp, pose_t> TTimePosePair;
69  typedef std::map<mrpt::system::TTimeStamp, pose_t> TPath;
70  typedef typename TPath::iterator iterator;
72  typedef typename TPath::reverse_iterator reverse_iterator;
73  typedef typename TPath::const_reverse_iterator const_reverse_iterator;
74 
75  inline iterator begin() { return m_path.begin(); }
76  inline const_iterator begin() const { return m_path.begin(); }
77  inline const_iterator cbegin() const { return m_path.cbegin(); }
78  inline iterator end() { return m_path.end(); }
79  inline const_iterator end() const { return m_path.end(); }
80  inline const_iterator cend() const { return m_path.cend(); }
81  inline reverse_iterator rbegin() { return m_path.rbegin(); }
82  inline const_reverse_iterator rbegin() const { return m_path.rbegin(); }
83  inline reverse_iterator rend() { return m_path.rend(); }
84  inline const_reverse_iterator rend() const { return m_path.rend(); }
86  {
87  return m_path.lower_bound(t);
88  }
90  {
91  return m_path.lower_bound(t);
92  }
93 
95  {
96  return m_path.upper_bound(t);
97  }
99  {
100  return m_path.upper_bound(t);
101  }
102 
103  iterator erase(iterator element_to_erase)
104  {
105  m_path.erase(element_to_erase++);
106  return element_to_erase;
107  }
108 
109  size_t size() const { return m_path.size(); }
110  bool empty() const { return m_path.empty(); }
111  iterator find(const mrpt::system::TTimeStamp& t) { return m_path.find(t); }
113  {
114  return m_path.find(t);
115  }
116  /** @} */
117 
118  /** Inserts a new pose in the sequence.
119  * It overwrites any previously existing pose at exactly the same time.
120  */
121  void insert(mrpt::system::TTimeStamp t, const pose_t& p);
122  /** Overload (slower) */
123  void insert(mrpt::system::TTimeStamp t, const cpose_t& p);
124 
125  /** Returns the pose at a given time, or interpolates using splines if there
126  * is not an exact match.
127  * \param t The time of the point to interpolate.
128  * \param out_interp The output interpolated pose.
129  * \param out_valid_interp Whether there was information enough to compute
130  * the interpolation.
131  * \return A reference to out_interp
132  */
134  mrpt::system::TTimeStamp t, pose_t& out_interp,
135  bool& out_valid_interp) const;
136  /** \overload (slower) */
138  mrpt::system::TTimeStamp t, cpose_t& out_interp,
139  bool& out_valid_interp) const;
140 
141  /** Clears the current sequence of poses */
142  void clear();
143 
144  /** Set value of the maximum time to consider interpolation.
145  * If set to a negative value, the check is disabled (default behavior). */
146  void setMaxTimeInterpolation(double time);
147  /** Set value of the maximum time to consider interpolation */
148  double getMaxTimeInterpolation();
149 
150  /** Get the previous CPose3D in the map with a minimum defined distance.
151  * \return true if pose was found, false otherwise */
153  const mrpt::system::TTimeStamp& t, double distance, pose_t& out_pose);
154  /** \overload (slower) */
156  const mrpt::system::TTimeStamp& t, double distance, cpose_t& out_pose);
157 
158  /** Saves the points in the interpolator to a text file, with this format:
159  * Each row contains these elements separated by spaces:
160  * - Timestamp: As a "double time_t" (see mrpt::system::timestampTotime_t).
161  * - x y z: The 3D position in meters.
162  * - yaw pitch roll: The angles, in radians
163  * \sa loadFromTextFile
164  * \return true on success, false on any error.
165  */
166  bool saveToTextFile(const std::string& s) const;
167 
168  /** Saves the points in the interpolator to a text file, with the same
169  * format that saveToTextFile, but interpolating the path with the given
170  * period in seconds.
171  * \sa loadFromTextFile
172  * \return true on success, false on any error.
173  */
174  bool saveInterpolatedToTextFile(const std::string& s, double period) const;
175 
176  /** Loads from a text file, in the format described by saveToTextFile.
177  * \return true on success, false on any error.
178  * \exception std::exception On invalid file format
179  */
180  bool loadFromTextFile(const std::string& s);
181 
182  /** Computes the bounding box in all Euclidean coordinates of the whole
183  * path. \exception std::exception On empty path */
184  void getBoundingBox(point_t& minCorner, point_t& maxCorner) const;
185 
186  /** Change the method used to interpolate the robot path. The default method
187  * at construction is "imSpline". \sa getInterpolationMethod() */
189  /** Returns the currently set interpolation method. \sa
190  * setInterpolationMethod() */
192 
193  /** Filters by averaging one of the components of the pose data within the
194  * interpolator. The width of the filter is set by the number of samples.
195  * \param component [IN] The index of the component to filter: 0 (x),
196  * 1 (y), 2 (z), 3 (yaw), 4 (pitch) or 5 (roll)
197  * \param samples [IN] The width of the average filter.
198  */
199  void filter(unsigned int component, unsigned int samples);
200 
201  protected:
202  /** The sequence of poses */
204  /** Maximum time considered to interpolate. If the difference between the
205  * desired timestamp where to interpolate and the next timestamp stored in
206  * the map is bigger than this value, the interpolation will not be done. */
209 
211  const mrpt::math::CArrayDouble<4>& ts, const TTimePosePair p1,
212  const TTimePosePair p2, const TTimePosePair p3, const TTimePosePair p4,
213  const TInterpolatorMethod method, double td, pose_t& out_interp) const;
214 
215 }; // End of class def.
216 
217 } // End of namespace
218 
219 // Specializations MUST occur at the same namespace:
220 namespace utils
221 {
222 template <>
224 {
226  static void fill(bimap<enum_t, std::string>& m_map)
227  {
228  m_map.insert(poses::imSpline, "imSpline");
229  m_map.insert(poses::imLinear2Neig, "imLinear2Neig");
230  m_map.insert(poses::imLinear4Neig, "imLinear4Neig");
231  m_map.insert(poses::imSSLLLL, "imSSLLLL");
232  m_map.insert(poses::imLinearSlerp, "imLinearSlerp");
233  m_map.insert(poses::imSplineSlerp, "imSplineSlerp");
234  }
235 };
236 } // End of namespace
237 } // End of namespace
A partial specialization of CArrayNumeric for double numbers.
Definition: CArrayNumeric.h:88
Base class for SE(2)/SE(3) interpolators.
mrpt::poses::SE_traits< DIM >::lightweight_pose_t pose_t
TPose2D or TPose3D.
void impl_interpolation(const mrpt::math::CArrayDouble< 4 > &ts, const TTimePosePair p1, const TTimePosePair p2, const TTimePosePair p3, const TTimePosePair p4, const TInterpolatorMethod method, double td, pose_t &out_interp) const
bool loadFromTextFile(const std::string &s)
Loads from a text file, in the format described by saveToTextFile.
const_iterator lower_bound(const mrpt::system::TTimeStamp &t) const
iterator upper_bound(const mrpt::system::TTimeStamp &t)
std::pair< mrpt::system::TTimeStamp, pose_t > TTimePosePair
TPath::reverse_iterator reverse_iterator
void setMaxTimeInterpolation(double time)
Set value of the maximum time to consider interpolation.
bool saveToTextFile(const std::string &s) const
Saves the points in the interpolator to a text file, with this format: Each row contains these elemen...
void insert(mrpt::system::TTimeStamp t, const pose_t &p)
Inserts a new pose in the sequence.
iterator erase(iterator element_to_erase)
TInterpolatorMethod getInterpolationMethod() const
Returns the currently set interpolation method.
iterator find(const mrpt::system::TTimeStamp &t)
bool saveInterpolatedToTextFile(const std::string &s, double period) const
Saves the points in the interpolator to a text file, with the same format that saveToTextFile,...
void getBoundingBox(point_t &minCorner, point_t &maxCorner) const
Computes the bounding box in all Euclidean coordinates of the whole path.
const_iterator find(const mrpt::system::TTimeStamp &t) const
double getMaxTimeInterpolation()
Set value of the maximum time to consider interpolation.
pose_t & interpolate(mrpt::system::TTimeStamp t, pose_t &out_interp, bool &out_valid_interp) const
Returns the pose at a given time, or interpolates using splines if there is not an exact match.
void clear()
Clears the current sequence of poses.
const_reverse_iterator rend() const
bool getPreviousPoseWithMinDistance(const mrpt::system::TTimeStamp &t, double distance, pose_t &out_pose)
Get the previous CPose3D in the map with a minimum defined distance.
CPoseInterpolatorBase()
Default ctor: empty sequence of poses.
mrpt::poses::SE_traits< DIM >::pose_t cpose_t
CPose2D or CPose3D.
void filter(unsigned int component, unsigned int samples)
Filters by averaging one of the components of the pose data within the interpolator.
std::map< mrpt::system::TTimeStamp, pose_t > TPath
const_iterator upper_bound(const mrpt::system::TTimeStamp &t) const
TPath m_path
The sequence of poses.
const_reverse_iterator rbegin() const
void setInterpolationMethod(TInterpolatorMethod method)
Change the method used to interpolate the robot path.
mrpt::poses::SE_traits< DIM >::point_t point_t
TPoint2D or TPoint3D.
iterator lower_bound(const mrpt::system::TTimeStamp &t)
TPath::const_reverse_iterator const_reverse_iterator
double maxTimeInterpolation
Maximum time considered to interpolate.
A bidirectional version of std::map, declared as bimap<KEY,VALUE> and which actually contains two std...
Definition: bimap.h:35
void insert(const KEY &k, const VALUE &v)
Insert a new pair KEY<->VALUE in the bi-map.
Definition: bimap.h:75
Scalar * iterator
Definition: eigen_plugins.h:26
const Scalar * const_iterator
Definition: eigen_plugins.h:27
GLdouble GLdouble t
Definition: glext.h:3689
GLfloat GLfloat p
Definition: glext.h:6305
GLsizei samples
Definition: glext.h:8068
GLdouble s
Definition: glext.h:3676
GLsizei const GLchar ** string
Definition: glext.h:4101
double distance(const TPoint2D &p1, const TPoint2D &p2)
Gets the distance between two points in a 2D space.
Definition: geometry.cpp:1885
TInterpolatorMethod
Type to select the interpolation method in CPoseInterpolatorBase derived classes.
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1,...
Definition: datetime.h:32
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A helper class for SE(2) and SE(3) geometry-related transformations, on-manifold optimization Jacobia...
Definition: SE_traits.h:29
static void fill(bimap< enum_t, std::string > &m_map)
Only specializations of this class are defined for each enum type of interest.
Definition: TEnumType.h:25



Page generated by Doxygen 1.9.1 for MRPT 1.9.9 Git: 63ea9d1f1 Thu Nov 23 00:06:53 2017 +0100 at mar 26 may 2026 12:19:29 CEST