A basic rectangle class. More...
#include <Image/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 | |
double | getOverlapRatio (const Rectangle &r2) const |
compute overlap as area of intersection / area of union | |
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). | |
static Rectangle | centerDims (const Point2D< int > ¢er, const Dims &dims) |
Build from center loc and dims. |
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.
Build from a top-left corner and some dims.
Definition at line 395 of file Rectangle.H.
Rectangle::Rectangle | ( | const Rectangle & | rect | ) | [inline] |
Copy constructor.
Definition at line 402 of file Rectangle.H.
Rectangle::Rectangle | ( | ) | [inline] |
Uninitialized constructor (useful for arrays).
Definition at line 407 of file Rectangle.H.
Referenced by centerDims(), CudaFramework::drawRectangle_centrepoint(), CudaFramework::drawRectangle_topleftpoint(), getOverlap(), tlbrI(), and tlbrO().
int Rectangle::area | ( | ) | const [inline] |
Access some metric info.
Definition at line 451 of file Rectangle.H.
References height(), and width().
Referenced by getOverlapRatio(), and SDLdisplay::start2().
float Rectangle::aspect | ( | ) | const [inline] |
Access some metric info.
Definition at line 457 of file Rectangle.H.
int Rectangle::bottomI | ( | ) | const [inline] |
get inner bottom coordinate (=top+height-1)
Definition at line 488 of file Rectangle.H.
References ASSERT.
Referenced by BitObject::doesIntersect(), BitObject::drawBoundingBox(), VisualObjectMatch::getOverlapRect(), VisualObjectMatch::isOverlapping(), Image< T >::rectangleOk(), CudaImage< T >::rectangleOk(), and BitObject::writeToStream().
Point2D< int > Rectangle::bottomLeft | ( | ) | const [inline] |
Get (outer) bottom left corner point.
Definition at line 509 of file Rectangle.H.
References ASSERT.
Referenced by InferoTemporalSIFT::attentionShift().
int Rectangle::bottomO | ( | ) | const [inline] |
get outer bottom coordinate (=top+height)
Definition at line 491 of file Rectangle.H.
References ASSERT.
Referenced by buildPyrRetinexLog(), constrainRect(), convertToString(), BitObject::drawOutline(), BitObject::drawShape(), extractBitObjects(), getOverlap(), SimulationViewerCompress::getTraj(), BitObject::setMaxMinAvgIntensity(), and SDLdisplay::start2().
Point2D< int > Rectangle::bottomRight | ( | ) | const [inline] |
Get (outer) bottom right corner point.
Definition at line 512 of file Rectangle.H.
References ASSERT.
Referenced by InferoTemporalSIFT::attentionShift().
Point2D< int > Rectangle::center | ( | ) | const [inline] |
The center of the rectangle.
Definition at line 463 of file Rectangle.H.
Referenced by InferoTemporalSIFT::attentionShift().
Rectangle Rectangle::centerDims | ( | const Point2D< int > & | center, | |
const Dims & | dims | |||
) | [inline, static] |
Build from center loc and dims.
Definition at line 391 of file Rectangle.H.
References Dims::h(), Point2D< T >::i, Rectangle(), and Dims::w().
Referenced by InferoTemporalSIFT::attentionShift().
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 476 of file Rectangle.H.
bool Rectangle::contains | ( | const Point2D< int > & | p | ) | const [inline] |
check if point p is within rectangle
CAUTION: boundaries are included.
Definition at line 470 of file Rectangle.H.
References Point2D< T >::i.
Referenced by constrainRect(), and InferotemporalCortexI::evolve().
Dims Rectangle::dims | ( | ) | const [inline] |
Get the rectangle's width, height.
Definition at line 515 of file Rectangle.H.
References ASSERT.
Referenced by InputFrameSeries::peekFrameSpec().
get overlap between this rectangle and passed in rectangle
Definition at line 420 of file Rectangle.H.
References bottomO(), isValid(), left(), max(), min(), Rectangle(), rightO(), tlbrO(), and top().
Referenced by buildPyrRetinexLog(), constrainRect(), SimulationViewerStd::drawEye(), SimulationViewerStd::drawHead(), VisualEventSet::drawTokens(), extractBitObjects(), getOverlapRatio(), VisualObjectMatch::getOverlapRect(), RetinaAdapter::getRawInputRectangle(), getSalRegions(), SimulationViewerCompress::getTraj(), and VisualEventSet::updateEvents().
double Rectangle::getOverlapRatio | ( | const Rectangle & | r2 | ) | const [inline] |
compute overlap as area of intersection / area of union
Definition at line 434 of file Rectangle.H.
References area(), getOverlap(), and isValid().
int Rectangle::height | ( | ) | const [inline] |
Access some metric info.
Definition at line 524 of file Rectangle.H.
References ASSERT.
Referenced by area(), aspect(), SDLdisplay::clearScreen(), constrainRect(), cudaCrop(), ObjDetChannel::doInput(), BitObject::getBoundingBox(), VisualObjectMatch::getOverlapRect(), and VisualObjectMatch::isOverlapping().
bool Rectangle::isValid | ( | ) | const [inline] |
whether the rectangle is valid
Definition at line 527 of file Rectangle.H.
Referenced by SDLdisplay::clearScreen(), convertToString(), getOverlap(), getOverlapRatio(), VisualObjectMatch::isOverlapping(), BitObject::isValid(), SDLdisplay::makeBlittableSurface(), and BitObject::writeToStream().
int Rectangle::left | ( | ) | const [inline] |
get (inner) left coordinate
Definition at line 494 of file Rectangle.H.
References ASSERT.
Referenced by buildPyrRetinexLog(), SDLdisplay::clearScreen(), constrainRect(), convertToString(), cudaCrop(), BitObject::doesIntersect(), BitObject::drawBoundingBox(), BitObject::drawOutline(), BitObject::drawShape(), extractBitObjects(), TemplateMatchChannel::findBestMatch(), BitObject::getObjectOrigin(), getOverlap(), VisualObjectMatch::getOverlapRect(), SimulationViewerCompress::getTraj(), VisualObjectMatch::isOverlapping(), Image< T >::rectangleOk(), CudaImage< T >::rectangleOk(), BitObject::reset(), BitObject::setMaxMinAvgIntensity(), SDLdisplay::start2(), FOEestimator::updateFOE(), and BitObject::writeToStream().
int Rectangle::rightI | ( | ) | const [inline] |
get inner right coordinate (=left+width-1)
Definition at line 497 of file Rectangle.H.
References ASSERT.
Referenced by BitObject::doesIntersect(), BitObject::drawBoundingBox(), VisualObjectMatch::getOverlapRect(), VisualObjectMatch::isOverlapping(), Image< T >::rectangleOk(), CudaImage< T >::rectangleOk(), and BitObject::writeToStream().
int Rectangle::rightO | ( | ) | const [inline] |
get outer right coordinate (=left+width)
Definition at line 500 of file Rectangle.H.
References ASSERT.
Referenced by buildPyrRetinexLog(), constrainRect(), convertToString(), BitObject::drawOutline(), BitObject::drawShape(), extractBitObjects(), getOverlap(), SimulationViewerCompress::getTraj(), BitObject::setMaxMinAvgIntensity(), and SDLdisplay::start2().
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 383 of file Rectangle.H.
References Rectangle().
Referenced by centroid(), BitObject::doesIntersect(), dogFilterHmax(), ArrayCreator::draw(), SimulationViewerStd::drawEye(), SimulationViewerStd::drawHead(), SimulationViewerNerdCam::drawMegaCombo(), TemplateMatchChannel::drawResults(), VisualEventSet::drawTokens(), HmaxFL::extractRandC1Patch(), CudaHmaxFLSal::extractRandC1Patches(), CudaHmaxFL::extractRandC1Patches(), findBoundingRect(), floodCleanBB(), formatMapForDisplay(), BitObject::getBoundingBox(), DPM::getBoundingBoxes(), VisualObjectMatch::getOverlapRect(), RetinaAdapter::getRawInputRectangle(), getSalRegions(), SimulationViewerStd::getTraj(), SimulationViewerNerdCam::getTraj(), SimulationViewerCompress::getTraj(), main(), BitObject::readFromStream(), BitObject::reset(), SimulationViewerNerdCam::saveResults(), MbariResultViewer::saveSingleEventFrame(), segmentImageTrackMC::SITdrawBlobBox(), segmentImageTrackMC::SITdrawBlobTrack(), segmentImageTrackMC::SITdrawBlobTrackMerged(), segmentImageTrackMC::SITdrawHistoValues(), StimMaker::SM_drawSingleTarget(), VisualEventSet::updateEvents(), CudaHmaxFL::windowedPatchDistance(), and HmaxFL::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 387 of file Rectangle.H.
References Rectangle().
Referenced by InferoTemporalSIFT::attentionShift(), buildPyrRetinexLog(), constrainRect(), convertFromString(), getOverlap(), getSearchCommand(), Beobot2_GistSalLocalizerMasterI::updateMessage(), GistSal_Navigation::updateMessage(), and Beobot2_GistSalLocalizerWorkerI::updateMessage().
int Rectangle::top | ( | ) | const [inline] |
get (inner) top coordinate
Definition at line 485 of file Rectangle.H.
References ASSERT.
Referenced by buildPyrRetinexLog(), SDLdisplay::clearScreen(), constrainRect(), convertToString(), cudaCrop(), BitObject::doesIntersect(), BitObject::drawBoundingBox(), BitObject::drawOutline(), BitObject::drawShape(), extractBitObjects(), TemplateMatchChannel::findBestMatch(), BitObject::getObjectOrigin(), getOverlap(), VisualObjectMatch::getOverlapRect(), SimulationViewerCompress::getTraj(), VisualObjectMatch::isOverlapping(), Image< T >::rectangleOk(), CudaImage< T >::rectangleOk(), BitObject::reset(), BitObject::setMaxMinAvgIntensity(), SDLdisplay::start2(), FOEestimator::updateFOE(), and BitObject::writeToStream().
Point2D< int > Rectangle::topLeft | ( | ) | const [inline] |
Get (outer) top left corner point.
Definition at line 503 of file Rectangle.H.
References ASSERT.
Referenced by InferoTemporalSIFT::attentionShift(), and ObjDetChannel::doInput().
Point2D< int > Rectangle::topRight | ( | ) | const [inline] |
Get (outer) top right corner point.
Definition at line 506 of file Rectangle.H.
References ASSERT.
Referenced by InferoTemporalSIFT::attentionShift().
int Rectangle::width | ( | ) | const [inline] |
Access some metric info.
Definition at line 521 of file Rectangle.H.
References ASSERT.
Referenced by area(), aspect(), SDLdisplay::clearScreen(), constrainRect(), cudaCrop(), ObjDetChannel::doInput(), BitObject::getBoundingBox(), VisualObjectMatch::getOverlapRect(), and VisualObjectMatch::isOverlapping().