ViSP  2.8.0
vpRect.h
1 /****************************************************************************
2  *
3  * $Id: vpRect.h 4056 2013-01-05 13:04:42Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 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 <visp/vpImagePoint.h>
81 
82 class VISP_EXPORT vpRect
83 {
84 public:
85 
86  vpRect();
87  vpRect(double left, double top, double width, double height);
88  vpRect(const vpImagePoint &topLeft, double width, double height);
89  vpRect(const vpImagePoint &topLeft, const vpImagePoint &bottomRight);
90  vpRect(const vpRect& r);
91 
92  vpRect &operator=(const vpRect& r);
93 
98  inline double getBottom() const { return (this->top + this->height - 1.0); };
103  inline vpImagePoint getBottomRight() const {
104  vpImagePoint bottomRight;
105  bottomRight.set_u( getRight() );
106  bottomRight.set_v( getBottom() );
107 
108  return bottomRight;
109  };
121  inline void getCenter(double & x, double & y) const {
122  x = this->left + this->width / 2.0 - 0.5;
123  y = this->top + this->height / 2.0 - 0.5;
124  };
136  inline vpImagePoint getCenter() const {
137  vpImagePoint center;
138  center.set_u( this->left + this->width / 2.0 - 0.5 );
139  center.set_v( this->top + this->height / 2.0 - 0.5 );
140  return center;
141  };
150  inline double getHeight() const { return this->height; };
156  inline double getLeft() const { return this->left; };
157 
162  inline double getRight() const { return (this->left + this->width - 1.0); };
163 
169  inline double getTop() const { return this->top; };
175  inline vpImagePoint getTopLeft() const {
176  vpImagePoint topLeft;
177  topLeft.set_u( this->left );
178  topLeft.set_v( this->top );
179  return topLeft;
180  };
188  inline double getWidth() const { return this->width; };
189 
198  inline void setBottom(double pos) { this->height = pos - this->top + 1.0; };
206  inline void setBottomRight(const vpImagePoint &bottomRight) {
207  this->height = bottomRight.get_v() - this->top + 1.0;
208  this->width = bottomRight.get_u() - this->left + 1.0;
209  };
217  inline void setHeight(double h) { this->height = h; };
227  inline void setLeft(double pos) { this->left = pos; };
234  inline void setRect(double left, double top, double width, double height) {
235  this->left = left;
236  this->top = top;
237  this->width = width;
238  this->height = height;
239  };
249  inline void setRight(double pos) { this->width = pos - this->left + 1.0; };
258  inline void setTop(double pos) { this->top = pos; };
267  inline void setTopLeft(const vpImagePoint &topLeft) {
268  this->left = topLeft.get_u();
269  this->top = topLeft.get_v();
270  };
278  inline void setWidth(double w) { this->width = w; }
279 
288  inline void moveCenter(double x, double y) {
289  this->left = x - this->width/2 + 0.5;
290  this->top = y - this->height/2 + 0.5;
291  };
292 
293 private:
294  double left; // Upper left corner position along the columns axis
295  double top; // Upper left corner position along the rows axis
296  double width; // Rectangle width
297  double height; // Rectangle height
298 };
299 
300 
311 VISP_EXPORT inline bool inRectangle( const vpImagePoint &ip, const vpRect &rect ) {
312  return ( ip.get_i() <= rect.getBottom() && ip.get_i() >= rect.getTop() && ip.get_j() <= rect.getRight() && ip.get_j() >= rect.getLeft());
313 }
314 
315 
316 #endif
double getTop() const
Definition: vpRect.h:169
double get_v() const
Definition: vpImagePoint.h:250
double get_i() const
Definition: vpImagePoint.h:181
void getCenter(double &x, double &y) const
Definition: vpRect.h:121
void setLeft(double pos)
Definition: vpRect.h:227
double get_u() const
Definition: vpImagePoint.h:239
double getHeight() const
Definition: vpRect.h:150
double getRight() const
Definition: vpRect.h:162
double get_j() const
Definition: vpImagePoint.h:192
vpImagePoint getTopLeft() const
Definition: vpRect.h:175
double getBottom() const
Definition: vpRect.h:98
double getWidth() const
Definition: vpRect.h:188
void setTop(double pos)
Definition: vpRect.h:258
void setRect(double left, double top, double width, double height)
Definition: vpRect.h:234
void setHeight(double h)
Definition: vpRect.h:217
void set_u(const double u)
Definition: vpImagePoint.h:203
vpImagePoint getBottomRight() const
Definition: vpRect.h:103
void set_v(const double v)
Definition: vpImagePoint.h:214
void moveCenter(double x, double y)
Definition: vpRect.h:288
void setTopLeft(const vpImagePoint &topLeft)
Definition: vpRect.h:267
void setRight(double pos)
Definition: vpRect.h:249
Defines a rectangle in the plane.
Definition: vpRect.h:82
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:136
double getLeft() const
Definition: vpRect.h:156
void setBottomRight(const vpImagePoint &bottomRight)
Definition: vpRect.h:206
void setBottom(double pos)
Definition: vpRect.h:198
void setWidth(double w)
Definition: vpRect.h:278