LTI-Lib latest version v1.9 - last update 10 Apr 2010

lti::trectangle< T, S > Class Template Reference
[Geometry Data Structures]

Rectangle representation class. More...

#include <ltiRectangle.h>

Inheritance diagram for lti::trectangle< T, S >:
Inheritance graph
[legend]

List of all members.

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
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

Detailed Description

template<class T, class S = rectSide<T>>
class lti::trectangle< T, S >

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).


Constructor & Destructor Documentation

template<class T, class S = rectSide<T>>
lti::trectangle< T, S >::trectangle (  )  [inline]

default constructor The two points ul and br will be initialized with (0,0)

template<class T, class S = rectSide<T>>
lti::trectangle< T, S >::trectangle ( const tpoint< T > &  p1,
const tpoint< T > &  p2 
) [inline]

constructor

template<class T, class S = rectSide<T>>
lti::trectangle< T, S >::trectangle ( const T &  x1,
const T &  y1,
const T &  x2,
const T &  y2 
) [inline]

constructor

template<class T, class S = rectSide<T>>
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.

template<class T, class S = rectSide<T>>
lti::trectangle< T, S >::trectangle ( const trectangle< T > &  other  )  [inline]

copy constructor


Member Function Documentation

template<class T, class S = rectSide<T>>
template<class U , class SU >
trectangle<T>& lti::trectangle< T, S >::castFrom ( const trectangle< U, SU > &  other  )  [inline]

cast from a rectangle of another type

template<class T, class S = rectSide<T>>
trectangle<T>& lti::trectangle< T, S >::copy ( const trectangle< T > &  other  )  [inline]
template<class T, class S = rectSide<T>>
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>.

template<class T, class S = rectSide<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.

Warning:
Note that the result of this method depends on the type T

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.

template<class T, class S = rectSide<T>>
tpoint<T> lti::trectangle< T, S >::getCenter (  )  const [inline]

Get center of trectangle<T>.

Referenced by lti::trectangle< T >::resize().

template<class T, class S = rectSide<T>>
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.

Warning:
Note that the result of this method depends on the type T

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.

template<class T, class S = rectSide<T>>
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.

Returns:
a reference to this (modified) instance.

Referenced by lti::trectangle< T >::intersectRect(), lti::trectangle< T >::operator&(), lti::trectangle< T >::operator&=(), and lti::trectangle< T >::overlaps().

template<class T, class S = rectSide<T>>
trectangle<T>& lti::trectangle< T, S >::intersectRect ( const trectangle< T > &  tRect  )  [inline]

Intersection of this trectangle with tRect.

Deprecated:
Please use intersect instead
template<class T, class S = rectSide<T>>
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.

template<class T, class S = rectSide<T>>
bool lti::trectangle< T, S >::isConsistent (  )  const [inline]

Check for consistent trectangle<T>.

Returns:
True if upper-left corner and bottom-right are correct

Referenced by lti::trectangle< T >::overlaps().

template<class T, class S = rectSide<T>>
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!)

template<class T, class S = rectSide<T>>
bool lti::trectangle< T, S >::isInside ( const tpoint< T > &  p  )  const [inline]

Check if tpoint<T> p is inside the trectangle<T>.

(border included!)

template<class T, class S = rectSide<T>>
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.

Returns:
a reference to this (modified) instance.

Referenced by lti::trectangle< T >::operator|(), lti::trectangle< T >::operator|=(), and lti::trectangle< T >::unionRect().

template<class T, class S = rectSide<T>>
bool lti::trectangle< T, S >::operator!= ( const trectangle< T > &  other  )  const [inline]

test for inequality

template<class T, class S = rectSide<T>>
trectangle<T> lti::trectangle< T, S >::operator& ( const trectangle< T > &  tRect  )  [inline]

new trectangle = intersection of trectangle with tRect

template<class T, class S = rectSide<T>>
trectangle<T>& lti::trectangle< T, S >::operator&= ( const trectangle< T > &  tRect  )  [inline]

trectangle = intersection of trectangle with tRect.

(alias for intersect)

template<class T, class S = rectSide<T>>
trectangle<T>& lti::trectangle< T, S >::operator= ( const trectangle< T > &  other  )  [inline]

alias for copy

template<class T, class S = rectSide<T>>
bool lti::trectangle< T, S >::operator== ( const trectangle< T > &  other  )  const [inline]

test for equality

template<class T, class S = rectSide<T>>
trectangle<T> lti::trectangle< T, S >::operator| ( const trectangle< T > &  tRect  )  [inline]

new trectangle = union of this trectangle with tRect

template<class T, class S = rectSide<T>>
trectangle<T>& lti::trectangle< T, S >::operator|= ( const trectangle< T > &  tRect  )  [inline]

trectangle = union of this trectangle with tRect (alias for join)

template<class T, class S = rectSide<T>>
bool lti::trectangle< T, S >::overlaps ( const trectangle< T > &  tRect  )  const [inline]

Check whether this rectangle overlaps with the given rectangle.

template<class T, class S = rectSide<T>>
void lti::trectangle< T, S >::resize ( const T &  x,
const T &  y 
) [inline]

resize trectangle<T> with new dimensions, but keep its center

template<class T, class S = rectSide<T>>
void lti::trectangle< T, S >::resize ( const tpoint< T > &  dim  )  [inline]

resize trectangle<T> with new dimensions, but keep its center

template<class T, class S = rectSide<T>>
void lti::trectangle< T, S >::setCenter ( tpoint< T >  center  )  [inline]

Set the center of this rectangle.

template<class T, class S = rectSide<T>>
void lti::trectangle< T, S >::shift ( const tpoint< T > &  delta  )  [inline]

Shift trectangle<T> by delta.

template<class T, class S = rectSide<T>>
trectangle<T>& lti::trectangle< T, S >::unionRect ( const trectangle< T > &  tRect  )  [inline]

Union of this trectangle with tRect.

Deprecated:
please use join instead.

Member Data Documentation

template<class T, class S = rectSide<T>>
tpoint<T> lti::trectangle< T, S >::br
template<class T, class S = rectSide<T>>
tpoint<T> lti::trectangle< T, S >::ul

The documentation for this class was generated from the following file:

Generated on Sat Apr 10 15:26:44 2010 for LTI-Lib by Doxygen 1.6.1