libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
crn::Rect Class Reference

A rectangle class. More...

#include <CRNRect.h>

+ Inheritance diagram for crn::Rect:
+ Collaboration diagram for crn::Rect:

Classes

class  AreaSorter
 Functor to sort rectangles regarding surfaces. More...
 
struct  BitwiseCompare
 Functor to sort Rects in sets and maps. More...
 
class  HeightSorter
 Functor to sort rectangles regarding surfaces. More...
 
class  HorizontalStretchingSorter
 Functor to sort rectangles regarding horizontal stretching values. More...
 
class  InclusionSorter
 Functor to sort rectangles by inclusion. More...
 
class  iterator
 iterator for a Rect More...
 
class  OrthogonalSorter
 Functor to sort rectangles regarding orthogonal directions. More...
 
class  Sorter
 Functor to sort rectangles regarding directions. More...
 
class  spiral_iterator
 Spiral iterator for a Rect. More...
 

Public Types

using Set = std::set< Rect, Rect::BitwiseCompare >
 A set of Rects. More...
 

Public Member Functions

 Rect () noexcept
 Dummy constructor. DO NOT USE. More...
 
 Rect (int begX, int begY, int endX, int endY) noexcept
 Rectangle constructor. More...
 
 Rect (int x, int y) noexcept
 Rectangle constructor. More...
 
 Rect (const Point2DInt &p) noexcept
 Rectangle constructor. More...
 
 Rect (const Rect &)=default
 
 Rect (Rect &&)=default
 
virtual ~Rect () override=default
 
Rectoperator= (const Rect &)=default
 
Rectoperator= (Rect &&)=default
 
bool operator== (const Rect &r) const noexcept
 Checks if two rectangles are identical. More...
 
bool operator!= (const Rect &r) const noexcept
 Checks if two rectangles are different. More...
 
bool IsValid () const noexcept
 Returns whether the rect is valid. More...
 
int GetLeft () const
 Returns the leftmost coordinate. More...
 
int GetRight () const
 Returns the rightmost coordinate. More...
 
int GetTop () const
 Returns the topmost coordinate. More...
 
int GetBottom () const
 Returns the bottommost coordinate. More...
 
int GetWidth () const
 Returns the width of the rectangle. More...
 
int GetHeight () const
 Returns the height of the rectangle. More...
 
Point2DInt GetTopLeft () const
 Returns the top-left coordinates. More...
 
Point2DInt GetBottomRight () const
 Returns the bottom-right coordinates. More...
 
Point2DInt GetCenter () const
 Returns the center coordinates. More...
 
int GetCenterX () const
 Returns the horizontal center coordinate. More...
 
int GetCenterY () const
 Returns the vertical center coordinate. More...
 
unsigned int GetArea () const noexcept
 Returns the area of the rectangle. More...
 
unsigned int GetPerimeter () const noexcept
 Returns the perimeter of the rectangle. More...
 
int SetLeft (int begX) noexcept
 Changes the leftmost coordinate. More...
 
int SetRight (int endX) noexcept
 Changes the rightmost coordinate. More...
 
int SetTop (int begY) noexcept
 Changes the topmost coordinate. More...
 
int SetBottom (int endY) noexcept
 Changes the bottommost coordinate. More...
 
int SetWidth (int wid)
 Changes the width of the rectangle. More...
 
int SetHeight (int hei)
 Changes the height of the rectangle. More...
 
int Overlap (const Rect &r, Orientation orientation) const
 Compute overlap in a given orientation. More...
 
Rect operator& (const Rect &r) const
 Computes the intersection of two rectangles. More...
 
Rect operator| (const Rect &r) const
 Computes the union of two rectangles. More...
 
void operator&= (const Rect &r)
 Keeps only the intersecting part with another rectangle. More...
 
void operator|= (const Rect &r)
 Merges with another rectangle. More...
 
bool Contains (int x, int y) const noexcept
 Checks if the rectangle contains a point. More...
 
bool Contains (const Rect &rct) const
 Checks if the rectangle contains another rectangle. More...
 
const Rectoperator*= (double s)
 Scales the rectangle. More...
 
Rect operator* (double s) const
 Creates a scaled rectangle. More...
 
