DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Data Structures | Public Types | Public Member Functions | Static Public Member Functions | Data Fields | Private Member Functions
DGtal::FreemanChain< TInteger > Class Template Reference

#include <FreemanChain.h>

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

Data Structures

class  CodesRange
 Aim: model of CRange that provides services to (circularly)iterate over the letters of the freeman chain. More...
class  ConstIterator

Public Types

typedef TInteger Integer
typedef FreemanChain< IntegerSelf
typedef PointVector< 2, IntegerPoint
typedef PointVector< 2, IntegerVector
typedef unsigned int Size
typedef unsigned int Index

Public Member Functions

 BOOST_CONCEPT_ASSERT ((CInteger< TInteger >))
CodesRange getCodesRange ()
 ~FreemanChain ()
 FreemanChain (const std::string &s="", TInteger x=0, TInteger y=0)
 FreemanChain (const std::vector< Point > &vectPoints)
 FreemanChain (std::istream &in)
 FreemanChain (const FreemanChain &other)
FreemanChainoperator= (const FreemanChain &other)
bool operator== (const FreemanChain &other) const
bool operator!= (const FreemanChain &other) const
char code (Index pos) const
Size size () const
FreemanChain subChain (Index pos, Size n) const
FreemanChain operator+ (const FreemanChain &other) const
FreemanChainoperator+= (const FreemanChain &other)
void computeBoundingBox (TInteger &min_x, TInteger &min_y, TInteger &max_x, TInteger &max_y) const
Self::ConstIterator findQuadrantChange (OrderedAlphabet &A) const
Self::ConstIterator findQuadrantChange4 (OrderedAlphabet &A) const
int isClosed () const
int ccwLoops () const
Point getPoint (Index pos) const
Point firstPoint () const
Point lastPoint () const
Vector totalDisplacement () const
FreemanChainextend (char code)
FreemanChainretract (Size n=1)
ConstIterator begin () const
ConstIterator end () const
Index next (Index pos) const
Index previous (Index pos) const
void selfDisplay (std::ostream &out) const
bool isValid () const
std::string className () const

Static Public Member Functions

static void write (std::ostream &out, const FreemanChain &c)
static void read (std::istream &in, FreemanChain &c)
template<typename TConstIterator >
static void readFromPointsRange (const TConstIterator &itBegin, const TConstIterator &itEnd, FreemanChain &c)
template<typename TRange >
static void readFromPointsRange (const TRange &aRange, FreemanChain &c)
static void getContourPoints (const FreemanChain &fc, std::vector< Point > &aVContour)
static void movePointFromFC (Point &aPoint, char aCode)
static char movement (char aCode1, char aCode2, bool ccw=true)
static char addToCode (char code, int n)
static void displacement (int &dx, int &dy, char aCode)
static Point displacement (char aCode)
static char turnedCode (char 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)

Data Fields

std::string chain
Integer x0
Integer y0
Integer xn
Integer yn

Private Member Functions

void computeLastPoint ()

Detailed Description

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

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 clockwise 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>::Point> aContourPointVector;
fc.getContourPoints(fc, aContourPointVector);
// Draw the Freeman chain
Board2D aBoard;
aBoard.setUnit(Board::UMillimeter);
aBoard << fc;
Template Parameters:
TIntegertype of the coordinates of the starting point
See also:
freemanChainDisplay.cpp freemanChainFromImage.cpp testFreemanChain.cpp

Definition at line 110 of file FreemanChain.h.


Member Typedef Documentation

template<typename TInteger>
typedef unsigned int DGtal::FreemanChain< TInteger >::Index

Definition at line 123 of file FreemanChain.h.

template<typename TInteger>
typedef TInteger DGtal::FreemanChain< TInteger >::Integer

Definition at line 116 of file FreemanChain.h.

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

Definition at line 119 of file FreemanChain.h.

template<typename TInteger>
typedef FreemanChain<Integer> DGtal::FreemanChain< TInteger >::Self

Definition at line 117 of file FreemanChain.h.

template<typename TInteger>
typedef unsigned int DGtal::FreemanChain< TInteger >::Size

Definition at line 122 of file FreemanChain.h.

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

Definition at line 120 of file FreemanChain.h.


Constructor & Destructor Documentation

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

Destructor.

Definition at line 551 of file FreemanChain.h.

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

Constructor.

Parameters:
sthe chain code.
xthe x-coordinate of the first point.
ythe y-coordinate of the first point.

Definition at line 182 of file FreemanChain.ih.

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

: chain( s ), x0( x ), y0( y ), xn( x ), yn( y )
{
}
template<typename TInteger>
DGtal::FreemanChain< TInteger >::FreemanChain ( const std::vector< Point > &  vectPoints)

Constructor.

Parameters:
vectorPointsthe vector containing all the points.

Constructor.

Definition at line 194 of file FreemanChain.ih.

{
readFromPointsRange(vectPoints.begin(), vectPoints.end(), *this);
}
template<typename TInteger>
DGtal::FreemanChain< TInteger >::FreemanChain ( std::istream &  in)

Constructor.

Parameters:
inany input stream,

Definition at line 206 of file FreemanChain.ih.

{
read(in, *this);
}
template<typename TInteger>
DGtal::FreemanChain< TInteger >::FreemanChain ( const FreemanChain< TInteger > &  other)

Copy constructor.

Parameters:
otherthe object to clone.

Definition at line 217 of file FreemanChain.ih.

