Main MRPT website > C++ reference
MRPT logo
math_frwds.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (c) 2005-2013, Individual contributors, see AUTHORS file |
7  | Copyright (c) 2005-2013, MAPIR group, University of Malaga |
8  | Copyright (c) 2012-2013, University of Almeria |
9  | All rights reserved. |
10  | |
11  | Redistribution and use in source and binary forms, with or without |
12  | modification, are permitted provided that the following conditions are |
13  | met: |
14  | * Redistributions of source code must retain the above copyright |
15  | notice, this list of conditions and the following disclaimer. |
16  | * Redistributions in binary form must reproduce the above copyright |
17  | notice, this list of conditions and the following disclaimer in the |
18  | documentation and/or other materials provided with the distribution. |
19  | * Neither the name of the copyright holders nor the |
20  | names of its contributors may be used to endorse or promote products |
21  | derived from this software without specific prior written permission.|
22  | |
23  | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
24  | 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
25  | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR|
26  | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE |
27  | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL|
28  | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR|
29  | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
30  | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
31  | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
32  | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
33  | POSSIBILITY OF SUCH DAMAGE. |
34  +---------------------------------------------------------------------------+ */
35 #ifndef mrpt_math_forwddecls_H
36 #define mrpt_math_forwddecls_H
37 
38 #include <mrpt/config.h>
39 #include <mrpt/base/link_pragmas.h>
40 #include <cmath>
41 #include <cstdlib>
42 #include <algorithm>
43 #include <string>
44 
45 /*! \file math_frwds.h
46  * Forward declarations of all mrpt::math classes related to vectors, arrays and matrices.
47  * Many of the function implementations are in ops_matrices.h, others in ops_containers.h
48  */
49 
50 namespace mrpt
51 {
52  namespace utils
53  {
55  template<class T> inline T square(const T x);
56  }
57 
58  namespace system
59  {
60  std::string BASE_IMPEXP MRPT_getVersion();
61  }
62 
63  namespace poses
64  {
65  class CPoint2D;
66  class CPoint3D;
67  class CPose2D;
68  class CPose3D;
69  class CPose3DQuat;
70  }
71 
72  namespace math
73  {
74  struct TPoint2D;
75  struct TPoint3D;
76  struct TPose2D;
77  struct TPose3D;
78  struct TPose3DQuat;
79 
80  namespace detail
81  {
82  /** Internal resize which compiles to nothing on fixed-size matrices. */
83  template <typename MAT,int TypeSizeAtCompileTime>
84  struct TAuxResizer {
85  static inline void internal_resize(MAT &obj, size_t row, size_t col) { }
86  static inline void internal_resize(MAT &obj, size_t nsize) { }
87  };
88  template <typename MAT>
89  struct TAuxResizer<MAT,-1> {
90  static inline void internal_resize(MAT &obj, size_t row, size_t col) { obj.derived().conservativeResize(row,col); }
91  static inline void internal_resize(MAT &obj, size_t nsize) { obj.derived().conservativeResize(nsize); }
92  };
93  }
94 
95 
96  /*! Selection of the number format in CMatrixTemplate::saveToTextFile
97  */
99  {
100  MATRIX_FORMAT_ENG = 0, //!< engineering format '%e'
101  MATRIX_FORMAT_FIXED = 1, //!< fixed floating point '%f'
102  MATRIX_FORMAT_INT = 2 //!< intergers '%i'
103  };
104 
105  /** For usage in one of the constructors of CMatrixFixedNumeric or CMatrixTemplate (and derived classes), if it's not required
106  to fill it with zeros at the constructor to save time. */
108  {
110  };
111 
112  // ---------------- Forward declarations: Classes ----------------
113  template <class T> class CMatrixTemplate;
114  template <class T> class CMatrixTemplateObjects;
115 
116 #define MRPT_MATRIX_CONSTRUCTORS_FROM_POSES(_CLASS_) \
117  explicit inline _CLASS_( const mrpt::math::TPose2D &p) { mrpt::math::containerFromPoseOrPoint(*this,p); } \
118  explicit inline _CLASS_( const mrpt::math::TPose3D &p) { mrpt::math::containerFromPoseOrPoint(*this,p); } \
119  explicit inline _CLASS_( const mrpt::math::TPose3DQuat &p) { mrpt::math::containerFromPoseOrPoint(*this,p); } \
120  explicit inline _CLASS_( const mrpt::math::TPoint2D &p) { mrpt::math::containerFromPoseOrPoint(*this,p); } \
121  explicit inline _CLASS_( const mrpt::math::TPoint3D &p) { mrpt::math::containerFromPoseOrPoint(*this,p); } \
122  explicit inline _CLASS_( const mrpt::poses::CPose2D &p) { mrpt::math::containerFromPoseOrPoint(*this,p); } \
123  explicit inline _CLASS_( const mrpt::poses::CPose3D &p) { mrpt::math::containerFromPoseOrPoint(*this,p); } \
124  explicit inline _CLASS_( const mrpt::poses::CPose3DQuat &p) { mrpt::math::containerFromPoseOrPoint(*this,p); } \
125  explicit inline _CLASS_( const mrpt::poses::CPoint2D &p) { mrpt::math::containerFromPoseOrPoint(*this,p); } \
126  explicit inline _CLASS_( const mrpt::poses::CPoint3D &p) { mrpt::math::containerFromPoseOrPoint(*this,p); }
127 
128 
129  template <class CONTAINER1,class CONTAINER2> void cumsum(const CONTAINER1 &in_data, CONTAINER2 &out_cumsum);
130 
131  template <class CONTAINER> inline typename CONTAINER::Scalar norm(const CONTAINER &v);
132  template <class CONTAINER> inline typename CONTAINER::Scalar norm_inf(const CONTAINER &v);
133 
134  template <class MAT_A,class SKEW_3VECTOR,class MAT_OUT> void multiply_A_skew3(const MAT_A &A,const SKEW_3VECTOR &v, MAT_OUT &out);
135  template <class SKEW_3VECTOR,class MAT_A,class MAT_OUT> void multiply_skew3_A(const SKEW_3VECTOR &v,const MAT_A &A, MAT_OUT &out);
136 
137  namespace detail
138  {
139  // Implemented in "lightweight_geom_data.cpp"
140  TPoint2D BASE_IMPEXP lightFromPose(const mrpt::poses::CPoint2D &p); //!< Convert a pose into a light-weight structure (functional form, needed for forward declarations)
141  TPoint3D BASE_IMPEXP lightFromPose(const mrpt::poses::CPoint3D &p); //!< Convert a pose into a light-weight structure (functional form, needed for forward declarations)
142  TPose2D BASE_IMPEXP lightFromPose(const mrpt::poses::CPose2D &p); //!< Convert a pose into a light-weight structure (functional form, needed for forward declarations)
143  TPose3D BASE_IMPEXP lightFromPose(const mrpt::poses::CPose3D &p); //!< Convert a pose into a light-weight structure (functional form, needed for forward declarations)
144  TPose3DQuat BASE_IMPEXP lightFromPose(const mrpt::poses::CPose3DQuat &p); //!< Convert a pose into a light-weight structure (functional form, needed for forward declarations)
145 
146  template <class MATORG, class MATDEST>
147  void extractMatrix(
148  const MATORG &M,
149  const size_t first_row,
150  const size_t first_col,
151  MATDEST &outMat);
152  }
153 
154  /** Conversion of poses to MRPT containers (vector/matrix) */
155  template <class CONTAINER> CONTAINER & containerFromPoseOrPoint(CONTAINER &C, const TPoint2D &p);
156  template <class CONTAINER> CONTAINER & containerFromPoseOrPoint(CONTAINER &C, const TPoint3D &p);
157  template <class CONTAINER> CONTAINER & containerFromPoseOrPoint(CONTAINER &C, const TPose2D &p);
158  template <class CONTAINER> CONTAINER & containerFromPoseOrPoint(CONTAINER &C, const TPose3D &p);
159  template <class CONTAINER> CONTAINER & containerFromPoseOrPoint(CONTAINER &C, const TPose3DQuat &p);
160 
161  template <class CONTAINER> inline CONTAINER & containerFromPoseOrPoint(CONTAINER &C, const mrpt::poses::CPoint2D &p) { return containerFromPoseOrPoint(C, mrpt::math::detail::lightFromPose(p)); }
162  template <class CONTAINER> inline CONTAINER & containerFromPoseOrPoint(CONTAINER &C, const mrpt::poses::CPoint3D &p) { return containerFromPoseOrPoint(C, mrpt::math::detail::lightFromPose(p)); }
163  template <class CONTAINER> inline CONTAINER & containerFromPoseOrPoint(CONTAINER &C, const mrpt::poses::CPose2D &p) { return containerFromPoseOrPoint(C, mrpt::math::detail::lightFromPose(p)); }
164  template <class CONTAINER> inline CONTAINER & containerFromPoseOrPoint(CONTAINER &C, const mrpt::poses::CPose3D &p) { return containerFromPoseOrPoint(C, mrpt::math::detail::lightFromPose(p)); }
165  template <class CONTAINER> inline CONTAINER & containerFromPoseOrPoint(CONTAINER &C, const mrpt::poses::CPose3DQuat &p) { return containerFromPoseOrPoint(C, mrpt::math::detail::lightFromPose(p)); }
166 
167 
168  // Vicinity classes ----------------------------------------------------
169  namespace detail {
170  /**
171  * The purpose of this class is to model traits for containers, so that they can be used as return values for the function CMatrixTemplate::getVicinity.
172  * This class is NOT defined for any base container, because correctness would not be guaranteed. Instead, each class must define its own specialization
173  * of the template, containing two functions:
174  * - static void initialize(container<T>,size_t N): must reserve space to allow at least the insertion of N*N elements, in a square fashion when appliable.
175  * - static void insertInContainer(container<T>,size_t r,size_t c,const T &): must insert the given element in the container. Whenever it's possible, it
176  * must insert it in the (r,c) coordinates.
177  * For linear containers, the vicinity functions are guaranteed to insert elements in order, i.e., starting from the top and reading from left to right.
178  */
179  template<typename T> class VicinityTraits;
180 
181  /**
182  * This huge template encapsulates a function to get the vicinity of an element, with maximum genericity. Although it's not meant to be called directly,
183  * every type defining the ASSERT_ENOUGHROOM assert and the get_unsafe method will work. The assert checks if the boundaries (r-N,r+N,c-N,c+N) fit in
184  * the matrix.
185  * The template parameters are the following:
186  * - MatrixType: the matrix or container base type, from which the vicinity is required.
187  * - T: the base type of the matrix or container.
188  * - ReturnType: the returning container type. The class VicinityTraits<ReturnType> must be completely defined.
189  * - D: the dimension of the vicinity. Current implementations are 4, 5, 8, 9, 12, 13, 20, 21, 24 and 25, although it's easy to implement new variants.
190  */
191  template<typename MatrixType,typename T,typename ReturnType,size_t D> struct getVicinity;
192 
193  }
194 
195  // Other forward decls:
196  template <class T> T wrapTo2Pi(T a);
197 
198 
199  } // End of namespace
200 } // End of namespace
201 
202 #endif
TConstructorFlags_Matrices
For usage in one of the constructors of CMatrixFixedNumeric or CMatrixTemplate (and derived classes)...
Definition: math_frwds.h:107
engineering format &#39;e&#39;
Definition: math_frwds.h:100
TPoint2D BASE_IMPEXP lightFromPose(const mrpt::poses::CPoint2D &p)
Convert a pose into a light-weight structure (functional form, needed for forward declarations) ...
void multiply_A_skew3(const MAT_A &A, const SKEW_3VECTOR &v, MAT_OUT &out)
Only for vectors/arrays "v" of length3, compute out = A * Skew(v), where Skew(v) is the skew symmetri...
Definition: ops_matrices.h:255
static void internal_resize(MAT &obj, size_t row, size_t col)
Definition: math_frwds.h:85
static void internal_resize(MAT &obj, size_t nsize)
Definition: math_frwds.h:91
std::string BASE_IMPEXP MRPT_getVersion()
Returns a string describing the MRPT version including the SVN number.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:62
void extractMatrix(const MATORG &M, const size_t first_row, const size_t first_col, MATDEST &outMat)
Extract a submatrix - The output matrix must be set to the required size before call.
Definition: ops_matrices.h:296
The purpose of this class is to model traits for containers, so that they can be used as return value...
Definition: math_frwds.h:179
static void internal_resize(MAT &obj, size_t row, size_t col)
Definition: math_frwds.h:90
T wrapTo2Pi(T a)
Modifies the given angle to translate it into the [0,2pi[ range.
A class used to store a 3D pose as a translation (x,y,z) and a quaternion (qr,qx,qy,qz).
Definition: CPose3DQuat.h:70
TMatrixTextFileFormat
Definition: math_frwds.h:98
class BASE_IMPEXP CPose3DQuat
Definition: CPose3D.h:48
A class used to store a 2D point.
Definition: CPoint2D.h:61
A class used to store a 3D point.
Definition: CPoint3D.h:59
void cumsum(const CONTAINER1 &in_data, CONTAINER2 &out_cumsum)
intergers &#39;i&#39;
Definition: math_frwds.h:102
CONTAINER::Scalar norm_inf(const CONTAINER &v)
Internal resize which compiles to nothing on fixed-size matrices.
Definition: math_frwds.h:84
T square(const T x)
Inline function for the square of a number.
Definition: bits.h:184
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A class used to store a 2D pose.
Definition: CPose2D.h:61
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:97
CONTAINER & containerFromPoseOrPoint(CONTAINER &C, const TPoint2D &p)
Conversion of poses to MRPT containers (vector/matrix)
static void internal_resize(MAT &obj, size_t nsize)
Definition: math_frwds.h:86
TPoint2D BASE_IMPEXP lightFromPose(const mrpt::poses::CPoint2D &p)
Convert a pose into a light-weight structure (functional form, needed for forward declarations) ...
This huge template encapsulates a function to get the vicinity of an element, with maximum genericity...
Definition: math_frwds.h:191
void multiply_skew3_A(const SKEW_3VECTOR &v, const MAT_A &A, MAT_OUT &out)
Only for vectors/arrays "v" of length3, compute out = Skew(v) * A, where Skew(v) is the skew symmetri...
Definition: ops_matrices.h:274
fixed floating point &#39;f&#39;
Definition: math_frwds.h:101
CONTAINER::Scalar norm(const CONTAINER &v)



Page generated by Doxygen 1.8.14 for MRPT 1.0.2 SVN: at lun oct 28 00:52:41 CET 2019 Hosted on:
SourceForge.net Logo