Ocean
|
This class implements an axis aligned 2D box object. More...
Public Types | |
typedef T | Type |
Definition of the used data type. More... | |
Public Member Functions | |
BoxT2 () | |
Creates an invalid box object. More... | |
BoxT2 (const VectorT2< T > &first, const VectorT2< T > &second) | |
Creates a new box object by two opposite corner positions. More... | |
BoxT2 (const VectorT2< T > ¢er, const T width, const T height) | |
Creates a new box object by the center position and the box's dimension. More... | |
BoxT2 (const T width, const T height, const VectorT2< T > &topLeft) | |
Creates a new box object by the center position and the box's dimension. More... | |
BoxT2 (const T left, const T top, const T right, const T bottom) | |
Creates a new box object by the four borders. More... | |
BoxT2 (const std::vector< VectorT2< T >> &points) | |
Creates a new box object by a set of points. More... | |
BoxT2 (const TriangleT2< T > &triangle) | |
Creates a new box object that covers a given triangle. More... | |
BoxT2 (const std::vector< TriangleT2< T >> &triangles) | |
Creates a new box object by a set of triangles. More... | |
BoxT2 (const VectorT2< T > *points, const size_t number) | |
Creates a new box object by a set of points. More... | |
const VectorT2< T > & | lower () const |
Returns the lower corner of this box. More... | |
const VectorT2< T > & | higher () const |
Returns the higher corner of this box. More... | |
const T & | left () const |
Returns the horizontal position of the lower corner of this box. More... | |
const T & | top () const |
Returns the vertical position of the lower corner of this box. More... | |
const T & | right () const |
Returns the horizontal position of the higher corner of this box. More... | |
const T & | bottom () const |
Returns the vertical position of the higher corner of this box. More... | |
T | width () const |
Returns the width of the box. More... | |
T | height () const |
Returns the height of the box. More... | |
VectorT2< T > | center () const |
Returns the center of this box. More... | |
T | xDimension () const |
Returns the dimension in x axis, which could e.g. More... | |
T | yDimension () const |
Returns the dimension in x axis, which could e.g. More... | |
T | area () const |
Returns the area covered by this box. More... | |
bool | isInside (const VectorT2< T > &point) const |
Returns whether a given point is inside the box. More... | |
bool | isInside (const VectorT2< T > &point, const T &epsilon) const |
Returns whether a given point is inside the box including a thin epsilon boundary. More... | |
bool | isInside (const BoxT2< T > &box) const |
Returns whether a given box is entirely inside this box. More... | |
bool | intersects (const BoxT2< T > &box) const |
Returns whether a given box intersects this one. More... | |
BoxT2< T > | intersection (const BoxT2< T > &box) const |
Returns the intersection of two boxes. More... | |
BoxT2< T > | rounded () const |
Returns this box with corners rounded to integer locations. More... | |
VectorT2< T > | corner (const unsigned int index) const |
Returns one of the four corners of this 2D box. More... | |
bool | isPoint () const |
Returns whether the box holds exactly one point. More... | |
bool | isEqual (const BoxT2< T > &box, const T epsilon=NumericT< T >::eps()) const |
Returns whether two box objects are equal up to an epsilon. More... | |
bool | isValid () const |
Returns whether the box holds valid parameters. More... | |
BoxT2< T > | operator+ (const BoxT2< T > &right) const |
Returns the combined box given by this one and a second box. More... | |
BoxT2< T > | operator+ (const TriangleT2< T > &triangle) const |
Extends this box by a triangle (by the three points of the triangle). More... | |
BoxT2< T > | operator+ (const VectorT2< T > &point) const |
Extends this box by another 2D point and returns the result. More... | |
BoxT2< T > | operator+ (const T signedBorder) const |
Extends this box by adding a border around the box. More... | |
BoxT2< T > & | operator+= (const BoxT2< T > &right) |
Adds a box to this box. More... | |
BoxT2< T > & | operator+= (const TriangleT2< T > &triangle) |
Adds a triangle (the three points of the triangle) to this box. More... | |
BoxT2< T > & | operator+= (const VectorT2< T > &point) |
Extends this box by another 2D point. More... | |
BoxT2< T > & | operator+= (const T signedBorder) |
Extends this box by adding a border around the box. More... | |
BoxT2< T > | operator* (const T factor) const |
Returns a new bounding box with scaled dimensions. More... | |
BoxT2< T > & | operator*= (const T factor) |
Scales this bounding box with a scalar factor. More... | |
BoxT2< T > | operator* (const SquareMatrixT3< T > &transformation) const |
Returns a new bounding box enclosing the transformed corners of this bounding box. More... | |
BoxT2< T > & | operator*= (const SquareMatrixT3< T > &transformation) |
Transforms this bounding box with a transformation matrix. More... | |
bool | operator== (const BoxT2< T > &right) const |
Returns whether two boxes are identical. More... | |
bool | operator!= (const BoxT2< T > &right) const |
Returns whether two boxes are not identical. More... | |
operator bool () const | |
Returns whether this box is not a default box. More... | |
bool | box2integer (const int constraintLeft, const int constraintTop, const int constraintRight, const int constraintBottom, int &intersectionLeft, int &intersectionTop, unsigned int &intersectionWidth, unsigned int &intersectionHeight) const |
Calculates the intersection of this bounding box (with floating point accuracy) and a second bounding box (with integer accuracy). More... | |
bool | box2integer (const unsigned int maximalWidth, const unsigned int maximalHeight, unsigned int &intersectionLeft, unsigned int &intersectionTop, unsigned int &intersectionWidth, unsigned int &intersectionHeight) const |
Calculates the intersection of this bounding box (with floating point accuracy) and a second bounding box (with integer accuracy). More... | |
bool | box2integer (const unsigned int maximalWidth, const unsigned int maximalHeight, const unsigned int extraBorder, unsigned int &intersectionLeft, unsigned int &intersectionTop, unsigned int &intersectionWidth, unsigned int &intersectionHeight) const |
Calculates the intersection of this bounding box (with floating point accuracy) and a second bounding box (with integer accuracy). More... | |
Protected Attributes | |
VectorT2< T > | lower_ |
Lower box corner. More... | |
VectorT2< T > | higher_ |
Higher box corner. More... | |
This class implements an axis aligned 2D box object.
T | Data type used to represent coordinates |
typedef T Ocean::BoxT2< T >::Type |
Definition of the used data type.
Ocean::BoxT2< T >::BoxT2 |
Creates an invalid box object.
Ocean::BoxT2< T >::BoxT2 | ( | const VectorT2< T > & | first, |
const VectorT2< T > & | second | ||
) |
Creates a new box object by two opposite corner positions.
first | The first 2D corner position, (-infinity, infinity)x(-infinity, infinity) |
second | The second 2D corner position (opposite to the first position), (-infinity, infinity)x(-infinity, infinity) |
Ocean::BoxT2< T >::BoxT2 | ( | const VectorT2< T > & | center, |
const T | width, | ||
const T | height | ||
) |
Creates a new box object by the center position and the box's dimension.
center | The center position of the box to create |
width | The width or horizontal dimension of the box, with range [0, infinity) |
height | The height or vertical dimension of the box, with range [0, infinity) |
Ocean::BoxT2< T >::BoxT2 | ( | const T | width, |
const T | height, | ||
const VectorT2< T > & | topLeft | ||
) |
Creates a new box object by the center position and the box's dimension.
width | The width or horizontal dimension of the box, with range [0, infinity) |
height | The height or vertical dimension of the box, with range [0, infinity) |
topLeft | The top left location of this bounding box, with range (-infinity, infinity)x(-infinity, infinity) |
Ocean::BoxT2< T >::BoxT2 | ( | const T | left, |
const T | top, | ||
const T | right, | ||
const T | bottom | ||
) |
Creates a new box object by the four borders.
left | Left box border position, with range (-infinity, infinity) |
top | Top box border position, with range (-infinity, infinity) |
right | Right box border position, with range [left, infinity) |
bottom | Bottom box border position, with range [top, infinity) |
|
explicit |
Creates a new box object by a set of points.
The resulting box will cover all given points.
If no point is provided, the resulting box will be invalid.
points | Points to create the box from, can be empty |
|
inlineexplicit |
Creates a new box object that covers a given triangle.
triangle | Triangle to create the box from |
|
explicit |
Creates a new box object by a set of triangles.
The resulting box will cover all given triangles.
If no triangle is provided, the resulting box will be invalid.
triangles | Triangles to create the box from, can be empty |
Ocean::BoxT2< T >::BoxT2 | ( | const VectorT2< T > * | points, |
const size_t | number | ||
) |
Creates a new box object by a set of points.
The resulting box will cover all given points.
If no point is provided, the resulting box will be invalid.
points | The points to create the box from, can be nullptr if number == 0 |
number | The number of given points, with range [0, infinity) |
|
inline |
Returns the area covered by this box.
The result is undefined for invalid boxes.
|
inline |
Returns the vertical position of the higher corner of this box.
bool Ocean::BoxT2< T >::box2integer | ( | const int | constraintLeft, |
const int | constraintTop, | ||
const int | constraintRight, | ||
const int | constraintBottom, | ||
int & | intersectionLeft, | ||
int & | intersectionTop, | ||
unsigned int & | intersectionWidth, | ||
unsigned int & | intersectionHeight | ||
) | const |
Calculates the intersection of this bounding box (with floating point accuracy) and a second bounding box (with integer accuracy).
The resulting intersection (with integer accuracy) will entirely enclose this floating point bounding box - unless not possible due to the given constraints e.g., 'constraintLeft', 'constraintTop', ...
If this box is invalid, than the provided integer bounding box will be returned.
constraintLeft | Most left (including) position of the resulting intersection, with range (-infinity, infinity) |
constraintTop | Most top (including) position of the resulting intersection, with range (-infinity, infinity) |
constraintRight | Most right (including) position of the resulting intersection, with range [left, infinity) |
constraintBottom | Most bottom (including) position of the resulting intersection, with range [top, infinity) |
intersectionLeft | Resulting horizontal start position of the intersection, with range [constraintLeft, constraintRight] |
intersectionTop | Resulting vertical start position of the intersection, with range [constraintTop, constraintBottom] |
intersectionWidth | Resulting width of the sub-region, with range [0, constraintRight - constraintLeft + 1] |
intersectionHeight | Resulting height of the sub-region, with range [0, constraintBottom - constraintTop + 1] |
bool Ocean::BoxT2< T >::box2integer | ( | const unsigned int | maximalWidth, |
const unsigned int | maximalHeight, | ||
const unsigned int | extraBorder, | ||
unsigned int & | intersectionLeft, | ||
unsigned int & | intersectionTop, | ||
unsigned int & | intersectionWidth, | ||
unsigned int & | intersectionHeight | ||
) | const |
Calculates the intersection of this bounding box (with floating point accuracy) and a second bounding box (with integer accuracy).
The resulting intersection (with integer accuracy) will entirely enclose this floating point bounding box - unless not possible due to the given constraints e.g., 'maximalWidth', 'maximalHeight', ...
If this box is invalid, than the provided integer bounding box will be returned.
maximalWidth | Maximal width of the sub-region, with range [0, infinity) |
maximalHeight | Maximal height of the sub-region, with range [0, infinity) |
extraBorder | Explicit border that will be added to the left, top, right and bottom borders of the resulting intersection (as long as the specified constraints 'maximalWidth' and 'maximalHeight' parameters are not violated) |
intersectionLeft | Resulting horizontal start position of the intersection, with range [0, maximalWidth - 1] |
intersectionTop | Resulting vertical start position of the intersection, with range [0, maximalHeight - 1] |
intersectionWidth | Resulting width of the sub-region, with range [0, maximalWidth] |
intersectionHeight | Resulting height of the sub-region, with range [0, maximalHeight] |
bool Ocean::BoxT2< T >::box2integer | ( | const unsigned int | maximalWidth, |
const unsigned int | maximalHeight, | ||
unsigned int & | intersectionLeft, | ||
unsigned int & | intersectionTop, | ||
unsigned int & | intersectionWidth, | ||
unsigned int & | intersectionHeight | ||
) | const |
Calculates the intersection of this bounding box (with floating point accuracy) and a second bounding box (with integer accuracy).
The resulting intersection (with integer accuracy) will entirely enclose this floating point bounding box - unless not possible due to the given constraints e.g., 'maximalWidth', 'maximalHeight', ...
If this box is invalid, than the provided integer bounding box will be returned.
Actually, this function returns box2integer(0, 0, maximalWidth - 1, maximalHeight - 1, intersectionLeft, intersectionTop, intersectionWidth, intersectionHeight)
maximalWidth | Maximal width of the resulting intersection, with range [0, infinity) |
maximalHeight | Maximal height of the resulting intersection, with range [0, infinity) |
intersectionLeft | Resulting horizontal start position of the intersection, with range [0, maximalWidth - 1] |
intersectionTop | Resulting vertical start position of the intersection, with range [0, maximalHeight - 1] |
intersectionWidth | Resulting width of the sub-region, with range [0, maximalWidth] |
intersectionHeight | Resulting height of the sub-region, with range [0, maximalHeight] |
|
inline |
Returns the center of this box.
|
inline |
Returns one of the four corners of this 2D box.
The corners have a counter-clockwise order: (left, top), (left, bottom), (right, bottom), (right top).
index | The index of the corner to return, with range [0, 3] |
|
inline |
Returns the height of the box.
|
inline |
Returns the higher corner of this box.
BoxT2< T > Ocean::BoxT2< T >::intersection | ( | const BoxT2< T > & | box | ) | const |
Returns the intersection of two boxes.
box | Second box for the intersection |
|
inline |
Returns whether a given box intersects this one.
box | The box to check |
|
inline |
Returns whether two box objects are equal up to an epsilon.
box | The box to compare with, can be invalid |
epsilon | The accuracy epsilon, with range [0, infinity) |
|
inline |
Returns whether a given box is entirely inside this box.
box | The box to check |
|
inline |
Returns whether a given point is inside the box.
point | The point to check |
|
inline |
Returns whether a given point is inside the box including a thin epsilon boundary.
point | The point to check |
epsilon | The accuracy epsilon, with range [0, infinity) |
|
inline |
Returns whether the box holds exactly one point.
|
inline |
Returns whether the box holds valid parameters.
A valid box can have a dimension of zero.
|
inline |
Returns the horizontal position of the lower corner of this box.
|
inline |
Returns the lower corner of this box.
|
inlineexplicit |
Returns whether this box is not a default box.
|
inline |
Returns whether two boxes are not identical.
right | Second box object |
|
inline |
Returns a new bounding box enclosing the transformed corners of this bounding box.
The corners of this bounding box will be transformed with a given 3x3 transformation matrix (a homography).
transformation | The transformation to be applied to each bounding box corner, must be valid |
|
inline |
Returns a new bounding box with scaled dimensions.
The corners of this bounding box will be scaled with a scalar defining new scaled corners for the new bounding box object.
This box needs to be valid.
factor | Factor that is applied to each bounding box corner, with range (-infinity, infinity) |
|
inline |
Transforms this bounding box with a transformation matrix.
The corners of the bounding box will be transformed with a given 3x3 transformation matrix (a homography).
transformation | The transformation to be applied to each bounding box corner, must be valid |
|
inline |
Scales this bounding box with a scalar factor.
The corners of this bounding box will be scaled with a scalar.
This box needs to be valid.
factor | Factor that is applied to each bounding box corner, with range (-infinity, infinity) |
BoxT2< T > Ocean::BoxT2< T >::operator+ | ( | const BoxT2< T > & | right | ) | const |
Returns the combined box given by this one and a second box.
right | Second box |
BoxT2< T > Ocean::BoxT2< T >::operator+ | ( | const T | signedBorder | ) | const |
Extends this box by adding a border around the box.
signedBorder | The size of the signed border to extend the box, a positive border increases the box; a negative border decreases the box, with range (-infinity, infinity) |
BoxT2< T > Ocean::BoxT2< T >::operator+ | ( | const TriangleT2< T > & | triangle | ) | const |
Extends this box by a triangle (by the three points of the triangle).
triangle | The triangle that extends this box |
BoxT2< T > Ocean::BoxT2< T >::operator+ | ( | const VectorT2< T > & | point | ) | const |
Extends this box by another 2D point and returns the result.
If the 2D point fits into this box the box is untouched, otherwise the dimension of the box will be extended.
point | The point to be added |
BoxT2< T > & Ocean::BoxT2< T >::operator+= | ( | const BoxT2< T > & | right | ) |
Adds a box to this box.
right | Right box to add |
BoxT2< T > & Ocean::BoxT2< T >::operator+= | ( | const T | signedBorder | ) |
Extends this box by adding a border around the box.
This box needs to be valid.
signedBorder | The size of the signed border to extend the box, a positive border increases the box; a negative border decreases the box, with range (-infinity, infinity) |
BoxT2< T > & Ocean::BoxT2< T >::operator+= | ( | const TriangleT2< T > & | triangle | ) |
Adds a triangle (the three points of the triangle) to this box.
triangle | Triangle to add |
BoxT2< T > & Ocean::BoxT2< T >::operator+= | ( | const VectorT2< T > & | point | ) |
Extends this box by another 2D point.
If the 2D point fits into this box the box is untouched, otherwise the dimension of the box will be extended.
point | Point to be added |
|
inline |
Returns whether two boxes are identical.
right | Second box object |
|
inline |
Returns the horizontal position of the higher corner of this box.
|
inline |
Returns this box with corners rounded to integer locations.
Beware: Ensure that this box is valid before calling the function.
|
inline |
Returns the vertical position of the lower corner of this box.
|
inline |
Returns the width of the box.
|
inline |
Returns the dimension in x axis, which could e.g.
be the width of this box. Beware: The result is undefined for an invalid box.
|
inline |
Returns the dimension in x axis, which could e.g.
be the height of this box. Beware: The result is undefined for an invalid box.
|
protected |
Higher box corner.
|
protected |
Lower box corner.