: chain( aOther.chain ), x0( aOther.x0 ), y0( aOther.y0 ),
xn( aOther.xn), yn( aOther.yn)
{ }

Member Function Documentation

template<typename TInteger >
char DGtal::FreemanChain< TInteger >::addToCode ( char  code,
int  n 
)
inlinestatic

Increment (or decrement if negative) the code by 'n'. '0' + 1 = '1', '1' + 1 = '2', ... , '3' + 1 = '0'

Parameters:
codethe initial code.
nthe number to add/remove to the code
Returns:
'code' increment 'n' times.

Definition at line 793 of file FreemanChain.ih.

{
return '0' + ( ( (code - '0' ) + n ) & 3 );
}
template<typename TInteger >
DGtal::FreemanChain< TInteger >::ConstIterator DGtal::FreemanChain< TInteger >::begin ( ) const

Iterator service on points.

Returns:
an iterator pointing on the first point of the chain.

Definition at line 255 of file FreemanChain.ih.

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

{
return ConstIterator( *this, 0 );
}
template<typename TInteger>
DGtal::FreemanChain< TInteger >::BOOST_CONCEPT_ASSERT ( (CInteger< TInteger >)  )
template<typename TInteger >
int DGtal::FreemanChain< TInteger >::ccwLoops ( ) const
inline

This method takes O(n) operations. 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' if the contour is open or invalid.

Definition at line 468 of file FreemanChain.ih.

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

{
ConstIterator it = this->begin();
ConstIterator it_end = this->end();
--it_end;
ConstIterator it_suiv = it;
Point spos = *it;
int nb_ccw_turns = 0;
while ( it != it_end )
{
int code1 = it.getCode();
it_suiv.nextInLoop();
int code2 = it_suiv.getCode();
char diff = ( code2 - code1 + 4 ) % 4;
if ( diff == 1 )
++nb_ccw_turns;
else
if ( diff == 3 )
--nb_ccw_turns;
else
if ( diff == 2 )
return 0;
++it;
}
if ( spos == *it_suiv )
return nb_ccw_turns / 4;
else
return 0;
}
template<typename TInteger >
std::string DGtal::FreemanChain< TInteger >::className ( ) const
inline

Default drawing style object.

Returns:
the dyn. alloc. default style for this object.
the style name used for drawing this object.

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.
cthe input chain code.
hthe subsampling along x
vthe subsampling along y
x0the x-origin of the frame (X,Y) in (x,y)
y0the y-origin of the frame (X,Y) in (x,y)
Returns:
'false' if initial contour was empty or if [subc] is empty, 'true' otherwise.

Definition at line 1304 of file FreemanChain.ih.

Referenced by DGtal::Display2DFactory::draw().

{
return "FreemanChain";
}
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 
)
inlinestatic

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.
cthe 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.

Definition at line 1056 of file FreemanChain.h.

{
// \TODO not implemented yet.
}
template<typename TInteger >
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 
)
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.
cthe 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.

Definition at line 962 of file FreemanChain.ih.

References DGtal::PointVector< dim, TEuclideanRing >::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::ModuloComputer< TInteger >::next(), DGtal::FreemanChain< TInteger >::ConstIterator::nextInLoop(), DGtal::FreemanChain< TInteger >::ConstIterator::previousInLoop(), DGtal::FreemanChain< TInteger >::x0, DGtal::FreemanChain< TInteger >::xn, DGtal::FreemanChain< TInteger >::y0, and DGtal::FreemanChain< TInteger >::yn.

