]> Creatis software - FrontAlgorithms.git/blob - appli/CTArteries/algorithms/RandomWalkLabelling.hxx
...
[FrontAlgorithms.git] / appli / CTArteries / algorithms / RandomWalkLabelling.hxx
1 // =========================================================================
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // =========================================================================
4 #ifndef __RandomWalkerLabelling__hxx__
5 #define __RandomWalkerLabelling__hxx__
6
7 // -------------------------------------------------------------------------
8 template< class _TRawImage, class _TLabelsImage >
9 void RandomWalkLabelling< _TRawImage, _TLabelsImage >::
10 SetInputImage( const TRawImage* i )
11 {
12   this->SetInput( i );
13 }
14
15 // -------------------------------------------------------------------------
16 template< class _TRawImage, class _TLabelsImage >
17 typename RandomWalkLabelling< _TRawImage, _TLabelsImage >::
18 TLabelsImage* RandomWalkLabelling< _TRawImage, _TLabelsImage >::
19 GetOutputLabels( )
20 {
21   return( this->GetOutput( ) );
22 }
23
24 // -------------------------------------------------------------------------
25 template< class _TRawImage, class _TLabelsImage >
26 const typename RandomWalkLabelling< _TRawImage, _TLabelsImage >::
27 TLabelsImage* RandomWalkLabelling< _TRawImage, _TLabelsImage >::
28 GetOutputLabels( ) const
29 {
30   return( this->GetOutput( ) );
31 }
32
33 // -------------------------------------------------------------------------
34 template< class _TRawImage, class _TLabelsImage >
35 typename RandomWalkLabelling< _TRawImage, _TLabelsImage >::
36 TLabel RandomWalkLabelling< _TRawImage, _TLabelsImage >::
37 GetOutsideLabel( ) const
38 {
39   return( this->GetInitValue( ) );
40 }
41
42 // -------------------------------------------------------------------------
43 template< class _TRawImage, class _TLabelsImage >
44 void RandomWalkLabelling< _TRawImage, _TLabelsImage >::
45 SetOutsideLabel( const TLabel& v )
46 {
47   this->SetInitValue( v );
48 }
49
50 // -------------------------------------------------------------------------
51 template< class _TRawImage, class _TLabelsImage >
52 RandomWalkLabelling< _TRawImage, _TLabelsImage >::
53 RandomWalkLabelling( )
54   : Superclass( ),
55     m_InsideLabel( TLabel( 1 ) ),
56     m_LowerLabel( TLabel( 3 ) ),
57     m_UpperLabel( TLabel( 4 ) ),
58     m_Radius( double( 1 ) ),
59     m_LowerThreshold( double( 0 ) ),
60     m_UpperThreshold( double( 0 ) )
61 {
62   fpaFilterInputConfigureMacro( InputMarks, TLabelsImage );
63   fpaFilterInputConfigureMacro( InputPath, TPath );
64   this->SetOutsideLabel( TLabel( 2 ) );
65 }
66
67 // -------------------------------------------------------------------------
68 template< class _TRawImage, class _TLabelsImage >
69 RandomWalkLabelling< _TRawImage, _TLabelsImage >::
70 ~RandomWalkLabelling( )
71 {
72 }
73
74 // -------------------------------------------------------------------------
75 template< class _TRawImage, class _TLabelsImage >
76 void RandomWalkLabelling< _TRawImage, _TLabelsImage >::
77 _PrepareSeeds( const itk::DataObject* reference )
78 {
79   const TPath* path = this->GetInputPath( );
80   if( path->GetSize( ) > 0 )
81   {
82     TNode node;
83     node.Vertex = node.Parent = path->GetVertex( 0 );
84     node.FrontId = 1;
85     this->m_UnifiedSeeds.clear( );
86     this->m_UnifiedSeeds.insert( node );
87     this->m_CurrIdx = 0;
88
89   } // fi
90 }
91
92 // -------------------------------------------------------------------------
93 template< class _TRawImage, class _TLabelsImage >
94 void RandomWalkLabelling< _TRawImage, _TLabelsImage >::
95 _PostComputeOutputValue( TNode& n )
96 {
97   const TRawImage* raw = this->GetInput( );
98   const TLabelsImage* labels = this->GetInputMarks( );
99   const TPath* path = this->GetInputPath( );
100
101   TPoint c, p;
102   raw->TransformIndexToPhysicalPoint( path->GetVertex( this->m_CurrIdx ), c );
103   raw->TransformIndexToPhysicalPoint( n.Vertex, p );
104   double d = double( c.EuclideanDistanceTo( p ) );
105   if( d <= this->m_Radius )
106   {
107     n.FrontId = 1;
108     if( labels->GetPixel( n.Vertex ) == 0 )
109     {
110       double v = double( raw->GetPixel( n.Vertex ) );
111       if( v <= this->m_LowerThreshold )
112         n.Value = this->GetLowerLabel( );
113       else if( v >= this->m_UpperThreshold )
114         n.Value = this->GetUpperLabel( );
115       else
116         n.Value = TLabel( 0 );
117     }
118     else
119       n.Value = this->GetInsideLabel( );
120   }
121   else
122   {
123     n.Value = this->GetOutsideLabel( );
124     n.FrontId = 0;
125
126   } // fi
127 }
128
129 // -------------------------------------------------------------------------
130 template< class _TRawImage, class _TLabelsImage >
131 void RandomWalkLabelling< _TRawImage, _TLabelsImage >::
132 _Reinitialize( )
133 {
134   const TPath* path = this->GetInputPath( );
135   while(
136     this->_GetMark( path->GetVertex( this->m_CurrIdx ) ) > 0 &&
137     this->m_CurrIdx < path->GetSize( )
138     )
139     this->m_CurrIdx += 1;
140   if( this->m_CurrIdx < path->GetSize( ) )
141   {
142     TNode node;
143     node.Vertex = node.Parent = path->GetVertex( this->m_CurrIdx );
144     node.FrontId = 1;
145     this->_QueuePush( node );
146
147   } // fi
148 }
149
150 #endif // __RandomWalkLabelling__hxx__
151
152 // eof - $RCSfile$