Visual Servoing Platform  version 3.6.1 under development (2024-04-24)
vpRect Class Reference

#include <visp3/core/vpRect.h>

Public Member Functions

 vpRect ()
 
 vpRect (double left, double top, double width, double height)
 
 vpRect (const vpImagePoint &topLeft, double width, double height)
 
 vpRect (const vpImagePoint &topLeft, const vpImagePoint &bottomRight)
 
 vpRect (const vpRect &r)
 
 vpRect (const std::vector< vpImagePoint > &ip)
 
double getArea () const
 
double getBottom () const
 
vpImagePoint getBottomLeft () const
 
vpImagePoint getBottomRight () const
 
void getCenter (double &x, double &y) const
 
vpImagePoint getCenter () const
 
double getHeight () const
 
double getLeft () const
 
double getRight () const
 
double getSize () const
 
double getTop () const
 
vpImagePoint getTopLeft () const
 
vpImagePoint getTopRight () const
 
double getWidth () const
 
bool isInside (const vpImagePoint &ip) const
 
bool operator== (const vpRect &r) const
 
bool operator!= (const vpRect &r) const
 
vpRectoperator&= (const vpRect &r)
 
vpRectoperator= (const vpRect &r)
 
vpRect operator& (const vpRect &r) const
 
void set (double left, double top, double width, double height)
 
void set (const vpImagePoint &topLeft, double width, double height)
 
void set (const vpImagePoint &topLeft, const vpImagePoint &bottomRight)
 
void set (const vpRect &r)
 
void set (const std::vector< vpImagePoint > &ip)
 
void setBottom (double pos)
 
void setBottomRight (const vpImagePoint &bottomRight)
 
void setHeight (double h)
 
void setLeft (double pos)
 
void setRect (double l, double t, double w, double h)
 
void setRight (double pos)
 
void setTop (double pos)
 
void setTopLeft (const vpImagePoint &topLeft)
 
void setWidth (double w)
 
void moveCenter (double x, double y)
 
void moveCenter (const vpImagePoint &center)
 

Friends

VISP_EXPORT bool inRectangle (const vpImagePoint &ip, const vpRect &rect)
 
VISP_EXPORT std::ostream & operator<< (std::ostream &os, const vpRect &r)
 

Detailed Description

Defines a rectangle in the plane.

A rectangle is internally represented as an upper-left corner and a width and height, but it is normally expressed as an upper-left corner and bottom-right corner.

Note that the size (width and height) of a rectangle might be different from what you are used to. If the top-left corner and the bottom-right corner are the same, the height and the width of the rectangle will both be 1.

Generally, width = right - left + 1 and height = bottom - top + 1.

We designed it this way to make it correspond to rectangular spaces used by drawing functions in which the width and height denote a number of pixels. For example, drawing a rectangle with width and height 1 draws a single pixel.

The default coordinate system has origin (0, 0) in the top-left corner. The positive direction of the y axis is down, and the positive x axis is from left to right.

A vpRect can be constructed with a set of left, top, width and height double. After creation the dimensions can be changed, e.g. with setLeft(), setRight(), setTop() and setBottom(), or by setting sizes, e.g. setWidth(), setHeight()

Examples
servoAfma6MegaposePBVS.cpp, testCrop.cpp, testCropAdvanced.cpp, testDisplayRoi.cpp, testDisplays.cpp, testGenericTracker.cpp, testGenericTrackerDepth.cpp, testImageDraw.cpp, testImageNormalizedCorrelation.cpp, testImageTemplateMatching.cpp, testPolygon2.cpp, tutorial-apriltag-detector.cpp, tutorial-barcode-detector-live.cpp, tutorial-barcode-detector.cpp, tutorial-circle-hough.cpp, tutorial-face-detector-live-threaded.cpp, tutorial-face-detector-live.cpp, tutorial-face-detector.cpp, and tutorial-megapose-live-single-object-tracking.cpp.

Definition at line 75 of file vpRect.h.

Constructor & Destructor Documentation

◆ vpRect() [1/6]

vpRect::vpRect ( )

Constructs a default rectangle with the top, left corner set to (0,0) and width and height set to 1.

Definition at line 50 of file vpRect.cpp.