{
unsigned int nb = (unsigned int)c.chain.size();
if ( nb == 0 )
{
cerr << "[DGtal::FreemanChain::cleanOuterSpikes]"
<< " cleanOuterSpikes: Empty input chain"
<< endl;
return false;
}
ModuloComputer< DGtal::int32_t > mc( nb );
ModuloComputer< DGtal::int32_t >::UnsignedInteger i = 0;
ModuloComputer< DGtal::int32_t >::UnsignedInteger j = 0;
vector<unsigned int> c2cleanTMP;
aCleanC.chain.reserve( nb );
aCleanC.chain = "";
aC2clean.clear();
aClean2c.clear();
aC2clean.reserve( nb );
aClean2c.reserve( nb );
c2cleanTMP.reserve( nb );
ConstIterator it = c.begin();
ConstIterator itn = c.begin();
itn.nextInLoop();
// Find a consistent starting point.
unsigned int n;
unsigned int size_spike = 0;
for ( n = 0; n < nb; ++n )
{
size_spike = 0;
while ( movement( it.getCode(), itn.getCode(), ccw ) == '0' )
{
it.previousInLoop();
itn.nextInLoop();
mc.increment( i );
size_spike += 2;
if ( size_spike >= nb )
{
cerr << "[DGtal::FreemanChain::cleanOuterSpikes]"
<< " Spike is longer than contour !"
<< " size_spike=" << size_spike
<< " nb=" << nb
<< endl;
return false;
}
}
mc.increment( i );
it = itn;
itn.nextInLoop();
if ( size_spike > 0 )
break;
}
unsigned int start_idx = it.getPosition();
i = start_idx;
// JOL : 2009/07/07, added starting coordinates
// XP : 2011/09/06, added ending coordinates
Point P = *it;
aCleanC.x0 = P.at(0);
aCleanC.y0 = P.at(1);
aCleanC.xn = P.at(0);
aCleanC.yn = P.at(1);
// cerr << "Starting point is " << i << endl;
ASSERT( ( n < nb ) || ( i == 0 ) );
if ( n == nb )
{ // do nothing
aCleanC.chain = c.chain;
for ( unsigned int ni = 0; ni < nb; ++ni )
{
aC2clean.push_back( ni );
aClean2c.push_back( ni );
}
if ( size_spike != 0 )
cerr << "[DGtal::FreemanChain::cleanOuterSpikes]"
<< "No starting point found (only spikes !)" << endl;
return size_spike == 0;
}
// Loops over all letters.
ConstIterator it_begin = it;
deque<unsigned int> clean_code;
deque<unsigned int> clean_idx;
vector<unsigned int> begin_outer_spike;
vector<unsigned int> end_outer_spike;
// i follows iterator it.
do
{
clean_code.push_back( it.getCode() );
clean_idx.push_back( i );
itn = it;
it.nextInLoop();
mc.increment( i );
// cerr << "- i=" << i << " (" << clean_code.back()
// << it.getCode() << ") ";
size_spike = 0;
unsigned int last_spike_idx = end_outer_spike.empty() ?
start_idx :
end_outer_spike.back();
j = i;
while ( ( ! clean_code.empty() )
&& ( j != last_spike_idx )
&& ( movement( clean_code.back(), it.getCode(), ccw ) == '0' )
&& ( it != it_begin ) )
{
clean_code.pop_back();
clean_idx.pop_back();
mc.increment( i );
mc.decrement( j );
it.nextInLoop();
itn.previousInLoop();
size_spike += 2;
}
// cerr << "i=" << i << " size_spike=" << size_spike
// << " last_spike_idx=" << last_spike_idx
// << endl;
if ( size_spike != 0 )
{
// There is a spike. Is it an outer one ?
unsigned int previous_code = itn.getCode();
unsigned int previous_idx = itn.getPosition();
// JOL : do not
// consider any more "cleaned contour" since we cannot go
// further than the last spike.
// unsigned int previous_code =
// clean_code.empty() ? itn.getCode() : clean_code.back();
// unsigned int previous_idx =
// clean_code.empty() ? itn.getPosition() : clean_idx.back();
itn = it;
itn.previousInLoop();
unsigned int move1 = movement( previous_code, addToCode ( itn.getCode() , 2 ), ccw );
unsigned int move2 = movement( itn.getCode(), it.getCode() , ccw );
bool return_spike = ( move1 == '0' ) || ( move2 == '0' );
bool outer_spike = ( move1 == '3' ) || ( move2 == '3' );
// if ( return_spike )
// cerr << "[DGtal::FreemanChain::cleanOuterSpikes] return spike."
// << endl;
// if ( ! ( ( outer_spike && ( move1 != 1 ) && ( move2 != 1 ) )
// || ( ! outer_spike && ( move1 != 3 ) && ( move2 != 3 ) ) ) )
// cerr << "[DGtal::FreemanChain::cleanOuterSpikes] "
// << "Weird spike. Invalid contour (expected 3 3) ?"
// << " move1=" << move1
// << " move2=" << move2
// << " ccw=" << ccw
// << " start_idx=" << start_idx
// << " size_spike=" << size_spike
// << " it=" << it.getPosition()
// << " itp=" << previous_idx
// << endl
// << c.chain << endl;
// Process waiting steps.
if ( outer_spike || return_spike )
{
begin_outer_spike.push_back( mc.next( previous_idx ) );
end_outer_spike.push_back( i );
// cout << " outer spike [" << begin_outer_spike.back()
// << "," << end_outer_spike.back() << "[ " << endl;
}
}
}
while ( it != it_begin );
// Once outer spikes are known, we can create the new contour.
aC2clean.resize( nb );
i = start_idx % nb;
j = 0;
unsigned int nb_spikes = (unsigned int)begin_outer_spike.size();
unsigned int k = 0;
n = 0;
while ( n < nb )
{
if ( ( k == nb_spikes ) || ( i != begin_outer_spike[ k ] ) )
{
aCleanC.chain.push_back( c.chain[ i ] );
aC2clean[ i ] = j;
aClean2c.push_back( i );
mc.increment( i );
++j;
++n;
}
else
{
while ( i != end_outer_spike[ k ] )
{
aC2clean[ i ] = j;
mc.increment( i );
++n;
}
++k;
}
}
for ( unsigned int ii = 0; ii < nb; ++ii )
if ( aC2clean[ ii ] >= aCleanC.chain.size() )
{
if ( aC2clean[ ii ] == aCleanC.chain.size() )
aC2clean[ ii ] = 0;
else
{
cerr << "[DGtal::FreemanChain::cleanOuterSpikes]"
<< "Bad correspondence for aC2clean[" << ii << "]"
<< " = " << aC2clean[ ii ] << " >= " << aCleanC.chain.size()
<< endl;
aC2clean[ ii ] = aC2clean[ ii ] % aCleanC.chain.size();
}
}
for ( unsigned int jj = 0; j < aCleanC.chain.size(); ++jj )
if ( aClean2c[ jj ] >= nb )
{
cerr << "[DGtal::FreemanChain::cleanOuterSpikes]"
<< "Bad correspondence for aClean2c[" << jj << "]"
<< " = " << aClean2c[ jj ] << " >= " << nb
<< endl;
aClean2c[ jj ] = aClean2c[ jj ] % nb;
}
return true;
}
template<typename TInteger >
char DGtal::FreemanChain< TInteger >::code ( Index  aPos) const
Parameters:
posa position in the chain code.
Returns:
the code at position [pos].

