1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
6 #ifndef __CTBronchi__MoriLabelling__hxx__
7 #define __CTBronchi__MoriLabelling__hxx__
10 #include <itkImageRegionConstIteratorWithIndex.h>
12 // -------------------------------------------------------------------------
13 template< class _TInputImage, class _TLabelImage, class _TTraits >
14 const typename CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
15 TLabelImage* CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
16 GetInputLabelImage( ) const
18 return( this->GetLabels( ) );
21 // -------------------------------------------------------------------------
22 template< class _TInputImage, class _TLabelImage, class _TTraits >
23 void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
24 SetInputLabelImage( TLabelImage* image )
26 this->SetLabels( image );
29 // -------------------------------------------------------------------------
30 template< class _TInputImage, class _TLabelImage, class _TTraits >
31 const typename CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
32 TInputImage* CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
33 GetInputRawImage( ) const
35 return( this->GetInput( ) );
38 // -------------------------------------------------------------------------
39 template< class _TInputImage, class _TLabelImage, class _TTraits >
40 void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
41 SetInputRawImage( TInputImage* image )
43 this->SetInput( image );
46 // -------------------------------------------------------------------------
47 template< class _TInputImage, class _TLabelImage, class _TTraits >
48 typename CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
49 TInputValue CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
50 GetUpperThreshold( ) const
52 const TThresholdFunction* func =
53 dynamic_cast< const TThresholdFunction* >( this->GetValuePredicate( ) );
55 return( func->GetUpper( ) );
57 return( TInputValue( 0 ) );
60 // -------------------------------------------------------------------------
61 template< class _TInputImage, class _TLabelImage, class _TTraits >
62 void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
63 SetUpperThreshold( TInputValue t )
65 TThresholdFunction* func =
66 dynamic_cast< TThresholdFunction* >( this->GetValuePredicate( ) );
71 // -------------------------------------------------------------------------
72 template< class _TInputImage, class _TLabelImage, class _TTraits >
73 typename CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
74 TOutputValue CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
75 GetOutsideValue( ) const
77 return( this->GetInitValue( ) );
80 // -------------------------------------------------------------------------
81 template< class _TInputImage, class _TLabelImage, class _TTraits >
82 void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
83 SetOutsideLabel( TOutputValue o )
85 this->SetInitValue( o );
88 // -------------------------------------------------------------------------
89 template< class _TInputImage, class _TLabelImage, class _TTraits >
90 CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
93 m_InsideLabel( TOutputValue( 0 ) )
95 typename TThresholdFunction::Pointer func = TThresholdFunction::New( );
96 this->SetPredicate( func );
99 // -------------------------------------------------------------------------
100 template< class _TInputImage, class _TLabelImage, class _TTraits >
101 CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
106 // -------------------------------------------------------------------------
107 template< class _TInputImage, class _TLabelImage, class _TTraits >
108 typename CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
109 TNodes CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
112 this->m_Seeds.clear( );
113 const TLabelImage* lbl = this->GetLabels( );
116 std::ostringstream msg;
117 msg << "itk::ERROR: CTBronchi::MoriLabelling (" << this
118 << "): Labelled image not defined.";
119 ::itk::ExceptionObject e(
120 __FILE__, __LINE__, msg.str( ).c_str( ), ITK_LOCATION
126 // Iterate over labels
127 typename TLabelImage::RegionType reg = lbl->GetRequestedRegion( );
128 itk::ImageRegionConstIteratorWithIndex< TLabelImage > lIt( lbl, reg );
129 for( lIt.GoToBegin( ); !lIt.IsAtEnd( ); ++lIt )
133 bool is_seed = false;
134 for( unsigned int d = 0; d < TLabelImage::ImageDimension; ++d )
136 for( int s = -1; s <= 1; s += 2 )
138 TVertex neigh = lIt.GetIndex( );
140 if( reg.IsInside( neigh ) )
141 is_seed |= ( lbl->GetPixel( neigh ) == 0 );
149 typename TSeedsInterface::TNode node;
150 node.Vertex = lIt.GetIndex( );
151 node.Parent = lIt.GetIndex( );
152 node.FrontId = lIt.Get( );
153 node.Value = this->m_InsideLabel;
154 this->_Mark( node.Vertex, node.FrontId );
155 this->_UpdateOutputValue( node );
159 typename TSeedsInterface::TSeed seed;
160 seed.Vertex = lIt.GetIndex( );
161 seed.IsPoint = false;
162 seed.FrontId = lIt.Get( );
163 this->m_Seeds.push_back( seed );
171 // Ok, finish initialization
172 return( this->Superclass::_UnifySeeds( ) );
175 // -------------------------------------------------------------------------
176 template< class _TInputImage, class _TLabelImage, class _TTraits >
177 void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
178 _UpdateOutputValue( TNode& n )
180 const TLabelImage* input_labels = this->GetInputLabelImage( );
182 this->Superclass::_UpdateOutputValue( n );
185 if( input_labels->GetPixel( n.Vertex ) == this->GetInsideValue( ) )
186 n.Value = this->GetInsideLabel( );
188 n.Value = TOutputValue( 0 );
189 this->TAlgorithm::_UpdateOutputValue( n );
195 #endif // __CTBronchi__MoriLabelling__hxx__