1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5 #ifndef __fpa__Filters__MarksWithCollisionsInterface__hxx__
6 #define __fpa__Filters__MarksWithCollisionsInterface__hxx__
10 // -------------------------------------------------------------------------
11 template< class _TTraits >
12 fpa::Filters::MarksWithCollisionsInterface< _TTraits >::
13 MarksWithCollisionsInterface( itk::ProcessObject* f )
15 m_StopAtOneFront( false ),
16 m_NumberOfFronts( 0 ),
21 // -------------------------------------------------------------------------
22 template< class _TTraits >
23 fpa::Filters::MarksWithCollisionsInterface< _TTraits >::
24 ~MarksWithCollisionsInterface( )
28 // -------------------------------------------------------------------------
29 template< class _TTraits >
30 bool fpa::Filters::MarksWithCollisionsInterface< _TTraits >::
31 StopAtOneFront( ) const
33 return( this->m_StopAtOneFront );
36 // -------------------------------------------------------------------------
37 template< class _TTraits >
38 void fpa::Filters::MarksWithCollisionsInterface< _TTraits >::
41 this->SetStopAtOneFront( true );
44 // -------------------------------------------------------------------------
45 template< class _TTraits >
46 void fpa::Filters::MarksWithCollisionsInterface< _TTraits >::
49 this->SetStopAtOneFront( false );
52 // -------------------------------------------------------------------------
53 template< class _TTraits >
54 void fpa::Filters::MarksWithCollisionsInterface< _TTraits >::
55 SetStopAtOneFront( bool v )
57 if( this->m_StopAtOneFront != v )
59 this->m_StopAtOneFront = v;
60 if( this->m_Filter != NULL )
61 this->m_Filter->Modified( );
66 // -------------------------------------------------------------------------
67 template< class _TTraits >
68 void fpa::Filters::MarksWithCollisionsInterface< _TTraits >::
69 _InitCollisions( unsigned long nSeeds )
71 this->m_NumberOfFronts = this->m_NumberOfSeeds = nSeeds;
72 TCollision coll( TVertex( ), false );
73 TCollisionsRow row( this->m_NumberOfFronts, coll );
74 this->m_Collisions.clear( );
75 this->m_Collisions.resize( this->m_NumberOfFronts, row );
78 // -------------------------------------------------------------------------
79 template< class _TTraits >
80 bool fpa::Filters::MarksWithCollisionsInterface< _TTraits >::
81 _Collisions( const TVertex& a, const TVertex& b )
83 unsigned long ma = this->_GetMark( a );
84 unsigned long mb = this->_GetMark( b );
85 if( ma == mb || ma == 0 || mb == 0 )
88 // Mark collision, if it is new
91 bool exists = this->m_Collisions[ ma ][ mb ].second;
92 exists &= this->m_Collisions[ mb ][ ma ].second;
95 this->m_Collisions[ ma ][ mb ].first = a;
96 this->m_Collisions[ ma ][ mb ].second = true;
97 this->m_Collisions[ mb ][ ma ].first = b;
98 this->m_Collisions[ mb ][ ma ].second = true;
100 // Update number of fronts
101 unsigned long count = 0;
102 std::vector< bool > m( this->m_NumberOfSeeds, false );
103 std::queue< unsigned long > q;
107 unsigned long f = q.front( );
115 for( unsigned int n = 0; n < this->m_NumberOfSeeds; ++n )
116 if( this->m_Collisions[ f ][ n ].second && !m[ n ] )
120 this->m_NumberOfFronts = this->m_NumberOfSeeds - count + 1;
124 this->m_StopAtOneFront &&
125 this->m_NumberOfSeeds > 1 &&
126 this->m_NumberOfFronts == 1
130 #endif // __fpa__Filters__MarksWithCollisionsInterface__hxx__