Data Structures | Public Types | Public Member Functions | Static Public Member Functions | Data Fields

DGtal::FreemanChain< TInteger > Class Template Reference

#include <FreemanChain.h>

Collaboration diagram for DGtal::FreemanChain< TInteger >:
Collaboration graph
[legend]

Data Structures

class  ConstIterator
struct  DefaultDrawStyle
struct  SelfDrawStyle

Public Types

typedef TInteger Integer
typedef PointVector< 2, IntegerPointI2

Public Member Functions

 ~FreemanChain ()
 FreemanChain (const std::string &s="", int x=0, int y=0)
 FreemanChain (std::istream &in)
 FreemanChain (const FreemanChain &other)
FreemanChainoperator= (const FreemanChain &other)
ConstIterator begin () const
ConstIterator end () const
unsigned int code (unsigned int pos) const
unsigned int next (unsigned int pos) const
unsigned int previous (unsigned int pos) const
unsigned int size () const
void computeBoundingBox (int &min_x, int &min_y, int &max_x, int &max_y) const
FreemanChain< TInteger >
::ConstIterator 
findQuadrantChange (OrderedAlphabet &A) const
FreemanChain< TInteger >
::ConstIterator 
findQuadrantChange4 (OrderedAlphabet &A) const
int isClosed () const
void selfDisplay (std::ostream &out) const
bool isValid () const
DrawableWithDGtalBoarddefaultStyle (std::string mode="") const
std::string styleName () const
template<typename Functor >
void selfDraw (DGtalBoard &board) const
void selfDraw (DGtalBoard &board) const

Static Public Member Functions

static void write (std::ostream &out, const FreemanChain &c)
static void read (std::istream &in, FreemanChain &c)
static void alphabet (char &aZero, char &aOne, char aQuadrant)
static unsigned int movement (unsigned int aCode1, unsigned int aCode2, bool ccw=true)
static void displacement (int &dx, int &dy, unsigned int aCode)
static PointI2 displacement (unsigned int aCode)
static unsigned int turnedCode (unsigned int aCode, bool ccw=true)
static void pointel2pixel (FreemanChain &aPixChain, std::vector< unsigned int > &aPl2pix, std::vector< unsigned int > &aPix2pl, const FreemanChain &aPlChain)
static void innerContour (FreemanChain &aInnerChain, std::vector< unsigned int > &aOuter2inner, std::vector< unsigned int > &aInner2outer, const FreemanChain &aOuterChain, bool ccw=true)
static void cleanContour (std::vector< FreemanChain > &aCleanCs, std::vector< std::pair< unsigned int, unsigned int > > &aC2clean, std::vector< std::vector< unsigned int > > &aClean2c, const FreemanChain &c, bool ccw=true)
static bool cleanOuterSpikes (FreemanChain &aCleanC, std::vector< unsigned int > &aC2clean, std::vector< unsigned int > &aClean2c, const FreemanChain &c, bool ccw=true)
static void getContourPoints (const FreemanChain &fc, std::vector< PointI2 > &aVContour)
static void movePointFromFC (PointI2 &aPoint, unsigned int aCode)

Data Fields

std::string chain
int x0
int y0

Detailed Description

template<typename TInteger>
class DGtal::FreemanChain< TInteger >

Description of class 'FreemanChain'

Aim: Describes a digital 4-connected contour as a string of '0', '1', '2', and '3' and the coordinate of the first point. When it is a loop, it is the counterclockwise boundary of the shape.

Example :

   // A Freeman chain code is a string composed by the coordinates of the first pixel, and the list of elementary displacements. 
   std::stringstream ss (stringstream::in | stringstream::out);
   ss << "0 0 00001111222233" << endl;
   
   // Construct the Freeman chain
   FreemanChain<int> fc(ss);
   
   // Compute a bounding box 
   int minX, maxX, minY, maxY;
   fc.computeBoundingBox(minX, minY, maxX, maxY);  
   
   // Compute the list of points of the contour
   vector<FreemanChain<int>::PointI2> aContourPointVector; 
   fc.getContourPoints(fc, aContourPointVector);
   
   // Draw the Freeman chain
   DGtalBoard::Board aBoard;
   aBoard.setUnit(Board::UMillimeter);
   fc.selfDraw(aBoard);
Examples:

dgtalboard-5-greedy-dss.cpp, and DSS.cpp.


Member Typedef Documentation

template<typename TInteger>
typedef TInteger DGtal::FreemanChain< TInteger >::Integer
template<typename TInteger>
typedef PointVector<2, Integer> DGtal::FreemanChain< TInteger >::PointI2

