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 namespace mira {
53 
55 
59 template <typename T, int D>
60 class Line
61 {
62 public:
64 
65 public:
67  Line() {}
68 
70  Line(const PointType& p1, const PointType& p2) :
71  first(p1), second(p2) {}
72 
73 public:
75  const PointType& front() const { return first; }
76 
78  PointType& front() { return first; }
79 
81  const PointType& back() const { return second; }
82 
84  PointType& back() { return second; }
85 
86 public:
87 
88  template<typename Reflector>
89  void reflect(Reflector& r)
90  {
91  r.property("P0", first, "The first point");
92  r.property("P1", second, "The second point");
93  }
94 
95 public:
97  PointType first, second; // must be called first and second
98  // for compatibility with boost::geometry
99 
100 };
101 
103 
108 
110 
111 } // end of MIRA namespace
112 
114 
115 // BOOST specialization on Line to accept them as geometry entity
116 namespace boost { namespace geometry { namespace traits {
117 
119 
120 template <typename T, int D>
121 struct tag<mira::Line<T,D> > {
122  typedef segment_tag type;
123 };
124 
125 template <typename T, int D>
126 struct point_type<mira::Line<T,D> > {
127  typedef mira::Point<T,D> type;
128 };
129 
130 template <typename T, int D, std::size_t Dimension>
131 struct indexed_access<mira::Line<T,D>, 0, Dimension>
132 {
133  typedef mira::Line<T,D> segment_type;
134  typedef typename geometry::coordinate_type<segment_type>::type coordinate_type;
135 
136  static inline coordinate_type get(segment_type const& s) {
137  return geometry::get<Dimension>(s.first);
138  }
139 
140  static inline void set(segment_type& s, coordinate_type const& value) {
141  geometry::set<Dimension>(s.first, value);
142  }
143 };
144 
145 template <typename T, int D, std::size_t Dimension>
146 struct indexed_access<mira::Line<T,D>, 1, Dimension>
147 {
148  typedef mira::Line<T,D> segment_type;
149  typedef typename geometry::coordinate_type<segment_type>::type coordinate_type;
150 
151  static inline coordinate_type get(segment_type const& s) {
152  return geometry::get<Dimension>(s.second);
153  }
154 
155  static inline void set(segment_type& s, coordinate_type const& value) {
156  geometry::set<Dimension>(s.second, value);
157  }
158 };
159 
161 
162 }}} // end of boost namespaces
163 
165 
167 
168 #endif
Represents a line segment that is spanned by two given points.
Definition: Line.h:60
Line< float, 2 > Line2f
A 2D 32 bit floating precision line.
Definition: Line.h:106
Definition: SyncTimedRead.h:62
General point class template.
Definition: Point.h:133
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:107
PointType & front()
Returns a reference to the first point of the line segment.
Definition: Line.h:78
Line< int, 2 > Line2i
A 2D integer line.
Definition: Line.h:104
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:70
PointType second
Definition: Line.h:97
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:63
PointType & back()
Returns a reference to the second point of the line segment.
Definition: Line.h:84
Line()
Creates an uninitialized line segment.
Definition: Line.h:67
Line< int, 3 > Line3i
A 3D integer line.
Definition: Line.h:105
const PointType & front() const
Returns a reference to the first point of the line segment.
Definition: Line.h:75
const PointType & back() const
Returns a reference to the second point of the line segment.
Definition: Line.h:81
PointType first
The two points of the line segment.
Definition: Line.h:97
void reflect(Reflector &r)
Definition: Line.h:89