IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
Segment2d.h
1 // Segment2d.h:
3 // ------------
4 //
14 
15 #ifndef __IPSDKGEOMETRY_SEGMENT2D_H__
16 #define __IPSDKGEOMETRY_SEGMENT2D_H__
17 
18 // suppression warnings
19 // warning C4251: 'ipsdk::geom::Segment2d<ipsdk::ipInt32>::_pt0' : struct 'ipsdk::geom::Point2dData<T>' needs to have dll-interface to be used by clients of class 'ipsdk::geom::Segment2d<ipsdk::ipInt32>'
20 #pragma warning (push)
21 #pragma warning (disable : 4251)
22 
23 #include <IPSDKGeometry/Entity/2d/BaseTypedGeometryEntity2d.h>
25 #include <IPSDKGeometry/Entity/2d/Point/Point2d.h>
26 #include <IPSDKGeometry/Entity/2d/Vector/Vector2d.h>
28 
29 namespace ipsdk {
30 namespace geom {
31 
32 class Vector2d;
33 
36 
37 template <typename T>
39 {
40  // declare 2d geometry entity
42 
43 // predefined public types
44 public:
46  static const eCoordinateSystem2dType::domain g_coordinateSystem2dType = eCoordinateSystem2dType::eCS2DT_Cartesian;
47 
49  static const eEntity2dType::domain g_entity2dType = eEntity2dType::eE2DT_Segment;
50 
51 public:
54  Segment2d();
55  Segment2d(const T x0, const T y0, const T x1, const T y1);
56  Segment2d(const Point2d<T>& pt0, const Point2d<T>& pt1);
57  Segment2d(const Point2dData<T>& pt0, const Point2dData<T>& pt1);
58  Segment2d(const Point2d<T>& pt0, const Vector2d& v10);
59  Segment2d(const Point2dData<T>& pt0, const Vector2d& v10);
60  ~Segment2d();
62 
63 // methods
64 public:
66  inline eCoordinateSystem2dType getCoordinateSystem2dType() const;
67 
69  inline eEntity2dType getEntity2dType() const;
70 
73  inline void setCoords(const T x0, const T y0, const T x1, const T y1);
74  inline void setCoords(const Point2d<T>& pt0, const Point2d<T>& pt1);
75  inline void setCoords(const Point2dData<T>& pt0, const Point2dData<T>& pt1);
76  inline void setCoords(const Point2d<T>& pt, const Vector2d& v01);
77  inline void setCoords(const Point2dData<T>& pt, const Vector2d& v01);
78  inline void setPoint0(const Point2d<T>& pt0);
79  inline void setPoint0(const Point2dData<T>& pt0);
80  inline void setPoint1(const Point2d<T>& pt1);
81  inline void setPoint1(const Point2dData<T>& pt1);
82  inline const Point2dData<T>& getPoint0() const;
83  inline const Point2dData<T>& getPoint1() const;
85 
87  ipReal64 getLength() const;
88 
91  Vector2d getDirection() const;
92 
95  Vector2d getUnitDirection() const;
96 
99  Vector2d getUnitNormal() const;
100 
103  inline ipReal64 getMiddleX() const;
104  inline ipReal64 getMiddleY() const;
105  inline Point2dData<ipReal64> getMiddlePoint() const;
107 
110  inline ipReal64 distance(const Point2d<T>& pt) const;
111  inline ipReal64 distance(const Point2d<T>& pt,
112  Point2d<ipReal64>& nearestPointOnSegment) const;
113  ipReal64 distance(const Point2dData<T>& pt) const;
114  ipReal64 distance(const Point2dData<T>& pt,
115  Point2dData<ipReal64>& nearestPointOnSegment) const;
117 
120  ipReal64 distance(const Segment2d<T>& otherSegment) const;
121  inline ipReal64 distance(const Segment2d<T>& otherSegment,
122  Point2d<ipReal64>& nearestPointOnThisSegment,
123  Point2d<ipReal64>& nearestPointOnOtherSegment) const;
124  ipReal64 distance(const Segment2d<T>& otherSegment,
125  Point2dData<ipReal64>& nearestPointOnThisSegment,
126  Point2dData<ipReal64>& nearestPointOnOtherSegment) const;
128 
129 // attributes
130 protected:
133 
136 };
137 
140 
141 template <typename T>
142 inline
143 Segment2d<T>::Segment2d(const T x0, const T y0, const T x1, const T y1) :
144  _pt0(x0, y0),
145  _pt1(x1, y1)
146 {
147 
148 }
149 
150 template <typename T>
151 inline
152 Segment2d<T>::Segment2d(const Point2d<T>& pt0, const Point2d<T>& pt1) :
153  _pt0(pt0.getCoords()),
154  _pt1(pt1.getCoords())
155 {
156 
157 }
158 
159 template <typename T>
160 inline
161 Segment2d<T>::Segment2d(const Point2dData<T>& pt0, const Point2dData<T>& pt1) :
162  _pt0(pt0),
163  _pt1(pt1)
164 {
165 
166 }
167 
168 template <typename T>
169 inline
170 Segment2d<T>::Segment2d(const Point2d<T>& pt0, const Vector2d& v01)
171 {
172  setCoords(pt0, v01);
173 }
174 
175 template <typename T>
176 inline
177 Segment2d<T>::Segment2d(const Point2dData<T>& pt0, const Vector2d& v01)
178 {
179  setCoords(pt0, v01);
180 }
181 
182 template <typename T>
185 {
186  return g_coordinateSystem2dType;
187 }
188 
189 template <typename T>
190 inline eEntity2dType
192 {
193  return g_entity2dType;
194 }
195 
196 template <typename T>
197 inline void
198 Segment2d<T>::setCoords(const T x0, const T y0, const T x1, const T y1)
199 {
200  _pt0.setCoords(x0, y0);
201  _pt1.setCoords(x1, y1);
202 }
203 
204 template <typename T>
205 inline void
207 {
208  _pt0 = pt0.getCoords();
209  _pt1 = pt1.getCoords();
210 }
211 
212 template <typename T>
213 inline void
215 {
216  _pt0 = pt0;
217  _pt1 = pt1;
218 }
219 
220 template <typename T>
221 inline void
223 {
224  setCoords(pt.getCoords(), v01);
225 }
226 
227 template <typename T>
228 inline void
230 {
231  _pt0 = pt;
232  _pt1 = pt;
233  _pt1._x += math::round<T>(v01.getX());
234  _pt1._y += math::round<T>(v01.getY());
235 }
236 
237 template <typename T>
238 inline void
240 {
241  _pt0 = pt0.getCoords();
242 }
243 
244 template <typename T>
245 inline void
247 {
248  _pt0 = pt0;
249 }
250 
251 template <typename T>
252 inline void
254 {
255  _pt1 = pt1.getCoords();
256 }
257 
258 template <typename T>
259 inline void
261 {
262  _pt1 = pt1;
263 }
264 
265 template <typename T>
266 inline const Point2dData<T>&
268 {
269  return _pt0;
270 }
271 
272 template <typename T>
273 inline const Point2dData<T>&
275 {
276  return _pt1;
277 }
278 
279 template <typename T>
280 inline ipReal64
282 {
283  return (_pt0._x + _pt1._x) / 2.0;
284 }
285 
286 template <typename T>
287 inline ipReal64
289 {
290  return (_pt0._y + _pt1._y) / 2.0;
291 }
292 
293 template <typename T>
296 {
297  return Point2dData<ipReal64>(getMiddleX(), getMiddleY());
298 }
299 
300 template <typename T>
301 inline ipReal64
303 {
304  return distance(pt.getCoords());
305 }
306 
307 template <typename T>
308 inline ipReal64
310  Point2d<ipReal64>& nearestPointOnSegment) const
311 {
312  return distance(pt.getCoords(), nearestPointOnSegment.getCoords());
313 }
314 
315 template <typename T>
316 inline ipReal64
318  Point2d<ipReal64>& nearestPointOnThisSegment,
319  Point2d<ipReal64>& nearestPointOnOtherSegment) const
320 {
321  return distance(otherSegment, nearestPointOnThisSegment.getCoords(), nearestPointOnOtherSegment.getCoords());
322 }
323 
326 
327 } // end of namespace geom
328 } // end of namespace ipsdk
329 
330 #pragma warning (pop)
331 
332 #endif // __IPSDKGEOMETRY_SEGMENT2D_H__
Operators associated to segment 2d entities.
Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22
T _x
x coordinate of point
Definition: Point2dData.h:69
Point class associated to cartesian 2d coordinates.
Definition: GeometryEntity2dTypes.h:28
ipReal64 getMiddleY() const
retrieve segment middle point coordinates
Definition: Segment2d.h:288
double ipReal64
Base types definition.
Definition: BaseTypes.h:57
ipReal64 getY() const
retrieve cartesian components of vector
Definition: Vector2d.h:240
ipReal64 getX() const
retrieve cartesian components of vector
Definition: Vector2d.h:234
eCoordinateSystem2dType
Enumerate describing coordinate system 2d type.
Definition: GeometryEntity2dTypes.h:76
Segment.
Definition: GeometryEntity2dTypes.h:68
ipReal64 getMiddleX() const
retrieve segment middle point coordinates
Definition: Segment2d.h:281
void setPoint1(const Point2d< T > &pt1)
access to segment coordinates
Definition: Segment2d.h:253
IPSDKGEOMETRY_API ipReal64 distance(const Point2d< T > &pt1, const Point2d< T > &pt2)
compute euclidian distance between two points
eEntity2dType getEntity2dType() const
method allowing to retrieve entity 2d type
Definition: Segment2d.h:191
#define IPSDKGEOMETRY_API
Import/Export macro for library IPSDKGeometry.
Definition: IPSDKGeometryExports.h:25
Base class for typed 3d geometry entities.
Definition: BaseTypedGeometryEntity2d.h:27
const Point2dData< T > & getPoint0() const
access to segment coordinates
Definition: Segment2d.h:267
#define IPSDK_DECLARE_GEOMETRY_ENTITY_2D(libraryName, className)
Macro allowing to declare a geometry entity 2d.
Definition: GeometryEntity2dHdrMacros.h:131
void setPoint0(const Point2d< T > &pt0)
access to segment coordinates
Definition: Segment2d.h:239
2d segment associated to two points
Definition: Segment2d.h:38
Utility functions for ipsdk math library.
Point2dData< ipReal64 > getMiddlePoint() const
retrieve segment middle point coordinates
Definition: Segment2d.h:295
ipReal64 distance(const Point2d< T > &pt) const
retrieve orthogonal distance between point and segment
Definition: Segment2d.h:302
Point2dData< T > _pt1
second point associated to segment
Definition: Segment2d.h:135
const Point2dData< T > & getPoint1() const
access to segment coordinates
Definition: Segment2d.h:274
Vector class associated to polar 2d coordinates.
Definition: Vector2d.h:32
const Point2dData< T > & getCoords() const
access to point coordinates
Definition: Point2d.h:139
boost::numeric::ublas::bounded_vector< ipReal64, 2 > Vector2d
2d vector type associated to library
Definition: LinearAlgebraTypes.h:39
eEntity2dType
Enumerate describing entity 2d type.
Definition: GeometryEntity2dTypes.h:38
Point2dData< T > _pt0
first point associated to segment
Definition: Segment2d.h:132
eCoordinateSystem2dType getCoordinateSystem2dType() const
method allowing to retrieve coordinate system 2d type
Definition: Segment2d.h:184
void setCoords(const T x0, const T y0, const T x1, const T y1)
access to segment coordinates
Definition: Segment2d.h:198
Lightweight structure used to store Point2d data.
Definition: GeometryEntity2dTypes.h:26
Cartesian coordinate system.
Definition: GeometryEntity2dTypes.h:78