CVR-Lib last update 20 Sep 2009

cvr::rectangle< T, S > Class Template Reference
[Geometry Data Structures]

Rectangle representation class. More...

#include <cvrRectangle.h>

Inheritance diagram for cvr::rectangle< T, S >:

Inheritance graph
[legend]

List of all members.

Public Types

typedef T value_type
typedef S side_type

Public Member Functions

 rectangle ()
 rectangle (const point< T > &ul, const point< T > &br)
 rectangle (const T &left, const T &top, const T &right, const T &bottom)
 rectangle (const T &size)
template<typename U , class US >
 rectangle (const rectangle< U, US > &other)
bool set (const T &left, const T &top, const T &right, const T &bottom)
bool set (const point< T > &ul, const point< T > &br)
bool setConsistent (const T &left, const T &top, const T &right, const T &bottom)
bool setConsistent (const point< T > &ul, const point< T > &br)
Location and Dimensions
void resize (const point< T > &dim)
void resize (const T &x, const T &y)
point< T > getDimensions () const
typeInfo< T >
::square_accumulation_type 
getArea () const
point< T > getCenter () const
void setCenter (point< T > center)
void ensureConsistency ()
bool isConsistent () const
void shift (const point< T > &delta)
void shift (const rectangle< T, S > &other, const point< T > &delta)
Simple operations
bool contains (const point< T > &p) const
bool contains (const T &x, const T &y) const
Duplication
rectangle< T, S > & copy (const rectangle< T, S > &other)
template<class U , class SU >
rectangle< T, S > & castFrom (const rectangle< U, SU > &other)
rectangle< T, S > & operator= (const rectangle< T, S > &other)
Comparison
bool operator== (const rectangle< T, S > &other) const
bool operator!= (const rectangle< T, S > &other) const
Geometrical combination
rectangle< T, S > & intersect (const rectangle< T, S > &tRect)
bool overlaps (const rectangle< T, S > &tRect) const
bool isClose (const rectangle< T, S > &tRect, const point< T > &dist) const
rectangle< T, S > & operator&= (const rectangle< T, S > &tRect)
rectangle< T, S > operator& (const rectangle< T, S > &tRect)
rectangle< T, S > & join (const rectangle< T, S > &tRect)
rectangle< T, S > & operator|= (const rectangle< T, S > &tRect)
rectangle< T, S > operator| (const rectangle< T, S > &tRect)

Public Attributes

The two corners of the rectangle
point< T > ul
point< T > br


Detailed Description

template<typename T, class S = rectangleSide<T>>
class cvr::rectangle< 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 point<T>. For example, the type rectangle<int> (which has the alias irectangle) contains to ipoints (point<int>) as corner representation. You can access the type T through the public type value_type.

The second template parameter S is optional and allows the rectangle to behave correctly in a discrete integer grid or in a continuous real grid (please see the cvr::rectangleSide policy for more information).


Member Typedef Documentation

template<typename T, class S = rectangleSide<T>>
typedef S cvr::rectangle< T, S >::side_type

Type used for the side policy.

template<typename T, class S = rectangleSide<T>>
typedef T cvr::rectangle< T, S >::value_type

Type used in each coordinate of the two internal points.


Constructor & Destructor Documentation

template<typename T, class S = rectangleSide<T>>
cvr::rectangle< T, S >::rectangle (  ) 

Default constructor.

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

template<typename T, class S = rectangleSide<T>>
cvr::rectangle< T, S >::rectangle ( const point< T > &  ul,
const point< T > &  br 
)

Constructor with two points.

Parameters:
ul upper left corner
br bottom right corner

template<typename T, class S = rectangleSide<T>>
cvr::rectangle< T, S >::rectangle ( const T &  left,
const T &  top,
const T &  right,
const T &  bottom 
)

Construct a rectangle via separate coordinates.

Parameters:
left left side coordinate
top top side coordinate
right right side coordinate
bottom bottom side coordinate