◆ vpRect() [2/6]

vpRect::vpRect ( double  l,
double  t,
double  w,
double  h 
)

Constructs a rectangle with the top, left corner and width and height.

Parameters
l: coordinate of the top/left corner along the horizontal axis.
t: coordinate of the top/left corner along the vertical axis.
w: rectangle width.
h: rectangle height.

Definition at line 61 of file vpRect.cpp.

◆ vpRect() [3/6]

vpRect::vpRect ( const vpImagePoint topLeft,
double  w,
double  h 
)

Constructs a rectangle with topLeft the top-left corner location and width and height the rectangle size.

Parameters
topLeft: coordinates of the top/left corner.
w: rectangle width.
h: rectangle height.

Definition at line 71 of file vpRect.cpp.

◆ vpRect() [4/6]

vpRect::vpRect ( const vpImagePoint topLeft,
const vpImagePoint bottomRight 
)

Constructs a rectangle with topLeft the top-left corner location and bottomRight the bottom-right corner.

Definition at line 79 of file vpRect.cpp.

References vpImagePoint::get_u(), vpImagePoint::get_v(), setBottom(), and setRight().

◆ vpRect() [5/6]

vpRect::vpRect ( const vpRect r)

Constructs a rectangle that is a copy of r.

Definition at line 92 of file vpRect.cpp.

◆ vpRect() [6/6]

vpRect::vpRect ( const std::vector< vpImagePoint > &  ip)
explicit

Create a rectangle as the bounding box of a vector of image points.

Parameters
ip: Vector of image points. At least 1 points is mandatory, otherwise an exception is thrown.

Definition at line 112 of file vpRect.cpp.

References set().

Member Function Documentation

◆ getArea()

double vpRect::getArea ( ) const
inline

Returns the area of the rectangle.

Definition at line 88 of file vpRect.h.

◆ getBottom()

◆ getBottomLeft()

vpImagePoint vpRect::getBottomLeft ( ) const
inline

Returns the bottom-left position of the rectangle.

See also
getTopLeft(), getTopRight(), getBottomRight(), getBottom(), getLeft()

Definition at line 101 of file vpRect.h.

References vpImagePoint::set_u(), and vpImagePoint::set_v().

◆ getBottomRight()

vpImagePoint vpRect::getBottomRight ( ) const
inline

Returns the bottom-right coordinate of the rectangle.

See also
getTopLeft(), getTopRight(), getBottomLeft(), getBottom(), getRight()

Definition at line 114 of file vpRect.h.

References vpImagePoint::set_u(), and vpImagePoint::set_v().

◆ getCenter() [1/2]

vpImagePoint vpRect::getCenter ( ) const
inline

Returns the center point of the rectangle. The center point coordinates are (x, y).

The default coordinate system has origin (0, 0) in the top-left corner. The positive direction of the y axis is down, and the positive x axis is from left to right.

See also
moveCenter()

Definition at line 149 of file vpRect.h.

References vpImagePoint::set_u(), and vpImagePoint::set_v().

◆ getCenter() [2/2]

void vpRect::getCenter ( double &  x,
double &  y 
) const
inline

Returns the center point of the rectangle. The center point coordinates are (x, y).

The default coordinate system has origin (0, 0) in the top-left corner. The positive direction of the y axis is down, and the positive x axis is from left to right.

See also
moveCenter()
Examples
tutorial-megapose-live-single-object-tracking.cpp.

Definition at line 133 of file vpRect.h.

Referenced by vpRectOriented::operator=(), and vpRectOriented::vpRectOriented().

◆ getHeight()

double vpRect::getHeight ( ) const
inline

◆ getLeft()

◆ getRight()

◆ getSize()

double vpRect::getSize ( ) const
inline

Returns the size of the rectangle.

See also
getWidth(), getHeight()

Definition at line 182 of file vpRect.h.

◆ getTop()

◆ getTopLeft()

vpImagePoint vpRect::getTopLeft ( ) const
inline

◆ getTopRight()

vpImagePoint vpRect::getTopRight ( ) const
inline

Returns the top-right position of the rectangle.

See also
getTopLeft(), getBottomRight(), getBottomLeft(), getTop(), getRight()

