IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
Rectangle2d.h
1 // Rectangle2d.h:
3 // --------------
4 //
14 
15 #ifndef __IPSDKGEOMETRY_RECTANGLE2D_H__
16 #define __IPSDKGEOMETRY_RECTANGLE2D_H__
17 
18 // suppression warnings
19 // warning C4251: 'ipsdk::geom::Rectangle2d<T>::_centerPt' : struct 'ipsdk::geom::Point2dData<T>' needs to have dll-interface to be used by clients of class 'ipsdk::geom::Rectangle2d<T>'
20 #pragma warning (push)
21 #pragma warning (disable : 4251)
22 
24 #include <IPSDKGeometry/Entity/2d/BaseTypedGeometryEntity2d.h>
25 #include <IPSDKGeometry/Entity/2d/Point/Point2d.h>
27 
28 namespace ipsdk {
29 namespace geom {
30 
33 
34 template <typename T>
36 {
37  // declare 2d geometry entity
39 
40 // predefined public types
41 public:
43  static const eCoordinateSystem2dType::domain g_coordinateSystem2dType = eCoordinateSystem2dType::eCS2DT_Cartesian;
44 
46  static const eEntity2dType::domain g_entity2dType = eEntity2dType::eE2DT_Rectangle;
47 
48 public:
51  Rectangle2d();
52  Rectangle2d(const Point2dData<T>& centerPt, const T halfLength, const T halfWidth, const ipReal64 orientation);
53  Rectangle2d(const Point2d<T>& centerPt, const T halfLength, const T halfWidth, const ipReal64 orientation);
54  Rectangle2d(const T xCenter, const T yCenter, const T halfLength, const T halfWidth, const ipReal64 orientation);
55  ~Rectangle2d();
57 
58 // methods
59 public:
61  inline eCoordinateSystem2dType getCoordinateSystem2dType() const;
62 
64  inline eEntity2dType getEntity2dType() const;
65 
68  inline void setCenter(const Point2dData<T>& centerPt);
69  inline void setCenter(const Point2d<T>& centerPt);
70  inline void setCenter(const T xMin, const T yMin);
71  inline void setHalfLength(const T halfLength);
72  inline void setHalfWidth(const T halfWidth);
73  inline void setOrientation(const ipReal64 orientation);
74  inline ipReal64 getOrientation() const;
75  inline T centerX() const;
76  inline T centerY() const;
77  inline const Point2dData<T>& center() const;
78  inline T getHalfLength() const;
79  inline T getHalfWidth() const;
80  inline T getLength() const;
81  inline T getWidth() const;
82  inline T getArea() const;
84 
89  inline Point2dData<T> topLeftCorner() const;
90  inline Point2dData<T> topRightCorner() const;
91  inline Point2dData<T> bottomLeftCorner() const;
92  inline Point2dData<T> bottomRightCorner() const;
94 
95 // attributes
96 protected:
99 
102  T _halfWidth;
103 
106 
107 };
108 
111 
112 template <typename T>
115 {
116  return g_coordinateSystem2dType;
117 }
118 
119 template <typename T>
120 inline eEntity2dType
122 {
123  return g_entity2dType;
124 }
125 
126 template <typename T>
127 inline void
129 {
130  _centerPt = centerPt;
131 }
132 
133 template <typename T>
134 inline void
136 {
137  _centerPt = centerPt.getCoords();
138 }
139 
140 template <typename T>
141 inline void
142 Rectangle2d<T>::setCenter(const T xMin, const T yMin)
143 {
144  _centerPt.setCoords(xMin, yMin);
145 }
146 
147 template <typename T>
148 inline void
149 Rectangle2d<T>::setHalfLength(const T halfLength)
150 {
151  _halfLength = halfLength;
152 }
153 
154 template <typename T>
155 inline void
157 {
158  _halfWidth = halfWidth;
159 }
160 
161 template <typename T>
162 inline T
164 {
165  return _centerPt._x;
166 }
167 
168 template <typename T>
169 inline T
171 {
172  return _centerPt._y;
173 }
174 
175 template <typename T>
176 inline const Point2dData<T>&
178 {
179  return _centerPt;
180 }
181 
182 template <typename T>
183 inline void
185 {
186  _orientation = orientation;
187 }
188 
189 template <typename T>
190 inline T
192 {
193  return _halfLength;
194 }
195 
196 template <typename T>
197 inline T
199 {
200  return _halfWidth;
201 }
202 
203 template <typename T>
204 inline T
206 {
207  return 2 * this->getHalfLength();
208 }
209 
210 template <typename T>
211 inline T
213 {
214  return 2 * this->getHalfWidth();
215 }
216 
217 template <typename T>
218 inline T
220 {
221  return this->getLength() * this->getWidth();
222 }
223 
224 template <typename T>
225 inline ipReal64
227 {
228  return _orientation;
229 }
230 
231 template <typename T>
232 inline Point2dData<T>
234 {
235  const ipReal64 modulus = std::sqrt(_halfLength*_halfLength + _halfWidth*_halfWidth);
236  const ipReal64 alpha = std::atan(_halfWidth/_halfLength);
237  return Point2dData<T>(static_cast<T>(modulus*std::cos(_orientation+M_PI+alpha)) + _centerPt._x,
238  static_cast<T>(modulus*std::sin(_orientation+M_PI+alpha)) + _centerPt._y);
239 }
240 
241 template <typename T>
242 inline Point2dData<T>
244 {
245  const ipReal64 modulus = std::sqrt(_halfLength*_halfLength + _halfWidth*_halfWidth);
246  const ipReal64 alpha = std::atan(_halfWidth/_halfLength);
247  return Point2dData<T>(static_cast<T>(modulus*std::cos(_orientation-alpha)) + _centerPt._x,
248  static_cast<T>(modulus*std::sin(_orientation-alpha)) + _centerPt._y);
249 }
250 
251 template <typename T>
252 inline Point2dData<T>
254 {
255  const ipReal64 modulus = std::sqrt(_halfLength*_halfLength + _halfWidth*_halfWidth);
256  const ipReal64 alpha = std::atan(_halfWidth/_halfLength);
257  return Point2dData<T>(static_cast<T>(modulus*std::cos(_orientation+M_PI-alpha) )+ _centerPt._x,
258  static_cast<T>(modulus*std::sin(_orientation+M_PI-alpha)) + _centerPt._y);
259 }
260 
261 template <typename T>
262 inline Point2dData<T>
264 {
265  const ipReal64 modulus = std::sqrt(_halfLength*_halfLength + _halfWidth*_halfWidth);
266  const ipReal64 alpha = std::atan(_halfWidth/_halfLength);
267  return Point2dData<T>(static_cast<T>(modulus*std::cos(_orientation+alpha)) + _centerPt._x,
268  static_cast<T>(modulus*std::sin(_orientation+alpha)) + _centerPt._y);
269 }
270 
273 
274 } // end of namespace geom
275 } // end of namespace ipsdk
276 
277 #pragma warning (pop)
278 
279 #endif // __IPSDKGEOMETRY_RECTANGLE2D_H__
void setCenter(const Point2dData< T > &centerPt)
access to rectangle coordinates
Definition: Rectangle2d.h:128
T getHalfLength() const
access to rectangle coordinates
Definition: Rectangle2d.h:191
Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22
T getWidth() const
access to rectangle coordinates
Definition: Rectangle2d.h:212
Point class associated to cartesian 2d coordinates.
Definition: GeometryEntity2dTypes.h:28
Rectangle.
Definition: GeometryEntity2dTypes.h:60
IPSDK_FORCEINLINE PackT sqrt(const PackT &in)
returns the square root of a pack
Definition: sqrt.h:40
double ipReal64
Base types definition.
Definition: BaseTypes.h:57
eCoordinateSystem2dType
Enumerate describing coordinate system 2d type.
Definition: GeometryEntity2dTypes.h:76
eEntity2dType getEntity2dType() const
method allowing to retrieve entity 2d type
Definition: Rectangle2d.h:121
Point2dData< T > bottomRightCorner() const
compute rectangle corners coordinates For instance, the topLeftCorner() method calculates the coordin...
Definition: Rectangle2d.h:263
Point2dData< T > topRightCorner() const
compute rectangle corners coordinates For instance, the topLeftCorner() method calculates the coordin...
Definition: Rectangle2d.h:243
Definition of import/export macro for library.
T centerX() const
access to rectangle coordinates
Definition: Rectangle2d.h:163
#define IPSDKGEOMETRY_API
Import/Export macro for library IPSDKGeometry.
Definition: IPSDKGeometryExports.h:25
Base class for typed 3d geometry entities.
Definition: BaseTypedGeometryEntity2d.h:27
void setHalfLength(const T halfLength)
access to rectangle coordinates
Definition: Rectangle2d.h:149
#define IPSDK_DECLARE_GEOMETRY_ENTITY_2D(libraryName, className)
Macro allowing to declare a geometry entity 2d.
Definition: GeometryEntity2dHdrMacros.h:131
T getArea() const
access to rectangle coordinates
Definition: Rectangle2d.h:219
T getHalfWidth() const
access to rectangle coordinates
Definition: Rectangle2d.h:198
ipReal64 _orientation
orientation (in radian) of the rectangle
Definition: Rectangle2d.h:105
eCoordinateSystem2dType getCoordinateSystem2dType() const
method allowing to retrieve coordinate system 2d type
Definition: Rectangle2d.h:114
void setHalfWidth(const T halfWidth)
access to rectangle coordinates
Definition: Rectangle2d.h:156
void setOrientation(const ipReal64 orientation)
access to rectangle coordinates
Definition: Rectangle2d.h:184
const Point2dData< T > & getCoords() const
access to point coordinates
Definition: Point2d.h:139
2d rectangle class associated to cartesian 2d coordinates
Definition: Rectangle2d.h:35
eEntity2dType
Enumerate describing entity 2d type.
Definition: GeometryEntity2dTypes.h:38
T getLength() const
access to rectangle coordinates
Definition: Rectangle2d.h:205
T centerY() const
access to rectangle coordinates
Definition: Rectangle2d.h:170
Point2dData< T > topLeftCorner() const
compute rectangle corners coordinates For instance, the topLeftCorner() method calculates the coordin...
Definition: Rectangle2d.h:233
Lightweight structure used to store Point2d data.
Definition: GeometryEntity2dTypes.h:26
const Point2dData< T > & center() const
access to rectangle coordinates
Definition: Rectangle2d.h:177
ipReal64 getOrientation() const
access to rectangle coordinates
Definition: Rectangle2d.h:226
Point2dData< T > _centerPt
coordinates associated to the center of the rectangle
Definition: Rectangle2d.h:98
Point2dData< T > bottomLeftCorner() const
compute rectangle corners coordinates For instance, the topLeftCorner() method calculates the coordin...
Definition: Rectangle2d.h:253
Cartesian coordinate system.
Definition: GeometryEntity2dTypes.h:78
T _halfLength
half lengths of the rectangle sides
Definition: Rectangle2d.h:101