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

qgar::BoundingBox Class Reference
[Misc.]

#include <qgarlib/BoundingBox.H>

Inheritance diagram for qgar::BoundingBox:

qgar::ISerializable List of all members.

Detailed Description

A bounding box.

A bounding box is a rectangle with sides parallel to the coordinate system axis. It is represented by its top left and bottom right corners.

   0
    +---------------------------------------> X
    |
    |            <---- length ---->
    |   top left o----------------+  ^
    |            |                |  |
    |            |  Bounding Box  |height
    |            |                |  |
    |            +----------------o  v
    V                            bottom right

    Y
Warning:
Author:
Jan Rendek
Date:
February 23, 2004 16:08
Since:
Qgar 2.1.1

Definition at line 100 of file BoundingBox.H.

Public Member Functions

Constructors
 BoundingBox ()
 Default constructor.
 BoundingBox (const BoundingBox &aBox)
 Copy constructor.
 BoundingBox (const GenPoint< int > &aPt1, const GenPoint< int > &aPt2)
 Initialize from two points.
 BoundingBox (int aX1, int aY1, int aX2, int aY2)
 Initialize from coordinates of two points.
 BoundingBox (const GenPoint< int > &aTopLeft, int aLength, int aHeight) throw (QgarErrorDomain)
 Initialize from top left corner, length and height.
 BoundingBox (int aLength, int aHeight, const GenPoint< int > &aBottomRight) throw (QgarErrorDomain)
 Initialize from bottom right corner, length and height.
Destructor
 ~BoundingBox ()
 Non-virtual destructor.
Access to corners
const GenPoint< int > & accessTopLeft () const
 Get top left corner.
GenPoint< int > topLeft () const
 Get a copy of the top left corner.
const GenPoint< int > & accessBottomRight () const
 Get bottom right corner.
GenPoint< int > bottomRight () const
 Get a copy of the bottom right corner.
Access to coordinates
int xTopLeft () const
 Get X coordinate of top left corner.
int yTopLeft () const
 Get Y coordinate of top left corner.
int xBottomRight () const
 Get X coordinate of bottom right corner.
int yBottomRight () const
 Get Y coordinate of bottom right corner.
Access to dimensions
int length () const
 Same as qgar::BoundingBox::width.
int width () const
 Get width.
int height () const
 Get height.
int area () const
 Get area.
Geometrical predicates
bool contains (const GenPoint< int > &aPt) const
 Return true if the given point belongs to the current bounding box, including borders.
bool contains (int aX, int aY) const
 Return true if the point defined by the given coordinates belongs to the current bounding box, including borders.
bool contains (const BoundingBox &aBox) const
 Return true if the current bounding box contains the given bounding box.
bool intersects (const BoundingBox &aBox) const
 Return true if the current bounding box intersects the given bounding box.
Geometrical operations
BoundingBoxintersection (const BoundingBox &aBox) const
 Intersection between the current and given bounding boxes.
Set corners
void setTopLeft (const GenPoint< int > &aPt) throw (QgarErrorDomain)
 Set top left corner using a point.
void setTopLeft (int aX, int aY) throw (QgarErrorDomain)
 Set top left corner using X and Y coordinates.
void setXTopLeft (int aX) throw (QgarErrorDomain)
 Set X coordinate of top left corner.
void setYTopLeft (int aY) throw (QgarErrorDomain)
 Set Y coordinate of top left corner.
void setBottomRight (const GenPoint< int > &aPt) throw (QgarErrorDomain)
 Set bottom right corner using a point.
void setBottomRight (int aX, int aY) throw (QgarErrorDomain)
 Set bottom right corner using X and Y coordinates.
void setXBottomRight (int aX) throw (QgarErrorDomain)
 Set X coordinate of bottom right corner.
void setYBottomRight (int aY) throw (QgarErrorDomain)
 Set Y coordinate of bottom right corner.
void setCorners (const GenPoint< int > &aPt1, const GenPoint< int > &aPt2)
 Set both top left and bottom right corners from two points.
void setCorners (int aX1, int aY1, int aX2, int aY2)
 Set both top left and bottom right corners from coordinates of two points.
Operators
BoundingBoxoperator= (const BoundingBox &aBox)
 Assign the given bounding box to the current bounding box.
