Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef CMatrixTemplateNumeric_H
00029 #define CMatrixTemplateNumeric_H
00030
00031 #include <mrpt/math/CMatrixTemplate.h>
00032 #include <mrpt/utils/CSerializable.h>
00033
00034 #include <mrpt/system/os.h>
00035 #include <cmath>
00036 #include <limits>
00037
00038 namespace mrpt
00039 {
00040 namespace poses
00041 {
00042 class CPose2D;
00043 class CPose3D;
00044 class CPoint2D;
00045 class CPoint3D;
00046 }
00047
00048 namespace math
00049 {
00050 using namespace mrpt::system;
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 template <class T>
00063 class CMatrixTemplateNumeric :
00064 public Eigen::Matrix<
00065 T,
00066 Eigen::Dynamic,
00067 Eigen::Dynamic,
00068
00069 Eigen::AutoAlign | Eigen::RowMajor
00070 >
00071 {
00072 public:
00073 typedef Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic,Eigen::AutoAlign|Eigen::RowMajor> Base;
00074 typedef CMatrixTemplateNumeric<T> mrpt_autotype;
00075
00076 MRPT_MATRIX_CONSTRUCTORS_FROM_POSES(CMatrixTemplateNumeric)
00077
00078
00079 inline CMatrixTemplateNumeric() : Base(1,1) { Base::setZero(); }
00080
00081
00082
00083
00084
00085
00086
00087 inline CMatrixTemplateNumeric(TConstructorFlags_Matrices constructor_flag) : Base( 0,0 ) { }
00088
00089
00090 inline CMatrixTemplateNumeric(size_t row, size_t col) : Base(row,col) { Base::setZero(); }
00091
00092 MRPT_EIGEN_DERIVED_CLASS_CTOR_OPERATOR_EQUAL(CMatrixTemplateNumeric)
00093
00094
00095
00096 template <class R>
00097 inline CMatrixTemplateNumeric<T>& operator = (const CMatrixTemplate<R>& m)
00098 {
00099 Base::resize( m.getRowCount(), m.getColCount() );
00100
00101 for (size_t i=0; i < CMatrixTemplate<T>::getRowCount(); i++)
00102 for (size_t j=0; j < CMatrixTemplate<T>::getColCount(); j++)
00103 Base::coeffRef(i,j) = static_cast<T>(m.get_unsafe(i,j));
00104 return *this;
00105 }
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 template <typename V, size_t N>
00116 inline CMatrixTemplateNumeric(size_t row, size_t col, V (&theArray)[N] ) : Base(row,col)
00117 {
00118 ASSERT_EQUAL_(row*col,N)
00119 ASSERT_EQUAL_(sizeof(theArray[0]),sizeof(T))
00120 ::memcpy(Base::data(),&theArray[0],sizeof(T)*N);
00121 }
00122
00123
00124
00125 inline ~CMatrixTemplateNumeric() { }
00126
00127
00128 template <typename Derived>
00129 inline bool operator ==(const Eigen::MatrixBase<Derived>& m2) const
00130 {
00131 return Base::cols()==m2.cols() &&
00132 Base::rows()==m2.rows() &&
00133 Base::cwiseEqual(m2).all();
00134 }
00135
00136 template <typename Derived>
00137 inline bool operator !=(const Eigen::MatrixBase<Derived>& m2) const{ return !((*this)==m2); }
00138
00139 };
00140
00141
00142
00143
00144
00145
00146 typedef CMatrixTemplateNumeric<float> CMatrixFloat;
00147
00148
00149
00150
00151
00152 typedef CMatrixTemplateNumeric<double> CMatrixDouble;
00153
00154
00155
00156
00157 typedef CMatrixTemplateNumeric<unsigned int> CMatrixUInt;
00158
00159
00160
00161
00162 typedef CMatrixTemplate<bool> CMatrixBool;
00163
00164 #ifdef HAVE_LONG_DOUBLE
00165
00166
00167
00168 typedef CMatrixTemplateNumeric<long double> CMatrixLongDouble;
00169 #else
00170
00171
00172
00173 typedef CMatrixTemplateNumeric<double> CMatrixLongDouble;
00174 #endif
00175
00176
00177 namespace detail
00178 {
00179
00180
00181
00182 template<typename T> class VicinityTraits<CMatrixTemplateNumeric<T> > {
00183 public:
00184 inline static void initialize(CMatrixTemplateNumeric<T> &mat,size_t N) {
00185 mat.setSize(N,N);
00186 mat.fill(0);
00187 }
00188 inline static void insertInContainer(CMatrixTemplateNumeric<T> &mat,size_t r,size_t c,const T &t) {
00189 mat.get_unsafe(r,c)=t;
00190 }
00191 };
00192 }
00193
00194 }
00195
00196
00197 namespace utils
00198 {
00199
00200 template<typename T> struct TTypeName <mrpt::math::CMatrixTemplateNumeric<T> > {
00201 static std::string get() { return std::string("CMatrixTemplateNumeric<")+ std::string( TTypeName<T>::get() )+std::string(">"); }
00202 };
00203 }
00204
00205 }
00206
00207
00208 #endif