Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Rectangle Class Reference

#include <Image/Rectangle.H>

List of all members.


Detailed Description

A basic rectangle class.

This is a shorthand class to represent a 2D rectangle, as defined by integer top, left, bottom and right coordinates. The goal of this object is not to have to check if left < right, etc... for each function using a Rectangle. The object checks for that at its creation, and is always internally coherent. Image convention: top < bottom, left < right.

There is often some ambiguity about how to represent the left-right and top-bottom ranges involved in a rectangle. Imagine a pixel grid like this:

+---+---+---+---+ | | | | | | | | | | +---+---+---+---+ | | | | | | | | | | +---+---+---+---+ | | | | | | | | | | +---+---+---+---+ | | | | | | | | | | +---+---+---+---+

If we want a Rectangle that covers this whole 4x4 grid, how should we represent the coordinates? Clearly the upper left corner is (0,0), but what about the bottom right corner? One answer would be that the lower right corner is (4,4), in which we imagine the coordinate numbers falling between the cracks of the pixels:

. 0...1...2...3...4 0 +---+---+---+---+ . | | | | | . | | | | | 1 +---+---+---+---+ . | | | | | . | | | | | 2 +---+---+---+---+ . | | | | | . | | | | | 3 +---+---+---+---+ . | | | | | . | | | | | 4 +---+---+---+---+

Another answer is that the lower right corner should be labeled as (3,3), if we envision the coordinate numbers labeling the pixel centers, and this approach is more natural if we want to draw a line just inside the border of the rectangle as shown by the '*' here:

. ..0...1...2...3.. . +---+---+---+---+ 0 |***|***|***|***| . |***|***|***|***| . +---+---+---+---+ 1 |***| | |***| . |***| | |***| . +---+---+---+---+ 2 |***| | |***| . |***| | |***| . +---+---+---+---+ 3 |***|***|***|***| . |***|***|***|***| . +---+---+---+---+

In the Rectangle class we support both approaches; the (4,4) coords are called 'outer' coordinates and corresponding functions have a 'O' suffix (bottomO(), right(), and tlbrO()), while the (3,3) coords are called 'inner' coordinates and corresponding functions have an 'I' suffix (bottomI(), rightI(), and tlbrI()).

The internal representation of Rectangle is based on outer coordinates, but this has no effect on users of the class who are free to user whichever of inner or outer coords are more convenient for their purposes.

Outer coordinates are more natural for uniformly scaling a rectangle up or down by a factor. For example, if we want to scale the 4x4 rect up by a factor of 2 giving an 8x8 rect, then in outer coords we just do newright=right*2=4*2=8 and newbottom=bottom*2=4*2=8. But with inner coords we can't just multiply by 2: the inner bottom-right coords are (3,3), and if we scale those by 2 we get (6,6) which represents a 7x7 rectangle rather than the correct 8x8 result.

HISTORICAL NOTE (2007-Mar-20): The Rectangle class previously used only inner coordinates both for its implementation and in its public interface. This lead to clunky code in some places where many -1 or +1 offsets were needed to handle rectangle coordinates.

Definition at line 143 of file Rectangle.H.

Public Member Functions

 Rectangle (const Point2D< int > &topleft, const Dims &dims)
 Build from a top-left corner and some dims.
 Rectangle (const Rectangle &rect)
 Copy constructor.
 Rectangle ()
 Uninitialized constructor (useful for arrays).
Rectangle getOverlap (const Rectangle &r2) const
 get overlap between this rectangle and passed in rectangle
bool contains (const Point2D< int > &p) const
 check if point p is within rectangle
bool contains (const Rectangle &r) const
 check if this rect contains another
int top () const
 get (inner) top coordinate
int bottomI () const
 get inner bottom coordinate (=top+height-1)
int bottomO () const
 get outer bottom coordinate (=top+height)
int left () const
 get (inner) left coordinate
int rightI () const
 get inner right coordinate (=left+width-1)
int rightO () const
 get outer right coordinate (=left+width)