bool operator== (const BoundingBox &aBox) const
 Same as function qgar::BoundingBox::eq.
bool operator!= (const BoundingBox &aBox) const
 Same as function qgar::BoundingBox::NotEq.
Functional operators
bool eq (const BoundingBox &aBox) const
 Equality.
bool notEq (const BoundingBox &aBox) const
 Inequality.
Serialization/deserialization
virtual std::istream & read (std::istream &anInStream)
 Deserializes the current box from an input stream.
virtual std::ostream & write (std::ostream &anOutStream) const
 Serializes the current box to an input stream.

Protected Attributes

Representation of a bounding box
GenPoint< int > _topLeft
 Top left corner.
GenPoint< int > _bottomRight
 Bottom right corner.


Constructor & Destructor Documentation

qgar::BoundingBox::BoundingBox  ) 
 

Default constructor.

One-unit-length and one-unit-width bounding box located at the origin of the coordinate system.

Definition at line 61 of file BoundingBox.C.

Referenced by intersection().

qgar::BoundingBox::BoundingBox const BoundingBox aBox  ) 
 

Copy constructor.

Parameters:
aBox a bounding box

Definition at line 73 of file BoundingBox.C.

qgar::BoundingBox::BoundingBox const GenPoint< int > &  aPt1,
const GenPoint< int > &  aPt2
 

Initialize from two points.

The two given points, aPt1 and aPt2, are supposed to be two opposite corners (top left and bottom right, or top right and bottom left) of the resulting bounding box. The corresponding coordinates of top left and bottom right corners are automatically computed.

Parameters:
aPt1 a point
aPt2 a point

Definition at line 85 of file BoundingBox.C.

References setCorners().

qgar::BoundingBox::BoundingBox int  aX1,
int  aY1,
int  aX2,
int  aY2
 

Initialize from coordinates of two points.

The two given points are supposed to be two opposite corners (top left and bottom right, or top right and bottom left) of the resulting bounding box. The corresponding coordinates of top left and bottom right corners are automatically computed.

Parameters:
aX1 X coordinate of first point
aY1 Y coordinate of first point
aX2 X coordinate of second point
aY2 Y coordinate of second point

Definition at line 94 of file BoundingBox.C.

References setCorners().

qgar::BoundingBox::BoundingBox const GenPoint< int > &  aTopLeft,
int  aLength,
int  aHeight
throw (QgarErrorDomain)
 

Initialize from top left corner, length and height.

The length and the height must be greater than 0.

Parameters:
aTopLeft top left corner of the resulting bounding box
aLength length of the resulting bounding box
aHeight height of the resulting bounding box
Exceptions:
qgar::QgarErrorDomain if the length or the height is not valid.

Definition at line 102 of file BoundingBox.C.

qgar::BoundingBox::BoundingBox int  aLength,
int  aHeight,
const GenPoint< int > &  aBottomRight
throw (QgarErrorDomain)
 

Initialize from bottom right corner, length and height.

The length and the height must be greater than 0.

Parameters:
aLength length of the resulting bounding box
aHeight height of the resulting bounding box
aBottomRight bottom right corner of the resulting bounding box
Exceptions:
qgar::QgarErrorDomain if the length or the height is not valid.

Definition at line 141 of file BoundingBox.C.

qgar::BoundingBox::~BoundingBox  ) 
 

Non-virtual destructor.

Definition at line 183 of file BoundingBox.C.


Member Function Documentation

const GenPoint< int > & qgar::BoundingBox::accessBottomRight  )  const [inline]
 

Get bottom right corner.

Definition at line 640 of file BoundingBox.H.

References _bottomRight.

const GenPoint< int > & qgar::BoundingBox::accessTopLeft  )  const [inline]
 

Get top left corner.

Definition at line 622 of file BoundingBox.H.

References _topLeft.

int qgar::BoundingBox::area  )  const [inline]
 

Get area.

Warning:
The pixels of the borders belong to the box, and thus are counted in the area.

Definition at line 731 of file BoundingBox.H.

References height(), and length().

Referenced by qgar::Component::densityBox().

GenPoint< int > qgar::BoundingBox::bottomRight  )  const [inline]
 

Get a copy of the bottom right corner.

Definition at line 649 of file BoundingBox.H.

References _bottomRight.