Constructor & Destructor Documentation

template<typename TInteger>
DGtal::FreemanChain< TInteger >::~FreemanChain (  )  [inline]

Destructor.

template<typename TInteger>
DGtal::FreemanChain< TInteger >::FreemanChain ( const std::string &  s = "",
int  x = 0,
int  y = 0 
)

Constructor.

Parameters:
s the chain code.
x the x-coordinate of the first point.
y the y-coordinate of the first point.
template<typename TInteger>
DGtal::FreemanChain< TInteger >::FreemanChain ( std::istream &  in  ) 

Constructor.

Parameters:
in any input stream,
template<typename TInteger>
DGtal::FreemanChain< TInteger >::FreemanChain ( const FreemanChain< TInteger > &  other  ) 

Copy constructor.

Parameters:
other the object to clone.

Member Function Documentation

template<typename TInteger>
static void DGtal::FreemanChain< TInteger >::alphabet ( char &  aZero,
char &  aOne,
char  aQuadrant 
) [inline, static]

Creates a Freeman chaincode [chain] and a chain coding the quadrant of each step [qchain], given an iterator on a 4-connected path [it], a number of step [nb], the first step [freeman_code] and the first quadrant [quadrant].

Parameters:
chain (returns) a string of '0', '1', '2', or '3' (Freeman chaincode)
qchain (returns) a string of '0', '1', '2', or '3' giving the quadrants.
it any iterator
nb the number of 'next' performed on a copy of [it].
freeman the first code or step.
quadrant the first quadrant (equal to freeman_code or one below).
start_index the starting index in [chain] and [qchain], default is 0.
aZero (returns) the '0' or 'x' letter for quadrant [quadrant].
aOne (returns) the '1' or 'y' letter for quadrant [quadrant].
aQuadrant the quadrant as any of '0', '1', '2', or '3'.
template<typename TInteger>
ConstIterator DGtal::FreemanChain< TInteger >::begin (  )  const
template<typename TInteger>
static void DGtal::FreemanChain< TInteger >::cleanContour ( std::vector< FreemanChain< TInteger > > &  aCleanCs,
std::vector< std::pair< unsigned int, unsigned int > > &  aC2clean,
std::vector< std::vector< unsigned int > > &  aClean2c,
const FreemanChain< TInteger > &  c,
bool  ccw = true 
) [inline, static]

Reads the 4-connected contour [c] so that meaningless back and forth steps are removed. These operations may create one or several 4-connected contours (stored in [clean_cs]), whether these removals cuts the contour in several loops. Because of that, the mappings are more complex.

Parameters:
aClean_cs (output) the array of cleaned 4-connected contours.
aC2clean (output) the mapping associating an element to its clean element as a pair (n,i) where n is the index of the cleaned contour and i the indice of the element in this Freeman chain.
aClean2c (output) the array of mapping associating a clean element to its non-clean element. clean2c[n][j] gives the index of the non-clean element on c corresponding to the clean element of index j in the n-th contour.
c the input code of the 4-connected contour.
ccw 'true' if the contour is seen counterclockwise with its inside to the left.
Todo:
This method is not implemented.
template<typename TInteger>
static bool DGtal::FreemanChain< TInteger >::cleanOuterSpikes ( FreemanChain< TInteger > &  aCleanC,
std::vector< unsigned int > &  aC2clean,
std::vector< unsigned int > &  aClean2c,
const FreemanChain< TInteger > &  c,
bool  ccw = true 
) [inline, static]

Removes outer spikes along a 4-connected contour, meaning steps "02", "13", "20" or "31", which point outside the shape. The inside is given by parameter [ccw]. Note that 4-connected pointel contours should not have any outer spikes, while 4-connected pixel contours should not have any inner spikes.

Parameters:
aClean_c (output) the cleaned 4-connected contour.
aC2clean (output) the mapping associating an element to its clean element.
aClean2c (output) the inverse mapping associating a clean element to its non-clean element.
c the input code of the 4-connected contour (should be a loop !).
ccw 'true' if the contour is seen counterclockwise with its inside to the left.
Returns:
'true' if the contour add an interior, 'false' otherwise.

References ASSERT, DGtal::PointVector< N, T >::at(), DGtal::FreemanChain< TInteger >::begin(), DGtal::FreemanChain< TInteger >::chain, DGtal::ModuloComputer< TInteger >::decrement(), DGtal::FreemanChain< TInteger >::ConstIterator::getCode(), DGtal::FreemanChain< TInteger >::ConstIterator::getPosition(), DGtal::ModuloComputer< TInteger >::increment(), DGtal::FreemanChain< TInteger >::movement(), DGtal::ModuloComputer< TInteger >::next(), DGtal::FreemanChain< TInteger >::ConstIterator::nextInLoop(), DGtal::FreemanChain< TInteger >::ConstIterator::previousInLoop(), DGtal::FreemanChain< TInteger >::x0, and DGtal::FreemanChain< TInteger >::y0.

