MIRA
Line.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_LINE_H_
48 #define _MIRA_LINE_H_
49 
50 #include <geometry/Point.h>
51 
52 #include <utils/IsCheapToCopy.h>
53 
54 namespace mira {
55 
57 
61 template <typename T, int D>
62 class Line
63 {
64 public:
66 
67 public:
69  Line() {}
70 
72  Line(const PointType& p1, const PointType& p2) :
73  first(p1), second(p2) {}
74 
75 public:
77  const PointType& front() const { return first; }
78 
80  PointType& front() { return first; }
81 
83  const PointType& back() const { return second; }
84 
86  PointType& back() { return second; }
87 
88 public:
89 
90  template<typename Reflector>
91  void reflect(Reflector& r)
92  {
93  r.property("P0", first, "The first point");
94  r.property("P1", second, "The second point");
95  }
96 
97 public:
99  PointType first, second; // must be called first and second
100  // for compatibility with boost::geometry
101 
102 };
103 
105 
110 
112 
113 template <>
114 class IsCheapToCopy<Line2i> : public std::true_type {};
115 
116 template <>
117 class IsCheapToCopy<Line3i> : public std::true_type {};
118 
119 template <>
120 class IsCheapToCopy<Line2f> : public std::true_type {};
121 
122 template <>
123 class IsCheapToCopy<Line3f> : public std::true_type {};
124 
126 
127 } // end of MIRA namespace
128 
130 
131 // BOOST specialization on Line to accept them as geometry entity
132 namespace boost { namespace geometry { namespace traits {
133 
135 
136 template <typename T, int D>
137 struct tag<mira::Line<T,D> > {
138  typedef segment_tag type;
139 };
140 
141 template <typename T, int D>
142 struct point_type<mira::Line<T,D> > {
143  typedef mira::Point<T,D> type;
144 };
145 
146 template <typename T, int D, std::size_t Dimension>
147 struct indexed_access<mira::Line<T,D>, 0, Dimension>
148 {
149  typedef mira::Line<T,D> segment_type;
150  typedef typename geometry::coordinate_type<segment_type>::type coordinate_type;
151 
152  static inline coordinate_type get(segment_type const& s) {
153  return geometry::get<Dimension>(s.first);
154  }
155 
156  static inline void set(segment_type& s, coordinate_type const& value) {
157  geometry::set<Dimension>(s.first, value);
158  }
159 };
160 
161 template <typename T, int D, std::size_t Dimension>
162 struct indexed_access<mira::Line<T,D>, 1, Dimension>
163 {
164  typedef mira::Line<T,D> segment_type;
165  typedef typename geometry::coordinate_type<segment_type>::type coordinate_type;
166 
167  static inline coordinate_type get(segment_type const& s) {
168  return geometry::get<Dimension>(s.second);
169  }
170 
171  static inline void set(segment_type& s, coordinate_type const& value) {
172  geometry::set<Dimension>(s.second, value);
173  }
174 };
175 
177 
178 }}} // end of boost namespaces
179 
181 
183 
184 #endif
Represents a line segment that is spanned by two given points.
Definition: Line.h:62
Line< float, 2 > Line2f
A 2D 32 bit floating precision line.
Definition: Line.h:108
Definition: SyncTimedRead.h:62
General point class template.
Definition: Point.h:135
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
Line< float, 3 > Line3f
A 3D 32 bit floating precision line.
Definition: Line.h:109
PointType & front()
Returns a reference to the first point of the line segment.
Definition: Line.h:80
Line< int, 2 > Line2i
A 2D integer line.
Definition: Line.h:106
Class for 2D, 3D and N-dimensional points.
Line(const PointType &p1, const PointType &p2)
Creates a line segment that is spanned by two given points.
Definition: Line.h:72
PointType second
Definition: Line.h:99
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
Point< T, D > PointType
Definition: Line.h:65
Type trait to define if a class is cheap to copy.
PointType & back()
Returns a reference to the second point of the line segment.
Definition: Line.h:86
Line()
Creates an uninitialized line segment.
Definition: Line.h:69
Line< int, 3 > Line3i
A 3D integer line.
Definition: Line.h:107
const PointType & front() const
Returns a reference to the first point of the line segment.
Definition: Line.h:77
const PointType & back() const
Returns a reference to the second point of the line segment.
Definition: Line.h:83
PointType first
The two points of the line segment.
Definition: Line.h:99
void reflect(Reflector &r)
Definition: Line.h:91