Definition at line 209 of file vpRect.h.

References vpImagePoint::set_u(), and vpImagePoint::set_v().

◆ getWidth()

◆ isInside()

bool vpRect::isInside ( const vpImagePoint ip) const

Returns true if the point belongs to the rectangle.

Check if an image point belongs to the rectangle.

Parameters
ip: the image point.
Returns
Returns true if the point belongs to the rectangle.

Definition at line 121 of file vpRect.cpp.

References vpImagePoint::get_i(), and vpImagePoint::get_j().

Referenced by vpImageCircle::computeAngularCoverageInRoI().

◆ moveCenter() [1/2]

void vpRect::moveCenter ( const vpImagePoint center)
inline

Center the rectangle to the image point given as parameter, leaving the size unchanged.

See also
getCenter()

Definition at line 399 of file vpRect.h.

References vpImagePoint::get_u(), and vpImagePoint::get_v().

◆ moveCenter() [2/2]

void vpRect::moveCenter ( double  x,
double  y 
)
inline

Sets the center point of the rectangle to (x, y), leaving the size unchanged.

See also
getCenter()

Definition at line 387 of file vpRect.h.

◆ operator!=()

bool vpRect::operator!= ( const vpRect r) const

Operator to compare two rectangles.

Returns
true if both objects differ, false otherwise.

Definition at line 238 of file vpRect.cpp.

◆ operator&()

vpRect vpRect::operator& ( const vpRect r) const
inline

Intersection operator.

Returns
Intersection rectangle or null rectangle if the two rectangles do not intersect.

Definition at line 263 of file vpRect.h.

◆ operator&=()

vpRect& vpRect::operator&= ( const vpRect r)
inline

Intersection operator.

Parameters
r: Rectangle with which the intersection should be calculated.
Returns
Intersected rectangle or null rectangle if the two rectangles do not intersect.

Definition at line 240 of file vpRect.h.

◆ operator=()

vpRect & vpRect::operator= ( const vpRect r)

Assign r to this rectangle and return a reference to this rectangle.

Definition at line 98 of file vpRect.cpp.

◆ operator==()

bool vpRect::operator== ( const vpRect r) const

Operator to compare two rectangles.

Returns
true if both objects are similar, false otherwise.

Definition at line 225 of file vpRect.cpp.

◆ set() [1/5]

void vpRect::set ( const std::vector< vpImagePoint > &  ip)

Set the rectangle as the bounding box of a vector of image points.

Parameters
ip: Vector of image points. At least 1 points is mandatory, otherwise an exception is thrown.

Definition at line 164 of file vpRect.cpp.

References vpException::dimensionError, setBottom(), setLeft(), setRight(), and setTop().

◆ set() [2/5]

void vpRect::set ( const vpImagePoint topLeft,
const vpImagePoint bottomRight 
)

Set the rectangle with topLeft the top-left corner location and bottomRight the bottom-right corner.

Parameters
topLeft: coordinates of the top-left corner.
bottomRight: coordinates of the bottom-right corner.

Definition at line 207 of file vpRect.cpp.

References vpImagePoint::get_u(), vpImagePoint::get_v(), setBottom(), and setRight().

◆ set() [3/5]

void vpRect::set ( const vpImagePoint topLeft,
double  w,
double  h 
)

Set the rectangle with topLeft the top-left corner location and width and height the rectangle size.

Parameters
topLeft: coordinates of the top-left corner.
w: rectangle width.
h: rectangle height.

Definition at line 151 of file vpRect.cpp.

References vpImagePoint::get_u(), and vpImagePoint::get_v().

◆ set() [4/5]

void vpRect::set ( const vpRect r)

Set the rectangle from r.

Definition at line 219 of file vpRect.cpp.

◆ set() [5/5]

void vpRect::set ( double  l,
double  t,
double  w,
double  h 
)

Set the rectangle with the top, left corner and width and height.

Parameters
l: coordinate of the top/left corner along the horizontal axis.
t: coordinate of the top/left corner along the vertical axis.
w: rectangle width.
h: rectangle height.

Definition at line 135 of file vpRect.cpp.

Referenced by vpRect().

◆ setBottom()

void vpRect::setBottom ( double  pos)
inline

