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) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef mrpt_math_forwddecls_H
29 #define mrpt_math_forwddecls_H
30 
31 #include <mrpt/config.h>
32 #include <mrpt/base/link_pragmas.h>
33 #include <cmath>
34 #include <cstdlib>
35 #include <algorithm>
36 #include <string>
37 
38 /*! \file math_frwds.h
39  * Forward declarations of all mrpt::math classes related to vectors, arrays and matrices.
40  * Many of the function implementations are in ops_matrices.h, others in ops_containers.h
41  */
42 
43 namespace mrpt
44 {
45  namespace utils
46  {
48  template<class T> inline T square(const T x);
49  }
50 
51  namespace system
52  {
53  std::string BASE_IMPEXP MRPT_getVersion();
54  }
55 
56  namespace poses
57  {
58  class CPoint2D;
59  class CPoint3D;
60  class CPose2D;
61  class CPose3D;
62  class CPose3DQuat;
63  }
64 
65  namespace math
66  {
67  struct TPoint2D;
68  struct TPoint3D;
69  struct TPose2D;
70  struct TPose3D;
71  struct TPose3DQuat;
72 
73  namespace detail
74  {
75  /** Internal resize which compiles to nothing on fixed-size matrices. */
76  template <typename MAT,int TypeSizeAtCompileTime>
77  struct TAuxResizer {
78  static inline void internal_resize(MAT &obj, size_t row, size_t col) { }
79  static inline void internal_resize(MAT &obj, size_t nsize) { }
80  };
81  template <typename MAT>
82  struct TAuxResizer<MAT,-1> {
83  static inline void internal_resize(MAT &obj, size_t row, size_t col) { obj.derived().conservativeResize(row,col); }
84  static inline void internal_resize(MAT &obj, size_t nsize) { obj.derived().conservativeResize(nsize); }
85  };
86  }
87 
88 
89  /*! Selection of the number format in CMatrixTemplate::saveToTextFile
90  */
92  {
93  MATRIX_FORMAT_ENG = 0, //!< engineering format '%e'
94  MATRIX_FORMAT_FIXED = 1, //!< fixed floating point '%f'
95  MATRIX_FORMAT_INT = 2 //!< intergers '%i'
96  };
97 
98  /** For usage in one of the constructors of CMatrixFixedNumeric or CMatrixTemplate (and derived classes), if it's not required
99  to fill it with zeros at the constructor to save time. */
101  {
103  };
104 
105  // ---------------- Forward declarations: Classes ----------------
106  template <class T> class CMatrixTemplate;
107  template <class T> class CMatrixTemplateObjects;
108 
109 #define MRPT_MATRIX_CONSTRUCTORS_FROM_POSES(_CLASS_) \
110  explicit inline _CLASS_( const mrpt::math::TPose2D &p) { mrpt::math::containerFromPoseOrPoint(*this,p); } \
111  explicit inline _CLASS_( const mrpt::math::TPose3D &p) { mrpt::math::containerFromPoseOrPoint(*this,p); } \
112  explicit inline _CLASS_( const mrpt::math::TPose3DQuat &p) { mrpt::math::containerFromPoseOrPoint(*this,p); } \
113  explicit inline _CLASS_( const mrpt::math::TPoint2D &p) { mrpt::math::containerFromPoseOrPoint(*this,p); } \
114  explicit inline _CLASS_( const mrpt::math::TPoint3D &p) { mrpt::math::containerFromPoseOrPoint(*this,p); } \
115  explicit inline _CLASS_( const mrpt::poses::CPose2D &p) { mrpt::math::containerFromPoseOrPoint(*this,p); } \
116  explicit inline _CLASS_( const mrpt::poses::CPose3D &p) { mrpt::math::containerFromPoseOrPoint(*this,p); } \
117  explicit inline _CLASS_( const mrpt::poses::CPose3DQuat &p) { mrpt::math::containerFromPoseOrPoint(*this,p); } \
118  explicit inline _CLASS_( const mrpt::poses::CPoint2D &p) { mrpt::math::containerFromPoseOrPoint(*this,p); } \
119  explicit inline _CLASS_( const mrpt::poses::CPoint3D &p) { mrpt::math::containerFromPoseOrPoint(*this,p); }
120 
121 
122  template <class CONTAINER1,class CONTAINER2> void cumsum(const CONTAINER1 &in_data, CONTAINER2 &out_cumsum);
123 
124  template <class CONTAINER> inline typename CONTAINER::value_type norm(const CONTAINER &v);
125  template <class CONTAINER> inline typename CONTAINER::value_type norm_inf(const CONTAINER &v);
126 
127  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);
128  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);
129 
130  namespace detail
131  {
132  // Implemented in "lightweight_geom_data.cpp"
133  TPoint2D BASE_IMPEXP lightFromPose(const mrpt::poses::CPoint2D &p); //!< Convert a pose into a light-weight structure (functional form, needed for forward declarations)
134  TPoint3D BASE_IMPEXP lightFromPose(const mrpt::poses::CPoint3D &p); //!< Convert a pose into a light-weight structure (functional form, needed for forward declarations)
135  TPose2D BASE_IMPEXP lightFromPose(const mrpt::poses::CPose2D &p); //!< Convert a pose into a light-weight structure (functional form, needed for forward declarations)
136  TPose3D BASE_IMPEXP lightFromPose(const mrpt::poses::CPose3D &p); //!< Convert a pose into a light-weight structure (functional form, needed for forward declarations)
137  TPose3DQuat BASE_IMPEXP lightFromPose(const mrpt::poses::CPose3DQuat &p); //!< Convert a pose into a light-weight structure (functional form, needed for forward declarations)
138 
139  template <class MATORG, class MATDEST>
140  void extractMatrix(
141  const MATORG &M,
142  const size_t first_row,
143  const size_t first_col,
144  MATDEST &outMat);
145  }
146 
147  /** Conversion of poses to MRPT containers (vector/matrix) */
148  template <class CONTAINER> CONTAINER & containerFromPoseOrPoint(CONTAINER &C, const TPoint2D &p);
149  template <class CONTAINER> CONTAINER & containerFromPoseOrPoint(CONTAINER &C, const TPoint3D &p);
150  template <class CONTAINER> CONTAINER & containerFromPoseOrPoint(CONTAINER &C, const TPose2D &p);
151  template <class CONTAINER> CONTAINER & containerFromPoseOrPoint(CONTAINER &C, const TPose3D &p);
152  template <class CONTAINER> CONTAINER & containerFromPoseOrPoint(CONTAINER &C, const TPose3DQuat &p);
153 
154  template <class CONTAINER> inline CONTAINER & containerFromPoseOrPoint(CONTAINER &C, const mrpt::poses::CPoint2D &p) { return containerFromPoseOrPoint(C, mrpt::math::detail::lightFromPose(p)); }
155  template <class CONTAINER> inline CONTAINER & containerFromPoseOrPoint(CONTAINER &C, const mrpt::poses::CPoint3D &p) { return containerFromPoseOrPoint(C, mrpt::math::detail::lightFromPose(p)); }
156  template <class CONTAINER> inline CONTAINER & containerFromPoseOrPoint(CONTAINER &C, const mrpt::poses::CPose2D &p) { return containerFromPoseOrPoint(C, mrpt::math::detail::lightFromPose(p)); }
157  template <class CONTAINER> inline CONTAINER & containerFromPoseOrPoint(CONTAINER &C, const mrpt::poses::CPose3D &p) { return containerFromPoseOrPoint(C, mrpt::math::detail::lightFromPose(p)); }
158  template <class CONTAINER> inline CONTAINER & containerFromPoseOrPoint(CONTAINER &C, const mrpt::poses::CPose3DQuat &p) { return containerFromPoseOrPoint(C, mrpt::math::detail::lightFromPose(p)); }
159 
160 
161  // Vicinity classes ----------------------------------------------------
162  namespace detail {
163  /**
164  * 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.
165  * This class is NOT defined for any base container, because correctness would not be guaranteed. Instead, each class must define its own specialization
166  * of the template, containing two functions:
167  * - 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.
168  * - 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
169  * must insert it in the (r,c) coordinates.
170  * 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.
171  */
172  template<typename T> class VicinityTraits;
173 
174  /**
175  * 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,
176  * 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
177  * the matrix.
178  * The template parameters are the following:
179  * - MatrixType: the matrix or container base type, from which the vicinity is required.
180  * - T: the base type of the matrix or container.
181  * - ReturnType: the returning container type. The class VicinityTraits<ReturnType> must be completely defined.
182  * - 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.
183  */
184  template<typename MatrixType,typename T,typename ReturnType,size_t D> struct getVicinity;
185 
186  }
187 
188  // Other forward decls:
189  template <class T> T wrapTo2Pi(T a);
190 
191 
192  } // End of namespace
193 } // End of namespace
194 
195 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013