1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
6 #ifndef __fpa__Base__MarksInterfaceWithCollisions__hxx__
7 #define __fpa__Base__MarksInterfaceWithCollisions__hxx__
11 // -------------------------------------------------------------------------
12 template< class _TVertex >
13 bool fpa::Base::MarksInterfaceWithCollisions< _TVertex >::
14 StopAtOneFront( ) const
16 return( this->m_StopAtOneFront );
19 // -------------------------------------------------------------------------
20 template< class _TVertex >
21 void fpa::Base::MarksInterfaceWithCollisions< _TVertex >::
24 this->SetStopAtOneFront( true );
27 // -------------------------------------------------------------------------
28 template< class _TVertex >
29 void fpa::Base::MarksInterfaceWithCollisions< _TVertex >::
32 this->SetStopAtOneFront( false );
35 // -------------------------------------------------------------------------
36 template< class _TVertex >
37 void fpa::Base::MarksInterfaceWithCollisions< _TVertex >::
38 SetStopAtOneFront( bool v )
40 if( this->m_StopAtOneFront != v )
42 this->m_StopAtOneFront = v;
43 if( this->m_Filter != NULL )
44 this->m_Filter->Modified( );
49 // -------------------------------------------------------------------------
50 template< class _TVertex >
51 fpa::Base::MarksInterfaceWithCollisions< _TVertex >::
52 MarksInterfaceWithCollisions( itk::ProcessObject* filter )
53 : Superclass( filter ),
54 m_StopAtOneFront( false ),
59 // -------------------------------------------------------------------------
60 template< class _TVertex >
61 fpa::Base::MarksInterfaceWithCollisions< _TVertex >::
62 ~MarksInterfaceWithCollisions( )
66 // -------------------------------------------------------------------------
67 template< class _TVertex >
68 void fpa::Base::MarksInterfaceWithCollisions< _TVertex >::
69 _InitMarks( unsigned long nSeeds )
71 this->Superclass::_InitMarks( nSeeds );
72 this->m_NumberOfFronts = nSeeds;
73 TCollision coll( TVertex( ), false );
74 TCollisionsRow row( this->m_NumberOfFronts, coll );
75 this->m_Collisions.clear( );
76 this->m_Collisions.resize( this->m_NumberOfFronts, row );
79 // -------------------------------------------------------------------------
80 template< class _TVertex >
81 bool fpa::Base::MarksInterfaceWithCollisions< _TVertex >::
82 _Collisions( const TVertex& a, const TVertex& b )
84 unsigned long ma = this->_GetMark( a );
85 unsigned long mb = this->_GetMark( b );
86 if( ma == mb || ma == 0 || mb == 0 )
89 // Mark collision, if it is new
92 bool exists = this->m_Collisions[ ma ][ mb ].second;
93 exists &= this->m_Collisions[ mb ][ ma ].second;
96 this->m_Collisions[ ma ][ mb ].first = a;
97 this->m_Collisions[ ma ][ mb ].second = true;
98 this->m_Collisions[ mb ][ ma ].first = b;
99 this->m_Collisions[ mb ][ ma ].second = true;
101 // Update number of fronts
102 unsigned long count = 0;
103 std::vector< bool > m( this->m_NumberOfSeeds, false );
104 std::queue< unsigned long > q;
108 unsigned long f = q.front( );
116 for( unsigned int n = 0; n < this->m_NumberOfSeeds; ++n )
117 if( this->m_Collisions[ f ][ n ].second && !m[ n ] )
121 this->m_NumberOfFronts = this->m_NumberOfSeeds - count + 1;
125 this->m_StopAtOneFront &&
126 this->m_NumberOfSeeds > 1 &&
127 this->m_NumberOfFronts == 1
131 #endif // __fpa__Base__MarksInterfaceWithCollisions__hxx__