Point2D< int > topLeft () const
 Get (outer) top left corner point.
Point2D< int > topRight () const
 Get (outer) top right corner point.
Point2D< int > bottomLeft () const
 Get (outer) bottom left corner point.
Point2D< int > bottomRight () const
 Get (outer) bottom right corner point.
Dims dims () const
 Get the rectangle's width, height.
int width () const
 Access some metric info.
int height () const
 Access some metric info.
int area () const
 Access some metric info.
float aspect () const
 Access some metric info.
Point2D< int > center () const
 The center of the rectangle.
bool isValid () const
 whether the rectangle is valid

Static Public Member Functions

static Rectangle tlbrI (int tt, int ll, int bb, int rr)
 Build from 4 coordinates (top, left, inner-bottom, inner-right).
static Rectangle tlbrO (int tt, int ll, int bb, int rr)
 Build from 4 coordinates (top, left, outer-bottom, outer-right).


Constructor & Destructor Documentation

Rectangle::Rectangle const Point2D< int > &  topleft,
const Dims dims
[inline]
 

Build from a top-left corner and some dims.

Definition at line 385 of file Rectangle.H.

Rectangle::Rectangle const Rectangle rect  )  [inline]
 

Copy constructor.

Definition at line 392 of file Rectangle.H.

Rectangle::Rectangle  )  [inline]
 

Uninitialized constructor (useful for arrays).

Definition at line 397 of file Rectangle.H.

Referenced by getOverlap(), tlbrI(), and tlbrO().


Member Function Documentation

int Rectangle::area  )  const [inline]
 

Access some metric info.

Definition at line 424 of file Rectangle.H.

References height(), and width().

Referenced by isRectEmpty().

float Rectangle::aspect  )  const [inline]
 

Access some metric info.

Definition at line 430 of file Rectangle.H.

References height(), and width().

int Rectangle::bottomI  )  const [inline]
 

get inner bottom coordinate (=top+height-1)

Definition at line 461 of file Rectangle.H.

References ASSERT.

Referenced by BitObject::doesIntersect(), BitObject::drawBoundingBox(), drawRect(), drawRectEZ(), drawRectOR(), drawRectSquareCorners(), fillEyeData(), fillMouthData(), fillNoseData(), getLocalSalPt(), VisualObjectMatch::getOverlapRect(), VisualObjectMatch::isOverlapping(), Image< T >::rectangleOk(), CudaImage< T >::rectangleOk(), Hmax::sumFilter(), CudaHmax::sumFilter(), within(), and BitObject::writeToStream().

Point2D< int > Rectangle::bottomLeft  )  const [inline]
 

Get (outer) bottom left corner point.

Definition at line 482 of file Rectangle.H.

References ASSERT.

Referenced by RoiExtractor::label().

int Rectangle::bottomO  )  const [inline]
 

get outer bottom coordinate (=top+height)

Definition at line 464 of file Rectangle.H.

References ASSERT.

Referenced by buildPyrRetinexLog(), constrainRect(), convertToString(), BitObject::drawOutline(), BitObject::drawShape(), SegmenterI::evolve(), extractBitObjects(), getLocalSalPt(), getOverlap(), SimulationViewerCompress::getTraj(), operator *(), operator+(), operator-(), operator/(), operator==(), retinexCompareNeighbors(), and BitObject::setMaxMinAvgIntensity().

Point2D< int > Rectangle::bottomRight  )  const [inline]
 

Get (outer) bottom right corner point.

Definition at line 485 of file Rectangle.H.

References ASSERT.

Point2D< int > Rectangle::center  )  const [inline]
 

The center of the rectangle.

Definition at line 436 of file Rectangle.H.

Referenced by main().

bool Rectangle::contains const Rectangle r  )  const [inline]
 

check if this rect contains another

The boundaries are allowed to coincide, such that by this definition a rectangle "contains" itself.

Definition at line 449 of file Rectangle.H.

References b1, l, r1, and t.

bool Rectangle::contains const Point2D< int > &  p  )  const [inline]
 

