1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
6 #ifndef __CTBronchi__MoriLabelling__hxx__
7 #define __CTBronchi__MoriLabelling__hxx__
9 #include <itkImageRegionConstIteratorWithIndex.h>
11 // -------------------------------------------------------------------------
12 template< class _TInputImage, class _TLabelImage >
13 const typename CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
14 TLabelImage* CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
15 GetInputLabelImage( ) const
17 return( this->GetLabels( ) );
20 // -------------------------------------------------------------------------
21 template< class _TInputImage, class _TLabelImage >
22 void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
23 SetInputLabelImage( TLabelImage* image )
25 this->SetLabels( image );
28 // -------------------------------------------------------------------------
29 template< class _TInputImage, class _TLabelImage >
30 const typename CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
31 TInputImage* CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
32 GetInputRawImage( ) const
34 return( this->GetInput( ) );
37 // -------------------------------------------------------------------------
38 template< class _TInputImage, class _TLabelImage >
39 void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
40 SetInputRawImage( TInputImage* image )
42 this->SetInput( image );
45 // -------------------------------------------------------------------------
46 template< class _TInputImage, class _TLabelImage >
47 typename CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
48 TInputValue CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
49 GetUpperThreshold( ) const
51 const TThresholdFunction* func =
52 dynamic_cast< const TThresholdFunction* >( this->GetValuePredicate( ) );
54 return( func->GetUpper( ) );
56 return( TInputValue( 0 ) );
59 // -------------------------------------------------------------------------
60 template< class _TInputImage, class _TLabelImage >
61 void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
62 SetUpperThreshold( TInputValue t )
64 TThresholdFunction* func =
65 dynamic_cast< TThresholdFunction* >( this->GetValuePredicate( ) );
70 // -------------------------------------------------------------------------
71 template< class _TInputImage, class _TLabelImage >
72 typename CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
73 TOutputValue CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
74 GetOutsideValue( ) const
76 return( this->GetInitValue( ) );
79 // -------------------------------------------------------------------------
80 template< class _TInputImage, class _TLabelImage >
81 void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
82 SetOutsideLabel( TOutputValue o )
84 this->SetInitValue( o );
87 // -------------------------------------------------------------------------
88 template< class _TInputImage, class _TLabelImage >
89 CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
92 m_InsideLabel( TOutputValue( 0 ) )
94 typename TThresholdFunction::Pointer func = TThresholdFunction::New( );
95 this->SetPredicate( func );
98 // -------------------------------------------------------------------------
99 template< class _TInputImage, class _TLabelImage >
100 CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
105 // -------------------------------------------------------------------------
106 template< class _TInputImage, class _TLabelImage >
107 typename CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
108 TNodes CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
111 this->m_Seeds.clear( );
112 const TLabelImage* lbl = this->GetLabels( );
115 std::ostringstream msg;
116 msg << "itk::ERROR: CTBronchi::MoriLabelling (" << this
117 << "): Labelled image not defined.";
118 ::itk::ExceptionObject e(
119 __FILE__, __LINE__, msg.str( ).c_str( ), ITK_LOCATION
125 // Iterate over labels
126 typename TLabelImage::RegionType reg = lbl->GetRequestedRegion( );
127 itk::ImageRegionConstIteratorWithIndex< TLabelImage > lIt( lbl, reg );
128 for( lIt.GoToBegin( ); !lIt.IsAtEnd( ); ++lIt )
132 bool is_seed = false;
133 for( unsigned int d = 0; d < TLabelImage::ImageDimension; ++d )
135 for( int s = -1; s <= 1; s += 2 )
137 TVertex neigh = lIt.GetIndex( );
139 if( reg.IsInside( neigh ) )
140 is_seed |= ( lbl->GetPixel( neigh ) == 0 );
148 typename TSeedsInterface::TNode node;
149 node.Vertex = lIt.GetIndex( );
150 node.Parent = lIt.GetIndex( );
151 node.FrontId = lIt.Get( );
152 node.Value = this->m_InsideLabel;
153 this->_Mark( node.Vertex, node.FrontId );
154 this->_UpdateOutputValue( node );
158 typename TSeedsInterface::TSeed seed;
159 seed.Vertex = lIt.GetIndex( );
160 seed.IsPoint = false;
161 seed.FrontId = lIt.Get( );
162 this->m_Seeds.push_back( seed );
170 // Ok, finish initialization
171 return( this->Superclass::_UnifySeeds( ) );
174 // -------------------------------------------------------------------------
175 template< class _TInputImage, class _TLabelImage >
176 void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
177 _UpdateOutputValue( TNode& n )
179 const TLabelImage* input_labels = this->GetInputLabelImage( );
181 this->Superclass::_UpdateOutputValue( n );
184 if( input_labels->GetPixel( n.Vertex ) == this->GetInsideValue( ) )
185 n.Value = this->GetInsideLabel( );
187 n.Value = TOutputValue( 0 );
188 this->TAlgorithm::_UpdateOutputValue( n );
193 #endif // __CTBronchi__MoriLabelling__hxx__