]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Filters/Image/LabelsSeedFilter.hxx
b23a4c31d770cad3d1237e5de5b99ed5e5fa8b04
[FrontAlgorithms.git] / lib / fpa / Filters / Image / LabelsSeedFilter.hxx
1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5 #ifndef __fpa__Filters__Image__LabelsSeedFilter__hxx__
6 #define __fpa__Filters__Image__LabelsSeedFilter__hxx__
7
8 #include <itkImageRegionConstIteratorWithIndex.h>
9
10 // -------------------------------------------------------------------------
11 template< class _TFilter, class _TInputLabels >
12 fpa::Filters::Image::LabelsSeedFilter< _TFilter, _TInputLabels >::
13 LabelsSeedFilter( )
14   : Superclass( )
15 {
16   fpaFilterInputConfigureMacro( InputLabels, TInputLabels );
17 }
18
19 // -------------------------------------------------------------------------
20 template< class _TFilter, class _TInputLabels >
21 fpa::Filters::Image::LabelsSeedFilter< _TFilter, _TInputLabels >::
22 ~LabelsSeedFilter( )
23 {
24 }
25
26 // -------------------------------------------------------------------------
27 template< class _TFilter, class _TInputLabels >
28 const itk::DataObject*
29 fpa::Filters::Image::LabelsSeedFilter< _TFilter, _TInputLabels >::
30 _GetReferenceInput( ) const
31 {
32   return( this->GetInputLabels( ) );
33 }
34
35 // -------------------------------------------------------------------------
36 template< class _TFilter, class _TInputLabels >
37 void fpa::Filters::Image::LabelsSeedFilter< _TFilter, _TInputLabels >::
38 _PrepareSeeds( const itk::DataObject* input )
39 {
40   // Input object is a labelled image?
41   const TInputLabels* labels = dynamic_cast< const TInputLabels* >( input );
42   if( labels != NULL )
43   {
44     this->m_UnifiedSeeds.clear( );
45
46     // Iterate over labels
47     typedef itk::ImageRegionConstIteratorWithIndex< TInputLabels > _TIt;
48     typename TInputLabels::RegionType reg = labels->GetRequestedRegion( );
49     _TIt lIt( labels, reg );
50     for( lIt.GoToBegin( ); !lIt.IsAtEnd( ); ++lIt )
51     {
52       if( lIt.Get( ) > 0 )
53       {
54         bool is_seed = false;
55         for( unsigned int d = 0; d < Self::Dimension; ++d )
56         {
57           for( int s = -1; s <= 1; s += 2 )
58           {
59             TVertex neigh = lIt.GetIndex( );
60             neigh[ d ] += s;
61             if( reg.IsInside( neigh ) )
62               is_seed |= ( labels->GetPixel( neigh ) == 0 );
63
64           } // rof
65
66         } // rof
67
68         // Add pixel as seed or already marked
69         TNode node;
70         node.Vertex = lIt.GetIndex( );
71         node.Parent = lIt.GetIndex( );
72         node.FrontId = lIt.Get( );
73         node.Value = TOutputValue( 0 );
74         if( !is_seed )
75         {
76           this->_Mark( node.Vertex, node.FrontId );
77           this->_UpdateOutputValue( node );
78         }
79         else
80           this->m_UnifiedSeeds.insert( node );
81
82       } // fi
83
84     } // rof
85
86   } // fi
87 }
88
89 #endif // __fpa__Filters__Image__LabelsSeedFilter__hxx__
90 // eof - $RCSfile$