ViSP  2.9.0
vpRect.h
1 /****************************************************************************
2  *
3  * $Id: vpRect.h 4649 2014-02-07 14:57:11Z 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 
174  inline double getTop() const { return this->top; };
180  inline vpImagePoint getTopLeft() const {
181  vpImagePoint topLeft;
182  topLeft.set_u( this->left );
183  topLeft.set_v( this->top );
184  return topLeft;
185  };
193  inline double getWidth() const { return this->width; };
194 
195  friend VISP_EXPORT bool inRectangle( const vpImagePoint &ip, const vpRect &rect );
196  friend VISP_EXPORT std::ostream& operator<< (std::ostream &os, const vpRect& r);
197  void set(const std::vector<vpImagePoint> &ip);
198 
207  inline void setBottom(double pos) { this->height = pos - this->top + 1.0; };
215  inline void setBottomRight(const vpImagePoint &bottomRight) {
216  this->height = bottomRight.get_v() - this->top + 1.0;
217  this->width = bottomRight.get_u() - this->left + 1.0;
218  };
226  inline void setHeight(double h) { this->height = h; };
236  inline void setLeft(double pos) { this->left = pos; };
246  inline void setRect(double l, double t, double w, double h) {
247  this->left = l;
248  this->top = t;
249  this->width = w;
250  this->height = h;
251  };
261  inline void setRight(double pos) { this->width = pos - this->left + 1.0; };
270  inline void setTop(double pos) { this->top = pos; };
279  inline void setTopLeft(const vpImagePoint &topLeft) {
280  this->left = topLeft.get_u();
281  this->top = topLeft.get_v();
282  };
290  inline void setWidth(double w) { this->width = w; }
291 
300  inline void moveCenter(double x, double y) {
301  this->left = x - this->width/2 + 0.5;
302  this->top = y - this->height/2 + 0.5;
303  };
304 
305 private:
306  double left; // Upper left corner position along the columns axis
307  double top; // Upper left corner position along the rows axis
308  double width; // Rectangle width
309  double height; // Rectangle height
310 };
311 
312 #endif
double getTop() const
Definition: vpRect.h:174
double get_v() const
Definition: vpImagePoint.h:263
void getCenter(double &x, double &y) const
Definition: vpRect.h:126
void setLeft(double pos)
Definition: vpRect.h:236
double get_u() const
Definition: vpImagePoint.h:252
double getHeight() const
Definition: vpRect.h:155
double getRight() const
Definition: vpRect.h:167
vpImagePoint getTopLeft() const
Definition: vpRect.h:180
double getBottom() const
Definition: vpRect.h:103
double getWidth() const
Definition: vpRect.h:193
void setTop(double pos)
Definition: vpRect.h:270
void setHeight(double h)
Definition: vpRect.h:226
void set_u(const double u)
Definition: vpImagePoint.h:216
vpImagePoint getBottomRight() const
Definition: vpRect.h:108
void set_v(const double v)
Definition: vpImagePoint.h:227
void moveCenter(double x, double y)
Definition: vpRect.h:300
void setTopLeft(const vpImagePoint &topLeft)
Definition: vpRect.h:279
void setRight(double pos)
Definition: vpRect.h:261
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:92
vpImagePoint getCenter() const
Definition: vpRect.h:141
void setRect(double l, double t, double w, double h)
Definition: vpRect.h:246
double getLeft() const
Definition: vpRect.h:161
void setBottomRight(const vpImagePoint &bottomRight)
Definition: vpRect.h:215
void setBottom(double pos)
Definition: vpRect.h:207
void setWidth(double w)
Definition: vpRect.h:290