Note, it is assumed that 0 <= pos < this->size()

Parameters:
aPosa position in the chain code.
Returns:
the code at position [aPos].

Definition at line 303 of file FreemanChain.ih.

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

{
ASSERT( aPos < chain.size() );
//return chain[ aPos ] - '0';
return chain[ aPos ];
}
template<typename TInteger>
void DGtal::FreemanChain< TInteger >::computeBoundingBox ( TInteger &  min_x,
TInteger &  min_y,
TInteger &  max_x,
TInteger &  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.

Definition at line 325 of file FreemanChain.ih.

References DGtal::PointVector< dim, TEuclideanRing >::at().

Referenced by DGtal::Display2DFactory::drawAsGrid(), and DGtal::Display2DFactory::drawAsInterGrid().

{
min_x = max_x = x0;
min_y = max_y = y0;
for ( ConstIterator it = begin();
it != end();
++it )
{
Point p( *it );
if ( p.at(0) < min_x )
min_x = p.at(0);
else
if ( p.at(0) > max_x )
max_x = p.at(0);
if ( p.at(1) < min_y )
min_y = p.at(1);
else
if ( p.at(1) > max_y )
max_y = p.at(1);
}
}
template<typename TInteger >
void DGtal::FreemanChain< TInteger >::computeLastPoint ( )
inlineprivate

Default constructor Not valid. Computes the coordinates of the last point. nb: in O(n)

Definition at line 1312 of file FreemanChain.ih.

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

{
ConstIterator it = this->begin();
for (unsigned int i=0; i < chain.size(); ++i)
it++;
xn = (*it).at(0);
yn = (*it).at(1);
}
template<typename TInteger >
void DGtal::FreemanChain< TInteger >::displacement ( int &  dx,
int &  dy,
char  aCode 
)
inlinestatic

Returns the displacement vector of a Freeman code.

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

Definition at line 805 of file FreemanChain.ih.

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

{
switch ( aCode )
{
case '0': dx = 1; dy = 0; break;
case '1': dx = 0; dy = 1; break;
case '2': dx = -1; dy = 0; break;
case '3': dx = 0; dy = -1; break;
}
}
template<typename TInteger >
DGtal::PointVector< 2, TInteger > DGtal::FreemanChain< TInteger >::displacement ( char  aCode)
inlinestatic
Parameters:
aCodea Freeman code (between 0-3). Returns the displacement vector of the Freeman code.

Definition at line 820 of file FreemanChain.ih.

{
#ifdef CPP11_INITIALIZER_LIST
switch ( aCode )
{
case '0': return Point({1,0});
case '1': return Point({0,1});
case '2': return Point({-1,0});
case '3': return Point({0,-1});
}
return Point({0,0});
#else
int t[2] = {0,0};
switch ( aCode )
{
case '0': t[0]++; return Point( t );
case '1': t[1]++; return Point( t );
case '2': t[0]--; return Point( t );
case '3': t[1]--; return Point( t );
}
return Point( t );
#endif //CPP11_INITIALIZER_LIST
}
template<typename TInteger >
DGtal::FreemanChain< TInteger >::ConstIterator DGtal::FreemanChain< TInteger >::end ( ) const

Iterator service on points.

Returns:
an iterator pointing after the last point of the chain.

Definition at line 263 of file FreemanChain.ih.

Referenced by DGtal::Display3DFactory::draw(), and DGtal::FreemanChain< TInteger >::getContourPoints().

{
Point p(0,0); // *(end()) is invalid
return ConstIterator( *this, (typename DGtal::FreemanChain<TInteger>::Index)(chain.size() + 1), p );
}
template<typename TInteger >
DGtal::FreemanChain< TInteger > & DGtal::FreemanChain< TInteger >::extend ( char  code)
inline

Add one symbol at the end of the FreemanChain

Returns:
reference to this.

Definition at line 574 of file FreemanChain.ih.

{
chain += std::string( &aCode, 1);
int dx=0, dy=0;
//displacement( dx, dy, aCode - '0' );
displacement( dx, dy, aCode );
xn += dx;
yn += dy;
return *this;
}
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.

Definition at line 352 of file FreemanChain.ih.

References 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().

{
ConstIterator it = begin();
ConstIterator it_end = end();
// find first letters a and b.
char code1 = it.getCode();
it.next();
while ( ( it != it_end ) && ( it.getCode() == code1 ) )
it.next();
ASSERT( ( it != it_end )
&& "[DGtal::FreemanChain::findQuadrantChange( OrderedAlphabet & A ) const] 1-letter freeman chain." );
char code2 = it.getCode();
// find third letter c.
while ( ( it != it_end ) && ( ( it.getCode() == code1 )
|| ( it.getCode() == code2 ) ) )
it.next();
ASSERT( ( it != it_end )
&& "[DGtal::FreemanChain::findQuadrantChange( OrderedAlphabet & A ) const] 2-letters Freeman chain." );
// reorder a and b.
it.previous();
if ( it.getCode() != code2 )
swap( code1, code2 );
// find first a.
do
{
it.previous();
}
while ( it.getCode() == code2 );
char a_char = chain[ it.getPosition() ];
// the next is the first b.
it.next();
char b_char = chain[ it.getPosition() ];
// Reorder the alphabet to match the quadrant change.
while ( A.order( b_char ) != 1 )
A.shiftLeft();
if ( A.order( a_char ) == 0 )
{
A.reverse();
while ( A.order( b_char ) != 1 )
A.shiftLeft();
}
ASSERT( ( A.order( b_char ) == 1 )
&& ( A.order( a_char ) == 2 )
&& "[DGtal::FreemanChain::findQuadrantChange( OrderedAlphabet & A ) const] Internal error: invalid Quadrant change found." );
return it;
}
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.

Definition at line 403 of file FreemanChain.ih.

References 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().

{
ConstIterator it = begin();
ConstIterator it_end = end();
// find first letters a and b.
uint8_t code1 = it.getCode();
it.next();
while ( ( it != it_end ) && ( it.getCode() == code1 ) )
it.next();
ASSERT( ( it != it_end )
&& "[DGtal::FreemanChain::findQuadrantChange( OrderedAlphabet & A ) const] 1-letter freeman chain." );
uint8_t code2 = it.getCode();
// find third letter c.
while ( ( it != it_end ) && ( ( it.getCode() == code1 )
|| ( it.getCode() == code2 ) ) )
it.next();
ASSERT( ( it != it_end )
&& "[DGtal::FreemanChain::findQuadrantChange( OrderedAlphabet & A ) const] 2-letters Freeman chain." );
uint8_t code3 = it.getCode();
// find fourth letter d.
while ( ( it != it_end ) && ( ( it.getCode() == code1 )
|| ( it.getCode() == code2 )
|| ( it.getCode() == code3 ) ) )
it.next();
ASSERT( ( it != it_end )
&& "[DGtal::FreemanChain::findQuadrantChange( OrderedAlphabet & A ) const] 3-letters Freeman chain." );
// define true c.
it.previous();
code3 = it.getCode();
// find first b.
do
{
it.previous();
}
while ( it.getCode() == code3 );
char a_char = chain[ it.getPosition() ];
// the next is the first c.
it.next();
char b_char = chain[ it.getPosition() ];
// Reorder the alphabet to match the quadrant change.
while ( A.order( b_char ) != 1 )
A.shiftLeft();
if ( A.order( a_char ) == 0 )
{
A.reverse();
while ( A.order( b_char ) != 1 )
A.shiftLeft();
}
ASSERT( ( A.order( b_char ) == 1 )
&& ( A.order( a_char ) == 2 )
&& "[DGtal::FreemanChain::findQuadrantChange( OrderedAlphabet & A ) const] Internal error: invalid Quadrant change found." );
return it;
}
template<typename TInteger>
Point DGtal::FreemanChain< TInteger >::firstPoint ( ) const
inline
template<typename TInteger>
CodesRange DGtal::FreemanChain< TInteger >::getCodesRange ( )
inline
Returns:
an instance of CodesRange.

Definition at line 537 of file FreemanChain.h.

{
return CodesRange(chain);
}
template<typename TInteger >
void DGtal::FreemanChain< TInteger >::getContourPoints ( const FreemanChain< TInteger > &  fc,
std::vector< Point > &  aVContour 
)
inlinestatic

Return a vector containing all the interger points of the freemanchain.

Parameters:
fcthe FreemanChain
aVContour(returns) the vector containing all the integer contour points.

Definition at line 717 of file FreemanChain.ih.

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

Referenced by DGtal::Display2DFactory::drawAsGrid(), and DGtal::Display2DFactory::drawAsInterGrid().

{
aVContour.clear();
for ( ConstIterator it = fc.begin();
it != fc.end();
++it )
{
aVContour.push_back(*it);
}
}
template<typename TInteger >
DGtal::FreemanChain< TInteger >::Point DGtal::FreemanChain< TInteger >::getPoint ( Index  pos) const
inline

Computes the point where starts the step at position 'pos' of the FreemanChain. If 'pos' is equal to the length of the FreemanChain then the last point is returned.

Note: for a chain of length 'n' the computation time in O( min( pos, n-pos ) ).

Parameters:
posthe position of the point in the FreemanChain
Returns:
the point at position 'pos'.

Definition at line 548 of file FreemanChain.ih.

{
ConstIterator it;
Size n = this->size();
if ( aPos < n / 2 ) {
it = begin();
for (unsigned int i=0; i<aPos; ++i)
it++;
}
else
{
it = end();
it--;
n = n-aPos;
for (unsigned int i=0; i<n; ++i) {
it--;
}
}
return *it;
}
template<typename TInteger >
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 
)
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_chainthe input code of the 4-connected contour.
ccw'true' if the contour is seen counterclockwise with its inside to the left.

