|
CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
|
Axis-aligned rectangle defined by an upper-left corner and a Size, with overlap/containment math. More...
#include <MathClasses.h>
Public Member Functions | |
| Box () | |
| Empty box at the origin. | |
| Box (PointFloat upperleft, Size boxsize, double linewidth=0) | |
| From corner + size. | |
| Box (PointFloat upperleft, PointFloat lowerright, double linewidth=0) | |
| From two opposite corners. | |
| Box (double x, double y, double w, double h, double linewidth=0) | |
| From scalar corner and dimensions. | |
| virtual | ~Box () |
| double | getUpperY () const |
| double | getLowerY () const |
| double | getLeftX () const |
| double | getRightX () const |
| double | getArea () const |
| double | getCMX () const |
| double | getCMY () const |
| PointFloat | getCM () const |
| PointFloat | getUpperLeft () const |
| PointFloat | getUpperRight () const |
| PointFloat | getLowerLeft () const |
| PointFloat | getLowerRight () const |
| double | getLineWidth () const |
| Size | getSize () const |
| double | getWidth () const |
| double | getHeight () const |
| Box | operator- (const Point &p) const |
| Box translated by -p. | |
| Box | operator- (const PointFloat &p) const |
| Box translated by -p. | |
| Box | operator+ (const Point &p) const |
| Box translated by +p. | |
| Box | operator+ (const PointFloat &p) const |
| Box translated by +p. | |
| bool | move (double dx, double dy) |
| Translate in place. | |
| bool | moveTo (double x, double y) |
| Move the upper-left corner to (x,y). | |
| bool | set (double x, double y, double w, double h, double linewidth=0) |
| Reset all geometry. | |
| bool | setUpperLeft (const PointFloat &point) |
| Set the corner. | |
| bool | setSize (const Size &boxsize) |
| Set the extent. | |
| bool | setLineWidth (double width) |
| Set the stroke width. | |
| bool | grow (double dw, double dh) |
| Enlarge by (dw,dh), keeping the upper-left corner. | |
| bool | isPointWithin (const PointFloat &point) const |
| bool | isPointWithin (int x, int y) const |
| PointFloat | getCentreMass () const |
| bool | hasZeroSize () const |
| bool | equals (const Box &otherbox) const |
| Exact geometric equality. | |
| bool | equals (const Box &otherbox, double maxerror) const |
Approximate equality within maxerror per component. | |
| Box | getBoundingBox (const Box &otherbox) const |
| bool | growToBoundingBox (const Box &otherbox) |
Enlarge in place to include otherbox. | |
| bool | growToIncludePoint (const Point &point, int padX=0, int padY=0) |
Enlarge to include point plus padding. | |
| Box | getOverlapBox (const Box &otherbox) const |
| double | percentOverlap (const Box &otherbox) const |
| Overlap between the two boxes as a fraction of the larger area. | |
| Box | getDoubleSizeSameCenter () |
| bool | constrainTo (const Box &box) |
Clip this box in place to lie within box. | |
| bool | constrainTo (double x, double y, double w, double h) |
| Clip in place to the given rectangle. | |
| Box | getConstrainedCopy (const Box &box) |
| Box | getConstrainedCopy (double x, double y, double w, double h) |
| std::string | print () |
| Human-readable representation for debugging. | |
Public Attributes | |
| PointFloat | upperLeft |
| Upper-left corner. | |
| Size | size |
| Extent. | |
| double | lineWidth |
| Stroke width (drawing hint). | |
| std::string | name |
| Optional label. | |
| std::string | comment |
| Optional free-form comment. | |
| double | orientation |
| Optional rotation metadata (radians); not applied by the geometric queries. | |
Axis-aligned rectangle defined by an upper-left corner and a Size, with overlap/containment math.
Widely used for image regions and tracked object bounding boxes. Y grows downward (screen convention): getUpperY() < getLowerY(), and "upper left" is the minimum-x/minimum-y corner. All geometric queries treat the box as axis-aligned; the orientation field is metadata only. Optional metadata (name, comment, orientation) travels with the box.
Definition at line 557 of file MathClasses.h.
| cmlabs::Box::Box | ( | ) |
Empty box at the origin.
Definition at line 489 of file MathClasses.cpp.
References lineWidth, and orientation.
Referenced by constrainTo(), equals(), equals(), getBoundingBox(), getConstrainedCopy(), getConstrainedCopy(), getDoubleSizeSameCenter(), getOverlapBox(), growToBoundingBox(), operator+(), operator+(), operator-(), operator-(), and percentOverlap().
| cmlabs::Box::Box | ( | PointFloat | upperleft, |
| Size | boxsize, | ||
| double | linewidth = 0 ) |
From corner + size.
Definition at line 512 of file MathClasses.cpp.
References lineWidth, orientation, size, and upperLeft.
| cmlabs::Box::Box | ( | PointFloat | upperleft, |
| PointFloat | lowerright, | ||
| double | linewidth = 0 ) |
From two opposite corners.
Definition at line 530 of file MathClasses.cpp.
References cmlabs::PointFloat::getX(), cmlabs::PointFloat::getY(), lineWidth, orientation, size, and upperLeft.
| cmlabs::Box::Box | ( | double | x, |
| double | y, | ||
| double | w, | ||
| double | h, | ||
| double | linewidth = 0 ) |
From scalar corner and dimensions.
Definition at line 494 of file MathClasses.cpp.
References lineWidth, orientation, size, and upperLeft.
|
virtual |
Definition at line 548 of file MathClasses.cpp.
| bool cmlabs::Box::constrainTo | ( | const Box & | box | ) |
Clip this box in place to lie within box.
Definition at line 670 of file MathClasses.cpp.
References Box(), constrainTo(), cmlabs::Size::h, size, upperLeft, cmlabs::Size::w, cmlabs::PointFloat::x, and cmlabs::PointFloat::y.
Referenced by constrainTo(), getConstrainedCopy(), and getConstrainedCopy().
| bool cmlabs::Box::constrainTo | ( | double | x, |
| double | y, | ||
| double | w, | ||
| double | h ) |
Clip in place to the given rectangle.
Definition at line 674 of file MathClasses.cpp.
| bool cmlabs::Box::equals | ( | const Box & | otherbox | ) | const |
Exact geometric equality.
Definition at line 762 of file MathClasses.cpp.
References Box(), orientation, size, and upperLeft.
| bool cmlabs::Box::equals | ( | const Box & | otherbox, |
| double | maxerror ) const |
Approximate equality within maxerror per component.
Definition at line 769 of file MathClasses.cpp.
References Box(), and percentOverlap().
| double cmlabs::Box::getArea | ( | ) | const |
Definition at line 605 of file MathClasses.cpp.
References size.
Referenced by cmlabs::MathClasses_UnitTest().
Definition at line 804 of file MathClasses.cpp.
References Box(), getLeftX(), getLowerY(), getRightX(), and getUpperY().
Referenced by growToBoundingBox(), and cmlabs::MathClasses_UnitTest().
| PointFloat cmlabs::Box::getCentreMass | ( | ) | const |
Definition at line 754 of file MathClasses.cpp.
| PointFloat cmlabs::Box::getCM | ( | ) | const |
Definition at line 560 of file MathClasses.cpp.
References size, and upperLeft.
Referenced by getCMX(), getCMY(), and cmlabs::MathClasses_UnitTest().
| double cmlabs::Box::getCMX | ( | ) | const |
Definition at line 552 of file MathClasses.cpp.
References getCM(), and cmlabs::PointFloat::getX().
| double cmlabs::Box::getCMY | ( | ) | const |
Definition at line 556 of file MathClasses.cpp.
References getCM(), and cmlabs::PointFloat::getY().
box. Definition at line 658 of file MathClasses.cpp.
References Box(), and constrainTo().
| Box cmlabs::Box::getConstrainedCopy | ( | double | x, |
| double | y, | ||
| double | w, | ||
| double | h ) |
Definition at line 664 of file MathClasses.cpp.
References Box(), and constrainTo().
| Box cmlabs::Box::getDoubleSizeSameCenter | ( | ) |
Definition at line 686 of file MathClasses.cpp.
References Box(), cmlabs::Size::h, size, upperLeft, cmlabs::Size::w, cmlabs::PointFloat::x, and cmlabs::PointFloat::y.
| double cmlabs::Box::getHeight | ( | ) | const |
Definition at line 613 of file MathClasses.cpp.
References size.
Referenced by cmlabs::Bitmap::drawBitmap(), cmlabs::Bitmap::fillBox(), grow(), cmlabs::MathClasses_UnitTest(), move(), and moveTo().
| double cmlabs::Box::getLeftX | ( | ) | const |
Definition at line 588 of file MathClasses.cpp.
References upperLeft.
Referenced by cmlabs::Bitmap::addBitmapUpdateRegion(), cmlabs::Bitmap::drawBitmap(), cmlabs::Bitmap::fillBox(), getBoundingBox(), getOverlapBox(), isPointWithin(), cmlabs::MathClasses_UnitTest(), and move().
| double cmlabs::Box::getLineWidth | ( | ) | const |
Definition at line 597 of file MathClasses.cpp.
References lineWidth.
Referenced by cmlabs::Bitmap::drawBox().
| PointFloat cmlabs::Box::getLowerLeft | ( | ) | const |
Definition at line 572 of file MathClasses.cpp.
References size, and upperLeft.
Referenced by cmlabs::Bitmap::drawBox().
| PointFloat cmlabs::Box::getLowerRight | ( | ) | const |
Definition at line 576 of file MathClasses.cpp.
References size, and upperLeft.
Referenced by cmlabs::Bitmap::drawBox(), and print().
| double cmlabs::Box::getLowerY | ( | ) | const |
Definition at line 584 of file MathClasses.cpp.
References size, and upperLeft.
Referenced by getBoundingBox(), getOverlapBox(), isPointWithin(), and cmlabs::MathClasses_UnitTest().
Definition at line 831 of file MathClasses.cpp.
References Box(), getLeftX(), getLowerY(), getRightX(), and getUpperY().
Referenced by cmlabs::MathClasses_UnitTest(), and percentOverlap().
| double cmlabs::Box::getRightX | ( | ) | const |
Definition at line 592 of file MathClasses.cpp.
References size, and upperLeft.
Referenced by getBoundingBox(), getOverlapBox(), isPointWithin(), and cmlabs::MathClasses_UnitTest().
| Size cmlabs::Box::getSize | ( | ) | const |
Definition at line 601 of file MathClasses.cpp.
References size.
Referenced by cmlabs::MathClasses_UnitTest(), and percentOverlap().
| PointFloat cmlabs::Box::getUpperLeft | ( | ) | const |
Definition at line 564 of file MathClasses.cpp.
References upperLeft.
Referenced by cmlabs::Bitmap::drawBox(), and print().
| PointFloat cmlabs::Box::getUpperRight | ( | ) | const |
Definition at line 568 of file MathClasses.cpp.
References size, and upperLeft.
Referenced by cmlabs::Bitmap::drawBox().
| double cmlabs::Box::getUpperY | ( | ) | const |
Definition at line 580 of file MathClasses.cpp.
References upperLeft.
Referenced by cmlabs::Bitmap::addBitmapUpdateRegion(), cmlabs::Bitmap::drawBitmap(), cmlabs::Bitmap::fillBox(), getBoundingBox(), getOverlapBox(), isPointWithin(), cmlabs::MathClasses_UnitTest(), and move().
| double cmlabs::Box::getWidth | ( | ) | const |
Definition at line 609 of file MathClasses.cpp.
References size.
Referenced by cmlabs::Bitmap::drawBitmap(), cmlabs::Bitmap::fillBox(), grow(), cmlabs::MathClasses_UnitTest(), move(), and moveTo().
| bool cmlabs::Box::grow | ( | double | dw, |
| double | dh ) |
Enlarge by (dw,dh), keeping the upper-left corner.
Definition at line 650 of file MathClasses.cpp.
References getHeight(), getWidth(), and setSize().
Referenced by cmlabs::MathClasses_UnitTest().
| bool cmlabs::Box::growToBoundingBox | ( | const Box & | otherbox | ) |
Enlarge in place to include otherbox.
Definition at line 775 of file MathClasses.cpp.
References Box(), getBoundingBox(), hasZeroSize(), size, and upperLeft.
| bool cmlabs::Box::growToIncludePoint | ( | const Point & | point, |
| int | padX = 0, | ||
| int | padY = 0 ) |
Enlarge to include point plus padding.
Definition at line 784 of file MathClasses.cpp.
References size, upperLeft, cmlabs::Point::x, and cmlabs::Point::y.
| bool cmlabs::Box::hasZeroSize | ( | ) | const |
Definition at line 758 of file MathClasses.cpp.
References size.
Referenced by growToBoundingBox().
| bool cmlabs::Box::isPointWithin | ( | const PointFloat & | point | ) | const |
point lies inside (inclusive). Definition at line 742 of file MathClasses.cpp.
References cmlabs::PointFloat::getX(), and cmlabs::PointFloat::getY().
Referenced by cmlabs::MathClasses_UnitTest().
| bool cmlabs::Box::isPointWithin | ( | int | x, |
| int | y ) const |
Definition at line 730 of file MathClasses.cpp.
References getLeftX(), getLowerY(), getRightX(), and getUpperY().
| bool cmlabs::Box::move | ( | double | dx, |
| double | dy ) |
Translate in place.
Definition at line 642 of file MathClasses.cpp.
References getHeight(), getLeftX(), getUpperY(), getWidth(), and set().
Referenced by cmlabs::MathClasses_UnitTest().
| bool cmlabs::Box::moveTo | ( | double | x, |
| double | y ) |
Move the upper-left corner to (x,y).
Definition at line 646 of file MathClasses.cpp.
References getHeight(), getWidth(), and set().
Box translated by +p.
Definition at line 630 of file MathClasses.cpp.
| Box cmlabs::Box::operator+ | ( | const PointFloat & | p | ) | const |
Box translated by +p.
Definition at line 636 of file MathClasses.cpp.
Box translated by -p.
Definition at line 618 of file MathClasses.cpp.
| Box cmlabs::Box::operator- | ( | const PointFloat & | p | ) | const |
Box translated by -p.
Definition at line 624 of file MathClasses.cpp.
| double cmlabs::Box::percentOverlap | ( | const Box & | otherbox | ) | const |
Overlap between the two boxes as a fraction of the larger area.
Computed as overlapArea/myArea when this box is the larger, otherwise the ratio is inverted so the result stays in [0,1].
Definition at line 872 of file MathClasses.cpp.
References Box(), cmlabs::Size::getArea(), getOverlapBox(), getSize(), cmlabs::Size::isNonZero(), and size.
Referenced by equals(), and cmlabs::MathClasses_UnitTest().
| std::string cmlabs::Box::print | ( | ) |
Human-readable representation for debugging.
Definition at line 895 of file MathClasses.cpp.
References getLowerRight(), getUpperLeft(), lineWidth, print(), and cmlabs::utils::StringFormat().
Referenced by print().
| bool cmlabs::Box::set | ( | double | x, |
| double | y, | ||
| double | w, | ||
| double | h, | ||
| double | linewidth = 0 ) |
| bool cmlabs::Box::setLineWidth | ( | double | width | ) |
Set the stroke width.
Definition at line 724 of file MathClasses.cpp.
References lineWidth.
| bool cmlabs::Box::setSize | ( | const Size & | boxsize | ) |
Set the extent.
Definition at line 719 of file MathClasses.cpp.
References size.
Referenced by grow().
| bool cmlabs::Box::setUpperLeft | ( | const PointFloat & | point | ) |
| std::string cmlabs::Box::comment |
Optional free-form comment.
Definition at line 570 of file MathClasses.h.
| double cmlabs::Box::lineWidth |
Stroke width (drawing hint).
Definition at line 568 of file MathClasses.h.
Referenced by Box(), Box(), Box(), Box(), getLineWidth(), print(), set(), and setLineWidth().
| std::string cmlabs::Box::name |
Optional label.
Definition at line 569 of file MathClasses.h.
| double cmlabs::Box::orientation |
| Size cmlabs::Box::size |
Extent.
Definition at line 567 of file MathClasses.h.
Referenced by Box(), Box(), Box(), constrainTo(), constrainTo(), equals(), getArea(), getCentreMass(), getCM(), cmlabs::Bitmap::getCopy(), getDoubleSizeSameCenter(), getHeight(), getLowerLeft(), getLowerRight(), getLowerY(), getRightX(), getSize(), getUpperRight(), getWidth(), growToBoundingBox(), growToIncludePoint(), hasZeroSize(), percentOverlap(), set(), and setSize().
| PointFloat cmlabs::Box::upperLeft |
Upper-left corner.
Definition at line 566 of file MathClasses.h.
Referenced by Box(), Box(), Box(), constrainTo(), constrainTo(), equals(), getCentreMass(), getCM(), cmlabs::Bitmap::getCopy(), getDoubleSizeSameCenter(), getLeftX(), getLowerLeft(), getLowerRight(), getLowerY(), getRightX(), getUpperLeft(), getUpperRight(), getUpperY(), growToBoundingBox(), growToIncludePoint(), operator+(), operator+(), operator-(), operator-(), set(), and setUpperLeft().