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