check if point p is within rectangle

CAUTION: boundaries are included.

Definition at line 443 of file Rectangle.H.

References Point2D< T >::i, and Point2D< T >::j.

Referenced by constrainRect(), InferotemporalCortexI::evolve(), getContextPt(), Context::testFrame(), and Context::trainingFrame().

Dims Rectangle::dims  )  const [inline]
 

Get the rectangle's width, height.

Definition at line 488 of file Rectangle.H.

References ASSERT.

Referenced by lobot::membrane_potential(), InputFrameSeries::peekFrameSpec(), and TigsInputFrame::toGhostString().

Rectangle Rectangle::getOverlap const Rectangle r2  )  const [inline]
 

get overlap between this rectangle and passed in rectangle

Definition at line 410 of file Rectangle.H.

References bottomO(), isValid(), left(), rutz::max(), rutz::min(), Rectangle(), rightO(), tlbrO(), and top().

Referenced by buildPyrRetinexLog(), constrainRect(), doRescale(), SimulationViewerStd::drawEye(), SimulationViewerStd::drawHead(), drawRectEZ(), drawRectSquareCorners(), VisualEventSet::drawTokens(), extractBitObjects(), EnvSegmenterCannyContour::getFoa(), EnvObjDetection::getFoa(), VisualObjectMatch::getOverlapRect(), RetinaSpaceVariant::getRawInputRectangle(), RetinaStd::getRawInputRectangle(), Retina::getRawInputRectangle(), getSalRegions(), EnvSegmenterCannyContour::getSquares(), SimulationViewerCompress::getTraj(), inplaceClearRegion(), main(), processSalCue(), Rectangle_xx_getOverlap_xx_1(), and VisualEventSet::updateEvents().

int Rectangle::height  )  const [inline]
 

Access some metric info.

Definition at line 497 of file Rectangle.H.

References ASSERT.

Referenced by area(), aspect(), lobot::compute_horz_dsmd_rect(), lobot::compute_vert_dsmd_rect(), constrainRect(), crop(), cudaCrop(), ObjDetChannel::doInput(), drawFilledRect(), BitObject::getBoundingBox(), getEyeFeature(), getFacePartProb(), getLocalSalPt(), getMouthFeature(), getNoseFeature(), VisualObjectMatch::getOverlapRect(), inplaceClearRegion(), inplaceEmbed(), VisualObjectMatch::isOverlapping(), main(), Nv2UiJob::makeInputMarkup(), lobot::rect_height(), Nv2UiJob::run(), and MbariResultViewer::saveSingleEventFrame().

bool Rectangle::isValid  )  const [inline]
 

whether the rectangle is valid

Definition at line 500 of file Rectangle.H.

Referenced by convertToString(), doRescale(), drawRect(), drawRectEZ(), drawRectSquareCorners(), SimulationViewerI::evolve(), EnvSegmenterCannyContour::getFoa(), getOverlap(), inplaceClearRegion(), VisualObjectMatch::isOverlapping(), isRectEmpty(), BitObject::isValid(), main(), Nv2UiJob::makeInputMarkup(), operator *(), operator/(), operator==(), Rectangle_xx_getOverlap_xx_1(), Nv2UiJob::run(), EnvInferoTemporal::sendPatch(), and BitObject::writeToStream().

int Rectangle::left  )  const [inline]
 

get (inner) left coordinate

Definition at line 467 of file Rectangle.H.

References ASSERT.

