1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
6 #ifndef __fpa__Image__RandomWalker__hxx__
7 #define __fpa__Image__RandomWalker__hxx__
11 #include <itkImageRegionConstIteratorWithIndex.h>
12 #include <itkExceptionObject.h>
14 #include <fpa/Image/Functors/Dijkstra/Gaussian.h>
16 // -------------------------------------------------------------------------
17 template< class _TInputImage, class _TLabelImage, class _TScalar, class _TTraits >
19 fpa::Image::RandomWalker< _TInputImage, _TLabelImage, _TScalar, _TTraits >::
22 const TLabelImage* labels = this->GetLabels( );
23 itk::ModifiedTimeType t = this->Superclass::GetMTime( );
26 itk::ModifiedTimeType q = labels->GetMTime( );
33 // -------------------------------------------------------------------------
34 template< class _TInputImage, class _TLabelImage, class _TScalar, class _TTraits >
35 fpa::Image::RandomWalker< _TInputImage, _TLabelImage, _TScalar, _TTraits >::
39 typedef fpa::Image::Functors::Dijkstra::Gaussian< TInputImage, TScalar > _TDefaultFunction;
40 this->SetWeightFunction( _TDefaultFunction::New( ) );
43 // -------------------------------------------------------------------------
44 template< class _TInputImage, class _TLabelImage, class _TScalar, class _TTraits >
45 fpa::Image::RandomWalker< _TInputImage, _TLabelImage, _TScalar, _TTraits >::
50 // -------------------------------------------------------------------------
51 template< class _TInputImage, class _TLabelImage, class _TScalar, class _TTraits >
52 void fpa::Image::RandomWalker< _TInputImage, _TLabelImage, _TScalar, _TTraits >::
53 _BeforeGenerateData( )
55 this->Superclass::_BeforeGenerateData( );
57 dynamic_cast< TWeightFunction* >( this->GetWeightFunction( ) );
59 wf->SetImage( this->GetInput( ) );
62 // -------------------------------------------------------------------------
63 template< class _TInputImage, class _TLabelImage, class _TScalar, class _TTraits >
64 typename fpa::Image::RandomWalker< _TInputImage, _TLabelImage, _TScalar, _TTraits >::
65 TNodes fpa::Image::RandomWalker< _TInputImage, _TLabelImage, _TScalar, _TTraits >::
68 this->m_Seeds.clear( );
69 const TLabelImage* lbl = this->GetLabels( );
72 std::ostringstream msg;
73 msg << "itk::ERROR: fpa::Image::RandomWalker (" << this
74 << "): Labelled image not defined.";
75 ::itk::ExceptionObject e(
76 __FILE__, __LINE__, msg.str( ).c_str( ), ITK_LOCATION
82 // Iterate over labels
83 typename TLabelImage::RegionType reg = lbl->GetRequestedRegion( );
84 itk::ImageRegionConstIteratorWithIndex< TLabelImage > lIt( lbl, reg );
85 for( lIt.GoToBegin( ); !lIt.IsAtEnd( ); ++lIt )
90 for( unsigned int d = 0; d < TLabelImage::ImageDimension; ++d )
92 for( int s = -1; s <= 1; s += 2 )
94 TVertex neigh = lIt.GetIndex( );
96 if( reg.IsInside( neigh ) )
97 is_seed |= ( lbl->GetPixel( neigh ) == 0 );
106 node.Vertex = lIt.GetIndex( );
107 node.Parent = lIt.GetIndex( );
108 node.FrontId = lIt.Get( );
109 node.Value = TScalar( 0 );
110 this->_Mark( node.Vertex, node.FrontId );
111 this->_UpdateOutputValue( node );
116 seed.Vertex = lIt.GetIndex( );
117 seed.IsPoint = false;
118 seed.FrontId = lIt.Get( );
119 this->m_Seeds.push_back( seed );
127 // Ok, finish initialization
128 return( this->Superclass::_UnifySeeds( ) );
131 #endif // __fpa__Image__RandomWalker__hxx__