Referenced by contains(), eq(), and notEq().

bool qgar::BoundingBox::contains const BoundingBox aBox  )  const [inline]
 

Return true if the current bounding box contains the given bounding box.

Parameters:
aBox a bounding box

Definition at line 754 of file BoundingBox.H.

References bottomRight(), contains(), and topLeft().

bool qgar::BoundingBox::contains int  aX,
int  aY
const
 

Return true if the point defined by the given coordinates belongs to the current bounding box, including borders.

Parameters:
aX an integer X coordinate
aY an integer Y coordinate

Definition at line 450 of file BoundingBox.C.

References _bottomRight, _topLeft, qgar::GenPoint< T >::x(), and qgar::GenPoint< T >::y().

bool qgar::BoundingBox::contains const GenPoint< int > &  aPt  )  const [inline]
 

Return true if the given point belongs to the current bounding box, including borders.

Parameters:
aPt a point with integer coordinates

Definition at line 745 of file BoundingBox.H.

References qgar::GenPoint< T >::x(), and qgar::GenPoint< T >::y().

Referenced by contains().

bool qgar::BoundingBox::eq const BoundingBox aBox  )  const
 

Equality.

Return true if the current bounding box and the given bounding box have the same coordinates.

Parameters:
aBox a bounding box

Definition at line 578 of file BoundingBox.C.

References _bottomRight, _topLeft, bottomRight(), and topLeft().

Referenced by operator==().

int qgar::BoundingBox::height  )  const [inline]
 

Get height.

Warning:
As the pixels of the borders belong to the box, the width is $ Y_{bottom-right-corner} - Y_{top-left-corner} + 1 $

Definition at line 722 of file BoundingBox.H.

References _bottomRight, _topLeft, and qgar::GenPoint< T >::y().

Referenced by area(), and qgar::TTBinaryImage::TTBinaryImage().

BoundingBox * qgar::BoundingBox::intersection const BoundingBox aBox  )  const
 

Intersection between the current and given bounding boxes.

If the two bounding boxes intersect, returns a pointer to the bounding box representing the intersection. If the two bounding boxes do not intersect, returns a null pointer.

Parameters:
aBox a bounding box

Definition at line 518 of file BoundingBox.C.

References _bottomRight, _topLeft, BoundingBox(), qgar::GenPoint< T >::x(), xBottomRight(), xTopLeft(), qgar::GenPoint< T >::y(), yBottomRight(), and yTopLeft().

bool qgar::BoundingBox::intersects const BoundingBox aBox  )  const
 

Return true if the current bounding box intersects the given bounding box.

Parameters:
aBox a bounding box

Definition at line 478 of file BoundingBox.C.

References _bottomRight, _topLeft, qgar::GenPoint< T >::x(), xBottomRight(), xTopLeft(), qgar::GenPoint< T >::y(), yBottomRight(), and yTopLeft().

int qgar::BoundingBox::length  )  const [inline]
 

Same as qgar::BoundingBox::width.

Definition at line 704 of file BoundingBox.H.

References width().

Referenced by area().

bool qgar::BoundingBox::notEq const BoundingBox aBox  )  const
 

Inequality.

Return true if the current bounding box and the given bounding box have different coordinates.

Parameters:
aBox a bounding box

Definition at line 588 of file BoundingBox.C.

References _bottomRight, _topLeft, bottomRight(), and topLeft().

Referenced by operator!=().

bool qgar::BoundingBox::operator!= const BoundingBox aBox  )  const [inline]
 

Same as function qgar::BoundingBox::NotEq.

Parameters:
aBox a bounding box

Definition at line 778 of file BoundingBox.H.

References notEq().

BoundingBox & qgar::BoundingBox::operator= const BoundingBox aBox  ) 
 

Assign the given bounding box to the current bounding box.

Parameters:
aBox a bounding box

Definition at line 558 of file BoundingBox.C.

References _bottomRight, and _topLeft.

bool qgar::BoundingBox::operator== const BoundingBox aBox  )  const [inline]
 

Same as function qgar::BoundingBox::eq.

Parameters:
aBox a bounding box

Definition at line 769 of file BoundingBox.H.

References eq().

std::istream & qgar::BoundingBox::read std::istream &  anInStream  )  [virtual]
 

Deserializes the current box from an input stream.