Referenced by buildPyrRetinexLog(), constrainRect(), convertToString(), crop(), cudaCrop(), BitObject::doesIntersect(), BitObject::drawBoundingBox(), drawFilledRect(), BitObject::drawOutline(), drawRect(), drawRectEZ(), drawRectOR(), drawRectSquareCorners(), BitObject::drawShape(), SegmenterI::evolve(), extractBitObjects(), fillMouthData(), fillNoseData(), TemplateMatchChannel::findBestMatch(), getEyeFeature(), getFacePartProb(), getLocalSalPt(), getMouthFeature(), getNoseFeature(), BitObject::getObjectOrigin(), getOverlap(), VisualObjectMatch::getOverlapRect(), getSearchCommand(), SimulationViewerCompress::getTraj(), inplaceClearRegion(), inplaceEmbed(), VisualObjectMatch::isOverlapping(), operator *(), operator+(), operator-(), operator/(), operator==(), processSalCue(), Image< T >::rectangleOk(), CudaImage< T >::rectangleOk(), BitObject::reset(), retinexCompareNeighbors(), MbariResultViewer::saveSingleEventFrame(), BitObject::setMaxMinAvgIntensity(), Hmax::sumFilter(), CudaHmax::sumFilter(), FOEestimator::updateFOE(), within(), and BitObject::writeToStream().

int Rectangle::rightI  )  const [inline]
 

get inner right coordinate (=left+width-1)

Definition at line 470 of file Rectangle.H.

References ASSERT.

Referenced by BitObject::doesIntersect(), BitObject::drawBoundingBox(), drawRect(), drawRectEZ(), drawRectOR(), drawRectSquareCorners(), fillMouthData(), fillNoseData(), getLocalSalPt(), VisualObjectMatch::getOverlapRect(), VisualObjectMatch::isOverlapping(), Image< T >::rectangleOk(), CudaImage< T >::rectangleOk(), Hmax::sumFilter(), CudaHmax::sumFilter(), within(), and BitObject::writeToStream().

int Rectangle::rightO  )  const [inline]
 

get outer right coordinate (=left+width)

Definition at line 473 of file Rectangle.H.

References ASSERT.

Referenced by buildPyrRetinexLog(), constrainRect(), convertToString(), BitObject::drawOutline(), BitObject::drawShape(), SegmenterI::evolve(), extractBitObjects(), getLocalSalPt(), getOverlap(), SimulationViewerCompress::getTraj(), operator *(), operator+(), operator-(), operator/(), operator==(), retinexCompareNeighbors(), and BitObject::setMaxMinAvgIntensity().

Rectangle Rectangle::tlbrI int  tt,
int  ll,
int  bb,
int  rr
[inline, static]
 

Build from 4 coordinates (top, left, inner-bottom, inner-right).

Definition at line 377 of file Rectangle.H.

References Rectangle().

Referenced by centroid(), lobot::compute_horz_dsmd_rect(), lobot::compute_vert_dsmd_rect(), BitObject::doesIntersect(), dogFilterHmax(), SimulationViewerStd::drawEye(), SimulationViewerStd::drawHead(), SimulationViewerNerdCam::drawMegaCombo(), TemplateMatchChannel::drawResults(), VisualEventSet::drawTokens(), HmaxFL::extractRandC1Patches(), CudaHmaxFL::extractRandC1Patches(), findBoundingRect(), floodCleanBB(), formatMapForDisplay(), getBoundBox(), BitObject::getBoundingBox(), getEyeFeature(), getFacePartProb(), getMouthFeature(), getNoseFeature(), VisualObjectMatch::getOverlapRect(), getPartRect(), RetinaSpaceVariant::getRawInputRectangle(), RetinaStd::getRawInputRectangle(), Retina::getRawInputRectangle(), getSalRegions(), getSubSum2(), SimulationViewerStd::getTraj(), SimulationViewerNerdCam::getTraj(), SimulationViewerCompress::getTraj(), getWindow(), FourierFeatureExtractor::illustrate(), Image_xx_construct_and_clear_xx_1(), Image_xx_construct_from_array_xx_1(), Image_xx_crop_xx_1(), Image_xx_default_construct_xx_1(), main(), processSalCue(), processSplitImage(), BitObject::readFromStream(), BitObject::reset(), SimulationViewerNerdCam::saveResults(), MbariResultViewer::saveSingleEventFrame(), segmentImageTrackMC::SITdrawBlobBox(), segmentImageTrackMC::SITdrawBlobTrack(), segmentImageTrackMC::SITdrawBlobTrackMerged(), segmentImageTrackMC::SITdrawHistoValues(), StimMaker::SM_drawSingleTarget(), Hmax::sumFilter(), CudaHmax::sumFilter(), train(), VisualEventSet::updateEvents(), HmaxFL::windowedPatchDistance(), and CudaHmaxFL::windowedPatchDistance().