template<typename TInteger>
unsigned int DGtal::FreemanChain< TInteger >::code ( unsigned int  pos  )  const
template<typename TInteger>
void DGtal::FreemanChain< TInteger >::computeBoundingBox ( int &  min_x,
int &  min_y,
int &  max_x,
int &  max_y 
) const [inline]

Computes a bounding box for the Freeman chain code.

Parameters:
min_x (returns) the minimal x-coordinate.
min_y (returns) the minimal y-coordinate.
max_x (returns) the maximal x-coordinate.
max_y (returns) the maximal y-coordinate.

References DGtal::PointVector< N, T >::at(), DGtal::FreemanChain< TInteger >::begin(), DGtal::FreemanChain< TInteger >::end(), DGtal::FreemanChain< TInteger >::x0, and DGtal::FreemanChain< TInteger >::y0.

Referenced by testFreemanChain().

template<typename TInteger>
DrawableWithDGtalBoard* DGtal::FreemanChain< TInteger >::defaultStyle ( std::string  mode = ""  )  const

Default drawing style object.

Returns:
the dyn. alloc. default style for this object.
template<typename TInteger>
static void DGtal::FreemanChain< TInteger >::displacement ( int &  dx,
int &  dy,
unsigned int  aCode 
) [static]

Returns the displacement vector of a Freeman code.

Parameters:
dx (returns) the x-displacement.
dy (returns) the y-displacement.
aCode the code.

Referenced by DGtal::FreemanChain< TInteger >::innerContour().

template<typename TInteger>
static PointI2 DGtal::FreemanChain< TInteger >::displacement ( unsigned int  aCode  )  [static]
Parameters:
aCode a Freeman code (between 0-3). Returns the displacement vector of the Freeman code.
template<typename TInteger>
ConstIterator DGtal::FreemanChain< TInteger >::end (  )  const
template<typename TInteger>
FreemanChain<TInteger>::ConstIterator DGtal::FreemanChain< TInteger >::findQuadrantChange ( OrderedAlphabet A  )  const [inline]

Finds a quadrant change in 'this' Freeman chain and returns the position as an iterator. A quadrant change is some abb..bc | iterator <endcode>

The alphabet is possibly re-ordered so that a > b > c.

Parameters:
A (possibly updated) a Freeman chain alphabet, possibly re-ordered so that a > b > c.
Returns:
an iterator on 'this' that points on the first letter b.

References ASSERT, DGtal::FreemanChain< TInteger >::begin(), DGtal::FreemanChain< TInteger >::chain, DGtal::FreemanChain< TInteger >::end(), DGtal::FreemanChain< TInteger >::ConstIterator::getCode(), DGtal::FreemanChain< TInteger >::ConstIterator::getPosition(), DGtal::FreemanChain< TInteger >::ConstIterator::next(), DGtal::OrderedAlphabet::order(), DGtal::FreemanChain< TInteger >::ConstIterator::previous(), DGtal::OrderedAlphabet::reverse(), and DGtal::OrderedAlphabet::shiftLeft().

template<typename TInteger>
FreemanChain<TInteger>::ConstIterator DGtal::FreemanChain< TInteger >::findQuadrantChange4 ( OrderedAlphabet A  )  const [inline]

Finds a quadrant change in 'this' Freeman chain and returns the position as an iterator. A quadrant change is some (abc)*bc...cd | iterator <endcode>

This quadrant change also guarantees that is not a place where a convexity change occurs in the combinatorial MLP algorithm.

The alphabet is possibly re-ordered so that b > c > d > a.

Parameters:
A (possibly updated) a Freeman chain alphabet, possibly re-ordered so that b > c > d > a.
Returns:
an iterator on 'this' that points on the first letter c.

References ASSERT, DGtal::FreemanChain< TInteger >::begin(), DGtal::FreemanChain< TInteger >::chain, DGtal::FreemanChain< TInteger >::end(), DGtal::FreemanChain< TInteger >::ConstIterator::getCode(), DGtal::FreemanChain< TInteger >::ConstIterator::getPosition(), DGtal::FreemanChain< TInteger >::ConstIterator::next(), DGtal::OrderedAlphabet::order(), DGtal::FreemanChain< TInteger >::ConstIterator::previous(), DGtal::OrderedAlphabet::reverse(), and DGtal::OrderedAlphabet::shiftLeft().