void Translate (int x, int y)
 Translates the rectangle. More...
 
template<class ITER >
std::vector< RectFindIncluded (ITER it_begin, ITER it_end)
 Get the rectangles included in this. More...
 
template<class ITER >
std::vector< RectFindIntersecting (ITER it_begin, ITER it_end, double ratio=0)
 Get the rectangles intersecting significantly this from a collection. More...
 
String ToString () const
 Dumps to a string. More...
 
iterator begin () const
 Returns an iterator to the first point of the rectangle. More...
 
iterator end () const
 Returns an iterator after the last point of the rectangle. More...
 
iterator cbegin () const
 Returns an iterator to the first point of the rectangle. More...
 
iterator cend () const
 Returns an iterator after the last point of the rectangle. More...
 
spiral_iterator SBegin () const
 Returns an spiral iterator to the first point of the rectangle. More...
 
spiral_iterator SEnd () const
 Returns an spiral iterator after the last point of the rectangle. More...
 
void Deserialize (xml::Element &el)
 Initializes the object from an XML element. Unsafe. More...
 
xml::Element Serialize (xml::Element &parent) const
 Dumps the object to an XML element. Unsafe. More...
 
- Public Member Functions inherited from crn::Object
virtual ~Object ()=default
 

Static Public Member Functions

template<class ITER >
static Rect SmallestRectEmbedding (ITER it_begin, ITER it_end)
 Get the smallest rectangle embedding a collection of rectangles. More...
 
template<class ITER >
static int MedianWidth (ITER it_begin, ITER it_end)
 Get median width value for a collection of rectangles. More...
 
template<class ITER >
static int MedianHeight (ITER it_begin, ITER it_end)
 Get median height value for a collection of rectangles. More...
 
template<class ITER >
static double MeanWidth (ITER it_begin, ITER it_end)
 Get average width value for a collection of rectangles. More...
 
template<class ITER >
static double MeanHeight (ITER it_begin, ITER it_end)
 Get median height value for a collection of rectangles. More...
 
template<class ITER >
static std::vector< RectFindClosestsToBorder (ITER it_begin, ITER it_end, Direction drt)
 Get rectangles closest to border in a direction from a collection of rectangles. More...
 
static Set EmptySet ()
 Creates an empty set of Rects. More...
 

Detailed Description

A rectangle class.

class CRNRect Convenience rectangle class. Uses signed int.

Author
Yann LEYDIER
Date
August 2006
Version
0.1

Definition at line 46 of file CRNRect.h.

Member Typedef Documentation

A set of Rects.

Definition at line 715 of file CRNRect.h.

Constructor & Destructor Documentation

crn::Rect::Rect ( )
inlinenoexcept

Dummy constructor. DO NOT USE.

Definition at line 50 of file CRNRect.h.

crn::Rect::Rect ( int  begX,
int  begY,
int  endX,
int  endY 
)
inlinenoexcept

Rectangle constructor.

Rectangle constructor.

Parameters
[in]begXleftmost coordinate
[in]begYtopmost coordinate
[in]endXrightmost coordinate
[in]endYbottommost coordinate

Definition at line 61 of file CRNRect.h.

crn::Rect::Rect ( int  x,
int  y 
)
inlinenoexcept

Rectangle constructor.

Point-rectangle constructor.

Parameters
[in]xabscissa coordinate
[in]yordinate coordinate

Definition at line 71 of file CRNRect.h.

crn::Rect::Rect ( const Point2DInt p)
inlinenoexcept

Rectangle constructor.

Point-rectangle constructor.

Parameters
[in]pa point

Definition at line 79 of file CRNRect.h.

crn::Rect::Rect ( const Rect )
default
crn::Rect::Rect ( Rect &&  )
default
virtual crn::Rect::~Rect ( )
overridevirtualdefault

Member Function Documentation

iterator crn::Rect::begin ( ) const
inline

Returns an iterator to the first point of the rectangle.

Definition at line 746 of file CRNRect.h.

iterator crn::Rect::cbegin ( ) const
inline

Returns an iterator to the first point of the rectangle.

Definition at line 750 of file CRNRect.h.

iterator crn::Rect::cend ( ) const
inline

Returns an iterator after the last point of the rectangle.

Definition at line 752 of file CRNRect.h.

