MIRA
Size.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 
49 #ifndef _MIRA_SIZE_H_
50 #define _MIRA_SIZE_H_
51 
52 #include <geometry/Point.h>
53 
54 #include <utils/IsCheapToCopy.h>
55 
56 namespace mira
57 {
58 
60 
68 template<typename T, int D>
69 class Size : public Eigen::Matrix<T,D,1>
70 {
71 public:
74 
75 public:
77  Size() {}
78 
81  template <typename MatrixDerived>
83  BaseType(matrix) {}
84 };
85 
87 
93 template<typename T>
94 class Size<T,2> : public Eigen::Matrix<T,2,1>
95 {
96 public:
99 
100 public:
103 
105  Size() {}
106 
109  template <typename MatrixDerived>
111  BaseType(matrix) {}
112 
114  Size(T width, T height) :
115  BaseType(width, height) {}
116 
118  explicit Size(const cv::Size_<T> size) :
119  BaseType(size.width, size.height) {}
120 
122 
123 public:
126 
128  T width() const {
129  return this->x();
130  }
131 
133  T height() const {
134  return this->y();
135  }
136 
138  T& width() {
139  return this->x();
140  }
141 
143  T& height() {
144  return this->y();
145  }
146 
147  template<typename Reflector>
148  void reflect(Reflector& reflector)
149  {
150  reflector.property("Width", this->x(), "The width");
151  reflector.property("Height", this->y(), "The height");
152  }
153 
155 
156 public:
159 
161  operator PointType() const
162  {
163  return PointType(this->x(), this->y());
164  }
165 
167  operator cv::Size_<T>() const
168  {
169  return cv::Size_<T>(this->x(), this->y());
170  }
171 
173  Size& operator=(const cv::Size_<T>& other)
174  {
175  (*this)[0] = other.width;
176  (*this)[1] = other.height;
177  return *this;
178  }
179 
181 };
182 
184 
190 template<typename T>
191 class Size<T,3> : public Eigen::Matrix<T,3,1>
192 {
193 public:
196 
197 public:
200 
202  Size() {}
203 
206  template <typename MatrixDerived>
208  BaseType(matrix) {}
209 
211  Size(T width, T height, T depth) :
212  BaseType(width, height, depth) {}
213 
215 
216 public:
219 
221  T width() const {
222  return this->x();
223  }
224 
226  T height() const {
227  return this->y();
228  }
229 
231  T depth() const {
232  return this->z();
233  }
234 
236  T& width() {
237  return this->x();
238  }
239 
241  T& height() {
242  return this->y();
243  }
244 
246  T& depth() {
247  return this->z();
248  }
249 
251  template<typename Reflector>
252  void reflect(Reflector& reflector)
253  {
254  reflector.property("Width", this->x(), "The width");
255  reflector.property("Height", this->y(), "The height");
256  reflector.property("Depth", this->z(), "The depth");
257  }
258 
260 
261 public:
264 
266  operator PointType() const
267  {
268  return PointType(this->x(), this->y(), this->z());
269  }
270 
272 };
273 
275 
278 
281 
284 
287 
290 
293 
295 
296 template <>
297 class IsCheapToCopy<Size2i> : public std::true_type {};
298 
299 template <>
300 class IsCheapToCopy<Size2f> : public std::true_type {};
301 
302 template <>
303 class IsCheapToCopy<Size2d> : public std::true_type {};
304 
305 template <>
306 class IsCheapToCopy<Size3i> : public std::true_type {};
307 
308 template <>
309 class IsCheapToCopy<Size3f> : public std::true_type {};
310 
311 template <>
312 class IsCheapToCopy<Size3d> : public std::true_type {};
313 
315 
316 }
317 
318 #endif
void reflect(Reflector &reflector)
Definition: Size.h:148
T height() const
return the height
Definition: Size.h:133
Size(T width, T height)
a constructor with width and height for the 2D case
Definition: Size.h:114
General point class template.
Definition: Point.h:135
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
Size & operator=(const cv::Size_< T > &other)
converts from cv size
Definition: Size.h:173
Point< T, 3 > PointType
Definition: Size.h:195
Size< int, 2 > Size2i
The size type for 2D objects in integer precision.
Definition: Size.h:277
Class for 2D, 3D and N-dimensional points.
Size(const cv::Size_< T > size)
a copy constructor
Definition: Size.h:118
Size< double, 2 > Size2d
The size type for 2D objects in 64 bit floating point precision.
Definition: Size.h:283
Eigen::Matrix< T, 3, 1 > BaseType
Definition: Size.h:194
Specialization of Point for 2 dimensions with specialized constructors and converters.
Definition: Point.h:169
Specialization of Point for 3 dimensions with specialized constructors and converters.
Definition: Point.h:252
T & width()
return the width
Definition: Size.h:138
Size(T width, T height, T depth)
a constructor to initialize the size with width, height, and depth in the 3D case ...
Definition: Size.h:211
Size< float, 3 > Size3f
The size type for 3D objects in floating point precision.
Definition: Size.h:289
T & depth()
return the depth
Definition: Size.h:246
Size< int, 3 > Size3i
The size type for 3D objects in integer precision.
Definition: Size.h:286
T depth() const
return the depth
Definition: Size.h:231
By default, IsCheapToCopy<T>::value evaluates to true for fundamental types T, false for all other ty...
Definition: IsCheapToCopy.h:63
Eigen::Matrix< T, 2, 1 > BaseType
Definition: Size.h:97
Size()
the default constructor
Definition: Size.h:77
Size()
the default constructor
Definition: Size.h:202
Type trait to define if a class is cheap to copy.
Size(const Eigen::MatrixBase< MatrixDerived > &matrix)
a constructor to initialize width and height with a Eigen-matrix of correct dimension ...
Definition: Size.h:110
T & width()
return the width
Definition: Size.h:236
Point< T, 2 > PointType
Definition: Size.h:98
T & height()
return the height
Definition: Size.h:143
Size()
the default constructor
Definition: Size.h:105
Size(const Eigen::MatrixBase< MatrixDerived > &matrix)
a constructor to initialize width and height with a Eigen-matrix of correct dimension ...
Definition: Size.h:207
T & height()
return the height
Definition: Size.h:241
void reflect(Reflector &reflector)
the serialization definition
Definition: Size.h:252
Size(const Eigen::MatrixBase< MatrixDerived > &matrix)
a constructor to initialize width and height with a Eigen-matrix of correct dimension ...
Definition: Size.h:82
Size< double, 3 > Size3d
The size type for 3D objects in 64 bit floating point precision.
Definition: Size.h:292
T width() const
return the width
Definition: Size.h:221
Size class for defining sizes with different data types.
Definition: Size.h:69
Point< T, D > PointType
Definition: Size.h:73
Eigen::Matrix< T, D, 1 > BaseType
Definition: Size.h:72
Size< float, 2 > Size2f
The size type for 2D objects in floating point precision.
Definition: Size.h:280
T height() const
return the height
Definition: Size.h:226
T width() const
return the width
Definition: Size.h:128