Definition at line 868 of file FreemanChain.ih.

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

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

{
unsigned int nb = (unsigned int)aOuterChain.chain.size();
unsigned int j = 0;
aOuter2inner.clear();
aOuter2inner.reserve( nb );
// aInnerChain.chain.reserve( nb + 4 );
aInnerChain.chain = "";
aInner2outer.clear();
aInner2outer.reserve( nb + ( ccw ? 4 : -4 ) );
int dx0=0, dy0=0;
int dx1=0, dy1=0;
FreemanChain<TInteger>::displacement( dx0, dy0, aOuterChain.code( 0 ) );
int turn = ccw ? 1 : 3;
//FreemanChain<TInteger>::displacement( dx1, dy1, ( aOuterChain.code( 0 ) + turn ) % 4 );
FreemanChain<TInteger>::displacement( dx1, dy1, addToCode( aOuterChain.code( 0 ) , turn ) );
dx0 += dx1;
dy0 += dy1;
aInnerChain.x0 = dx0 > 0 ? aOuterChain.x0 : aOuterChain.x0 - 1;
aInnerChain.y0 = dy0 > 0 ? aOuterChain.y0 : aOuterChain.y0 - 1;
ConstIterator it_begin = aOuterChain.begin();
ConstIterator it = it_begin;
it.next();
for ( unsigned int i = 0; i < nb; ++i )
{
// Check if contour is open.
// cerr << "i=" << i << " code=" << aOuterChain.code( i ) << endl;
switch ( movement( aOuterChain.code( i ), aOuterChain.code( ( i + 1 ) % nb ), ccw ) )
{
case '0':
// contour going in then out.
aInnerChain.chain += aOuterChain.chain[ i ];
//aInnerChain.chain += ( ( ( (unsigned int) ( aOuterChain.chain[ i ] - '0' )
// + ( ccw ? 3 : 1 ) ) )
// % 4 ) + '0';
aInnerChain.chain += addToCode ( aOuterChain.chain[ i ], (ccw) ? 3 : 1 );
aInnerChain.chain += aOuterChain.chain[ ( i + 1 ) % nb ];
aOuter2inner.push_back( j );
aInner2outer.push_back( i );
aInner2outer.push_back( i + 1 );
aInner2outer.push_back( i + 1 );
j += 3;
break;
case '1':
// contour turning toward its inside.
aOuter2inner.push_back( j );
break;
case '2':
// contour going straight ahead
aInnerChain.chain += aOuterChain.chain[ i ];
aOuter2inner.push_back( j );
aInner2outer.push_back( i );
++j;
break;
case '3':
// contour turning toward its outside.
aInnerChain.chain += aOuterChain.chain[ i ];
aInnerChain.chain += aOuterChain.chain[ ( i + 1 ) % nb ];
aOuter2inner.push_back( j );
aInner2outer.push_back( i );
aInner2outer.push_back( i + 1 );
j += 2;
break;
}
// Advances along contour and check if it is a closed contour.
it.next();
if ( ( i == nb - 1 )
&& ( *it_begin != *it ) )
// freeman chain is *not* a closed loop.
{
aInnerChain.chain += aOuterChain.chain[ i ];
aOuter2inner.push_back( j );
aInner2outer.push_back( i );
++i;
++j;
break;
}
}
}
template<typename TInteger >
int DGtal::FreemanChain< TInteger >::isClosed ( ) const
inline

