Main MRPT website > C++ reference
MRPT logo
types.h
Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                       http://www.mrpt.org/                                |
00005    |                                                                           |
00006    |   Copyright (C) 2005-2011  University of Malaga                           |
00007    |                                                                           |
00008    |    This software was written by the Machine Perception and Intelligent    |
00009    |      Robotics Lab, University of Malaga (Spain).                          |
00010    |    Contact: Jose-Luis Blanco  <jlblanco@ctima.uma.es>                     |
00011    |                                                                           |
00012    |  This file is part of the MRPT project.                                   |
00013    |                                                                           |
00014    |     MRPT is free software: you can redistribute it and/or modify          |
00015    |     it under the terms of the GNU General Public License as published by  |
00016    |     the Free Software Foundation, either version 3 of the License, or     |
00017    |     (at your option) any later version.                                   |
00018    |                                                                           |
00019    |   MRPT is distributed in the hope that it will be useful,                 |
00020    |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |
00021    |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
00022    |     GNU General Public License for more details.                          |
00023    |                                                                           |
00024    |     You should have received a copy of the GNU General Public License     |
00025    |     along with MRPT.  If not, see <http://www.gnu.org/licenses/>.         |
00026    |                                                                           |
00027    +---------------------------------------------------------------------------+ */
00028 
00029 #ifndef mrpt_utils_types_H
00030 #define mrpt_utils_types_H
00031 
00032 #include <vector>
00033 #include <map>
00034 #include <string>
00035 #include <stdexcept>
00036 #include <cstdarg>
00037 #include <ctime>
00038 
00039 #include <mrpt/utils/mrpt_stdint.h>    // compiler-independent version of "stdint.h"
00040 #include <mrpt/utils/mrpt_inttypes.h>  // compiler-independent version of "inttypes.h"
00041 
00042 // needed here for a few basic types used in Eigen MRPT's plugin:
00043 #include <mrpt/math/math_frwds.h>
00044 
00045 // --------------------------------------------------
00046 // Include the Eigen3 library headers, including
00047 //  MRPT's extensions:
00048 // --------------------------------------------------
00049 #include <iostream> // These headers are assumed by <mrpt/math/eigen_plugins.h>:
00050 #include <fstream>
00051 #include <sstream>
00052 #ifdef EIGEN_MAJOR_VERSION
00053 #       error **FATAL ERROR**: MRPT headers must be included before Eigen headers.
00054 #endif
00055 #ifndef EIGEN_USE_NEW_STDVECTOR
00056 #  define EIGEN_USE_NEW_STDVECTOR
00057 #endif
00058 #include <Eigen/Dense>
00059 #include <Eigen/StdVector>
00060 #include <Eigen/StdDeque>
00061 
00062 #if !EIGEN_VERSION_AT_LEAST(2,90,0)
00063 #error MRPT needs version 3.0.0-beta of Eigen or newer
00064 #endif
00065 
00066 // Template implementations that need to be after all Eigen includes:
00067 #include EIGEN_MATRIXBASE_PLUGIN_POST_IMPL
00068 // --------------------------------------------------
00069 //  End of Eigen includes
00070 // --------------------------------------------------
00071 
00072 
00073 // This must be put inside any MRPT class that inherits from an Eigen class:
00074 #define MRPT_EIGEN_DERIVED_CLASS_CTOR_OPERATOR_EQUAL(_CLASS_) \
00075         /*! Assignment operator from any other Eigen class */ \
00076     template<typename OtherDerived> \
00077     inline mrpt_autotype & operator= (const Eigen::MatrixBase <OtherDerived>& other) { \
00078         /*Base::operator=(other.template cast<typename Base::Scalar>());*/ \
00079         Base::operator=(other); \
00080         return *this; \
00081     } \
00082         /*! Constructor from any other Eigen class */ \
00083     template<typename OtherDerived> \
00084         inline _CLASS_(const Eigen::MatrixBase <OtherDerived>& other) : Base(other.template cast<typename Base::Scalar>()) { } \
00085 
00086 namespace mrpt
00087 {
00088         /** The base class of MRPT vectors, actually, Eigen column matrices of dynamic size with specialized constructors that resemble std::vector.
00089          * \note For a summary and classification of all MRPT vector, array and matrix classes see: http://www.mrpt.org/Matrices_vectors_arrays_and_Linear_Algebra_MRPT_and_Eigen_classes
00090          * \ingroup mrpt_base_grp
00091          */
00092         template <typename T>
00093         struct dynamicsize_vector : public Eigen::Matrix<T,Eigen::Dynamic,1>
00094         {
00095                 typedef Eigen::Matrix<T,Eigen::Dynamic,1> Base;
00096                 typedef dynamicsize_vector<T> mrpt_autotype;
00097                 MRPT_EIGEN_DERIVED_CLASS_CTOR_OPERATOR_EQUAL(dynamicsize_vector)
00098 
00099                 /** Default constructor: empty vector */
00100                 inline dynamicsize_vector() : Base() {}
00101                 /** Constructor, initializes to a given initial size */
00102                 inline dynamicsize_vector(size_t N) : Base(N,1) { Base::derived().setZero(); }
00103                 /** Constructor, initializes to a given initial size, all elements to a given value */
00104                 inline dynamicsize_vector(size_t N, T init_val) : Base(N,1) { Base::derived().assign(init_val); }
00105                 /** Constructor, initializes from a std::vector<> of scalars */
00106                 template <typename R>
00107                 inline dynamicsize_vector(const std::vector<R>& v) : Base(v.size(),1) { for (size_t i=0;i<v.size();i++) (*this)[i]=v[i]; }
00108                 /** Overloaded resize method that mimics std::vector::resize(SIZE,DEFAULT_VALUE) instead of resize(nrows,ncols) \note This method exists for backward compatibility in MRPT  */
00109                 inline void resize(const size_t N, const T default_val) { Base::derived().resize(N,1); Base::derived().setConstant(default_val); }
00110                 /** Normal resize of the vector (preserving old contents). */
00111                 inline void resize(const size_t N) { Base::derived().conservativeResize(N); }
00112                 /** Reset the vector to a 0-length */
00113                 inline void clear() { *this = dynamicsize_vector<T>(); }
00114                 /** DOES NOTHING (it's here for backward compatibility) */
00115                 inline void reserve(size_t dummy_size) { }
00116         };
00117 
00118         typedef dynamicsize_vector<float>  vector_float;
00119         typedef dynamicsize_vector<double> vector_double;
00120 
00121         typedef std::vector<int8_t>      vector_signed_byte;
00122         typedef std::vector<int16_t>     vector_signed_word;
00123         typedef std::vector<int32_t>     vector_int;
00124         typedef std::vector<int64_t>     vector_long;
00125         typedef std::vector<size_t>      vector_size_t;
00126         typedef std::vector<uint8_t>     vector_byte;
00127         typedef std::vector<uint16_t>    vector_word;
00128         typedef std::vector<uint32_t>    vector_uint;
00129         typedef std::vector<bool>        vector_bool;   //!<  A type for passing a vector of bools.
00130         typedef std::vector<std::string> vector_string; //!<  A type for passing a vector of strings.
00131 
00132         /** Helper types for STL containers with Eigen memory allocators. */
00133         template <class TYPE1,class TYPE2=TYPE1>
00134         struct aligned_containers
00135         {
00136                 typedef std::pair<TYPE1,TYPE2> pair_t;
00137                 typedef std::vector<TYPE1, Eigen::aligned_allocator<TYPE1> > vector_t;
00138                 typedef std::deque<TYPE1, Eigen::aligned_allocator<TYPE1> > deque_t;
00139                 typedef std::map<TYPE1,TYPE2,std::less<TYPE1>,Eigen::aligned_allocator<std::pair<const TYPE1,TYPE2> > > map_t;
00140                 typedef std::multimap<TYPE1,TYPE2,std::less<TYPE1>,Eigen::aligned_allocator<std::pair<const TYPE1,TYPE2> > > multimap_t;
00141         };
00142 
00143         namespace utils
00144         {
00145                 /** For performing type casting from a pointer to its numeric value.
00146                 */
00147                 #if defined(_MSC_VER) && (_MSC_VER>=1300)
00148                         typedef unsigned long long POINTER_TYPE;
00149                 #else
00150                         typedef unsigned long POINTER_TYPE;
00151                 #endif
00152 
00153                 typedef uint64_t TNodeID;  //!< The type for node IDs in graphs of different types.
00154                 typedef std::pair<TNodeID,TNodeID> TPairNodeIDs; //!< A pair of node IDs.
00155                 #define INVALID_NODEID  static_cast<TNodeID>(-1)
00156 
00157         } // end namespace
00158 }
00159 
00160 #endif
00161 



Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011