template<typename TInteger>
static void DGtal::FreemanChain< TInteger >::getContourPoints ( const FreemanChain< TInteger > &  fc,
std::vector< PointI2 > &  aVContour 
) [inline, static]

Given a Freeman chain [c] coding a 4-connected pixel loop, computes its subsampling by the transformation: X = ( x - x0 ) div h, Y = ( y - y0 ) div v.

Parameters:
aSubc (output) the subsampled Freeman chain code (may contain spikes)
aC2subc (output) the mapping associating an element to its subsampled element.
aSubc2c (output) the inverse mapping associating a subsampled element to its element. More precisely, subc2c[ j ] is the last pointel to be in j.
c the input chain code.
h the subsampling along x
v the subsampling along y
x0 the x-origin of the frame (X,Y) in (x,y)
y0 the y-origin of the frame (X,Y) in (x,y)
Returns:
'false' if initial contour was empty or if [subc] is empty, 'true' otherwise. Return a vector containing all the interger points of the freemanchain.
Parameters:
fc the FreemanChain
aVContour (returns) the vector containing all the integer contour points.

References DGtal::FreemanChain< TInteger >::begin(), and DGtal::FreemanChain< TInteger >::end().

Referenced by testFreemanChain().

template<typename TInteger>
static void DGtal::FreemanChain< TInteger >::innerContour ( FreemanChain< TInteger > &  aInnerChain,
std::vector< unsigned int > &  aOuter2inner,
std::vector< unsigned int > &  aInner2outer,
const FreemanChain< TInteger > &  aOuterChain,
bool  ccw = true 
) [inline, static]

From the Freeman chain [outer_chain] representing a 4-connected contour, constructs the Freeman chain [inner_chain] that represents its inner 4-connected contour (which lies in its interpixel space). The boolean [ccw] specifies if the inside is to the left (ccw) or to the right (cw).

Note that chain codes going back and forth are never considered useless: it means that the chain is always supposed to have its interior to the left (ccw) or right (cw) even at configurations "02", "13", "20", "31".

Parameters:
aInner_chain (output) the code of the 4-connected inner border, with starting coordinates that are floored to the closest integer.
aOuter2inner (output) the mapping associating outer to inner elements as indices in their respective Freeman chain.
aInner2outer (output) the mapping associating inner to outer elements as indices in their respective Freeman chain.
aOuter_chain the input code of the 4-connected contour.
ccw 'true' if the contour is seen counterclockwise with its inside to the left.

References DGtal::FreemanChain< TInteger >::begin(), DGtal::FreemanChain< TInteger >::chain, DGtal::FreemanChain< TInteger >::code(), DGtal::FreemanChain< TInteger >::displacement(), DGtal::FreemanChain< TInteger >::movement(), DGtal::FreemanChain< TInteger >::ConstIterator::next(), DGtal::FreemanChain< TInteger >::x0, and DGtal::FreemanChain< TInteger >::y0.

Referenced by DGtal::FreemanChain< TInteger >::pointel2pixel().

template<typename TInteger>
int DGtal::FreemanChain< TInteger >::isClosed (  )  const [inline]

This method takes O(n) operations and works only for Freeman chains whose successive codes are between +1/-1. It determines if the FreemanChain corresponds to a closed contour, and if this is the case, determines how many counterclockwise loops the contour has done. Of course, it the contour has done clockwise loops, then the given number is accordingly negative.

Returns:
the number of counterclockwise loops, or '0' is the contour is open or invalid.

References DGtal::FreemanChain< TInteger >::begin(), DGtal::FreemanChain< TInteger >::end(), DGtal::FreemanChain< TInteger >::ConstIterator::getCode(), and DGtal::FreemanChain< TInteger >::ConstIterator::nextInLoop().

Referenced by testFreemanChain().

template<typename TInteger>
bool DGtal::FreemanChain< TInteger >::isValid (  )  const [inline]

Checks the validity/consistency of the object.

Returns:
'true' if the object is valid, 'false' otherwise.
template<typename TInteger>
static unsigned int DGtal::FreemanChain< TInteger >::movement ( unsigned int  aCode1,
unsigned int  aCode2,
bool  ccw = true 
) [inline, static]

Given two consecutive moves on a Freeman chain code, this method returns the type of movement: 0: return move, 1: turning toward the interior, 2: going straight, 3: turning toward exterior. Interior/exterior is specified by [ccw].

Parameters:
aCode1 the code of the first step as an integer in 0..3.
aCode2 the code of the second step as an integer in 0..3.
ccw 'true' if the contour is seen counterclockwise with its inside to the left.

