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 namespace mira
55 {
56 
58 
66 template<typename T, int D>
67 class Size : public Eigen::Matrix<T,D,1>
68 {
69 public:
72 
73 public:
75  Size() {}
76 
79  template <typename MatrixDerived>
81  BaseType(matrix) {}
82 };
83 
85 
91 template<typename T>
92 class Size<T,2> : public Eigen::Matrix<T,2,1>
93 {
94 public:
97 
98 public:
101 
103  Size() {}
104 
107  template <typename MatrixDerived>
109  BaseType(matrix) {}
110 
112  Size(T width, T height) :
113  BaseType(width, height) {}
114 
116  explicit Size(const cv::Size_<T> size) :
117  BaseType(size.width, size.height) {}
118 
120 
121 public:
124 
126  T width() const {
127  return this->x();
128  }
129 
131  T height() const {
132  return this->y();
133  }
134 
136  T& width() {
137  return this->x();
138  }
139 
141  T& height() {
142  return this->y();
143  }
144 
145  template<typename Reflector>
146  void reflect(Reflector& reflector)
147  {
148  reflector.property("Width", this->x(), "The width");
149  reflector.property("Height", this->y(), "The height");
150  }
151 
153 
154 public:
157 
159  operator PointType() const
160  {
161  return PointType(this->x(), this->y());
162  }
163 
165  operator cv::Size_<T>() const
166  {
167  return cv::Size_<T>(this->x(), this->y());
168  }
169 
171  Size& operator=(const cv::Size_<T>& other)
172  {
173  (*this)[0] = other.width;
174  (*this)[1] = other.height;
175  return *this;
176  }
177 
179 };
180 
182 
188 template<typename T>
189 class Size<T,3> : public Eigen::Matrix<T,3,1>
190 {
191 public:
194 
195 public:
198 
200  Size() {}
201 
204  template <typename MatrixDerived>
206  BaseType(matrix) {}
207 
209  Size(T width, T height, T depth) :
210  BaseType(width, height, depth) {}
211 
213 
214 public:
217 
219  T width() const {
220  return this->x();
221  }
222 
224  T height() const {
225  return this->y();
226  }
227 
229  T depth() const {
230  return this->z();
231  }
232 
234  T& width() {
235  return this->x();
236  }
237 
239  T& height() {
240  return this->y();
241  }
242 
244  T& depth() {
245  return this->z();
246  }
247 
249  template<typename Reflector>
250  void reflect(Reflector& reflector)
251  {
252  reflector.property("Width", this->x(), "The width");
253  reflector.property("Height", this->y(), "The height");
254  reflector.property("Depth", this->z(), "The depth");
255  }
256 
258 
259 public:
262 
264  operator PointType() const
265  {
266  return PointType(this->x(), this->y(), this->z());
267  }
268 
270 };
271 
273 
276 
279 
282 
285 
288 
291 
293 
294 }
295 
296 #endif
void reflect(Reflector &reflector)
Definition: Size.h:146
T height() const
return the height
Definition: Size.h:131
Size(T width, T height)
a constructor with width and height for the 2D case
Definition: Size.h:112
General point class template.
Definition: Point.h:133
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:171
Point< T, 3 > PointType
Definition: Size.h:193
Size< int, 2 > Size2i
The size type for 2D objects in integer precision.
Definition: Size.h:275
Class for 2D, 3D and N-dimensional points.
Size(const cv::Size_< T > size)
a copy constructor
Definition: Size.h:116
Size< double, 2 > Size2d
The size type for 2D objects in 64 bit floating point precision.
Definition: Size.h:281
Eigen::Matrix< T, 3, 1 > BaseType
Definition: Size.h:192
Specialization of Point for 2 dimensions with specialized constructors and converters.
Definition: Point.h:167
Specialization of Point for 3 dimensions with specialized constructors and converters.
Definition: Point.h:239
T & width()
return the width
Definition: Size.h:136
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:209
Size< float, 3 > Size3f
The size type for 3D objects in floating point precision.
Definition: Size.h:287
T & depth()
return the depth
Definition: Size.h:244
Size< int, 3 > Size3i
The size type for 3D objects in integer precision.
Definition: Size.h:284
T depth() const
return the depth
Definition: Size.h:229
Eigen::Matrix< T, 2, 1 > BaseType
Definition: Size.h:95
Size()
the default constructor
Definition: Size.h:75
Size()
the default constructor
Definition: Size.h:200
Size(const Eigen::MatrixBase< MatrixDerived > &matrix)
a constructor to initialize width and height with a Eigen-matrix of correct dimension ...
Definition: Size.h:108
T & width()
return the width
Definition: Size.h:234
Point< T, 2 > PointType
Definition: Size.h:96
T & height()
return the height
Definition: Size.h:141
Size()
the default constructor
Definition: Size.h:103
Size(const Eigen::MatrixBase< MatrixDerived > &matrix)
a constructor to initialize width and height with a Eigen-matrix of correct dimension ...
Definition: Size.h:205
T & height()
return the height
Definition: Size.h:239
void reflect(Reflector &reflector)
the serialization definition
Definition: Size.h:250
Size(const Eigen::MatrixBase< MatrixDerived > &matrix)
a constructor to initialize width and height with a Eigen-matrix of correct dimension ...
Definition: Size.h:80
Size< double, 3 > Size3d
The size type for 3D objects in 64 bit floating point precision.
Definition: Size.h:290
T width() const
return the width
Definition: Size.h:219
Size class for defining sizes with different data types.
Definition: Size.h:67
Point< T, D > PointType
Definition: Size.h:71
Eigen::Matrix< T, D, 1 > BaseType
Definition: Size.h:70
Size< float, 2 > Size2f
The size type for 2D objects in floating point precision.
Definition: Size.h:278
T height() const
return the height
Definition: Size.h:224
T width() const
return the width
Definition: Size.h:126