template<typename T, class S = rectangleSide<T>>
cvr::rectangle< T, S >::rectangle ( const T &  size  ) 

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<typename T, class S = rectangleSide<T>>
template<typename U , class US >
cvr::rectangle< T, S >::rectangle ( const rectangle< U, US > &  other  )  [inline]

Copy constructor.


Member Function Documentation

template<typename T, class S = rectangleSide<T>>
template<class U , class SU >
rectangle<T,S>& cvr::rectangle< T, S >::castFrom ( const rectangle< U, SU > &  other  )  [inline]

Cast from a rectangle of another type.

template<typename T, class S = rectangleSide<T>>
bool cvr::rectangle< T, S >::contains ( const T &  x,
const T &  y 
) const [inline]

Check if the given coordinates are inside this rectangle.

(border included!)

template<typename T, class S = rectangleSide<T>>
bool cvr::rectangle< T, S >::contains ( const point< T > &  p  )  const [inline]

Check if point<T> p is inside this rectangle.

(border inclusive!)

template<typename T, class S = rectangleSide<T>>
rectangle<T,S>& cvr::rectangle< T, S >::copy ( const rectangle< T, S > &  other  ) 

Copy member.

template<typename T, class S = rectangleSide<T>>
void cvr::rectangle< T, S >::ensureConsistency (  ) 

Ensure consistency of upper-left and bottom-right corners.

A rectangle<T,S> is called "consistent" if the upper-left point<T> has lower coordinate-values than the bottom-right point<T>.

template<typename T, class S = rectangleSide<T>>
typeInfo<T>::square_accumulation_type cvr::rectangle< 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<typename T, class S = rectangleSide<T>>
point<T> cvr::rectangle< T, S >::getCenter (  )  const [inline]

Get center of rectangle<T,S>.

template<typename T, class S = rectangleSide<T>>
point<T> cvr::rectangle< T, S >::getDimensions (  )  const [inline]

Get dimensions of rectangle<T,S>.

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<typename T, class S = rectangleSide<T>>
rectangle<T,S>& cvr::rectangle< T, S >::intersect ( const rectangle< T, S > &  tRect  ) 

Intersection of this rectangle 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.

template<typename T, class S = rectangleSide<T>>
bool cvr::rectangle< T, S >::isClose ( const rectangle< T, S > &  tRect,
const point< T > &  dist 
) const

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<typename T, class S = rectangleSide<T>>
bool cvr::rectangle< T, S >::isConsistent (  )  const [inline]

Check for consistent rectangle<T,S>.

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

template<typename T, class S = rectangleSide<T>>
rectangle<T,S>& cvr::rectangle< T, S >::join ( const rectangle< T, S > &  tRect  ) 

Union-rectangle of this rectangle with tRect.

This is the smallest rectangle containing both this rectangle and tRect. The result will be left in this instance.

Returns:
A reference to this (modified) instance.

template<typename T, class S = rectangleSide<T>>
bool cvr::rectangle< T, S >::operator!= ( const rectangle< T, S > &  other  )  const [inline]

Test for inequality.

template<typename T, class S = rectangleSide<T>>
rectangle<T,S> cvr::rectangle< T, S >::operator& ( const rectangle< T, S > &  tRect  )  [inline]

New rectangle equals the intersection of this rectangle with tRect.

template<typename T, class S = rectangleSide<T>>
rectangle<T,S>& cvr::rectangle< T, S >::operator&= ( const rectangle< T, S > &  tRect  )  [inline]

This rectangle is set to the intersection of himself with tRect.

(alias for intersect)

template<typename T, class S = rectangleSide<T>>
rectangle<T,S>& cvr::rectangle< T, S >::operator= ( const rectangle< T, S > &  other  )  [inline]

Alias for copy.

template<typename T, class S = rectangleSide<T>>
bool cvr::rectangle< T, S >::operator== ( const rectangle< T, S > &  other  )  const [inline]

Test for equality.

