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 CPOSE3DROTVEC_H
00029 #define CPOSE3DROTVEC_H
00030
00031 #include <mrpt/poses/CPose.h>
00032 #include <mrpt/math/CMatrixFixedNumeric.h>
00033 #include <mrpt/math/CQuaternion.h>
00034
00035 namespace mrpt
00036 {
00037 namespace poses
00038 {
00039 using namespace mrpt::math;
00040
00041 class BASE_IMPEXP CPose3D;
00042 class BASE_IMPEXP CPose3DQuat;
00043
00044 DEFINE_SERIALIZABLE_PRE( CPose3DRotVec )
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 class BASE_IMPEXP CPose3DRotVec : public CPose<CPose3DRotVec>, public mrpt::utils::CSerializable
00065 {
00066
00067 DEFINE_SERIALIZABLE( CPose3DRotVec )
00068
00069 public:
00070 CArrayDouble<3> m_coords;
00071 CArrayDouble<3> m_rotvec;
00072
00073
00074
00075
00076
00077 inline CPose3DRotVec() {
00078 m_coords[0]=m_coords[1]=m_coords[2]=0;
00079 m_rotvec[0]=m_rotvec[1]=m_rotvec[2]=0;
00080 }
00081
00082
00083 inline CPose3DRotVec(TConstructorFlags_Poses constructor_dummy_param) : m_coords(),m_rotvec() { }
00084
00085
00086 inline CPose3DRotVec(const double x,const double y,const double z,const double vx, const double vy, const double vz) {
00087 m_coords[0]= x; m_coords[1]= y; m_coords[2]= z;
00088 m_rotvec[0]=vx; m_rotvec[1]=vy; m_rotvec[2]=vz;
00089 }
00090
00091
00092 inline CPose3DRotVec(const CArrayDouble<6> &v) {
00093 m_coords[0]=v[0]; m_coords[1]=v[1]; m_coords[2]=v[2];
00094 m_rotvec[0]=v[3]; m_rotvec[1]=v[4]; m_rotvec[2]=v[5];
00095 }
00096
00097
00098 explicit CPose3DRotVec(const math::CMatrixDouble44 &m);
00099
00100
00101 explicit CPose3DRotVec(const CPose3D &);
00102
00103
00104 CPose3DRotVec(const mrpt::math::CQuaternionDouble &q, const double x, const double y, const double z );
00105
00106
00107
00108
00109
00110 inline explicit CPose3DRotVec(const double *vec6) {
00111 m_coords[0]=vec6[0]; m_coords[1]=vec6[1]; m_coords[2]=vec6[2];
00112 m_rotvec[0]=vec6[3]; m_rotvec[1]=vec6[4]; m_rotvec[2]=vec6[5];
00113 }
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 inline void getHomogeneousMatrix(CMatrixDouble44 & out_HM) const {
00125 out_HM.block<3,3>(0,0) = getRotationMatrix();
00126 out_HM.get_unsafe(0,3)=m_coords[0];
00127 out_HM.get_unsafe(1,3)=m_coords[1];
00128 out_HM.get_unsafe(2,3)=m_coords[2];
00129 out_HM.get_unsafe(3,0)=0; out_HM.get_unsafe(3,1)=0; out_HM.get_unsafe(3,2)=0; out_HM.get_unsafe(3,3)=1;
00130 }
00131
00132 inline CMatrixDouble44 getHomogeneousMatrixVal() const { CMatrixDouble44 M; getHomogeneousMatrix(M); return M;}
00133
00134
00135 void getRotationMatrix( mrpt::math::CMatrixDouble33 & ROT ) const;
00136
00137 inline const mrpt::math::CMatrixDouble33 getRotationMatrix() const { mrpt::math::CMatrixDouble33 ROT(UNINITIALIZED_MATRIX); getRotationMatrix(ROT); return ROT; }
00138
00139
00140
00141
00142
00143
00144
00145
00146 inline CPose3DRotVec operator + (const CPose3DRotVec& b) const
00147 {
00148 CPose3DRotVec ret(UNINITIALIZED_POSE);
00149 ret.composeFrom(*this,b);
00150 return ret;
00151 }
00152
00153
00154 CPoint3D operator + (const CPoint3D& b) const;
00155
00156
00157 CPoint3D operator + (const CPoint2D& b) const;
00158
00159
00160 void sphericalCoordinates(
00161 const TPoint3D &point,
00162 double &out_range,
00163 double &out_yaw,
00164 double &out_pitch ) const;
00165
00166
00167
00168
00169
00170 void composePoint(double lx,double ly,double lz, double &gx, double &gy, double &gz,
00171 mrpt::math::CMatrixFixedNumeric<double,3,3> *out_jacobian_df_dpoint=NULL,
00172 mrpt::math::CMatrixFixedNumeric<double,3,6> *out_jacobian_df_dpose=NULL) const;
00173
00174
00175
00176
00177 inline void composePoint(const TPoint3D local_point, TPoint3D &global_point) const {
00178 composePoint(local_point.x,local_point.y,local_point.z, global_point.x,global_point.y,global_point.z );
00179 }
00180
00181
00182
00183
00184
00185
00186 void inverseComposePoint(const double gx,const double gy,const double gz,double &lx,double &ly,double &lz,
00187 mrpt::math::CMatrixFixedNumeric<double,3,3> *out_jacobian_df_dpoint=NULL,
00188 mrpt::math::CMatrixFixedNumeric<double,3,6> *out_jacobian_df_dpose=NULL) const;
00189
00190
00191
00192
00193 void composeFrom(const CPose3DRotVec& A, const CPose3DRotVec& B );
00194
00195
00196 inline CPose3DRotVec& operator += (const CPose3DRotVec& b)
00197 {
00198 composeFrom(*this,b);
00199 return *this;
00200 }
00201
00202
00203
00204
00205
00206 void inverseComposeFrom(const CPose3DRotVec& A, const CPose3DRotVec& B );
00207
00208
00209 inline CPose3DRotVec operator - (const CPose3DRotVec& b) const
00210 {
00211 CPose3DRotVec ret(UNINITIALIZED_POSE);
00212 ret.inverseComposeFrom(*this,b);
00213 return ret;
00214 }
00215
00216
00217 void inverse();
00218
00219
00220 inline void changeCoordinatesReference( const CPose3DRotVec & p ) { composeFrom(p,CPose3DRotVec(*this)); }
00221
00222
00223
00224
00225
00226
00227
00228 inline double rx() const { return m_rotvec[0]; }
00229 inline double ry() const { return m_rotvec[1]; }
00230 inline double rz() const { return m_rotvec[2]; }
00231
00232 inline double &rx() { return m_rotvec[0]; }
00233 inline double &ry() { return m_rotvec[1]; }
00234 inline double &rz() { return m_rotvec[2]; }
00235
00236
00237 inline void addComponents(const CPose3DRotVec &p) {
00238 m_coords+=p.m_coords;
00239 m_rotvec+=p.m_rotvec;
00240 }
00241
00242
00243 inline void operator *=(const double s) {
00244 m_coords*=s;
00245 m_rotvec*=s;
00246 }
00247
00248
00249
00250
00251 void setFromValues(
00252 const double x0,
00253 const double y0,
00254 const double z0,
00255 const double vx,
00256 const double vy,
00257 const double vz )
00258 {
00259 m_coords[0]=x0; m_coords[1]=y0; m_coords[2]=z0;
00260 m_rotvec[0]=vx; m_rotvec[1]=vy; m_rotvec[2]=vz;
00261 }
00262
00263
00264
00265
00266
00267 template <class ARRAYORVECTOR>
00268 inline void setFrom6Vector(const ARRAYORVECTOR &vec6)
00269 {
00270 m_rotvec[0]=vec6[3]; m_rotvec[1]=vec6[4]; m_rotvec[2]=vec6[5];
00271 m_coords[0]=vec6[0]; m_coords[1]=vec6[1]; m_coords[2]=vec6[2];
00272 }
00273
00274
00275
00276
00277
00278
00279 template <class ARRAYORVECTOR>
00280 inline void getAs6Vector(ARRAYORVECTOR &vec6) const
00281 {
00282 vec6[0]=m_coords[0]; vec6[1]=m_coords[1]; vec6[2]=m_coords[2];
00283 vec6[3]=m_rotvec[0]; vec6[4]=m_rotvec[1]; vec6[5]=m_rotvec[2];
00284 }
00285
00286
00287 template <class ARRAYORVECTOR>
00288 inline void getAsVector(ARRAYORVECTOR &v) const { v.resize(6); getAs6Vector(v); }
00289
00290 inline const double &operator[](unsigned int i) const
00291 {
00292 switch(i)
00293 {
00294 case 0:return m_coords[0];
00295 case 1:return m_coords[1];
00296 case 2:return m_coords[2];
00297 case 3:return m_rotvec[0];
00298 case 4:return m_rotvec[1];
00299 case 5:return m_rotvec[2];
00300 default:
00301 throw std::runtime_error("CPose3DRotVec::operator[]: Index of bounds.");
00302 }
00303 }
00304 inline double &operator[](unsigned int i)
00305 {
00306 switch(i)
00307 {
00308 case 0:return m_coords[0];
00309 case 1:return m_coords[1];
00310 case 2:return m_coords[2];
00311 case 3:return m_rotvec[0];
00312 case 4:return m_rotvec[1];
00313 case 5:return m_rotvec[2];
00314 default:
00315 throw std::runtime_error("CPose3DRotVec::operator[]: Index of bounds.");
00316 }
00317 }
00318
00319
00320
00321
00322 void asString(std::string &s) const { s = mrpt::format("[%f %f %f %f %f %f]",m_coords[0],m_coords[1],m_coords[2],m_rotvec[0],m_rotvec[1],m_rotvec[2]); }
00323 inline std::string asString() const { std::string s; asString(s); return s; }
00324
00325
00326
00327
00328
00329 void fromString(const std::string &s) {
00330 CMatrixDouble m;
00331 if (!m.fromMatlabStringFormat(s)) THROW_EXCEPTION("Malformed expression in ::fromString");
00332 ASSERTMSG_(mrpt::math::size(m,1)==1 && mrpt::math::size(m,2)==6, "Wrong size of vector in ::fromString");
00333 for (int i=0;i<3;i++) m_coords[i]=m.get_unsafe(0,i);
00334 for (int i=0;i<3;i++) m_rotvec[i]=m.get_unsafe(0,3+i);
00335 }
00336
00337
00338
00339
00340
00341
00342
00343
00344 static CPose3DRotVec exp(const mrpt::math::CArrayDouble<6> & vect);
00345
00346
00347 void ln(mrpt::math::CArrayDouble<6> &out_ln) const;
00348
00349
00350 CArrayDouble<3> ln_rotation() const;
00351
00352
00353
00354 typedef CPose3DRotVec type_value;
00355 enum { is_3D_val = 1 };
00356 static inline bool is_3D() { return is_3D_val!=0; }
00357 enum { rotation_dimensions = 3 };
00358 enum { is_PDF_val = 0 };
00359 static inline bool is_PDF() { return is_PDF_val!=0; }
00360
00361 inline const type_value & getPoseMean() const { return *this; }
00362 inline type_value & getPoseMean() { return *this; }
00363
00364
00365
00366 typedef double value_type;
00367 typedef double& reference;
00368 typedef const double& const_reference;
00369 typedef std::size_t size_type;
00370 typedef std::ptrdiff_t difference_type;
00371
00372
00373
00374 enum { static_size = 6 };
00375 static inline size_type size() { return static_size; }
00376 static inline bool empty() { return false; }
00377 static inline size_type max_size() { return static_size; }
00378 static inline void resize(const size_t n) { if (n!=static_size) throw std::logic_error(format("Try to change the size of CPose3DRotVec to %u.",static_cast<unsigned>(n))); }
00379
00380
00381 };
00382
00383
00384 std::ostream BASE_IMPEXP & operator << (std::ostream& o, const CPose3DRotVec& p);
00385
00386
00387 CPose3DRotVec BASE_IMPEXP operator -(const CPose3DRotVec &p);
00388
00389 bool BASE_IMPEXP operator==(const CPose3DRotVec &p1,const CPose3DRotVec &p2);
00390 bool BASE_IMPEXP operator!=(const CPose3DRotVec &p1,const CPose3DRotVec &p2);
00391
00392
00393 }
00394 }
00395
00396 #endif