Test if the FreemanChain ends at the same point it starts. Take (1) operation since the last point has been stored at initialization.

Returns:
'true' if the path is closed, 'false' otherwise.

Definition at line 460 of file FreemanChain.ih.

{
return (x0 == xn) && (y0 == yn);
}
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.

Definition at line 625 of file FreemanChain.ih.

{
return true;
}
template<typename TInteger>
Point DGtal::FreemanChain< TInteger >::lastPoint ( ) const
inline
template<typename TInteger >
char DGtal::FreemanChain< TInteger >::movement ( char  aCode1,
char  aCode2,
bool  ccw = true 
)
inlinestatic

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:
aCode1the code of the first step as an integer in 0..3.
aCode2the 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.
Returns:
the type of movement given by aCode1 and aCode2.

Definition at line 775 of file FreemanChain.ih.

{
unsigned int cfg = ( ccw ? 0 : 16 ) + ( (aCode1 - '0') << 2 ) + (aCode2 - '0');
static const char tbl[ 32 ] =
{
'2', '1', '0', '3', '3', '2', '1', '0',
'0', '3', '2', '1', '1', '0', '3', '2',
'2', '3', '0', '1', '1', '2', '3', '0',
'0', '1', '2', '3', '3', '0', '1', '2'
};
return tbl[ cfg ];
}
template<typename TInteger >
void DGtal::FreemanChain< TInteger >::movePointFromFC ( Point aPoint,
char  aCode 
)
static

Translate a point by the displacement given a code from a FreemanChain

Parameters:
aPointthe point to translate
aCodea FreemanChain code

Definition at line 733 of file FreemanChain.ih.

References DGtal::PointVector< dim, TEuclideanRing >::at().

{
switch ( aCode )
{
case '0': aPoint.at(0)++; break;
case '1': aPoint.at(1)++; break;
case '2': aPoint.at(0)--; break;
case '3': aPoint.at(1)--; break;
}
}
template<typename TInteger >
DGtal::FreemanChain< TInteger >::Index DGtal::FreemanChain< TInteger >::next ( Index  aPos) const

Returns the next position in the chain code. The path coded by the chain code is assumed to be closed so that the position after the last letter is the first one.

Parameters:
posa position in the chain code.
Returns:
the next position.
Parameters:
posa position in the chain code.
Returns:
the next position.

Definition at line 276 of file FreemanChain.ih.

{
++aPos;
if ( aPos >= chain.size() )
aPos = 0;
return aPos;
}
template<typename TInteger>
bool DGtal::FreemanChain< TInteger >::operator!= ( const FreemanChain< TInteger > &  other) const
inline

Comparaison operator

Parameters:
other the object to compare to.
Returns:
'true' both FreemanChain are different, 'false' otherwise.