bool Rect::Contains ( int  x,
int  y 
) const
noexcept

Checks if the rectangle contains a point.

Checks if the rectangle contains a point

Parameters
[in]xthe abscissa
[in]ythe ordinate
Returns
true if the point is inside the rectangle, false else

Definition at line 514 of file CRNRect.cpp.

bool Rect::Contains ( const Rect rct) const

Checks if the rectangle contains another rectangle.

Checks if the rectangle contains another rectangle

Parameters
[in]rctthe possibly contained rectangle
Returns
true if the candidate is inside the rectangle, false else

Definition at line 533 of file CRNRect.cpp.

void Rect::Deserialize ( xml::Element el)

Initializes the object from an XML element. Unsafe.

Initializes the object from an XML element. Unsafe.

Exceptions
ExceptionInvalidArgumentnot a Rect
Parameters
[in]elthe XML element to read

Definition at line 550 of file CRNRect.cpp.

static Set crn::Rect::EmptySet ( )
inlinestatic

Creates an empty set of Rects.

Definition at line 717 of file CRNRect.h.

iterator crn::Rect::end ( ) const
inline

Returns an iterator after the last point of the rectangle.

Definition at line 748 of file CRNRect.h.

template<class ITER >
static std::vector<Rect> crn::Rect::FindClosestsToBorder ( ITER  it_begin,
ITER  it_end,
Direction  drt 
)
inlinestatic

Get rectangles closest to border in a direction from a collection of rectangles.

Get rectangles closest to border in a given direction from a collection of rectangles

Parameters
[in]it_beginThe iterator pointing to the begining of the collection
[in]it_endThe iterator pointing to the end of the collection
[in]drtThe reference direction
Returns
A vector of minimal rectangles for direction

Definition at line 367 of file CRNRect.h.

template<class ITER >
std::vector<Rect> crn::Rect::FindIncluded ( ITER  it_begin,
ITER  it_end 
)
inline

Get the rectangles included in this.

Get the rectangles included in this

Parameters
[in]it_beginThe iterator pointing to the begining of the collection
[in]it_endThe iterator pointing to the end of the collection
Returns
A vector of rectangles included

Definition at line 485 of file CRNRect.h.

template<class ITER >
std::vector<Rect> crn::Rect::FindIntersecting ( ITER  it_begin,
ITER  it_end,
double  ratio = 0 
)
inline

Get the rectangles intersecting significantly this from a collection.

Get the rectangles intersecting significantly this from a collection

Parameters
[in]it_beginThe iterator pointing to the begining of the collection
[in]it_endThe iterator pointing to the end of the collection
[in]ratioThe intersection significance threshold
Returns
A vector of rectangles intersecting

Definition at line 515 of file CRNRect.h.

unsigned int crn::Rect::GetArea ( ) const
inlinenoexcept

Returns the area of the rectangle.

Definition at line 142 of file CRNRect.h.

int crn::Rect::GetBottom ( ) const
inline

Returns the bottommost coordinate.

Exceptions
ExceptionUninitializedthe rectangle is not properly initialized

Definition at line 111 of file CRNRect.h.

Point2DInt crn::Rect::GetBottomRight ( ) const
inline

Returns the bottom-right coordinates.

Exceptions
ExceptionUninitializedthe rectangle is not properly initialized

Definition at line 127 of file CRNRect.h.

Point2DInt crn::Rect::GetCenter ( ) const
inline

Returns the center coordinates.

Exceptions
ExceptionUninitializedthe rectangle is not properly initialized

Definition at line 131 of file CRNRect.h.

int crn::Rect::GetCenterX ( ) const
inline

Returns the horizontal center coordinate.

Exceptions
ExceptionUninitializedthe rectangle is not properly initialized

Definition at line 135 of file CRNRect.h.

int crn::Rect::GetCenterY ( ) const
inline

Returns the vertical center coordinate.

Exceptions
ExceptionUninitializedthe rectangle is not properly initialized

Definition at line 139 of file CRNRect.h.

int crn::Rect::GetHeight ( ) const
inline

Returns the height of the rectangle.

Exceptions
ExceptionUninitializedthe rectangle is not properly initialized

Definition at line 119 of file CRNRect.h.

