]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Base/Algorithm.hxx
6af90482cef00943d3e6ee3121cb15c4d9957c5d
[FrontAlgorithms.git] / lib / fpa / Base / Algorithm.hxx
1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5
6 #ifndef __fpa__Base__Algorithm__hxx__
7 #define __fpa__Base__Algorithm__hxx__
8
9 // -------------------------------------------------------------------------
10 template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
11 fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >::
12 Algorithm( )
13   : Superclass( ),
14     _TMarksInterface( this ),
15     _TSeedsInterface( this )
16 {
17 }
18
19 // -------------------------------------------------------------------------
20 template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
21 fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >::
22 ~Algorithm( )
23 {
24 }
25
26 // -------------------------------------------------------------------------
27 template< class _TFilter, class _TMarksInterface, class _TSeedsInterface >
28 void fpa::Base::Algorithm< _TFilter, _TMarksInterface, _TSeedsInterface >::
29 GenerateData( )
30 {
31   // Init objects
32   this->_ConfigureOutput( this->m_InitValue );
33   this->_InitMarks( this->GetNumberOfSeeds( ) );
34
35   // Init queue
36   this->_QueueInit( );
37   typename TSeeds::const_iterator sIt = this->BeginSeeds( );
38   for( ; sIt != this->EndSeeds( ); ++sIt )
39     this->_QueuePush( *sIt );
40
41   // Main loop
42   while( this->_QueueSize( ) > 0 )
43   {
44     // Get next candidate
45     TNode node = this->_QueuePop( );
46     if( !( this->_IsMarked( node ) ) )
47     {
48       // Mark it
49       if( this->_Mark( node ) )
50       {
51         // Add neighborhood
52         TNeighborhood neighbors = this->_GetNeighbors( node );
53         typename TNeighborhood::const_iterator nIt = neighbors.begin( );
54         bool coll = false;
55         while( nIt != neighbors.end( ) && !coll )
56         {
57           if( this->_IsMarked( *nIt ) )
58           {
59             // Invoke stop at collisions
60             if( this->_Collisions( node, *nIt ) )
61             {
62               this->_QueueClear( );
63               coll = true;
64
65             } // fi
66           }
67           else
68             this->_QueuePush( *nIt );
69           ++nIt;
70
71         } // elihw
72
73       } // fi
74
75     } // fi
76
77   } // elihw
78 }
79
80 #endif // __fpa__Base__Algorithm__hxx__
81
82 // eof - $RCSfile$