latest version v1.9 - last update 10 Apr 2010 |
Rectangle representation class. More...
#include <ltiRectangle.h>
Public Member Functions | |
trectangle () | |
trectangle (const tpoint< T > &p1, const tpoint< T > &p2) | |
trectangle (const T &x1, const T &y1, const T &x2, const T &y2) | |
trectangle (const T &size) | |
trectangle (const trectangle< T > &other) | |
Location and Dimensions | |
void | resize (const tpoint< T > &dim) |
void | resize (const T &x, const T &y) |
tpoint< T > | getDimensions () const |
T | getArea () const |
tpoint< T > | getCenter () const |
void | setCenter (tpoint< T > center) |
void | ensureConsistency () |
bool | isConsistent () const |
void | shift (const tpoint< T > &delta) |
Simple operations | |
bool | isInside (const tpoint< T > &p) const |
bool | isInside (const T &x, const T &y) const |
Duplication | |
trectangle< T > & | copy (const trectangle< T > &other) |
template<class U , class SU > | |
trectangle< T > & | castFrom (const trectangle< U, SU > &other) |
trectangle< T > & | operator= (const trectangle< T > &other) |
Comparison | |
bool | operator== (const trectangle< T > &other) const |
bool | operator!= (const trectangle< T > &other) const |
Geometrical combination | |
trectangle< T > & | intersectRect (const trectangle< T > &tRect) |
trectangle< T > & | intersect (const trectangle< T > &tRect) |
bool | overlaps (const trectangle< T > &tRect) const |
bool | isClose (const trectangle< T > &tRect, const tpoint< T > &dist) const |
trectangle< T > & | operator&= (const trectangle< T > &tRect) |
trectangle< T > | operator& (const trectangle< T > &tRect) |
trectangle< T > & | unionRect (const trectangle< T > &tRect) |
trectangle< T > & | join (const trectangle< T > &tRect) |
trectangle< T > & | operator|= (const trectangle< T > &tRect) |
trectangle< T > | operator| (const trectangle< T > &tRect) |
Public Attributes | |
tpoint< T > | ul |
tpoint< T > | br |
Rectangle representation class.
A rectangle is described by a pair of points: the upper-left and bottom-right corners.
A consistent rectangle will have the x and y coordinates of its upper- left corner smaller than the ones of its bottom-right corner (note the use of a left coordinate system, as usual with imaging systems).
You can always check if a rectangle is consistent with the method isConsistent()
or even force its consistency with ensureConsistency()
.
This is a template class, where the first template parameter T
denotes the type used for the two points, which will be of type tpoint<T>
. For example, the type trectangle<int> (which has the alias rectangle) contains to points (tpoint<int>) as corner representation. The second template parameter is optional and allows the trectangle to behave correctly in a discrete integer grid or in a continuous real grid (please see the lti::rectSide policy for more information).
lti::trectangle< T, S >::trectangle | ( | ) | [inline] |
default constructor The two points ul and br will be initialized with (0,0)
lti::trectangle< T, S >::trectangle | ( | const tpoint< T > & | p1, | |
const tpoint< T > & | p2 | |||
) | [inline] |
constructor
lti::trectangle< T, S >::trectangle | ( | const T & | x1, | |
const T & | y1, | |||
const T & | x2, | |||
const T & | y2 | |||
) | [inline] |
constructor
lti::trectangle< T, S >::trectangle | ( | const T & | size | ) | [inline] |
construct a square with the given side size.
If the size is even and T is an integer type, the rectangle will be created from -|_size/2_| to size + |_size/2_| in both coordinates x and y.
lti::trectangle< T, S >::trectangle | ( | const trectangle< T > & | other | ) | [inline] |
copy constructor
trectangle<T>& lti::trectangle< T, S >::castFrom | ( | const trectangle< U, SU > & | other | ) | [inline] |
cast from a rectangle of another type
trectangle<T>& lti::trectangle< T, S >::copy | ( | const trectangle< T > & | other | ) | [inline] |
copy member
Referenced by lti::trectangle< T >::operator=(), and lti::tpointList< int >::setBoundary().
void lti::trectangle< T, S >::ensureConsistency | ( | ) | [inline] |
Ensure consistency of upper-left and bottom-right corners.
A trectangle<T> is called "consistent" if the upper-left tpoint<T> has lower coordinate-values than the bottom-right tpoint<T>.
T lti::trectangle< T, S >::getArea | ( | ) | const [inline] |
Get the area of this rectangle.
This value is always positive, regardless of the position of the upper left and bottom right corner. A rectangle whose corners coincide has an area of 1 for fixed point types or 0 for floating point ones.
For integer types it will be assumed that the rectangle lies on a discrete grid with grid elements of size 1x1, and that is not the rectangle itself what is described but the index of grid elements. This means that the size of a side defined by two scalar values x1 and x2 (x2>x1) is x2-x1+1. This is useful for example when dealing with rectangular regions of images.
For floating point values the size is just x2-x1, because of the assumtion that the rectangle lies on a real valued 2D space.
tpoint<T> lti::trectangle< T, S >::getCenter | ( | ) | const [inline] |
Get center of trectangle<T>.
Referenced by lti::trectangle< T >::resize().
tpoint<T> lti::trectangle< T, S >::getDimensions | ( | ) | const [inline] |
Get dimensions of trectangle<T>.
If one coordinate of the two points coincide and the rectangle contains fixed point typed points, the returned dimension is one. For floating point types this case will return 0.
For integer types it will be assumed that the rectangle lies on a discrete grid with grid elements of size 1x1, and that is not the rectangle itself what is described but the number of grid elements. This means that the size of a side defined by two scalar values x1 and x2 (x2>x1) is x2-x1+1. This is useful for example when dealing with rectangular regions of images.
For floating point values the size is just x2-x1, because of the assumtion that the rectangle lies on a real valued 2D space.
trectangle<T>& lti::trectangle< T, S >::intersect | ( | const trectangle< T > & | tRect | ) | [inline] |
Intersection of this trectangle with tRect.
(the largest rectangle which is contained both inside this rectangle and inside tRect).
The result will be left in this instance. If the rectangles do not intersect, the resul will be inconsistent, so you should call isConsistent() to check for this case unless you know for sure that it cannot occur.
Referenced by lti::trectangle< T >::intersectRect(), lti::trectangle< T >::operator&(), lti::trectangle< T >::operator&=(), and lti::trectangle< T >::overlaps().
trectangle<T>& lti::trectangle< T, S >::intersectRect | ( | const trectangle< T > & | tRect | ) | [inline] |
Intersection of this trectangle with tRect.
bool lti::trectangle< T, S >::isClose | ( | const trectangle< T > & | tRect, | |
const tpoint< T > & | dist | |||
) | const [inline] |
Check whether this rectangle is close to the given rectangle, i.e.
if the two rectangles overlap if one is extended by the given distance.
bool lti::trectangle< T, S >::isConsistent | ( | ) | const [inline] |
Check for consistent trectangle<T>.
Referenced by lti::trectangle< T >::overlaps().
bool lti::trectangle< T, S >::isInside | ( | const T & | x, | |
const T & | y | |||
) | const [inline] |
Check if the given coordinates are inside the trectangle<T>.
(border included!)
bool lti::trectangle< T, S >::isInside | ( | const tpoint< T > & | p | ) | const [inline] |
Check if tpoint<T> p is inside the trectangle<T>.
(border included!)
trectangle<T>& lti::trectangle< T, S >::join | ( | const trectangle< T > & | tRect | ) | [inline] |
Union of this trectangle with tRect (the smallest rectangle containing both this trectangle and tRect) The result will be left in this instance.
Referenced by lti::trectangle< T >::operator|(), lti::trectangle< T >::operator|=(), and lti::trectangle< T >::unionRect().
bool lti::trectangle< T, S >::operator!= | ( | const trectangle< T > & | other | ) | const [inline] |
test for inequality
trectangle<T> lti::trectangle< T, S >::operator& | ( | const trectangle< T > & | tRect | ) | [inline] |
new trectangle = intersection of trectangle with tRect
trectangle<T>& lti::trectangle< T, S >::operator&= | ( | const trectangle< T > & | tRect | ) | [inline] |
trectangle = intersection of trectangle with tRect.
(alias for intersect)
trectangle<T>& lti::trectangle< T, S >::operator= | ( | const trectangle< T > & | other | ) | [inline] |
alias for copy
bool lti::trectangle< T, S >::operator== | ( | const trectangle< T > & | other | ) | const [inline] |
test for equality
trectangle<T> lti::trectangle< T, S >::operator| | ( | const trectangle< T > & | tRect | ) | [inline] |
new trectangle = union of this trectangle with tRect
trectangle<T>& lti::trectangle< T, S >::operator|= | ( | const trectangle< T > & | tRect | ) | [inline] |
trectangle = union of this trectangle with tRect (alias for join)
bool lti::trectangle< T, S >::overlaps | ( | const trectangle< T > & | tRect | ) | const [inline] |
Check whether this rectangle overlaps with the given rectangle.
void lti::trectangle< T, S >::resize | ( | const T & | x, | |
const T & | y | |||
) | [inline] |
resize trectangle<T> with new dimensions, but keep its center
void lti::trectangle< T, S >::resize | ( | const tpoint< T > & | dim | ) | [inline] |
resize trectangle<T> with new dimensions, but keep its center
void lti::trectangle< T, S >::setCenter | ( | tpoint< T > | center | ) | [inline] |
Set the center of this rectangle.
void lti::trectangle< T, S >::shift | ( | const tpoint< T > & | delta | ) | [inline] |
Shift trectangle<T> by delta.
trectangle<T>& lti::trectangle< T, S >::unionRect | ( | const trectangle< T > & | tRect | ) | [inline] |
Union of this trectangle with tRect.
tpoint<T> lti::trectangle< T, S >::br |
bottom-right tpoint<T>
Referenced by lti::epsDraw< T >::box(), lti::drawBase< rgbPixel >::box(), lti::draw< rgbPixel >::box(), lti::trectangle< T >::castFrom(), lti::trectangle< T >::copy(), lti::trectangle< T >::ensureConsistency(), lti::trectangle< T >::getArea(), lti::trectangle< T >::getCenter(), lti::trectangle< T >::getDimensions(), lti::squareConvolution< T, A >::parameters::initSquare(), lti::maximumFilter< T >::parameters::initSquare(), lti::trectangle< T >::intersect(), lti::trectangle< T >::isClose(), lti::trectangle< T >::isConsistent(), lti::trectangle< T >::isInside(), lti::trectangle< T >::join(), lti::trectangle< T >::operator!=(), lti::trectangle< T >::operator==(), lti::read(), lti::epsDraw< T >::rectangle(), lti::drawBase< rgbPixel >::rectangle(), lti::draw< rgbPixel >::rectangle(), lti::trectangle< T >::resize(), lti::trectangle< T >::setCenter(), lti::trectangle< T >::shift(), lti::trectangle< T >::trectangle(), and lti::write().
tpoint<T> lti::trectangle< T, S >::ul |
upper-left tpoint<T>
Referenced by lti::epsDraw< T >::box(), lti::drawBase< rgbPixel >::box(), lti::draw< rgbPixel >::box(), lti::trectangle< T >::castFrom(), lti::trectangle< T >::copy(), lti::trectangle< T >::ensureConsistency(), lti::trectangle< T >::getArea(), lti::trectangle< T >::getCenter(), lti::trectangle< T >::getDimensions(), lti::squareConvolution< T, A >::parameters::initSquare(), lti::maximumFilter< T >::parameters::initSquare(), lti::trectangle< T >::intersect(), lti::trectangle< T >::isClose(), lti::trectangle< T >::isConsistent(), lti::trectangle< T >::isInside(), lti::trectangle< T >::join(), lti::trectangle< T >::operator!=(), lti::trectangle< T >::operator==(), lti::read(), lti::epsDraw< T >::rectangle(), lti::drawBase< rgbPixel >::rectangle(), lti::draw< rgbPixel >::rectangle(), lti::trectangle< T >::resize(), lti::trectangle< T >::setCenter(), lti::trectangle< T >::shift(), lti::trectangle< T >::trectangle(), and lti::write().