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
00101
00102
00103 void getHomogeneousMatrix(CMatrixDouble44 & out_HM ) const;
00104
00105
00106
00107 CPose2D operator + (const CPose2D& D) const ;
00108
00109
00110
00111
00112 void composeFrom(const CPose2D &A, const CPose2D &B);
00113
00114
00115
00116 CPose3D operator + (const CPose3D& D) const ;
00117
00118
00119
00120 CPoint2D operator + (const CPoint2D& u) const ;
00121
00122
00123 void composePoint(double lx,double ly,double &gx, double &gy) const;
00124
00125
00126
00127 CPoint3D operator + (const CPoint3D& u) const ;
00128
00129
00130
00131
00132
00133 void inverseComposeFrom(const CPose2D& A, const CPose2D& B );
00134
00135
00136 inline CPose2D operator - (const CPose2D& b) const
00137 {
00138 CPose2D ret(UNINITIALIZED_POSE);
00139 ret.inverseComposeFrom(*this,b);
00140 return ret;
00141 }
00142
00143
00144
00145
00146 void AddComponents(CPose2D &p);
00147
00148
00149
00150 void operator *=(const double s);
00151
00152
00153 inline CPose2D& operator += (const CPose2D& b)
00154 {
00155 composeFrom(*this,b);
00156 return *this;
00157 }
00158
00159
00160
00161 void normalizePhi();
00162
00163
00164
00165
00166 void asString(std::string &s) const { s = mrpt::format("[%f %f %f]",x(),y(),RAD2DEG(m_phi)); }
00167 inline std::string asString() const { std::string s; asString(s); return s; }
00168
00169
00170
00171
00172
00173 void fromString(const std::string &s) {
00174 CMatrixDouble m;
00175 if (!m.fromMatlabStringFormat(s)) THROW_EXCEPTION("Malformed expression in ::fromString");
00176 ASSERTMSG_(mrpt::math::size(m,1)==1 && mrpt::math::size(m,2)==3, "Wrong size of vector in ::fromString");
00177 x( m.get_unsafe(0,0) );
00178 y( m.get_unsafe(0,1) );
00179 phi( DEG2RAD(m.get_unsafe(0,2)) );
00180 }
00181
00182 inline const double &operator[](unsigned int i)const
00183 {
00184 switch(i)
00185 {
00186 case 0:return m_coords[0];
00187 case 1:return m_coords[1];
00188 case 2:return m_phi;
00189 default:
00190 throw std::runtime_error("CPose2D::operator[]: Index of bounds.");
00191 }
00192 }
00193 inline double &operator[](unsigned int i)
00194 {
00195 switch(i)
00196 {
00197 case 0:return m_coords[0];
00198 case 1:return m_coords[1];
00199 case 2:return m_phi;
00200 default:
00201 throw std::runtime_error("CPose2D::operator[]: Index of bounds.");
00202 }
00203 }
00204
00205
00206 inline void changeCoordinatesReference( const CPose2D & p ) { composeFrom(p,CPose2D(*this)); }
00207
00208 typedef CPose2D type_value;
00209 enum { is_3D_val = 0 };
00210 static inline bool is_3D() { return is_3D_val!=0; }
00211 enum { rotation_dimensions = 2 };
00212 enum { is_PDF_val = 0 };
00213 static inline bool is_PDF() { return is_PDF_val!=0; }
00214
00215 inline const type_value & getPoseMean() const { return *this; }
00216 inline type_value & getPoseMean() { return *this; }
00217
00218
00219
00220 typedef double value_type;
00221 typedef double& reference;
00222 typedef const double& const_reference;
00223 typedef std::size_t size_type;
00224 typedef std::ptrdiff_t difference_type;
00225
00226
00227 enum { static_size = 3 };
00228 static inline size_type size() { return static_size; }
00229 static inline bool empty() { return false; }
00230 static inline size_type max_size() { return static_size; }
00231 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))); }
00232
00233
00234
00235 };
00236
00237
00238 std::ostream BASE_IMPEXP & operator << (std::ostream& o, const CPose2D& p);
00239
00240
00241 CPose2D BASE_IMPEXP operator -(const CPose2D &p);
00242
00243 mrpt::math::TPoint2D BASE_IMPEXP operator +(const CPose2D &pose, const mrpt::math::TPoint2D &pnt);
00244
00245 bool BASE_IMPEXP operator==(const CPose2D &p1,const CPose2D &p2);
00246 bool BASE_IMPEXP operator!=(const CPose2D &p1,const CPose2D &p2);
00247
00248 typedef mrpt::aligned_containers<CPose2D>::vector_t StdVector_CPose2D;
00249 typedef mrpt::aligned_containers<CPose2D>::deque_t StdDeque_CPose2D;
00250
00251 }
00252 }
00253
00254 #endif