1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5 #ifndef __fpa__Filters__CollisionMarksInterface__hxx__
6 #define __fpa__Filters__CollisionMarksInterface__hxx__
10 // -------------------------------------------------------------------------
11 template< class _TTraits >
12 bool fpa::Filters::CollisionMarksInterface< _TTraits >::
13 StopAtOneFront( ) const
15 return( this->m_StopAtOneFront );
18 // -------------------------------------------------------------------------
19 template< class _TTraits >
20 void fpa::Filters::CollisionMarksInterface< _TTraits >::
23 this->SetStopAtOneFront( true );
26 // -------------------------------------------------------------------------
27 template< class _TTraits >
28 void fpa::Filters::CollisionMarksInterface< _TTraits >::
31 this->SetStopAtOneFront( false );
34 // -------------------------------------------------------------------------
35 template< class _TTraits >
36 void fpa::Filters::CollisionMarksInterface< _TTraits >::
37 SetStopAtOneFront( bool v )
39 if( this->m_StopAtOneFront != v )
41 this->m_StopAtOneFront = v;
42 if( this->m_Filter.IsNotNull( ) )
43 this->m_Filter->Modified( );
48 // -------------------------------------------------------------------------
49 template< class _TTraits >
50 fpa::Filters::CollisionMarksInterface< _TTraits >::
51 CollisionMarksInterface( itk::ProcessObject* f )
53 m_StopAtOneFront( false ),
54 m_NumberOfFronts( 0 ),
59 // -------------------------------------------------------------------------
60 template< class _TTraits >
61 fpa::Filters::CollisionMarksInterface< _TTraits >::
62 ~CollisionMarksInterface( )
66 // -------------------------------------------------------------------------
67 template< class _TTraits >
68 bool fpa::Filters::CollisionMarksInterface< _TTraits >::
69 _Collisions( const TVertex& a, const TVertex& b )
71 unsigned long ma = this->_GetMark( a );
72 unsigned long mb = this->_GetMark( b );
73 if( ma == mb || ma == 0 || mb == 0 )
76 // Mark collision, if it is new
79 bool exists = this->m_Collisions[ ma ][ mb ].second;
80 exists &= this->m_Collisions[ mb ][ ma ].second;
83 this->m_Collisions[ ma ][ mb ].first = a;
84 this->m_Collisions[ ma ][ mb ].second = true;
85 this->m_Collisions[ mb ][ ma ].first = b;
86 this->m_Collisions[ mb ][ ma ].second = true;
88 // Update number of fronts
89 unsigned long count = 0;
90 std::vector< bool > m( this->m_NumberOfSeeds, false );
91 std::queue< unsigned long > q;
95 unsigned long f = q.front( );
103 for( unsigned int n = 0; n < this->m_NumberOfSeeds; ++n )
104 if( this->m_Collisions[ f ][ n ].second && !m[ n ] )
108 this->m_NumberOfFronts = this->m_NumberOfSeeds - count + 1;
112 this->m_StopAtOneFront &&
113 this->m_NumberOfSeeds > 1 &&
114 this->m_NumberOfFronts == 1
118 // -------------------------------------------------------------------------
119 template< class _TTraits >
120 void fpa::Filters::CollisionMarksInterface< _TTraits >::
121 _InitCollisions( unsigned long nSeeds )
123 this->m_NumberOfFronts = this->m_NumberOfSeeds = nSeeds;
124 TCollision coll( TVertex( ), false );
125 TCollisionsRow row( this->m_NumberOfFronts, coll );
126 this->m_Collisions.clear( );
127 this->m_Collisions.resize( this->m_NumberOfFronts, row );
130 #endif // __fpa__Filters__CollisionMarksInterface__hxx__