ViSP  2.10.0
vpRect.h
1 /****************************************************************************
2  *
3  * $Id: vpRect.h 5009 2014-11-25 18:00:13Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Defines a rectangle in the plane.
36  *
37  * Author:
38  * Fabien Spindler
39  *
40  *****************************************************************************/
41 
42 
43 #ifndef vpRect_h
44 #define vpRect_h
45 
46 
47 
48 
80 #include <vector>
81 #include <visp/vpException.h>
82 #include <visp/vpImagePoint.h>
83 
84 
85 class VISP_EXPORT vpRect
86 {
87 public:
88 
89  vpRect();
90  vpRect(double left, double top, double width, double height);
91  vpRect(const vpImagePoint &topLeft, double width, double height);
92  vpRect(const vpImagePoint &topLeft, const vpImagePoint &bottomRight);
93  vpRect(const vpRect& r);
94  vpRect(const std::vector<vpImagePoint> &ip);
95 
96 
97  vpRect &operator=(const vpRect& r);
98 
103  inline double getBottom() const { return (this->top + this->height - 1.0); };
108  inline vpImagePoint getBottomRight() const {
109  vpImagePoint bottomRight;
110  bottomRight.set_u( getRight() );
111  bottomRight.set_v( getBottom() );
112 
113  return bottomRight;
114  };
126  inline void getCenter(double & x, double & y) const {
127  x = this->left + this->width / 2.0 - 0.5;
128  y = this->top + this->height / 2.0 - 0.5;
129  };
141  inline vpImagePoint getCenter() const {
142  vpImagePoint center;
143  center.set_u( this->left + this->width / 2.0 - 0.5 );
144  center.set_v( this->top + this->height / 2.0 - 0.5 );
145  return center;
146  };
155  inline double getHeight() const { return this->height; };
161  inline double getLeft() const { return this->left; };
162 
167  inline double getRight() const { return (this->left + this->width - 1.0); };
168 
173  inline double getSize() const { return (this->width * this->height); };
174 
180  inline double getTop() const { return this->top; };
186  inline vpImagePoint getTopLeft() const {
187  vpImagePoint topLeft;
188  topLeft.set_u( this->left );
189  topLeft.set_v( this->top );
190  return topLeft;
191  };
199  inline double getWidth() const { return this->width; };
200 
201  friend VISP_EXPORT bool inRectangle( const vpImagePoint &ip, const vpRect &rect );
202  friend VISP_EXPORT std::ostream& operator<< (std::ostream &os, const vpRect& r);
203  void set(double left, double top, double width, double height);
204  void set(const vpImagePoint &topLeft, double width, double height);
205  void set(const vpImagePoint &topLeft, const vpImagePoint &bottomRight);
206  void set(const vpRect& r);
207  void set(const std::vector<vpImagePoint> &ip);
208 
217  inline void setBottom(double pos) { this->height = pos - this->top + 1.0; };
225  inline void setBottomRight(const vpImagePoint &bottomRight) {
226  this->height = bottomRight.get_v() - this->top + 1.0;
227  this->width = bottomRight.get_u() - this->left + 1.0;
228  };
236  inline void setHeight(double h) { this->height = h; };
246  inline void setLeft(double pos) { this->left = pos; };
256  inline void setRect(double l, double t, double w, double h) {
257  this->left = l;
258  this->top = t;
259  this->width = w;
260  this->height = h;
261  };
271  inline void setRight(double pos) { this->width = pos - this->left + 1.0; };
280  inline void setTop(double pos) { this->top = pos; };
289  inline void setTopLeft(const vpImagePoint &topLeft) {
290  this->left = topLeft.get_u();
291  this->top = topLeft.get_v();
292  };
300  inline void setWidth(double w) { this->width = w; }
301 
310  inline void moveCenter(double x, double y) {
311  this->left = x - this->width/2 + 0.5;
312  this->top = y - this->height/2 + 0.5;
313  };
314 
323  inline void moveCenter(const vpImagePoint &center) {
324  this->left = center.get_u() - this->width/2 + 0.5;
325  this->top = center.get_v() - this->height/2 + 0.5;
326  };
327 
328 private:
329  double left; // Upper left corner position along the columns axis
330  double top; // Upper left corner position along the rows axis
331  double width; // Rectangle width
332  double height; // Rectangle height
333 };
334 
335 #endif
double getTop() const
Definition: vpRect.h:180
double get_v() const
Definition: vpImagePoint.h:264
void getCenter(double &x, double &y) const
Definition: vpRect.h:126
double getSize() const
Definition: vpRect.h:173
void setLeft(double pos)
Definition: vpRect.h:246
double get_u() const
Definition: vpImagePoint.h:253
double getHeight() const
Definition: vpRect.h:155
double getRight() const
Definition: vpRect.h:167
vpImagePoint getTopLeft() const
Definition: vpRect.h:186
double getBottom() const
Definition: vpRect.h:103
double getWidth() const
Definition: vpRect.h:199
void setTop(double pos)
Definition: vpRect.h:280
void setHeight(double h)
Definition: vpRect.h:236
void set_u(const double u)
Definition: vpImagePoint.h:217
vpImagePoint getBottomRight() const
Definition: vpRect.h:108
void moveCenter(const vpImagePoint &center)
Definition: vpRect.h:323
void set_v(const double v)
Definition: vpImagePoint.h:228
void moveCenter(double x, double y)
Definition: vpRect.h:310
void setTopLeft(const vpImagePoint &topLeft)
Definition: vpRect.h:289
void setRight(double pos)
Definition: vpRect.h:271
Defines a rectangle in the plane.
Definition: vpRect.h:85
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:93
vpImagePoint getCenter() const
Definition: vpRect.h:141
void setRect(double l, double t, double w, double h)
Definition: vpRect.h:256
double getLeft() const
Definition: vpRect.h:161
void setBottomRight(const vpImagePoint &bottomRight)
Definition: vpRect.h:225
void setBottom(double pos)
Definition: vpRect.h:217
void setWidth(double w)
Definition: vpRect.h:300