Referenced by DGtal::FreemanChain< TInteger >::cleanOuterSpikes(), and DGtal::FreemanChain< TInteger >::innerContour().

template<typename TInteger>
static void DGtal::FreemanChain< TInteger >::movePointFromFC ( PointI2 aPoint,
unsigned int  aCode 
) [static]
template<typename TInteger>
unsigned int DGtal::FreemanChain< TInteger >::next ( unsigned int  pos  )  const
Parameters:
pos a position in the chain code.
Returns:
the next position.
template<typename TInteger>
FreemanChain& DGtal::FreemanChain< TInteger >::operator= ( const FreemanChain< TInteger > &  other  ) 

Assignment.

Parameters:
other the object to copy.
Returns:
a reference on 'this'.
template<typename TInteger>
static void DGtal::FreemanChain< TInteger >::pointel2pixel ( FreemanChain< TInteger > &  aPixChain,
std::vector< unsigned int > &  aPl2pix,
std::vector< unsigned int > &  aPix2pl,
const FreemanChain< TInteger > &  aPlChain 
) [inline, static]

From the Freeman chain [pl_chain] representing a pointel 4-connected contour, constructs the Freeman chain [pix_chain] that represents its inner 4-connected border of pixels. The Freeman chain [pl_chain] has its inside to the left (ie. ccw).

Note that chain codes going back and forth are never considered useless: it means that the chain is always supposed to have its interior to the left (ccw) or right (cw) even at configurations "02", "13", "20", "31".

Parameters:
aPix_chain (output) the code of the 4-connected inner border.
aPl2pix (output) the mapping associating pointels to pixels as indices in their respective Freeman chain.
aPix2pl (output) the inverse mapping associating pixels to pointels as indices in their respective Freeman chain.
pl_chain the input code of the 4-connected pointel contour.

References DGtal::FreemanChain< TInteger >::innerContour().

template<typename TInteger>
unsigned int DGtal::FreemanChain< TInteger >::previous ( unsigned int  pos  )  const
Parameters:
pos a position in the chain code.
Returns:
the previous position.
template<typename TInteger>
static void DGtal::FreemanChain< TInteger >::read ( std::istream &  in,
FreemanChain< TInteger > &  c 
) [inline, static]

Reads a chain from the stream [in] and updates [c].

Parameters:
in any input stream,
c (returns) the Freeman chain.

References DGtal::FreemanChain< TInteger >::chain, DGtal::FreemanChain< TInteger >::x0, and DGtal::FreemanChain< TInteger >::y0.

template<typename TInteger>
void DGtal::FreemanChain< TInteger >::selfDisplay ( std::ostream &  out  )  const [inline]

Writes/Displays the object on an output stream.

Parameters:
out the output stream where the object is written.
template<typename TInteger>
void DGtal::FreemanChain< TInteger >::selfDraw ( DGtalBoard board  )  const

Draw the object on a DGtalBoard board

Parameters:
board the output board where the object is drawn.
template<typename TInteger>
template<typename Functor >
void DGtal::FreemanChain< TInteger >::selfDraw ( DGtalBoard board  )  const

Draw the object on a DGtalBoard board

Parameters:
board the output board where the object is drawn.
Template Parameters:
Functor a Functor to specialize the Board style
template<typename TInteger>
unsigned int DGtal::FreemanChain< TInteger >::size (  )  const
Returns:
the length of the Freeman chain code.
template<typename TInteger>
std::string DGtal::FreemanChain< TInteger >::styleName (  )  const
Returns:
the style name used for drawing this object.
template<typename TInteger>
static unsigned int DGtal::FreemanChain< TInteger >::turnedCode ( unsigned int  aCode,
bool  ccw = true 
) [static]
Parameters:
aCode any Freeman code.
ccw when 'true' turns counterclockwise (or left), otherwise turns clockwise (right).
Returns:
the turned code.
template<typename TInteger>
static void DGtal::FreemanChain< TInteger >::write ( std::ostream &  out,
const FreemanChain< TInteger > &  c 
) [inline, static]

Outputs the chain [c] to the stream [out].

Parameters:
out any output stream,
c a Freeman chain.

References DGtal::FreemanChain< TInteger >::chain, DGtal::FreemanChain< TInteger >::x0, and DGtal::FreemanChain< TInteger >::y0.


Field Documentation

template<typename TInteger>
std::string DGtal::FreemanChain< TInteger >::chain
template<typename TInteger>
int DGtal::FreemanChain< TInteger >::x0
template<typename TInteger>
int DGtal::FreemanChain< TInteger >::y0

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