Definition at line 608 of file FreemanChain.h.

{
return !( (*this) == other );
}
template<typename TInteger>
DGtal::FreemanChain< TInteger > DGtal::FreemanChain< TInteger >::operator+ ( const FreemanChain< TInteger > &  other) const
inline

Concatenation services.

Note: the starting point of 'other' is not considered.

Parameters:
otherthe chain to concatenate at the end of this.
Returns:
the concatenation of this and other.

Definition at line 519 of file FreemanChain.ih.

References DGtal::PointVector< dim, TEuclideanRing >::at(), DGtal::FreemanChain< TInteger >::chain, DGtal::FreemanChain< TInteger >::firstPoint(), DGtal::FreemanChain< TInteger >::lastPoint(), DGtal::FreemanChain< TInteger >::x0, DGtal::FreemanChain< TInteger >::xn, DGtal::FreemanChain< TInteger >::y0, and DGtal::FreemanChain< TInteger >::yn.

{
Self newChain;
newChain.chain = chain + aOther.chain;
newChain.x0 = x0;
newChain.y0 = y0;
Point newLastPoint = lastPoint() + ( aOther.lastPoint() - aOther.firstPoint() );
newChain.xn = newLastPoint.at(0);
newChain.yn = newLastPoint.at(1);
return newChain;
}
template<typename TInteger>
DGtal::FreemanChain< TInteger > & DGtal::FreemanChain< TInteger >::operator+= ( const FreemanChain< TInteger > &  other)
inline

Concatenation services.

Note: the starting point of 'other' is not considered.

Parameters:
otherthe chain to concatenate at the end of this.
Returns:
a reference to this.

Definition at line 535 of file FreemanChain.ih.

References DGtal::PointVector< dim, TEuclideanRing >::at(), DGtal::FreemanChain< TInteger >::chain, DGtal::FreemanChain< TInteger >::firstPoint(), and DGtal::FreemanChain< TInteger >::lastPoint().

{
chain += aOther.chain;
Point newLastPoint = lastPoint() + ( aOther.lastPoint() - aOther.firstPoint() );
xn = newLastPoint.at(0);
yn = newLastPoint.at(1);
return *this;
}
template<typename TInteger >
DGtal::FreemanChain< TInteger > & DGtal::FreemanChain< TInteger >::operator= ( const FreemanChain< TInteger > &  other)

Assignment.

Parameters:
otherthe object to copy.
Returns:
a reference on 'this'.

Assignment.

Parameters:
aOtherthe object to copy.
Returns:
a reference on 'this'.

Definition at line 232 of file FreemanChain.ih.

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

{
if ( this != &aOther )
{
chain = aOther.chain;
x0 = aOther.x0;
y0 = aOther.y0;
xn = aOther.xn;
yn = aOther.yn;
}
return *this;
}
template<typename TInteger>
bool DGtal::FreemanChain< TInteger >::operator== ( const FreemanChain< TInteger > &  other) const
inline

Comparaison operator

Parameters:
other the object to compare to.
Returns:
'true' both FreemanChain are equals, 'false' otherwise.

Definition at line 597 of file FreemanChain.h.

{
return (chain == other.chain) && ( x0 == other.x0 ) && ( y0 == other.y0 )
&& ( xn == other.xn ) && ( yn == other.yn );
}
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 
)
inlinestatic

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_chainthe input code of the 4-connected pointel contour.

Definition at line 989 of file FreemanChain.h.

{
innerContour( aPixChain, aPl2pix, aPix2pl, aPlChain, true );
};
template<typename TInteger >
DGtal::FreemanChain< TInteger >::Index DGtal::FreemanChain< TInteger >::previous ( Index  aPos) const

Returns the previous position in the chain code. The path coded by the chain code is assumed to be closed so that the position before the first letter is the first last one.

Parameters:
posa position in the chain code.
Returns:
the previous position.
Parameters:
posa position in the chain code.
Returns:
the previous position.

Definition at line 290 of file FreemanChain.ih.

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

{
if ( aPos == 0 ) aPos = chain.size() - 1;
else --aPos;
return aPos;
}
template<typename TInteger >
void DGtal::FreemanChain< TInteger >::read ( std::istream &  in,
FreemanChain< TInteger > &  c 
)
inlinestatic

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

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

Definition at line 644 of file FreemanChain.ih.

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

{
string str;
while ( true )
{
getline( in, str );
if ( ! in.good() )
return;
if ( ( str.size() > 0 ) && ( str[ 0 ] != '#' ) )
{
istringstream str_in( str );
str_in >> c.x0 >> c.y0 >> c.chain;
return;
}
}
}
template<typename TInteger >
template<typename TConstIterator >
void DGtal::FreemanChain< TInteger >::readFromPointsRange ( const TConstIterator &  itBegin,
const TConstIterator &  itEnd,
FreemanChain< TInteger > &  c 
)
inlinestatic

Reads a chain from the points range [ itBegin , itEnd ) and updates c.

Parameters:
itBeginbegin iterator,
itEndend iterator,
cthe returned Freeman chain.
Template Parameters:
TConstIteratortype of iterator

Definition at line 664 of file FreemanChain.ih.

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