A serialized bounding box is represented as:

   BoundingBox(<TOP LEFT CORNER>)(<BOTTOM RIGHT CORNER>)

Parameters:
anInStream the input stream

Implements qgar::ISerializable.

Definition at line 601 of file BoundingBox.C.

References qgar::qgReadObjData(), qgar::qgReadObjName(), and setCorners().

void qgar::BoundingBox::setBottomRight int  aX,
int  aY
throw (QgarErrorDomain)
 

Set bottom right corner using X and Y coordinates.

Parameters:
aX X coordinate
aY Y coordinate
Warning:
If the new corner does not match the current top left corner, the function raises an exception.
Exceptions:
qgar::QgarErrorDomain (new corner does not fit box)

Definition at line 330 of file BoundingBox.C.

void qgar::BoundingBox::setBottomRight const GenPoint< int > &  aPt  )  throw (QgarErrorDomain)
 

Set bottom right corner using a point.

Parameters:
aPt a point
Warning:
If the new corner (point aPt) does not match the current top left corner, the function raises an exception.
Exceptions:
qgar::QgarErrorDomain (new corner does not fit box)

Definition at line 304 of file BoundingBox.C.

void qgar::BoundingBox::setCorners int  aX1,
int  aY1,
int  aX2,
int  aY2
 

Set both top left and bottom right corners from coordinates of two points.

The two given points are supposed to be two opposite corners (top left and bottom right, or top right and bottom left) of the resulting bounding box. The corresponding coordinates of top left and bottom right corners are automatically computed.

Parameters:
aX1 X coordinate of first corner
aY1 Y coordinate of first corner
aX2 X coordinate of second corner
aY2 Y coordinate of second corner

Definition at line 419 of file BoundingBox.C.

References _bottomRight, _topLeft, and qgar::GenPoint< T >::setXY().

void qgar::BoundingBox::setCorners const GenPoint< int > &  aPt1,
const GenPoint< int > &  aPt2
 

Set both top left and bottom right corners from two points.

The two given points, aPt1 and aPt2, are supposed to be two opposite corners (top left and bottom right, or top right and bottom left) of the resulting bounding box. The corresponding coordinates of top left and bottom right corners are automatically computed.

Parameters:
aPt1 a point
aPt2 a point

Definition at line 410 of file BoundingBox.C.

References qgar::GenPoint< T >::x(), and qgar::GenPoint< T >::y().

Referenced by BoundingBox(), and read().

void qgar::BoundingBox::setTopLeft int  aX,
int  aY
throw (QgarErrorDomain)
 

Set top left corner using X and Y coordinates.

Parameters:
aX X coordinate
aY Y coordinate
Warning:
If the new corner does not match the current bottom right corner, the function raises an exception.
Exceptions:
qgar::QgarErrorDomain (new corner does not fit box)

Definition at line 223 of file BoundingBox.C.

void qgar::BoundingBox::setTopLeft const GenPoint< int > &  aPt  )  throw (QgarErrorDomain)
 

Set top left corner using a point.

Parameters:
aPt a point
Warning:
If the new corner (point aPt) does not match the current bottom right corner, the function raises an exception.
Exceptions:
qgar::QgarErrorDomain (new corner does not fit box)

Definition at line 197 of file BoundingBox.C.

void qgar::BoundingBox::setXBottomRight int  aX  )  throw (QgarErrorDomain)
 

Set X coordinate of bottom right corner.

Parameters:
aX X coordinate
Warning:
If the new corner does not match the top left corner, the function raises an exception.
Exceptions:
qgar::QgarErrorDomain (new corner does not fit box)

Definition at line 356 of file BoundingBox.C.

void qgar::BoundingBox::setXTopLeft int  aX  )  throw (QgarErrorDomain)
 

Set X coordinate of top left corner.

Parameters:
aX X coordinate
Warning:
If the new corner does not match the current bottom right corner, the function raises an exception.
Exceptions:
qgar::QgarErrorDomain (new corner does not fit box)

Definition at line 250 of file BoundingBox.C.

void qgar::BoundingBox::setYBottomRight int  aY  )  throw (QgarErrorDomain)
 

Set Y coordinate of bottom right corner.

