MIRA
Point.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
47 #ifndef _MIRA_POINT_H_
48 #define _MIRA_POINT_H_
49 
50 #include <opencv2/core/core.hpp>
51 
52 #ifndef Q_MOC_RUN
53 #include <boost/geometry/geometry.hpp>
54 #endif
55 
56 #include <utils/PParam.h>
57 #include <math/Eigen.h>
58 
59 #include <utils/IsCheapToCopy.h>
60 
61 namespace mira {
62 
64 
76 template <typename T, int D, typename Derived>
77 class PointBase : public Eigen::Matrix<T,D,1>
78 {
79  typedef Eigen::Matrix<T,D,1> Base;
80 
81 public:
82  typedef T Type;
83  enum { Dim = D};
84 
85 public:
87  PointBase() : Base(Eigen::Matrix<T,D,1>::Zero()) {}
88 
90  PointBase(const boost::geometry::model::point<T,D,boost::geometry::cs::cartesian>& other) {
91  operator=(other);
92  }
93 
95  template <typename DerivedMatrix>
97 
99  template <typename DerivedMatrix>
101  Base::operator=(other);
102  return *this;
103  }
104 
106  Derived& operator=(const boost::geometry::model::point<T,D,boost::geometry::cs::cartesian>& other)
107  {
108  for(int i=0; i < D; i++) // compiler will unroll loop
109  (*this)[i] = other(i);
110  return *this;
111  }
112 
114  operator boost::geometry::model::point<T,D,boost::geometry::cs::cartesian>() const
115  {
116  boost::geometry::model::point<T,D,boost::geometry::cs::cartesian> r;
117  for(int i=0; i < D; i++) // compiler will unroll loop
118  r(i) = (*this)[i];
119  return r;
120  }
121 };
122 
124 
134 template <typename T, int D>
135 class Point : public PointBase<T,D, Point<T,D> >
136 {
138 
139 public:
141  Point() {}
142 
144  template <typename DerivedMatrix>
145  Point(const Eigen::MatrixBase<DerivedMatrix>& other) : Base(other) {}
146 
148  Point(const boost::geometry::model::point<T,D,boost::geometry::cs::cartesian>& other) {
149  operator=(other);
150  }
151 };
152 
154 
156 template <typename T, int D, typename SerializerTag>
157 class IsTransparentSerializable<Point<T,D>,SerializerTag> : public std::true_type {};
159 
161 
168 template <typename T>
169 class Point<T,2> : public PointBase<T,2, Point<T,2> >
170 {
172 
173 public:
175  Point() {}
176 
178  Point(T x, T y)
179  {
180  (*this)[0] = x;
181  (*this)[1] = y;
182  }
183 
185  template <typename DerivedMatrix>
186  Point(const Eigen::MatrixBase<DerivedMatrix>& other) : Base(other) {}
187 
189  Point(const boost::geometry::model::point<T,2,boost::geometry::cs::cartesian>& other) {
190  operator=(other);
191  }
192 
194  explicit Point<T,2>(const cv::Point_<T> & other) {
195  operator=(other);
196  }
197 
199  Point& operator=(const cv::Point_<T>& other) {
200  (*this)[0] = other.x;
201  (*this)[1] = other.y;
202  return *this;
203  }
204 
206  operator cv::Point_<T>() const
207  {
208  return cv::Point_<T>( this->x(), this->y() );
209  }
210 
212  template<typename Reflector>
213  void reflect(Reflector& reflector)
214  {
215  reflector.property("X", this->x(), "The x-coordinate");
216  reflector.property("Y", this->y(), "The y-coordinate");
217  }
218 };
219 
221 
223 template <typename T, typename SerializerTag>
224 class IsTransparentSerializable<Point<T,2>,SerializerTag> : public std::false_type {};
226 
228 
232 
234 
235 template <>
236 class IsCheapToCopy<Point2i> : public std::true_type {};
237 
238 template <>
239 class IsCheapToCopy<Point2f> : public std::true_type {};
240 
241 template <>
242 class IsCheapToCopy<Point2d> : public std::true_type {};
243 
245 
251 template <typename T>
252 class Point<T,3> : public PointBase<T,3, Point<T,3> >
253 {
255 
256 public:
258  Point(){}
259 
261  Point(T x, T y, T z)
262  {
263  (*this)[0] = x;
264  (*this)[1] = y;
265  (*this)[2] = z;
266  }
267 
269  template <typename DerivedMatrix>
270  Point(const Eigen::MatrixBase<DerivedMatrix>& other) : Base(other) {}
271 
273  Point(const boost::geometry::model::point<T,3,boost::geometry::cs::cartesian>& other) {
274  operator=(other);
275  }
276 
278  explicit Point(const cv::Point3_<T> & other) {
279  operator=(other);
280  }
281 
283  Point& operator=(const cv::Point3_<T>& other) {
284  (*this)[0] = other.x;
285  (*this)[1] = other.y;
286  (*this)[2] = other.z;
287  return *this;
288  }
289 
291  operator cv::Point3_<T>() const
292  {
293  return cv::Point3_<T>(this->x(),this->y(),this->z());
294  }
295 
297  template<typename Reflector>
298  void reflect(Reflector& reflector)
299  {
300  reflector.property("X", this->x(), "The x-coordinate");
301  reflector.property("Y", this->y(), "The y-coordinate");
302  reflector.property("Z", this->z(), "The z-coordinate");
303  }
304 
305 };
306 
308 
310 template <typename T, typename SerializerTag>
311 class IsTransparentSerializable<Point<T,3>,SerializerTag> : public std::false_type {};
313 
315 
319 
321 
322 template <>
323 class IsCheapToCopy<Point3i> : public std::true_type {};
324 
325 template <>
326 class IsCheapToCopy<Point3f> : public std::true_type {};
327 
328 template <>
329 class IsCheapToCopy<Point3d> : public std::true_type {};
330 
332 
333 } // namespace MIRA
334 
336 // BOOST specialization on mira::point to accept them as geometry entity
337 namespace boost { namespace geometry { namespace traits {
338 
340 
341 template<typename T, int D>
342 struct tag<mira::Point<T, D> >
343 { typedef point_tag type; };
344 
345 template<typename T, int D>
346 struct dimension<mira::Point<T, D> > : boost::mpl::int_<D>
347 {};
348 
349 template<typename T, int D>
350 struct coordinate_type<mira::Point<T, D> >
351 { typedef T type; };
352 
353 template<typename T, int D>
354 struct coordinate_system<mira::Point<T, D> >
355 { typedef cs::cartesian type; };
356 
357 template<typename T, int D, std::size_t Dimension>
358 struct access<mira::Point<T, D>, Dimension>
359 {
360  static inline T get(mira::Point<T, D> const& p)
361  {
362  return p(Dimension, 0);
363  }
364  static inline void set(mira::Point<T, D>& p, T const& value)
365  {
366  p(Dimension, 0) = value;
367  }
368 };
369 
371 
372 }}} // namespace boost { namespace geometry { namespace traits {
373 
375 
377 
378 #endif
Point & operator=(const cv::Point3_< T > &other)
converts from OpenCV point
Definition: Point.h:283
void reflect(Reflector &reflector)
the reflect method for 2D point serialization
Definition: Point.h:213
T Type
Definition: Point.h:82
Point(const Eigen::MatrixBase< DerivedMatrix > &other)
Creates Point from Eigen matrix.
Definition: Point.h:270
Definition: SyncTimedRead.h:62
Include file for all eigen related things.
General point class template.
Definition: Point.h:135
Preprocessor workaround to handle single parameters that contain a comma.
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
Point()
Default constructor.
Definition: Point.h:141
Point< int, 2 > Point2i
a 2D integer point
Definition: Point.h:229
Definition: YawPitchRoll.h:684
void reflect(Reflector &reflector)
the reflect method for 3D point serialization
Definition: Point.h:298
Point< double, 2 > Point2d
a 2D 64 bit floating precision point
Definition: Point.h:231
Point(const Eigen::MatrixBase< DerivedMatrix > &other)
Creates Point from Eigen matrix.
Definition: Point.h:186
Specialization of Point for 2 dimensions with specialized constructors and converters.
Definition: Point.h:169
Point(const cv::Point3_< T > &other)
Creates Point from OpenCV point.
Definition: Point.h:278
Point & operator=(const cv::Point_< T > &other)
converts from OpenCV point
Definition: Point.h:199
PointBase(const boost::geometry::model::point< T, D, boost::geometry::cs::cartesian > &other)
Create from boost geometry point.
Definition: Point.h:90
Point< int, 3 > Point3i
a 3D integer point
Definition: Point.h:316
Derived & operator=(const boost::geometry::model::point< T, D, boost::geometry::cs::cartesian > &other)
converts from native boost::geometry::model::point
Definition: Point.h:106
Point(const boost::geometry::model::point< T, D, boost::geometry::cs::cartesian > &other)
Creates Point from boost::geometry::point.
Definition: Point.h:148
By default, IsCheapToCopy<T>::value evaluates to true for fundamental types T, false for all other ty...
Definition: IsCheapToCopy.h:63
PropertyHint type(const std::string &t)
Sets the attribute "type" to the specified value.
Definition: PropertyHint.h:295
Type trait to define if a class is cheap to copy.
Point()
Default-constructor.
Definition: Point.h:175
Matrix & operator=(const RotationBase< OtherDerived, ColsAtCompileTime > &r)
Point(T x, T y, T z)
Creates point from its three coordinates.
Definition: Point.h:261
PointBase(const Eigen::MatrixBase< DerivedMatrix > &other)
Create from Eigen matrix expression.
Definition: Point.h:96
Definition: Point.h:83
The base template class of point, which covers the basic functionality of each point.
Definition: Point.h:77
Point(T x, T y)
Creates point from its two coordinates.
Definition: Point.h:178
Point< float, 2 > Point2f
a 2D 32 bit floating precision point
Definition: Point.h:230
Point< float, 3 > Point3f
a 3D 32 bit floating precision point
Definition: Point.h:317
Point()
Default-constructor.
Definition: Point.h:258
Derived & operator=(const Eigen::MatrixBase< DerivedMatrix > &other)
assignment of Eigen matrix expression
Definition: Point.h:100
Point(const boost::geometry::model::point< T, 3, boost::geometry::cs::cartesian > &other)
Creates Point from boost::geometry::point.
Definition: Point.h:273
Point(const Eigen::MatrixBase< DerivedMatrix > &other)
Creates Point from Eigen matrix.
Definition: Point.h:145
Point< double, 3 > Point3d
a 3D 64 bit floating precision point
Definition: Point.h:318
PointBase()
Default constructor.
Definition: Point.h:87
Point(const boost::geometry::model::point< T, 2, boost::geometry::cs::cartesian > &other)
Creates Point from boost::geometry::point.
Definition: Point.h:189