39 #include <TooN/TooN.h> 47 template <
class Precision>
51 Point2_(Precision x_,Precision y_):x(x_),y(y_){}
53 template <
typename Scalar>
60 template <
typename Scalar>
61 operator Eigen::Matrix<Scalar,2,1>()
63 return Eigen::Matrix<Scalar,2,1>(x,y);
66 template <
typename Scalar>
67 Point2_(
const Eigen::Matrix<Scalar,2,1>& eig):x(eig[0]),y(eig[1]){}
70 inline Precision& operator[](
int index)
const 72 return ((Precision*)
this)[index];
75 friend Point2_ operator + (
const Point2_& a,
const Point2_& b)
77 return Point2_(a.x+b.x,a.y+b.y);
80 friend Point2_ operator - (
const Point2_& a,
const Point2_& b)
82 return Point2_(a.x-b.x,a.y-b.y);
85 friend Point2_ operator -(
const Point2_& a)
87 return Point2_(-a.x,-a.y);
90 friend Precision operator * (
const Point2_& a,
const Point2_& b)
92 return (a.x*b.x+a.y*b.y);
95 friend Point2_ operator * (
const Precision& a,
const Point2_& b)
97 return Point2_(a*b.x,a*b.y);
100 friend Point2_ operator * (
const Point2_& b,
const Precision& a)
102 return Point2_(a*b.x,a*b.y);
105 friend Point2_ operator / (
const Point2_& a,
const Precision& b)
110 inline Precision norm()
const 112 return sqrt(x*x+y*y);
118 return (*
this)*(1./norm());
123 inline Precision dot(
const Point2_& a)
const 128 Precision at(
int i)
const{
return (*
this)[i];}
129 Precision getX()
const{
return x;}
130 Precision getY()
const{
return y;}
132 void setX(Precision X){x=X;}
133 void setY(Precision Y){y=Y;}
140 std::string toString()
const{std::stringstream sst;sst<<*
this;
return sst.str();}
142 friend inline std::ostream& operator <<(std::ostream& os,
const Point2_& p)
144 os<<std::to_string(p.x)<<
" "<<std::to_string(p.y);
148 friend inline std::istream& operator >>(std::istream& is,Point2_& p)
161 template <
class Precision>
166 Point3_(Precision x_,Precision y_,Precision z_):x(x_),y(y_),z(z_){}
168 inline Precision& operator[](
int index)
const 170 return ((Precision*)
this)[index];
173 inline Precision norm()
const 175 return sqrt(x*x+y*y+z*z);
178 inline Precision dot(
const Point3_& a)
const 180 return x*a.x+y*a.y+z*a.z;
191 return (*
this)*(1./norm());
196 friend inline std::ostream& operator <<(std::ostream& os,
const Point3_& p)
198 os<<std::to_string(p.x)<<
" "<<std::to_string(p.y)<<
" "<<std::to_string(p.z);
202 friend inline std::istream& operator >>(std::istream& is,
Point3_& p)
210 return Point3_(a.x+b.x,a.y+b.y,a.z+b.z);
215 return Point3_(a.x-b.x,a.y-b.y,a.z-b.z);
220 return Point3_(-a.x,-a.y,-a.z);
225 return (a.x*b.x+a.y*b.y+a.z*b.z);
230 return Point3_(a.y*b.z-a.z*b.y,a.z*b.x-a.x*b.z,a.x*b.y-a.y*b.x);
235 return Point3_(a*b.x,a*b.y,a*b.z);
240 return Point3_(a*b.x,a*b.y,a*b.z);
253 template <
typename Scalar>
259 Precision at(
int i)
const{
return (*
this)[i];}
260 Precision getX()
const{
return x;}
261 Precision getY()
const{
return y;}
262 Precision getZ()
const{
return z;}
264 void setX(Precision X){x=X;}
265 void setY(Precision Y){y=Y;}
266 void setZ(Precision Z){z=Z;}
273 std::string toString()
const{std::stringstream sst;sst<<*
this;
return sst.str();}
275 #ifdef EIGEN_MATRIX_H 276 template <
typename Scalar>
277 operator Eigen::Matrix<Scalar,3,1>()
279 return Eigen::Matrix<Scalar,3,1>(x,y,z);
282 template <
typename Scalar>
283 Point3_(
const Eigen::Matrix<Scalar,3,1>& eig):x(eig[0]),y(eig[1]),z(eig[2]){}
287 operator TooN::Vector<3,Precision>& ()
289 return *((TooN::Vector<3,Precision>*)
this);
302 #endif // GSLAM_POINT_H