#include <qgarlib/FreemanChain.H>
Inheritance diagram for qgar::FreemanChain:

A Freeman chain represents a series of consecutive points, in an integer (i.e. discrete) coordinate system. It is coded as a series of integer vectors, defined by pairs (direction, length), starting from a point of given coordinates:
etc.
*
*
POINT-2 @ ^
* |
* |
^ * |
| * |
DIRECTION-2 | * LENGTH-2
| * |
* |
* |
(STARTING) DIRECTION-1 --> * |
POINT-0 @**********************@ V
<------ LENGTH-1 ------> POINT-1
A direction is coded using predefined enum type qgar::QGEdirection. As the origin of the coordinates system in images is at top left corner, North and South are upside down for more convenience:
(0,0) +---------------------------------------------> X
|
| QGE_DIRECTION_N
| |
| QGE_DIRECTION_NW \ | / QGE_DIRECTION_NE
| \|/
| QGE_DIRECTION_W -----+----- QGE_DIRECTION_E
| /|\
| QGE_DIRECTION_SW / | \ QGE_DIRECTION_SE
| |
| QGE_DIRECTION_S
Y V
A Freeman chain is implemented using a STL list of Freeman codes, instances of class qgar::FreemanCode:
_iter (current point)
|
V
+-----+ +----+ +----+ +----+
|North| | D1 | | D2 | | Dn |
_chain +-----+<==>+----+<==>+----+<==> ... <==>+----+
| 0 | | L1 | | L2 | | Ln |
+-----+ +----+ +----+ +----+
An (internal) iterator, qgar::FreemanChain::_iter, allows bidirectional traversal of the chain. The validity of the iterator is preserved by any legal operation on the chain, unless the chain is empty.
Three points are permanently available as effective points, i.e. instances of class qgar::GenPoint<int>:
Use cases of a Freeman chain:
Definition at line 173 of file FreemanChain.H.
Public Types | |
| typedef int | value_type |
| Type of the points stored in the chain. | |
| typedef value_type & | reference |
| Reference to qgar::AbstractGenPointChain::value_type. | |
| typedef const value_type & | const_reference |
| Constant reference to qgar::AbstractGenPointChain::value_type. | |
| typedef value_type * | pointer |
| Pointer to qgar::AbstractGenPointChain::value_type. | |
| typedef const value_type * | const_pointer |
| Constant pointer to qgar::AbstractGenPointChain::value_type. | |
Public Member Functions | |
| AbstractGenPointChain () | |
| Default constructor. | |
| virtual void | push_front (const GenPoint< value_type > &aPt)=0 |
| Insert a point at the beginning of the chain. | |
| virtual void | push_back (const GenPoint< value_type > &aPt)=0 |
| Insert a point at the end of the chain. | |
Constructors | |
| FreemanChain (const FreemanChain &aFreemanCh) | |
| Default constructor.Copy constructor. | |
| FreemanChain (const GenPoint< int > &aPt) | |
| Construct from a point, that becomes the current point. | |
| FreemanChain (const GenPoint< int > &aPt, QGEdirection aDir, unsigned int aLength) | |
| Construct from given point, direction and length. | |
Destructor | |
| virtual | ~FreemanChain () |
| Virtual destructor. | |
Access to chain characteristics | |
| virtual bool | empty () const |
| Is current chain empty? | |
| virtual int | size () const |
| Get chain length (number of points). | |
Iterator | |
| virtual void | setToBegin () |
| Make the internal iterator point to the beginning (first point) of the chain, that becomes the current point. | |
| virtual void | setToEnd () |
| Make the internal iterator point to the end (last point) of the chain, that becomes the current point. | |
| virtual bool | isAtBegin () const |
| Does internal iterator points to the beginning of the chain? | |
| virtual bool | isAtEnd () const |
| Does internal iterator points to the end of the chain? | |
| virtual bool | hasNext () const |
| Is there a point after the current point? | |
| virtual bool | hasPrevious () const |
| Is there a point before the current point? | |
| virtual void | moveNext () |
| Move to next point, that becomes the current point. | |
| virtual void | movePrevious () |
| Move to previous point, that becomes the current point. | |
Access to points | |
| virtual const GenPoint< int > & | accessFront () const |
| Get the first point. | |
| virtual GenPoint< int > | front () const |
| Get a copy of the first point. | |
| virtual const GenPoint< int > & | accessBack () const |
| Get the last point. | |
| virtual GenPoint< int > | back () const |
| Get a copy of the last point. | |
| virtual const GenPoint< int > & | accessCurrent () const |
| Get the current point. | |
| virtual GenPoint< int > | current () const |
| Get a copy of the current point. | |
| virtual const GenPoint< int > & | accessNext () |
| Get the successor of the current point. | |
| virtual GenPoint< int > | next () |
| Get a copy of the successor of the current point. | |
| virtual const GenPoint< int > & | accessPrevious () |
| Get the predecessor of the current point. | |
| virtual GenPoint< int > | previous () |
| Get a copy of the predecessor of the current point. | |
Access to Freeman codes | |
| const std::list< FreemanCode > & | accessCodesList () const |
| Get the (STL) list of Freeman codes. | |
Insertion | |
| virtual void | push_front (const GenPoint< int > &aPt) |
| Insert a point at the beginning of the chain. | |
| void | push_front (const FreemanCode &aCode) |
| Insert a point whose location is defined by the given Freeman code, starting from the first point of the chain. | |
| virtual void | push_back (const GenPoint< int > &aPt) |
| Insert a point at the end of the chain. | |
| void | push_back (const FreemanCode &aCode) |
| Insert a point whose location is defined by the given Freeman code, starting from the last point of the chain. | |
Transformations | |
| virtual void | reverse () |
| Reverse elements order in the list. | |
Conversions | |
| virtual std::list< GenPoint< int > > | toPointList () const |
| Convert into a (STL) list of points having integer coordinates. | |
| virtual std::list< GenPoint< float > > | toFPointList () const |
| Convert into a (STL) list of points having float coordinates. | |
| virtual std::list< GenPoint< double > > | toDPointList () const |
| Convert into a (STL) list of points having double coordinates. | |
Operators | |
| FreemanChain & | operator= (const FreemanChain &aFreemanCh) |
| Assignment. | |
Protected Attributes | |
Representation of a Freeman chain | |
| std::list< FreemanCode > | _chain |
| The (STL) list of Freeman codes defining the points of the chain. | |
| std::list< FreemanCode >::iterator | _iter |
| Iterator on the list of Freeman codes. | |
Pre-computed points | |
| GenPoint< int > | _first |
| First point of the chain. | |
| GenPoint< int > | _current |
| Current point of the chain. | |
| GenPoint< int > | _last |
| Last point of the chain. | |
Private Member Functions | |
Constructors | |
| FreemanChain () | |
| Disabled default constructor. | |
|
|
Constant pointer to qgar::AbstractGenPointChain::value_type.
Definition at line 169 of file AbstractGenPointChain.H. |
|
|
Constant reference to qgar::AbstractGenPointChain::value_type.
Definition at line 159 of file AbstractGenPointChain.H. |
|
|
Pointer to qgar::AbstractGenPointChain::value_type.
Definition at line 164 of file AbstractGenPointChain.H. |
|
|
Reference to qgar::AbstractGenPointChain::value_type.
Definition at line 154 of file AbstractGenPointChain.H. |
|
|
Type of the points stored in the chain.
Definition at line 149 of file AbstractGenPointChain.H. |
|
|
Default constructor.Copy constructor.
Definition at line 88 of file FreemanChain.C. |
|
|
Construct from a point, that becomes the current point.
Definition at line 103 of file FreemanChain.C. |
|
||||||||||||||||
|
Construct from given point, direction and length.
Definition at line 118 of file FreemanChain.C. References _chain, _current, _iter, _last, and qgar::FreemanCode::toPoint(). |
|
|
Virtual destructor.
Definition at line 143 of file FreemanChain.C. |
|
|
Disabled default constructor. The default constructor belongs to the private section so that a client cannot use it. Definition at line 67 of file FreemanChain.C. |
|
|
Default constructor.
|
|
|
Get the last point.
Implements qgar::AbstractGenPointChain< int >. Definition at line 296 of file FreemanChain.C. References _last. |
|
|
Get the (STL) list of Freeman codes. The first element is an extra code including qgar::QGE_DIRECTION_N as direction and 0 as length: +-----+ +----+ +----+ +----+
|North| | D1 | | D2 | | Dn |
+-----+ <==> +----+ <==> +----+ <==> ... <==> +----+
| 0 | | L1 | | L2 | | Ln |
+-----+ +----+ +----+ +----+
Using this function to traverse the chain is much more efficient than using appropriate member functions like qgar::FreemanChain::setToBegin, qgar::FreemanChain::hasNext, qgar::FreemanChain::moveNext, etc. In particular, the points represented by the chain may be obtained by applying the successive Freeman codes of the chain to a point initialized to the first point of the chain, in the following way: const std::list<FreemanCode>& lFc = myChain.accessCodesList();
GenPoint<int> p = myChain.first();
for (std::list<FreemanCode>::const_iterator it = lFc.begin();
it != lFc.end();
it++)
{
// Current point
p = (*it).toPoint(p);
// Processing continues...
...
}
Definition at line 266 of file FreemanChain.C. References _chain. |
|
|
Get the current point.
Implements qgar::AbstractGenPointChain< int >. Definition at line 312 of file FreemanChain.C. References _current. |
|
|
Get the first point.
Implements qgar::AbstractGenPointChain< int >. Definition at line 280 of file FreemanChain.C. References _first. |
|
|
Get the successor of the current point.
Implements qgar::AbstractGenPointChain< int >. Definition at line 328 of file FreemanChain.C. References _current, and moveNext(). |
|
|
Get the predecessor of the current point.
Implements qgar::AbstractGenPointChain< int >. Definition at line 346 of file FreemanChain.C. References _current, and movePrevious(). |
|
|
Get a copy of the last point.
Implements qgar::AbstractGenPointChain< int >. Definition at line 304 of file FreemanChain.C. References _last. |
|
|
Get a copy of the current point.
Implements qgar::AbstractGenPointChain< int >. Definition at line 320 of file FreemanChain.C. References _current. |
|
|
Is current chain empty?
Implements qgar::AbstractGenPointChain< int >. Definition at line 157 of file FreemanChain.C. References _chain. |
|
|
Get a copy of the first point.
Implements qgar::AbstractGenPointChain< int >. Definition at line 288 of file FreemanChain.C. References _first. |
|
|
Is there a point after the current point?
Implements qgar::AbstractGenPointChain< int >. Definition at line 221 of file FreemanChain.C. |
|
|
Is there a point before the current point?
Implements qgar::AbstractGenPointChain< int >. Definition at line 231 of file FreemanChain.C. |
|
|
Does internal iterator points to the beginning of the chain?
Implements qgar::AbstractGenPointChain< int >. Definition at line 203 of file FreemanChain.C. |
|
|
Does internal iterator points to the end of the chain?
Implements qgar::AbstractGenPointChain< int >. Definition at line 212 of file FreemanChain.C. |
|
|
Move to next point, that becomes the current point.
Implements qgar::AbstractGenPointChain< int >. Definition at line 240 of file FreemanChain.C. References _current, and _iter. Referenced by accessNext(), and next(). |
|
|
Move to previous point, that becomes the current point.
Implements qgar::AbstractGenPointChain< int >. Definition at line 251 of file FreemanChain.C. References _current, and _iter. Referenced by accessPrevious(), and previous(). |
|
|
Get a copy of the successor of the current point.
Implements qgar::AbstractGenPointChain< int >. Definition at line 337 of file FreemanChain.C. References _current, and moveNext(). |
|
|
Assignment.
Definition at line 662 of file FreemanChain.C. |
|
|
Get a copy of the predecessor of the current point.
Implements qgar::AbstractGenPointChain< int >. Definition at line 355 of file FreemanChain.C. References _current, and movePrevious(). |
|
|
Insert a point at the end of the chain.
|
|
|
Insert a point whose location is defined by the given Freeman code, starting from the last point of the chain.
Definition at line 498 of file FreemanChain.C. References _chain, _last, and qgar::FreemanCode::toPoint(). |
|
|
Insert a point at the end of the chain.
Definition at line 455 of file FreemanChain.C. References _chain, _current, _first, _iter, _last, qgar::qgDirection(), qgar::QGE_DIRECTION_N, qgar::GenPoint< T >::x(), and qgar::GenPoint< T >::y(). |
|
|
Insert a point at the beginning of the chain.
|
|
|
Insert a point whose location is defined by the given Freeman code, starting from the first point of the chain.
Definition at line 428 of file FreemanChain.C. References _chain, _first, qgar::FreemanCode::direction(), qgar::FreemanCode::length(), qgar::QGE_DIRECTION_N, qgar::qgOpposite(), qgar::FreemanCode::setDirLength(), and qgar::FreemanCode::toPoint(). |
|
|
Insert a point at the beginning of the chain.
Definition at line 380 of file FreemanChain.C. References _chain, _current, _first, _iter, _last, qgar::qgDirection(), qgar::QGE_DIRECTION_N, qgar::FreemanCode::setDirLength(), qgar::GenPoint< T >::x(), and qgar::GenPoint< T >::y(). |
|
|
Reverse elements order in the list.
Implements qgar::AbstractGenPointChain< int >. Definition at line 515 of file FreemanChain.C. References _chain, _current, _first, _iter, _last, qgar::qgOpposite(), qgar::GenPoint< T >::setXY(), qgar::GenPoint< T >::x(), and qgar::GenPoint< T >::y(). |
|
|
Make the internal iterator point to the beginning (first point) of the chain, that becomes the current point.
Implements qgar::AbstractGenPointChain< int >. Definition at line 181 of file FreemanChain.C. |
|
|
Make the internal iterator point to the end (last point) of the chain, that becomes the current point.
Implements qgar::AbstractGenPointChain< int >. Definition at line 192 of file FreemanChain.C. |
|
|
Get chain length (number of points).
Implements qgar::AbstractGenPointChain< int >. Definition at line 166 of file FreemanChain.C. References _chain. |
|
|
Convert into a (STL) list of points having double coordinates.
Definition at line 637 of file FreemanChain.C. References _chain, and _first. Referenced by qgar::Maer::Maer(). |
|
|
Convert into a (STL) list of points having float coordinates.
Definition at line 618 of file FreemanChain.C. |
|
|
Convert into a (STL) list of points having integer coordinates.
Implements qgar::AbstractGenPointChain< int >. Definition at line 599 of file FreemanChain.C. |
|
|
The (STL) list of Freeman codes defining the points of the chain.
Definition at line 583 of file FreemanChain.H. Referenced by accessCodesList(), empty(), FreemanChain(), hasNext(), hasPrevious(), isAtBegin(), isAtEnd(), operator=(), push_back(), push_front(), reverse(), setToBegin(), setToEnd(), size(), toDPointList(), toFPointList(), and toPointList(). |
|
|
Current point of the chain.
Definition at line 605 of file FreemanChain.H. Referenced by accessCurrent(), accessNext(), accessPrevious(), current(), FreemanChain(), moveNext(), movePrevious(), next(), operator=(), previous(), push_back(), push_front(), reverse(), setToBegin(), and setToEnd(). |
|
|
First point of the chain.
Definition at line 600 of file FreemanChain.H. Referenced by accessFront(), front(), operator=(), push_back(), push_front(), reverse(), setToBegin(), toDPointList(), toFPointList(), and toPointList(). |
|
|
Iterator on the list of Freeman codes.
Definition at line 588 of file FreemanChain.H. Referenced by FreemanChain(), hasNext(), hasPrevious(), isAtBegin(), isAtEnd(), moveNext(), movePrevious(), operator=(), push_back(), push_front(), reverse(), setToBegin(), and setToEnd(). |
|
|
Last point of the chain.
Definition at line 610 of file FreemanChain.H. Referenced by accessBack(), back(), FreemanChain(), operator=(), push_back(), push_front(), reverse(), and setToEnd(). |