
#include <Image/Rectangle.H>
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). | |
|
||||||||||||
|
Build from a top-left corner and some dims.
Definition at line 385 of file Rectangle.H. |
|
|
Copy constructor.
Definition at line 392 of file Rectangle.H. |
|
|
Uninitialized constructor (useful for arrays).
Definition at line 397 of file Rectangle.H. Referenced by getOverlap(), tlbrI(), and tlbrO(). |
|
|
Access some metric info.
Definition at line 424 of file Rectangle.H. References height(), and width(). Referenced by isRectEmpty(). |
|
|
Access some metric info.
Definition at line 430 of file Rectangle.H. |
|
|
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(). |
|
|
Get (outer) bottom left corner point.
Definition at line 482 of file Rectangle.H. References ASSERT. Referenced by RoiExtractor::label(). |
|
|
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(). |
|
|
Get (outer) bottom right corner point.
Definition at line 485 of file Rectangle.H. References ASSERT. |
|
|
The center of the rectangle.
Definition at line 436 of file Rectangle.H. Referenced by main(). |
|
|
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. |
|
|
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(). |
|
|
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(). |
|
|
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(). |
|
|
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(). |
|
|
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(). |
|
|
|
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(). |
|
|
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(). |
|
||||||||||||||||||||
|
||||||||||||||||||||
|
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(). |
|
|
|
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(). |
|
|
Get (outer) top right corner point.
Definition at line 479 of file Rectangle.H. References ASSERT. |
|
|
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(). |
1.4.4