Rectangle Rectangle::tlbrO int  tt,
int  ll,
int  bb,
int  rr
[inline, static]
 

Build from 4 coordinates (top, left, outer-bottom, outer-right).

Definition at line 381 of file Rectangle.H.

References Rectangle().

Referenced by buildPyrRetinexLog(), constrainRect(), convertFromString(), getLocalSalPt(), getOverlap(), getSearchCommand(), EnvSegmenterCannyContour::getSquares(), main(), operator *(), operator+(), operator-(), operator/(), segmentColor(), Beobot2_GistSalLocalizerWorkerI::updateMessage(), and Beobot2_GistSalLocalizerMasterI::updateMessage().

int Rectangle::top  )  const [inline]
 

get (inner) top coordinate

Definition at line 458 of file Rectangle.H.

References ASSERT.

Referenced by buildPyrRetinexLog(), constrainRect(), convertToString(), crop(), cudaCrop(), BitObject::doesIntersect(), BitObject::drawBoundingBox(), drawFilledRect(), BitObject::drawOutline(), drawRect(), drawRectEZ(), drawRectOR(), drawRectSquareCorners(), BitObject::drawShape(), SegmenterI::evolve(), extractBitObjects(), fillEyeData(), fillMouthData(), fillNoseData(), TemplateMatchChannel::findBestMatch(), getEyeFeature(), getFacePartProb(), getLocalSalPt(), getMouthFeature(), getNoseFeature(), BitObject::getObjectOrigin(), getOverlap(), VisualObjectMatch::getOverlapRect(), getSearchCommand(), SimulationViewerCompress::getTraj(), inplaceClearRegion(), inplaceEmbed(), VisualObjectMatch::isOverlapping(), operator *(), operator+(), operator-(), operator/(), operator==(), processSalCue(), Image< T >::rectangleOk(), CudaImage< T >::rectangleOk(), BitObject::reset(), retinexCompareNeighbors(), MbariResultViewer::saveSingleEventFrame(), BitObject::setMaxMinAvgIntensity(), Hmax::sumFilter(), CudaHmax::sumFilter(), FOEestimator::updateFOE(), within(), and BitObject::writeToStream().

Point2D< int > Rectangle::topLeft  )  const [inline]
 

Get (outer) top left corner point.

Definition at line 476 of file Rectangle.H.

References ASSERT.

Referenced by ObjDetChannel::doInput(), main(), lobot::membrane_potential(), and Nv2UiJob::run().

Point2D< int > Rectangle::topRight  )  const [inline]
 

Get (outer) top right corner point.

Definition at line 479 of file Rectangle.H.

References ASSERT.

int Rectangle::width  )  const [inline]
 

Access some metric info.

Definition at line 494 of file Rectangle.H.

References ASSERT.

Referenced by area(), aspect(), lobot::compute_horz_dsmd_rect(), lobot::compute_vert_dsmd_rect(), constrainRect(), crop(), cudaCrop(), ObjDetChannel::doInput(), drawFilledRect(), BitObject::getBoundingBox(), getEyeFeature(), getFacePartProb(), getLocalSalPt(), getMouthFeature(), getNoseFeature(), VisualObjectMatch::getOverlapRect(), inplaceClearRegion(), inplaceEmbed(), VisualObjectMatch::isOverlapping(), main(), Nv2UiJob::makeInputMarkup(), lobot::rect_width(), Nv2UiJob::run(), and MbariResultViewer::saveSingleEventFrame().


The documentation for this class was generated from the following file:
Generated on Sun Nov 22 13:46:17 2009 for iLab Neuromorphic Vision Toolkit by  doxygen 1.4.4