int crn::Rect::GetLeft ( ) const
inline

Returns the leftmost coordinate.

Exceptions
ExceptionUninitializedthe rectangle is not properly initialized

Definition at line 99 of file CRNRect.h.

unsigned int crn::Rect::GetPerimeter ( ) const
inlinenoexcept

Returns the perimeter of the rectangle.

Definition at line 144 of file CRNRect.h.

int crn::Rect::GetRight ( ) const
inline

Returns the rightmost coordinate.

Exceptions
ExceptionUninitializedthe rectangle is not properly initialized

Definition at line 103 of file CRNRect.h.

int crn::Rect::GetTop ( ) const
inline

Returns the topmost coordinate.

Exceptions
ExceptionUninitializedthe rectangle is not properly initialized

Definition at line 107 of file CRNRect.h.

Point2DInt crn::Rect::GetTopLeft ( ) const
inline

Returns the top-left coordinates.

Exceptions
ExceptionUninitializedthe rectangle is not properly initialized

Definition at line 123 of file CRNRect.h.

int crn::Rect::GetWidth ( ) const
inline

Returns the width of the rectangle.

Exceptions
ExceptionUninitializedthe rectangle is not properly initialized

Definition at line 115 of file CRNRect.h.

bool crn::Rect::IsValid ( ) const
inlinenoexcept

Returns whether the rect is valid.

Definition at line 94 of file CRNRect.h.

template<class ITER >
static double crn::Rect::MeanHeight ( ITER  it_begin,
ITER  it_end 
)
inlinestatic

Get median height value for a collection of rectangles.

Get median height value for a collection of rectangles

Parameters
[in]it_beginThe iterator pointing to the begining of the collection
[in]it_endThe iterator pointing to the end of the collection
Returns
The median height value as a double number

Definition at line 344 of file CRNRect.h.

template<class ITER >
static double crn::Rect::MeanWidth ( ITER  it_begin,
ITER  it_end 
)
inlinestatic

Get average width value for a collection of rectangles.

Get median width value for a collection of rectangles

Parameters
[in]it_beginThe iterator pointing to the begining of the collection
[in]it_endThe iterator pointing to the end of the collection
Returns
The average width value as a double number

Definition at line 322 of file CRNRect.h.

template<class ITER >
static int crn::Rect::MedianHeight ( ITER  it_begin,
ITER  it_end 
)
inlinestatic

Get median height value for a collection of rectangles.

Get median height value for a collection of rectangles

Parameters
[in]it_beginThe iterator pointing to the begining of the collection
[in]it_endThe iterator pointing to the end of the collection
Returns
The median height value as a double number

Definition at line 306 of file CRNRect.h.

template<class ITER >
static int crn::Rect::MedianWidth ( ITER  it_begin,
ITER  it_end 
)
inlinestatic

Get median width value for a collection of rectangles.

Get median width value for a collection of rectangles

Parameters
[in]it_beginThe iterator pointing to the begining of the collection
[in]it_endThe iterator pointing to the end of the collection
Returns
The median width value as a double number

Definition at line 290 of file CRNRect.h.

bool Rect::operator!= ( const Rect r) const
noexcept

Checks if two rectangles are different.

Checks if two rectangles are different

Parameters
[in]rThe rectangle to check
Returns
true if different, false else

Definition at line 56 of file CRNRect.cpp.

Rect Rect::operator& ( const Rect r) const

Computes the intersection of two rectangles.

Computes the intersection of two rectangles

Parameters
[in]rThe rectangle to intersect
Returns
The intersecting rectangle

Definition at line 74 of file CRNRect.cpp.

void Rect::operator&= ( const Rect r)

Keeps only the intersecting part with another rectangle.

Keeps only the intersecting part with another rectangle

Parameters
[in]rThe intersecting rectangle

Definition at line 147 of file CRNRect.cpp.

Rect Rect::operator* ( double  s) const

Creates a scaled rectangle.

Creates a scaled rectangle

Exceptions
ExceptionUninitializeduninitialized rectangle
ExceptionInvalidArgumentnegative scale
Parameters
[in]sthe scale
Returns
a new rectangle

Definition at line 460 of file CRNRect.cpp.

const Rect & Rect::operator*= ( double  s)

