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