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 namespace mira {
60 
62 
74 template <typename T, int D, typename Derived>
75 class PointBase : public Eigen::Matrix<T,D,1>
76 {
77  typedef Eigen::Matrix<T,D,1> Base;
78 
79 public:
80  typedef T Type;
81  enum { Dim = D};
82 
83 public:
85  PointBase() : Base(Eigen::Matrix<T,D,1>::Zero()) {}
86 
88  PointBase(const boost::geometry::model::point<T,D,boost::geometry::cs::cartesian>& other) {
89  operator=(other);
90  }
91 
93  template <typename DerivedMatrix>
95 
97  template <typename DerivedMatrix>
99  Base::operator=(other);
100  return *this;
101  }
102 
104  Derived& operator=(const boost::geometry::model::point<T,D,boost::geometry::cs::cartesian>& other)
105  {
106  for(int i=0; i < D; i++) // compiler will unroll loop
107  (*this)[i] = other(i);
108  return *this;
109  }
110 
112  operator boost::geometry::model::point<T,D,boost::geometry::cs::cartesian>() const
113  {
114  boost::geometry::model::point<T,D,boost::geometry::cs::cartesian> r;
115  for(int i=0; i < D; i++) // compiler will unroll loop
116  r(i) = (*this)[i];
117  return r;
118  }
119 };
120 
122 
132 template <typename T, int D>
133 class Point : public PointBase<T,D, Point<T,D> >
134 {
136 
137 public:
139  Point() {}
140 
142  template <typename DerivedMatrix>
143  Point(const Eigen::MatrixBase<DerivedMatrix>& other) : Base(other) {}
144 
146  Point(const boost::geometry::model::point<T,D,boost::geometry::cs::cartesian>& other) {
147  operator=(other);
148  }
149 };
150 
152 
154 template <typename T, int D, typename SerializerTag>
155 class IsTransparentSerializable<Point<T,D>,SerializerTag> : public std::true_type {};
157 
159 
166 template <typename T>
167 class Point<T,2> : public PointBase<T,2, Point<T,2> >
168 {
170 
171 public:
173  Point() {}
174 
176  Point(T x, T y)
177  {
178  (*this)[0] = x;
179  (*this)[1] = y;
180  }
181 
183  template <typename DerivedMatrix>
184  Point(const Eigen::MatrixBase<DerivedMatrix>& other) : Base(other) {}
185 
187  Point(const boost::geometry::model::point<T,2,boost::geometry::cs::cartesian>& other) {
188  operator=(other);
189  }
190 
192  explicit Point<T,2>(const cv::Point_<T> & other) {
193  operator=(other);
194  }
195 
197  Point& operator=(const cv::Point_<T>& other) {
198  (*this)[0] = other.x;
199  (*this)[1] = other.y;
200  return *this;
201  }
202 
204  operator cv::Point_<T>() const
205  {
206  return cv::Point_<T>( this->x(), this->y() );
207  }
208 
210  template<typename Reflector>
211  void reflect(Reflector& reflector)
212  {
213  reflector.property("X", this->x(), "The x-coordinate");
214  reflector.property("Y", this->y(), "The y-coordinate");
215  }
216 };
217 
219 
221 template <typename T, typename SerializerTag>
222 class IsTransparentSerializable<Point<T,2>,SerializerTag> : public std::false_type {};
224 
226 
230 
232 
238 template <typename T>
239 class Point<T,3> : public PointBase<T,3, Point<T,3> >
240 {
242 
243 public:
245  Point(){}
246 
248  Point(T x, T y, T z)
249  {
250  (*this)[0] = x;
251  (*this)[1] = y;
252  (*this)[2] = z;
253  }
254 
256  template <typename DerivedMatrix>
257  Point(const Eigen::MatrixBase<DerivedMatrix>& other) : Base(other) {}
258 
260  Point(const boost::geometry::model::point<T,3,boost::geometry::cs::cartesian>& other) {
261  operator=(other);
262  }
263 
265  explicit Point(const cv::Point3_<T> & other) {
266  operator=(other);
267  }
268 
270  Point& operator=(const cv::Point3_<T>& other) {
271  (*this)[0] = other.x;
272  (*this)[1] = other.y;
273  (*this)[2] = other.z;
274  return *this;
275  }
276 
278  operator cv::Point3_<T>() const
279  {
280  return cv::Point3_<T>(this->x(),this->y(),this->z());
281  }
282 
284  template<typename Reflector>
285  void reflect(Reflector& reflector)
286  {
287  reflector.property("X", this->x(), "The x-coordinate");
288  reflector.property("Y", this->y(), "The y-coordinate");
289  reflector.property("Z", this->z(), "The z-coordinate");
290  }
291 
292 };
293 
295 
297 template <typename T, typename SerializerTag>
298 class IsTransparentSerializable<Point<T,3>,SerializerTag> : public std::false_type {};
300 
302 
306 
308 
309 } // namespace MIRA
310 
312 // BOOST specialization on mira::point to accept them as geometry entity
313 namespace boost { namespace geometry { namespace traits {
314 
316 
317 template<typename T, int D>
318 struct tag<mira::Point<T, D> >
319 { typedef point_tag type; };
320 
321 template<typename T, int D>
322 struct dimension<mira::Point<T, D> > : boost::mpl::int_<D>
323 {};
324 
325 template<typename T, int D>
326 struct coordinate_type<mira::Point<T, D> >
327 { typedef T type; };
328 
329 template<typename T, int D>
330 struct coordinate_system<mira::Point<T, D> >
331 { typedef cs::cartesian type; };
332 
333 template<typename T, int D, std::size_t Dimension>
334 struct access<mira::Point<T, D>, Dimension>
335 {
336  static inline T get(mira::Point<T, D> const& p)
337  {
338  return p(Dimension, 0);
339  }
340  static inline void set(mira::Point<T, D>& p, T const& value)
341  {
342  p(Dimension, 0) = value;
343  }
344 };
345 
347 
348 }}} // namespace boost { namespace geometry { namespace traits {
349 
351 
353 
354 #endif
Point & operator=(const cv::Point3_< T > &other)
converts from OpenCV point
Definition: Point.h:270
void reflect(Reflector &reflector)
the reflect method for 2D point serialization
Definition: Point.h:211
T Type
Definition: Point.h:80
Point(const Eigen::MatrixBase< DerivedMatrix > &other)
Creates Point from Eigen matrix.
Definition: Point.h:257
Definition: SyncTimedRead.h:62
Include file for all eigen related things.
General point class template.
Definition: Point.h:133
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:139
Point< int, 2 > Point2i
a 2D integer point
Definition: Point.h:227
Definition: YawPitchRoll.h:684
void reflect(Reflector &reflector)
the reflect method for 3D point serialization
Definition: Point.h:285
Point< double, 2 > Point2d
a 2D 64 bit floating precision point
Definition: Point.h:229
Point(const Eigen::MatrixBase< DerivedMatrix > &other)
Creates Point from Eigen matrix.
Definition: Point.h:184
Specialization of Point for 2 dimensions with specialized constructors and converters.
Definition: Point.h:167
Point(const cv::Point3_< T > &other)
Creates Point from OpenCV point.
Definition: Point.h:265
Point & operator=(const cv::Point_< T > &other)
converts from OpenCV point
Definition: Point.h:197
PointBase(const boost::geometry::model::point< T, D, boost::geometry::cs::cartesian > &other)
Create from boost geometry point.
Definition: Point.h:88
Point< int, 3 > Point3i
a 3D integer point
Definition: Point.h:303
Derived & operator=(const boost::geometry::model::point< T, D, boost::geometry::cs::cartesian > &other)
converts from native boost::geometry::model::point
Definition: Point.h:104
Point(const boost::geometry::model::point< T, D, boost::geometry::cs::cartesian > &other)
Creates Point from boost::geometry::point.
Definition: Point.h:146
PropertyHint type(const std::string &t)
Sets the attribute "type" to the specified value.
Definition: PropertyHint.h:295
Point()
Default-constructor.
Definition: Point.h:173
Matrix & operator=(const RotationBase< OtherDerived, ColsAtCompileTime > &r)
Point(T x, T y, T z)
Creates point from its three coordinates.
Definition: Point.h:248
PointBase(const Eigen::MatrixBase< DerivedMatrix > &other)
Create from Eigen matrix expression.
Definition: Point.h:94
Definition: Point.h:81
The base template class of point, which covers the basic functionality of each point.
Definition: Point.h:75
Point(T x, T y)
Creates point from its two coordinates.
Definition: Point.h:176
Point< float, 2 > Point2f
a 2D 32 bit floating precision point
Definition: Point.h:228
Point< float, 3 > Point3f
a 3D 32 bit floating precision point
Definition: Point.h:304
Point()
Default-constructor.
Definition: Point.h:245
Derived & operator=(const Eigen::MatrixBase< DerivedMatrix > &other)
assignment of Eigen matrix expression
Definition: Point.h:98
Point(const boost::geometry::model::point< T, 3, boost::geometry::cs::cartesian > &other)
Creates Point from boost::geometry::point.
Definition: Point.h:260
Point(const Eigen::MatrixBase< DerivedMatrix > &other)
Creates Point from Eigen matrix.
Definition: Point.h:143
Point< double, 3 > Point3d
a 3D 64 bit floating precision point
Definition: Point.h:305
PointBase()
Default constructor.
Definition: Point.h:85
Point(const boost::geometry::model::point< T, 2, boost::geometry::cs::cartesian > &other)
Creates Point from boost::geometry::point.
Definition: Point.h:187