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 CPOSE2D_H
00029 #define CPOSE2D_H
00030
00031 #include <mrpt/poses/CPose.h>
00032
00033 namespace mrpt
00034 {
00035 namespace poses
00036 {
00037 DEFINE_SERIALIZABLE_PRE( CPose2D )
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 class BASE_IMPEXP CPose2D : public CPose<CPose2D>, public mrpt::utils::CSerializable
00054 {
00055 public:
00056
00057 DEFINE_SERIALIZABLE( CPose2D )
00058
00059 public:
00060 mrpt::math::CArrayDouble<2> m_coords;
00061
00062 protected:
00063 double m_phi;
00064
00065 public:
00066
00067 CPose2D();
00068
00069
00070 CPose2D(const double x,const double y,const double phi);
00071
00072
00073 CPose2D(const CPoint2D &);
00074
00075
00076 explicit CPose2D(const CPose3D &);
00077
00078
00079 CPose2D(const mrpt::math::TPose2D &);
00080
00081
00082 explicit CPose2D(const CPoint3D &);
00083
00084
00085 inline CPose2D(TConstructorFlags_Poses constructor_dummy_param) { }
00086
00087
00088 inline const double &phi() const { return m_phi; }
00089
00090 inline double &phi() { return m_phi; }
00091
00092
00093 inline void phi(double angle) { m_phi=angle; }
00094
00095 inline void phi_incr(const double Aphi) { m_phi+=Aphi; }
00096
00097
00098 void getAsVector(vector_double &v) const;
00099
00100 void getAsVector(mrpt::math::CArrayDouble<3> &v) const;
00101
00102
00103
00104
00105 void getHomogeneousMatrix(CMatrixDouble44 & out_HM ) const;
00106
00107
00108
00109 CPose2D operator + (const CPose2D& D) const ;
00110
00111
00112
00113
00114 void composeFrom(const CPose2D &A, const CPose2D &B);
00115
00116
00117
00118 CPose3D operator + (const CPose3D& D) const ;
00119
00120
00121
00122 CPoint2D operator + (const CPoint2D& u) const ;
00123
00124
00125 void composePoint(double lx,double ly,double &gx, double &gy) const;
00126
00127
00128
00129 CPoint3D operator + (const CPoint3D& u) const ;
00130
00131
00132
00133
00134
00135 void inverseComposeFrom(const CPose2D& A, const CPose2D& B );
00136
00137
00138 inline CPose2D operator - (const CPose2D& b) const
00139 {
00140 CPose2D ret(UNINITIALIZED_POSE);
00141 ret.inverseComposeFrom(*this,b);
00142 return ret;
00143 }
00144
00145
00146
00147
00148 void AddComponents(CPose2D &p);
00149
00150
00151
00152 void operator *=(const double s);
00153
00154
00155 inline CPose2D& operator += (const CPose2D& b)
00156 {
00157 composeFrom(*this,b);
00158 return *this;
00159 }
00160
00161
00162
00163 void normalizePhi();
00164
00165
00166
00167
00168 void asString(std::string &s) const { s = mrpt::format("[%f %f %f]",x(),y(),RAD2DEG(m_phi)); }
00169 inline std::string asString() const { std::string s; asString(s); return s; }
00170
00171
00172
00173
00174
00175 void fromString(const std::string &s) {
00176 CMatrixDouble m;
00177 if (!m.fromMatlabStringFormat(s)) THROW_EXCEPTION("Malformed expression in ::fromString");
00178 ASSERTMSG_(mrpt::math::size(m,1)==1 && mrpt::math::size(m,2)==3, "Wrong size of vector in ::fromString");
00179 x( m.get_unsafe(0,0) );
00180 y( m.get_unsafe(0,1) );
00181 phi( DEG2RAD(m.get_unsafe(0,2)) );
00182 }
00183
00184 inline const double &operator[](unsigned int i)const
00185 {
00186 switch(i)
00187 {
00188 case 0:return m_coords[0];
00189 case 1:return m_coords[1];
00190 case 2:return m_phi;
00191 default:
00192 throw std::runtime_error("CPose2D::operator[]: Index of bounds.");
00193 }
00194 }
00195 inline double &operator[](unsigned int i)
00196 {
00197 switch(i)
00198 {
00199 case 0:return m_coords[0];
00200 case 1:return m_coords[1];
00201 case 2:return m_phi;
00202 default:
00203 throw std::runtime_error("CPose2D::operator[]: Index of bounds.");
00204 }
00205 }
00206
00207
00208 inline void changeCoordinatesReference( const CPose2D & p ) { composeFrom(p,CPose2D(*this)); }
00209
00210 typedef CPose2D type_value;
00211 enum { is_3D_val = 0 };
00212 static inline bool is_3D() { return is_3D_val!=0; }
00213 enum { rotation_dimensions = 2 };
00214 enum { is_PDF_val = 0 };
00215 static inline bool is_PDF() { return is_PDF_val!=0; }
00216
00217 inline const type_value & getPoseMean() const { return *this; }
00218 inline type_value & getPoseMean() { return *this; }
00219
00220
00221
00222 typedef double value_type;
00223 typedef double& reference;
00224 typedef const double& const_reference;
00225 typedef std::size_t size_type;
00226 typedef std::ptrdiff_t difference_type;
00227
00228
00229 enum { static_size = 3 };
00230 static inline size_type size() { return static_size; }
00231 static inline bool empty() { return false; }
00232 static inline size_type max_size() { return static_size; }
00233 static inline void resize(const size_t n) { if (n!=static_size) throw std::logic_error(format("Try to change the size of CPose2D to %u.",static_cast<unsigned>(n))); }
00234
00235
00236
00237 };
00238
00239
00240 std::ostream BASE_IMPEXP & operator << (std::ostream& o, const CPose2D& p);
00241
00242
00243 CPose2D BASE_IMPEXP operator -(const CPose2D &p);
00244
00245 mrpt::math::TPoint2D BASE_IMPEXP operator +(const CPose2D &pose, const mrpt::math::TPoint2D &pnt);
00246
00247 bool BASE_IMPEXP operator==(const CPose2D &p1,const CPose2D &p2);
00248 bool BASE_IMPEXP operator!=(const CPose2D &p1,const CPose2D &p2);
00249
00250 typedef mrpt::aligned_containers<CPose2D>::vector_t StdVector_CPose2D;
00251 typedef mrpt::aligned_containers<CPose2D>::deque_t StdDeque_CPose2D;
00252
00253 }
00254 }
00255
00256 #endif