Sets the bottom edge position of the rectangle to pos. May change the height of the rectangle, but will never change the top edge position the rectangle.

See also
setTop()

Definition at line 285 of file vpRect.h.

Referenced by vpMbtFaceDepthDense::computeDesiredFeatures(), vpMbtFaceDepthNormal::computeDesiredFeatures(), set(), and vpRect().

◆ setBottomRight()

void vpRect::setBottomRight ( const vpImagePoint bottomRight)
inline

Sets the bottom-right position of the rectangle. Will never change the top-left position the rectangle.

See also
setTopLeft()

Definition at line 293 of file vpRect.h.

References vpImagePoint::get_u(), and vpImagePoint::get_v().

Referenced by vpTemplateTrackerZone::getBoundingBox(), and vpPolygon::updateBoundingBox().

◆ setHeight()

void vpRect::setHeight ( double  h)
inline

Sets the height of the rectangle to h. The top edge is not moved, but the bottom edge may be moved.

See also
setWidth()
Examples
testCrop.cpp.

Definition at line 305 of file vpRect.h.

◆ setLeft()

void vpRect::setLeft ( double  pos)
inline

Sets the left edge position of the rectangle to pos. May change the right edge position of the rectangle, but will never change the width of the rectangle.

See also
setRight()
Examples
testCrop.cpp.

Definition at line 318 of file vpRect.h.

Referenced by vpMbtFaceDepthDense::computeDesiredFeatures(), vpMbtFaceDepthNormal::computeDesiredFeatures(), and set().

◆ setRect()

void vpRect::setRect ( double  l,
double  t,
double  w,
double  h 
)
inline

Sets the coordinates of the rectangle's top left corner to (left, top), and its size to (width, height).

Parameters
l: horizontal position of the rectangle upper/left corner position.
t: vertical position of the rectangle upper/left corner position.
w: rectangle width.
h: rectangle height.

Definition at line 330 of file vpRect.h.

Referenced by vpDot::getBBox(), and vpDot2::getBBox().

◆ setRight()

void vpRect::setRight ( double  pos)
inline

Sets the right edge position of the rectangle to pos. May change the width of the rectangle, but will never change the left edge position of the rectangle.

See also
setLeft()

Definition at line 345 of file vpRect.h.

Referenced by vpMbtFaceDepthDense::computeDesiredFeatures(), vpMbtFaceDepthNormal::computeDesiredFeatures(), set(), and vpRect().

◆ setTop()

void vpRect::setTop ( double  pos)
inline

Sets the top edge position of the rectangle to pos. May change the bottom edge position of the rectangle, but will never change the height of the rectangle.

See also
setBottom()
Examples
testCrop.cpp.

Definition at line 354 of file vpRect.h.

Referenced by vpMbtFaceDepthDense::computeDesiredFeatures(), vpMbtFaceDepthNormal::computeDesiredFeatures(), and set().

◆ setTopLeft()

void vpRect::setTopLeft ( const vpImagePoint topLeft)
inline

Sets the top-left position of the rectangle. May change the bottom edge position of the rectangle, but will never change the height of the rectangle.

See also
setBottomRight()

Definition at line 363 of file vpRect.h.

References vpImagePoint::get_u(), and vpImagePoint::get_v().

Referenced by vpTemplateTrackerZone::getBoundingBox(), and vpPolygon::updateBoundingBox().

◆ setWidth()

void vpRect::setWidth ( double  w)
inline

Sets the width of the rectangle to w. The right edge is changed, but not the left edge.

See also
setHeight()
Examples
testCrop.cpp.

Definition at line 375 of file vpRect.h.

Friends And Related Function Documentation

◆ inRectangle

VISP_EXPORT bool inRectangle ( const vpImagePoint ip,
const vpRect rect 
)
friend

Check if an image point belongs to a rectangle.

Parameters
ip: the image point.
rect: the rectangle.
Returns
Returns true if the point belongs to the rectangle.

Definition at line 261 of file vpRect.cpp.

◆ operator<<

VISP_EXPORT std::ostream& operator<< ( std::ostream &  os,
const vpRect r 
)
friend

Definition at line 267 of file vpRect.cpp.