]> Creatis software - FrontAlgorithms.git/blob - appli/CTBronchi/MoriLabelling.hxx
228ed2d96f58b629a14e2d70866a633650f23f34
[FrontAlgorithms.git] / appli / CTBronchi / MoriLabelling.hxx
1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5
6 #ifndef __CTBronchi__MoriLabelling__hxx__
7 #define __CTBronchi__MoriLabelling__hxx__
8
9 /* TODO
10    #include <itkImageRegionConstIteratorWithIndex.h>
11
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
17    {
18    return( this->GetLabels( ) );
19    }
20
21    // -------------------------------------------------------------------------
22    template< class _TInputImage, class _TLabelImage, class _TTraits >
23    void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
24    SetInputLabelImage( TLabelImage* image )
25    {
26    this->SetLabels( image );
27    }
28
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
34    {
35    return( this->GetInput( ) );
36    }
37
38    // -------------------------------------------------------------------------
39    template< class _TInputImage, class _TLabelImage, class _TTraits >
40    void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
41    SetInputRawImage( TInputImage* image )
42    {
43    this->SetInput( image );
44    }
45
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
51    {
52    const TThresholdFunction* func =
53    dynamic_cast< const TThresholdFunction* >( this->GetValuePredicate( ) );
54    if( func != NULL )
55    return( func->GetUpper( ) );
56    else
57    return( TInputValue( 0 ) );
58    }
59
60    // -------------------------------------------------------------------------
61    template< class _TInputImage, class _TLabelImage, class _TTraits >
62    void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
63    SetUpperThreshold( TInputValue t )
64    {
65    TThresholdFunction* func =
66    dynamic_cast< TThresholdFunction* >( this->GetValuePredicate( ) );
67    if( func != NULL )
68    func->SetUpper( t );
69    }
70
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
76    {
77    return( this->GetInitValue( ) );
78    }
79
80    // -------------------------------------------------------------------------
81    template< class _TInputImage, class _TLabelImage, class _TTraits >
82    void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
83    SetOutsideLabel( TOutputValue o )
84    {
85    this->SetInitValue( o );
86    }
87
88    // -------------------------------------------------------------------------
89    template< class _TInputImage, class _TLabelImage, class _TTraits >
90    CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
91    MoriLabelling( )
92    : Superclass( ),
93    m_InsideLabel( TOutputValue( 0 ) )
94    {
95    typename TThresholdFunction::Pointer func = TThresholdFunction::New( );
96    this->SetPredicate( func );
97    }
98
99    // -------------------------------------------------------------------------
100    template< class _TInputImage, class _TLabelImage, class _TTraits >
101    CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
102    ~MoriLabelling( )
103    {
104    }
105
106    // -------------------------------------------------------------------------
107    template< class _TInputImage, class _TLabelImage, class _TTraits >
108    typename CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
109    TNodes CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
110    _UnifySeeds( )
111    {
112    this->m_Seeds.clear( );
113    const TLabelImage* lbl = this->GetLabels( );
114    if( lbl == NULL )
115    {
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
121    );
122    throw e;
123
124    } // fi
125
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 )
130    {
131    if( lIt.Get( ) > 0 )
132    {
133    bool is_seed = false;
134    for( unsigned int d = 0; d < TLabelImage::ImageDimension; ++d )
135    {
136    for( int s = -1; s <= 1; s += 2 )
137    {
138    TVertex neigh = lIt.GetIndex( );
139    neigh[ d ] += s;
140    if( reg.IsInside( neigh ) )
141    is_seed |= ( lbl->GetPixel( neigh ) == 0 );
142
143    } // rof
144
145    } // rof
146
147    if( !is_seed )
148    {
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 );
156    }
157    else
158    {
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 );
164
165    } // fi
166
167    } // fi
168
169    } // rof
170
171    // Ok, finish initialization
172    return( this->Superclass::_UnifySeeds( ) );
173    }
174
175    // -------------------------------------------------------------------------
176    template< class _TInputImage, class _TLabelImage, class _TTraits >
177    void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
178    _UpdateOutputValue( TNode& n )
179    {
180    const TLabelImage* input_labels = this->GetInputLabelImage( );
181
182    this->Superclass::_UpdateOutputValue( n );
183    if( n.FrontId != 0 )
184    {
185    if( input_labels->GetPixel( n.Vertex ) == this->GetInsideValue( ) )
186    n.Value = this->GetInsideLabel( );
187    else
188    n.Value = TOutputValue( 0 );
189    this->TAlgorithm::_UpdateOutputValue( n );
190
191    } // fi
192    }
193 */
194
195 #endif // __CTBronchi__MoriLabelling__hxx__
196
197 // eof - $RCSfile$