template<typename T, class S = rectangleSide<T>>
rectangle<T,S> cvr::rectangle< T, S >::operator| ( const rectangle< T, S > &  tRect  ) 

Generates a new rectangle equal to the smallest rectangle that contains the union of this rectangle with tRect.

template<typename T, class S = rectangleSide<T>>
rectangle<T,S>& cvr::rectangle< T, S >::operator|= ( const rectangle< T, S > &  tRect  )  [inline]

This rectangle is set to the union-rectangle of this rectangle with tRect (alias for join()).

template<typename T, class S = rectangleSide<T>>
bool cvr::rectangle< T, S >::overlaps ( const rectangle< T, S > &  tRect  )  const

Check whether this rectangle overlaps with the given rectangle.

template<typename T, class S = rectangleSide<T>>
void cvr::rectangle< T, S >::resize ( const T &  x,
const T &  y 
)

Resize rectangle<T,S> with new dimensions, but keep its center.

template<typename T, class S = rectangleSide<T>>
void cvr::rectangle< T, S >::resize ( const point< T > &  dim  ) 

Resize rectangle<T,S> with new dimensions, but keep its center.

template<typename T, class S = rectangleSide<T>>
bool cvr::rectangle< T, S >::set ( const point< T > &  ul,
const point< T > &  br 
) [inline]

Set the corners via two points.

You must ensure that the data is consistent, i.e. ul.x < br.x and ul.y < br.y. See setConsistent().

Parameters:
ul upper left corner
br bottom right corner
Returns:
true upon success, false otherwise

template<typename T, class S = rectangleSide<T>>
bool cvr::rectangle< T, S >::set ( const T &  left,
const T &  top,
const T &  right,
const T &  bottom 
) [inline]

Set the corners via separate coordinates.

You must ensure that the data is consistent, i.e. left < right and top < bottom. See setConsistent().

Parameters:
left left side coordinate
top top side coordinate
right right side coordinate
bottom bottom side coordinate
Returns:
true when successful, false otherwise

template<typename T, class S = rectangleSide<T>>
void cvr::rectangle< T, S >::setCenter ( point< T >  center  ) 

Set the center of this rectangle.

template<typename T, class S = rectangleSide<T>>
bool cvr::rectangle< T, S >::setConsistent ( const point< T > &  ul,
const point< T > &  br 
) [inline]

Set the corners via two points.

This method ensures consistency of the resulting rectangle, no matter if the given data implies negative sides.

Parameters:
ul upper left corner
br bottom right corner
Returns:
true upon success, false otherwise

template<typename T, class S = rectangleSide<T>>
bool cvr::rectangle< T, S >::setConsistent ( const T &  left,
const T &  top,
const T &  right,
const T &  bottom 
) [inline]

Set the corners via separate coordinates.

This method ensures consistency of the resulting rectangle, no matter if the given data implies negative sides.

Parameters:
left left side coordinate
top top side coordinate
right right side coordinate
bottom bottom side coordinate
Returns:
true when successful, false otherwise

template<typename T, class S = rectangleSide<T>>
void cvr::rectangle< T, S >::shift ( const rectangle< T, S > &  other,
const point< T > &  delta 
) [inline]

Shift the other rectangle<T,S> by delta and leave the result here.

Parameters:
other The reference rectangle
delta The shift amount to be added to both corners of the reference rectangle

template<typename T, class S = rectangleSide<T>>
void cvr::rectangle< T, S >::shift ( const point< T > &  delta  )  [inline]

Shift rectangle<T,S> by delta.

Parameters:
delta The shift amount to be added to both corners


Member Data Documentation

template<typename T, class S = rectangleSide<T>>
point<T> cvr::rectangle< T, S >::br

Bottom-right point<T>.

template<typename T, class S = rectangleSide<T>>
point<T> cvr::rectangle< T, S >::ul

Upper-left point<T>.


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

Generated on Sun Sep 20 22:09:08 2009 for CVR-Lib by Doxygen 1.5.8