{
TConstIterator it( itBegin );
if (it != itEnd)
{ //if the range is not empty
Point startingPt( *it );
++it;
if (it != itEnd)
{ //if there is more than one element
ostringstream oss;
Point pt( startingPt );
do
{
Point ptSuiv( *it );
Integer dx = ptSuiv[0] - pt[0];
Integer dy = ptSuiv[1] - pt[1];
short number = ( dx != 0 ? (1 - dx) : (2 - dy) );
if ( (number < 0) || (number > 3) )
{
std::cerr << "not connected points (method readFromPointsRange of FreemanChain)" << std::endl;
throw ConnectivityException();
}
oss << number;
pt = ptSuiv;
++it;
} while ( it != itEnd );
c.xn=pt[0];
c.yn=pt[1];
c.chain = oss.str();
}
c.x0=startingPt[0];
c.y0=startingPt[1];
}
}
template<typename TInteger >
template<typename TRange >
void DGtal::FreemanChain< TInteger >::readFromPointsRange ( const TRange &  aRange,
FreemanChain< TInteger > &  c 
)
inlinestatic

Reads a chain from the points range aRange and updates c.

Parameters:
aRangeany points range
cthe returned Freeman chain
Template Parameters:
TRangetype of points range

Definition at line 709 of file FreemanChain.ih.

{
BOOST_CONCEPT_ASSERT(( CConstSinglePassRange<TRange> ));
readFromPointsRange( aRange.begin(), aRange.end(), c );
}
template<typename TInteger >
DGtal::FreemanChain< TInteger > & DGtal::FreemanChain< TInteger >::retract ( Size  n = 1)
inline

Removes 'n' symbols at the end of the FreemanChain.

Returns:
reference to this.

Definition at line 592 of file FreemanChain.ih.

{
ConstIterator it = end();
for (unsigned int i=0; i<=n; ++i)
it--;
xn = (*it).at(0);
yn = (*it).at(1);
Size mySize = size();
ASSERT( (n <= mySize) && "Tried to shorten a FreemanChain by more then its length");
chain.resize( mySize - n );
return *this;
}
template<typename TInteger >
void DGtal::FreemanChain< TInteger >::selfDisplay ( std::ostream &  out) const
inline

Writes/Displays the object on an output stream.

Parameters:
outthe output stream where the object is written.

Definition at line 613 of file FreemanChain.ih.

Referenced by DGtal::operator<<().

{
out << x0 << " " << y0 << " " << chain;
}
template<typename TInteger >
DGtal::FreemanChain< TInteger >::Index DGtal::FreemanChain< TInteger >::size ( ) const
inline
Returns:
the length of the Freeman chain code.

Definition at line 317 of file FreemanChain.ih.

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

{
return (typename DGtal::FreemanChain<TInteger>::Size)(chain.size());
}
template<typename TInteger >
DGtal::FreemanChain< TInteger > DGtal::FreemanChain< TInteger >::subChain ( Index  pos,
Size  n 
) const
inline

Returns the subchain of the chain starting at position 'pos' and has 'n' letters long.

Parameters:
posposition of a character in the current FreemanChain object to be used as starting character for the subchain.
nlength of the subchain.
Returns:
the subchain starting at 'pos' having 'n' letters long.

Definition at line 502 of file FreemanChain.ih.

References DGtal::PointVector< dim, TEuclideanRing >::at(), DGtal::FreemanChain< TInteger >::chain, DGtal::FreemanChain< TInteger >::x0, DGtal::FreemanChain< TInteger >::xn, DGtal::FreemanChain< TInteger >::y0, and DGtal::FreemanChain< TInteger >::yn.

{
Self newChain;
Point startPoint = getPoint(pos);
Point endPoint = getPoint(pos+n);
newChain.chain = chain.substr(pos,n);
newChain.x0 = startPoint.at(0);
newChain.y0 = startPoint.at(1);
newChain.xn = endPoint.at(0);
newChain.yn = endPoint.at(1);
return newChain;
}
template<typename TInteger>
Vector DGtal::FreemanChain< TInteger >::totalDisplacement ( ) const
inline
Returns:
the vector given by displacement from the first point to the last point.

Definition at line 777 of file FreemanChain.h.

{
return lastPoint() - firstPoint();
}
template<typename TInteger >
char DGtal::FreemanChain< TInteger >::turnedCode ( char  aCode,
bool  ccw = true 
)
inlinestatic

Computes the code obtain from another one after a rotation by pi/2.

Parameters:
aCodeany Freeman code.
ccwwhen 'true' turns counterclockwise (or left), otherwise turns clockwise (right).
Returns:
the turned code.

Definition at line 850 of file FreemanChain.ih.

{
if ( ccw ) return ( aCode == '3' ) ? '0' : ( aCode + 1 );
else return ( aCode == '0' ) ? '3' : ( aCode - 1 );
}
template<typename TInteger>
static void DGtal::FreemanChain< TInteger >::write ( std::ostream &  out,
const FreemanChain< TInteger > &  c 
)
inlinestatic

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

Parameters:
outany output stream,
ca Freeman chain.

Definition at line 846 of file FreemanChain.h.

{
out << c.x0 << " " << c.y0 << " " << c.chain << endl;
}

Field Documentation

template<typename TInteger>
std::string DGtal::FreemanChain< TInteger >::chain
template<typename TInteger>
Integer DGtal::FreemanChain< TInteger >::x0
template<typename TInteger>
Integer DGtal::FreemanChain< TInteger >::xn
template<typename TInteger>
Integer DGtal::FreemanChain< TInteger >::y0
template<typename TInteger>
Integer DGtal::FreemanChain< TInteger >::yn

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