Scales the rectangle.

Scales the rectangle

Exceptions
ExceptionUninitializeduninitialized rectangle
ExceptionInvalidArgumentnegative scale
Parameters
[in]sthe scale
Returns
a new rectangle

Definition at line 436 of file CRNRect.cpp.

Rect& crn::Rect::operator= ( const Rect )
default
Rect& crn::Rect::operator= ( Rect &&  )
default
bool Rect::operator== ( const Rect r) const
noexcept

Checks if two rectangles are identical.

Checks if two rectangles are identical

Parameters
[in]rThe rectangle to check
Returns
true if identical, false else

Definition at line 38 of file CRNRect.cpp.

Rect Rect::operator| ( const Rect r) const

Computes the union of two rectangles.

Computes the union of two rectangles

Parameters
[in]rThe rectangle to unite
Returns
The union rectangle

Definition at line 124 of file CRNRect.cpp.

void Rect::operator|= ( const Rect r)

Merges with another rectangle.

Merges with another rectangle

Parameters
[in]rThe rectangle to merge

Definition at line 178 of file CRNRect.cpp.

int Rect::Overlap ( const Rect r,
Orientation  orientation 
) const

Compute overlap in a given orientation.

Computes overlap of with another rectangle in a given orientation

Exceptions
ExceptionInvalidArgumentno orientation given
Parameters
[in]rThe other rectangle
[in]orientationthe orientation in which the overlapping is considered
Returns
The overlap length if result>0, or the distance between the rectangles if result<0

Definition at line 101 of file CRNRect.cpp.

spiral_iterator crn::Rect::SBegin ( ) const
inline

Returns an spiral iterator to the first point of the rectangle.

Definition at line 792 of file CRNRect.h.

spiral_iterator crn::Rect::SEnd ( ) const
inline

Returns an spiral iterator after the last point of the rectangle.

Definition at line 794 of file CRNRect.h.

xml::Element Rect::Serialize ( xml::Element parent) const

Dumps the object to an XML element. Unsafe.

Dumps the object to an XML element. Unsafe.

Parameters
[in]parentthe element in which the new element will be stored
Returns
the newly created element

Definition at line 579 of file CRNRect.cpp.

int crn::Rect::SetBottom ( int  endY)
inlinenoexcept

Changes the bottommost coordinate.

Definition at line 194 of file CRNRect.h.

int crn::Rect::SetHeight ( int  hei)
inline

Changes the height of the rectangle.

Exceptions
ExceptionUninitializedthe rectangle is not properly initialized

Definition at line 221 of file CRNRect.h.

int crn::Rect::SetLeft ( int  begX)
inlinenoexcept

Changes the leftmost coordinate.

Definition at line 152 of file CRNRect.h.

int crn::Rect::SetRight ( int  endX)
inlinenoexcept

Changes the rightmost coordinate.

Definition at line 166 of file CRNRect.h.

int crn::Rect::SetTop ( int  begY)
inlinenoexcept

Changes the topmost coordinate.

Definition at line 180 of file CRNRect.h.

int crn::Rect::SetWidth ( int  wid)
inline

Changes the width of the rectangle.

Exceptions
ExceptionUninitializedthe rectangle is not properly initialized

Definition at line 210 of file CRNRect.h.

template<class ITER >
static Rect crn::Rect::SmallestRectEmbedding ( ITER  it_begin,
ITER  it_end 
)
inlinestatic

Get the smallest rectangle embedding a collection of rectangles.

Get the smallest rectangle embedding a collection of rectangles

Parameters
[in]it_beginThe iterator pointing to the begining of the collection
[in]it_endThe iterator pointing to the end of the collection
Returns
The enbedding rectangle

Definition at line 262 of file CRNRect.h.

String Rect::ToString ( ) const

Dumps to a string.

Creates a string with the coordiantes of the rectangle

Returns
the string

Definition at line 206 of file CRNRect.cpp.

void Rect::Translate ( int  x,
int  y 
)

Translates the rectangle.

Translates the rectangle

Exceptions
ExceptionUninitializedthe rectangle is not properly initialized
Parameters
[in]xthe x translation term
[in]ythe y translation term

Definition at line 598 of file CRNRect.cpp.


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