123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- #include "vislearning/cbaselib/BoundingBox.h"
- using namespace OBJREC;
- using namespace std;
- using namespace NICE;
- BoundingBox::BoundingBox()
- {
- top_left_.x = -1;
- top_left_.y = -1;
- bottom_right_.x = -1;
- bottom_right_.y = -1;
- id_ = -1;
- unique_id_ = -1;
- }
- BoundingBox::BoundingBox(const BoundingBox ©)
- {
- top_left_ = copy.topLeft();
- bottom_right_ = copy.bottomRight();
- id_ = copy.id();
- unique_id_ = copy.unique_id_;
- }
- BoundingBox::~BoundingBox()
- {
-
- }
- void
- BoundingBox::setTopLeft(const CoordT< int > &aTopLeft)
- {
- if (aTopLeft.x < 0 || aTopLeft.y < 0) {
- return;
-
- }
-
- top_left_ = aTopLeft;
- }
- void
- BoundingBox::setTopLeft(const int &x, const int &y)
- {
- if (x < 0 || y < 0) {
- return;
-
- }
-
- CoordT< int > topLeft(x, y);
- top_left_ = topLeft;
- }
- void
- BoundingBox::setBottomRight(const CoordT< int > &aBottomRight)
- {
- if (aBottomRight.x < 0 || aBottomRight.y < 0) {
- return;
-
- }
-
- bottom_right_ = aBottomRight;
- }
- void
- BoundingBox::setBottomRight(const int &x, const int &y)
- {
- if (x < 0 || y < 0) {
- return;
-
- }
-
- CoordT< int > bottomRight(x, y);
- bottom_right_ = bottomRight;
- }
- void
- BoundingBox::setWidth(const int &aWidth)
- {
- if (aWidth < 0) {
- return;
-
- }
-
- bottom_right_.x = top_left_.x + aWidth;
- }
- void
- BoundingBox::setHeight(const int &aHeight)
- {
- if (aHeight < 0) {
- return;
-
- }
-
- bottom_right_.y = top_left_.y + aHeight;
- }
- void
- BoundingBox::setID(const int &anID)
- {
- if (anID < 0) {
- return;
-
- }
- id_ = anID;
- }
- CoordT< int >
- BoundingBox::topLeft() const
- {
- return top_left_;
- }
- CoordT< int >
- BoundingBox::bottomRight() const
- {
- return bottom_right_;
- }
- int
- BoundingBox::width()
- {
- if (top_left_.x < bottom_right_.x)
- return bottom_right_.x - top_left_.x;
- else
- return -1;
- }
- int
- BoundingBox::height()
- {
- if (top_left_.y < bottom_right_.y)
- return bottom_right_.y - top_left_.y;
- else
- return -1;
- }
- int
- BoundingBox::id() const
- {
- return id_;
- }
- bool
- BoundingBox::isValid() const
- {
- if (id_ < 0 ||
- top_left_.x < 0 ||
- top_left_.y < 0 ||
- bottom_right_.x < 0 ||
- bottom_right_.y < 0 ||
- bottom_right_.y <= top_left_.y ||
- top_left_.x >= bottom_right_.x)
- {
- return false;
-
- }
-
- return true;
- }
- void
- BoundingBox::validate()
- {
- if (bottom_right_.y < top_left_.y ||
- top_left_.x < bottom_right_.x)
- {
- CoordT< int > buffer = top_left_;
- top_left_ = bottom_right_;
- bottom_right_ = buffer;
- }
- }
|