Parameters:
aY Y coordinate
Warning:
If the new corner does not match the current top left corner, the function raises an exception.
Exceptions:
qgar::QgarErrorDomain (new corner does not fit box)

Definition at line 383 of file BoundingBox.C.

void qgar::BoundingBox::setYTopLeft int  aY  )  throw (QgarErrorDomain)
 

Set Y coordinate of top left corner.

Parameters:
aY Y coordinate
Warning:
If the new corner does not match the current top left corner, the function raises an exception.
Exceptions:
qgar::QgarErrorDomain (new corner does not fit box)

Definition at line 277 of file BoundingBox.C.

GenPoint< int > qgar::BoundingBox::topLeft  )  const [inline]
 

Get a copy of the top left corner.

Definition at line 631 of file BoundingBox.H.

References _topLeft.

Referenced by contains(), eq(), and notEq().

int qgar::BoundingBox::width  )  const [inline]
 

Get width.

Warning:
As the pixels of the borders belong to the box, the width is $ X_{bottom-right-corner} - X_{top-left-corner} + 1 $

Definition at line 713 of file BoundingBox.H.

References _bottomRight, _topLeft, and qgar::GenPoint< T >::x().

Referenced by length(), and qgar::TTBinaryImage::TTBinaryImage().

std::ostream & qgar::BoundingBox::write std::ostream &  anOutStream  )  const [virtual]
 

Serializes the current box to an input stream.

A serialized bounding boxi is represented as:

   BoundingBox(<TOP LEFT CORNER>)(<BOTTOM RIGHT CORNER>)

Parameters:
anOutStream the output stream

Implements qgar::ISerializable.

Definition at line 616 of file BoundingBox.C.

References _bottomRight, and _topLeft.

int qgar::BoundingBox::xBottomRight  )  const [inline]
 

Get X coordinate of bottom right corner.

Definition at line 681 of file BoundingBox.H.

References _bottomRight, and qgar::GenPoint< T >::x().

Referenced by qgar::GenImage< T, CheckPolicy >::GenImage(), intersection(), intersects(), qgar::Component::PRIVATEcomputeContour(), qgar::TgifFile::write(), and qgar::DxfFile::write().

int qgar::BoundingBox::xTopLeft  )  const [inline]
 

Get X coordinate of top left corner.

Definition at line 663 of file BoundingBox.H.

References _topLeft, and qgar::GenPoint< T >::x().

Referenced by qgar::GenImage< T, CheckPolicy >::GenImage(), intersection(), intersects(), qgar::Component::PRIVATEcomputeContour(), qgar::TTBinaryImage::TTBinaryImage(), qgar::TgifFile::write(), and qgar::DxfFile::write().

int qgar::BoundingBox::yBottomRight  )  const [inline]
 

Get Y coordinate of bottom right corner.

Definition at line 690 of file BoundingBox.H.

References _bottomRight, and qgar::GenPoint< T >::y().

Referenced by qgar::GenImage< T, CheckPolicy >::GenImage(), intersection(), intersects(), qgar::Component::PRIVATEcomputeContour(), qgar::TgifFile::write(), and qgar::DxfFile::write().

int qgar::BoundingBox::yTopLeft  )  const [inline]
 

Get Y coordinate of top left corner.

Definition at line 672 of file BoundingBox.H.

References _topLeft, and qgar::GenPoint< T >::y().

Referenced by qgar::GenImage< T, CheckPolicy >::GenImage(), intersection(), intersects(), qgar::Component::PRIVATEcomputeContour(), qgar::TgifFile::write(), and qgar::DxfFile::write().


Member Data Documentation

GenPoint<int> qgar::BoundingBox::_bottomRight [protected]
 

Bottom right corner.

Definition at line 596 of file BoundingBox.H.

Referenced by accessBottomRight(), bottomRight(), contains(), eq(), height(), intersection(), intersects(), notEq(), operator=(), setCorners(), width(), write(), xBottomRight(), and yBottomRight().

GenPoint<int> qgar::BoundingBox::_topLeft [protected]
 

Top left corner.

Definition at line 591 of file BoundingBox.H.

Referenced by accessTopLeft(), contains(), eq(), height(), intersection(), intersects(), notEq(), operator=(), setCorners(), topLeft(), width(), write(), xTopLeft(), and yTopLeft().


The documentation for this class was generated from the following files: