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

qgar::Component Class Reference
[Connected components]

#include <qgarlib/Component.H>

List of all members.


Detailed Description

A (connected) component.

Representation of a component:

Author:
Gérald Masini
Date:
Mar 17, 2004 17:17
Since:
Qgar 2.1

Definition at line 88 of file Component.H.

Labels

label_type label () const
 Get component label.
label_type inLabel () const
 Get label of comprising component.
static const label_type _MAX_LABEL = std::numeric_limits<Component::label_type>::max()
 Maximum label.
static const label_type _NO_LABEL = -1
 Label to express that an object is not yet labelled.

Public Types

Types related to a component
typedef short label_type
 Type of a component label.

Public Member Functions

Constructors
 Component ()
 Default constructor.
 Component (GenImage< label_type > *aPCompImg, int aLabel, int anInLabel, QGEbw aBW, int aXTopLeftPix, int aYTopLeftPix, int aXTopLeft, int aYTopLeft, int aXBottomRight, int aYBottomRight, int anAreaPixels)
 Create from full data.
 Component (const Component &aCComp)
 Copy constructor.
Destructor
virtual ~Component ()
 Virtual destructor.
Color
QGEbw color () const
 Get color.
Coordinates
int xTopLeftPix () const
 Get X coordinate of the top left pixel of the component.
int yTopLeftPix () const
 Get Y coordinate of the top left pixel of the component.
const BoundingBoxaccessBoundingBox () const
 Get bounding box.
BoundingBox boundingBox () const
 Get a copy of the bounding box.
double densityBox () const
 Get density with regard to the bounding box.
Area
int areaPixels () const
 Get component area (in pixels).
Access to the MAER (Minimum-Area Encasing Rectangle)
const MaeraccessMaer ()
 Get the MAER.
Maer maer ()
 Get a copy of the MAER.
int maerAreaPixels ()
 Get MAER area in pixels.
double densityMaer ()
 Get density with regard to the MAER.
Contour
const std::list< DPoint > & accessContour ()
 Get a pointer to the component contour.
std::list< DPointcontour ()
 Get a copy of the component contour.
Operators
Componentoperator= (const Component &aCComp)
 Assignment.

Protected Attributes

Pixel map of the corresponding component image
GenImage< label_type > * _pCompImg
 Pointer to the corresponding component image.
Labels
label_type _label
 Label of the component.
label_type _inLabel
 Label of the comprising component.
Color
QGEbw _color
 Color.
Coordinates
int _xTopLeftPix
 X coordinate of the top left pixel of the component.
int _yTopLeftPix
 Y coordinate of the top left pixel of the component.
BoundingBox _boundingBox
 Bounding box.
Area
int _areaPixels
 Component effective area (in pixels).
MAER (Minimum-Area Encasing Rectangle)
Maer_maer
 Minimum-Area Enclosing Rectangle (MAER).
int _maerAreaPixels
 Minimum-Area Enclosing Rectangle (MAER).
Contour
std::list< DPoint_contour
 List of the points of the contour component.

Private Member Functions

Auxiliary functions
void PRIVATEcomputeContour ()
 Compute the external contour (hull) of the component.
void PRIVATEcomputeMaer ()
 Compute the MAER (Minimum-Area Encasing Rectangle).

Static Private Attributes

Tables to compute coordinates during contour following
  +---+---+---+
  |   | 1 | 2 |
  +---+---+---+
  | 7 | *-->3 |
  +---+---+---+
  | 6 | 5 | 4 |
  +---+---+---+

The outside of the component is always on the left when moving along the contour direction. The figure above gives an example: when following a contour in the EAST direction, the first new possible contour point (1) is at NORTH of the current point (*), the second (2) at NORTH-EAST, and so on.

             new contour directions (see table _s_new_dir)
             W   NW  N   NE  E   SE  S   SW  W   NW  N   NE  E   SE
 
  indexes    0   1   2   3   4   5   6   7   8   9   10  11  12  13
           +---+---+---+---+---+---+---+---+---+---+---+---+---+---+
_s_incr_x  | -1| -1| 0 | 1 | 1 | 1 | 0 | -1| -1| -1| 0 | 1 | 1 | 1 |
           +---+---+---+---+---+---+---+---+---+---+---+---+---+---+
           +---+---+---+---+---+---+---+---+---+---+---+---+---+---+
_s_incr_y  | 0 | -1| -1| -1| 0 | 1 | 1 | 1 | 0 | -1| -1| -1| 0 | 1 |
           +---+---+---+---+---+---+---+---+---+---+---+---+---+---+
             N   NE  E   SE  S   SW  W   NW
             entries corresponding to current contour directions

The _s_incr_x (resp. y) table (see figure above) contains the X (resp. Y) increment to get the X (resp. Y) coordinates of the 7 possible next contour points (points 1 to 7 on 1st figure) from the X (resp. Y) coordinate of the current point (*). The current contour direction (EAST on 1st figure) determines the first index to enter the tables.

             new contour directions
             W   NW  N   NE  E   SE  S   SW  W   NW  N   NE  E   SE
           +---+---+---+---+---+---+---+---+---+---+---+---+---+---+
_s_new_dir | 6 | 7 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 0 | 1 | 2 | 3 |
           +---+---+---+---+---+---+---+---+---+---+---+---+---+---+

Once a new contour point is found, table _s_new_dir gives the corresponding new contour direction, using the index corresponding to the new contour point in table _s_incr_x or _s_incr_y.

static const int _s_incr_x [14]
 Table for X coordinates increments.
static const int _s_incr_y [14]
 Table for Y coordinates increments.
static const int _s_new_dir [14]
 Table for new contour directions.


Member Typedef Documentation

typedef short qgar::Component::label_type
 

Type of a component label.

Definition at line 102 of file Component.H.


Constructor & Destructor Documentation

qgar::Component::Component  ) 
 

Default constructor.

Definition at line 158 of file Component.C.

qgar::Component::Component GenImage< label_type > *  aPCompImg,
int  aLabel,
int  anInLabel,
QGEbw  aBW,
int  aXTopLeftPix,
int  aYTopLeftPix,
int  aXTopLeft,
int  aYTopLeft,
int  aXBottomRight,
int  aYBottomRight,
int  anAreaPixels
 

Create from full data.

Parameters:
aPCompImg pointer to the corresponding component image
aLabel label
anInLabel label of comprising component
aBW color (black or white)
aXTopLeftPix X coordinate of the top left pixel
aYTopLeftPix Y coordinate of the top left pixel
aXTopLeft top left X coordinate of the bounding box
aYTopLeft top left Y coordinate of the bounding box
aXBottomRight bottom right X coordinate of the bounding box
aYBottomRight bottom right Y coordinate of the bounding box
anAreaPixels area (in pixels)

qgar::Component::Component const Component aCComp  ) 
 

Copy constructor.

Parameters:
aCComp a connected component
Warning:
Perform a deep copy: The whole data of the given connected component is duplicated.

Definition at line 193 of file Component.C.

References _maer.

qgar::Component::~Component  )  [virtual]
 

Virtual destructor.

Definition at line 219 of file Component.C.

References _maer.


Member Function Documentation

const BoundingBox & qgar::Component::accessBoundingBox  )  const
 

Get bounding box.

Definition at line 239 of file Component.C.

References _boundingBox.

Referenced by qgar::TgifFile::PRIVATEwriteComponent(), qgar::TTBinaryImage::TTBinaryImage(), and qgar::TgifFile::write().

const std::list< DPoint > & qgar::Component::accessContour  ) 
 

Get a pointer to the component contour.

Warning:
  • The component contour is computed and stored when first accessed
  • The coordinates of the contour points are double numbers

Definition at line 342 of file Component.C.

References _contour, and PRIVATEcomputeContour().

Referenced by PRIVATEcomputeMaer(), qgar::TgifFile::PRIVATEwriteComponent(), and qgar::TgifFile::write().

const Maer & qgar::Component::accessMaer  ) 
 

Get the MAER.

Warning:
The MAER is computed and stored when first accessed.

Definition at line 282 of file Component.C.

References _maer, and PRIVATEcomputeMaer().

int qgar::Component::areaPixels  )  const [inline]
 

Get component area (in pixels).

Definition at line 644 of file Component.H.

References _areaPixels.

Referenced by qgar::TgifFile::PRIVATEwriteComponent(), and qgar::TgifFile::write().

BoundingBox qgar::Component::boundingBox  )  const
 

Get a copy of the bounding box.

Definition at line 247 of file Component.C.

References _boundingBox.

QGEbw qgar::Component::color  )  const [inline]
 

Get color.

Definition at line 614 of file Component.H.

References _color.

Referenced by qgar::TgifFile::PRIVATEwriteComponent(), qgar::TTBinaryImage::TTBinaryImage(), and qgar::TgifFile::write().

std::list< DPoint > qgar::Component::contour  ) 
 

Get a copy of the component contour.

Warning:
  • The component contour is computed and stored when first accessed
  • The coordinates of the contour points are double numbers

Definition at line 355 of file Component.C.

References _contour, and PRIVATEcomputeContour().

double qgar::Component::densityBox  )  const
 

Get density with regard to the bounding box.

The density is the ratio between the area (number of pixels) of the component and the area of its bounding box.

Definition at line 255 of file Component.C.

References _areaPixels, _boundingBox, and qgar::BoundingBox::area().

double qgar::Component::densityMaer  ) 
 

Get density with regard to the MAER.

The density is the ratio between the area (number of pixels) of the component and the area of its MAER.

Warning:
The MAER is computed and stored when first accessed.

Definition at line 321 of file Component.C.

References _areaPixels, _maer, _maerAreaPixels, and PRIVATEcomputeMaer().

Component::label_type qgar::Component::inLabel  )  const [inline]
 

Get label of comprising component.

Definition at line 602 of file Component.H.

References _inLabel.

Component::label_type qgar::Component::label  )  const [inline]
 

Get component label.

Definition at line 595 of file Component.H.

References _label.

Referenced by qgar::ConnectedComponents::PRIVATEcopyCC().

Maer qgar::Component::maer  ) 
 

Get a copy of the MAER.

Warning:
The MAER is computed and stored when first accessed.

Definition at line 295 of file Component.C.

References _maer, and PRIVATEcomputeMaer().

int qgar::Component::maerAreaPixels  ) 
 

Get MAER area in pixels.

Warning:
  • The MAER is computed and stored when first accessed.
  • The area of the MAER is calculated in the continuous 2D space and is provided by the corresponding data of the object representing the MAER: (aComponent.accessMaer())->area(), for example. As connected components are constructed in the 2D discrete space, an approximated value of the MAER area is also available in pixels.

Definition at line 308 of file Component.C.

References _maer, _maerAreaPixels, and PRIVATEcomputeMaer().

Component & qgar::Component::operator= const Component aCComp  ) 
 

Assignment.

Parameters:
aCComp connected component to be assigned

Definition at line 374 of file Component.C.

References _areaPixels, _boundingBox, _color, _inLabel, _label, _maer, _pCompImg, _xTopLeftPix, and _yTopLeftPix.

void qgar::Component::PRIVATEcomputeContour  )  [private]
 

Compute the external contour (hull) of the component.

    . . . . . . . . .    . . . . . . . . .
    . . . . * . . . .    . . . . C . . . .
    . . . * . * . . .    . . . C . C . . .
    . . * . * . * . .    . . C . * . C . .
    . * . * * * . * .    . C . * * * . C .
    . . * . * . * . .    . . C . * . C . .
    . . . * . * . . .    . . . C . C . . .
    . . . . * . . . .    . . . . C . . . .
    . . . . . . . . .    . . . . . . . . .

In the example above, '*' is a black pixel, '.' is a white pixel, and 'C' is a pixel of the resulting contour.

Definition at line 409 of file Component.C.

References _areaPixels, _boundingBox, _contour, _label, _NO_LABEL, _pCompImg, _s_incr_x, _s_incr_y, _s_new_dir, _xTopLeftPix, _yTopLeftPix, qgar::GenImage< T, CheckPolicy >::pPixMap(), qgar::GenImage< T, CheckPolicy >::width(), qgar::BoundingBox::xBottomRight(), qgar::BoundingBox::xTopLeft(), qgar::BoundingBox::yBottomRight(), and qgar::BoundingBox::yTopLeft().

Referenced by accessContour(), and contour().

void qgar::Component::PRIVATEcomputeMaer  )  [private]
 

Compute the MAER (Minimum-Area Encasing Rectangle).

Definition at line 662 of file Component.C.

References _maer, _maerAreaPixels, accessContour(), and qgar::Maer::accessVertices().

Referenced by accessMaer(), densityMaer(), maer(), and maerAreaPixels().

int qgar::Component::xTopLeftPix  )  const [inline]
 

Get X coordinate of the top left pixel of the component.

Definition at line 625 of file Component.H.

References _xTopLeftPix.

Referenced by qgar::TTBinaryImage::TTBinaryImage().

int qgar::Component::yTopLeftPix  )  const [inline]
 

Get Y coordinate of the top left pixel of the component.

Definition at line 632 of file Component.H.

References _yTopLeftPix.

Referenced by qgar::TTBinaryImage::TTBinaryImage().


Member Data Documentation

int qgar::Component::_areaPixels [protected]
 

Component effective area (in pixels).

Definition at line 429 of file Component.H.

Referenced by areaPixels(), densityBox(), densityMaer(), operator=(), and PRIVATEcomputeContour().

BoundingBox qgar::Component::_boundingBox [protected]
 

Bounding box.

Definition at line 417 of file Component.H.

Referenced by accessBoundingBox(), boundingBox(), densityBox(), operator=(), and PRIVATEcomputeContour().

QGEbw qgar::Component::_color [protected]
 

Color.

Definition at line 395 of file Component.H.

Referenced by color(), and operator=().

std::list<DPoint> qgar::Component::_contour [protected]
 

List of the points of the contour component.

Each point corresponds to a change in the current contour direction, based on 8-connexity.

Definition at line 461 of file Component.H.

Referenced by accessContour(), contour(), and PRIVATEcomputeContour().

label_type qgar::Component::_inLabel [protected]
 

Label of the comprising component.

Definition at line 383 of file Component.H.

Referenced by inLabel(), and operator=().

label_type qgar::Component::_label [protected]
 

Label of the component.

Warning:
It must be an integer number: long, short...

Definition at line 378 of file Component.H.

Referenced by label(), operator=(), and PRIVATEcomputeContour().

Maer* qgar::Component::_maer [protected]
 

Minimum-Area Enclosing Rectangle (MAER).

Definition at line 441 of file Component.H.

Referenced by accessMaer(), Component(), densityMaer(), maer(), maerAreaPixels(), operator=(), PRIVATEcomputeMaer(), and ~Component().

int qgar::Component::_maerAreaPixels [protected]
 

Minimum-Area Enclosing Rectangle (MAER).

Definition at line 446 of file Component.H.

Referenced by densityMaer(), maerAreaPixels(), and PRIVATEcomputeMaer().

const Component::label_type qgar::Component::_MAX_LABEL = std::numeric_limits<Component::label_type>::max() [static]
 

Maximum label.

Warning:
This is a static data member.

Definition at line 70 of file Component.C.

Referenced by qgar::ConnectedComponentsImpl::run().

const Component::label_type qgar::Component::_NO_LABEL = -1 [static]
 

Label to express that an object is not yet labelled.

Warning:
This is a static data member.

Definition at line 76 of file Component.C.

Referenced by qgar::ConnectedComponents::makeBinaryImg(), qgar::ConnectedComponentsImpl::mergePrevAndCurrComponents(), qgar::ConnectedComponentsImpl::nextCurrRun(), PRIVATEcomputeContour(), qgar::ConnectedComponentsImpl::run(), and qgar::ConnectedComponentsImpl::validLabel().

GenImage<label_type>* qgar::Component::_pCompImg [protected]
 

Pointer to the corresponding component image.

Definition at line 364 of file Component.H.

Referenced by operator=(), and PRIVATEcomputeContour().

const int qgar::Component::_s_incr_x [static, private]
 

Initial value:

{
  -1, 
  -1, 
   0, 
   1, 
   1, 
   1, 
   0, 
  -1, 
  -1, 
  -1, 
   0, 
   1, 
   1, 
   1  
}
Table for X coordinates increments.

Definition at line 88 of file Component.C.

Referenced by PRIVATEcomputeContour().

const int qgar::Component::_s_incr_y [static, private]
 

Initial value:

{
   0, 
  -1, 
  -1, 
  -1, 
   0, 
   1, 
   1, 
   1, 
   0, 
  -1, 
  -1, 
  -1, 
   0, 
   1  
}
Table for Y coordinates increments.

Definition at line 109 of file Component.C.

Referenced by PRIVATEcomputeContour().

const int qgar::Component::_s_new_dir [static, private]
 

Initial value:

{
  6, 
  7, 
  0, 
  1, 
  2, 
  3, 
  4, 
  5, 
  6, 
  7, 
  0, 
  1, 
  2, 
  3  
}
Table for new contour directions.

Definition at line 130 of file Component.C.

Referenced by PRIVATEcomputeContour().

int qgar::Component::_xTopLeftPix [protected]
 

X coordinate of the top left pixel of the component.

Definition at line 407 of file Component.H.

Referenced by operator=(), PRIVATEcomputeContour(), and xTopLeftPix().

int qgar::Component::_yTopLeftPix [protected]
 

Y coordinate of the top left pixel of the component.

Definition at line 412 of file Component.H.

Referenced by operator=(), PRIVATEcomputeContour(), and yTopLeftPix().


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