]> Creatis software - FrontAlgorithms.git/blob - appli/CTBronchi/MoriLabelling.hxx
...
[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 // -------------------------------------------------------------------------
10 template< class _TInputImage, class _TLabelImage >
11 typename CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
12 TInputValue CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
13 GetUpperThreshold( ) const
14 {
15   return( this->m_Functor->GetUpperThreshold( ) );
16 }
17
18 // -------------------------------------------------------------------------
19 template< class _TInputImage, class _TLabelImage >
20 void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
21 SetUpperThreshold( TInputValue t )
22 {
23   this->m_Functor->SetUpperThreshold( t );
24 }
25
26 // -------------------------------------------------------------------------
27 template< class _TInputImage, class _TLabelImage >
28 CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
29 MoriLabelling( )
30   : Superclass( ),
31     m_LastThreshold( TInputValue( 0 ) )
32 {
33   fpaFilterInputConfigureMacro( InputLabels, TLabelImage );
34   this->m_Functor = TFunctor::New( );
35   this->SetPredicate( this->m_Functor );
36 }
37
38 // -------------------------------------------------------------------------
39 template< class _TInputImage, class _TLabelImage >
40 CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
41 ~MoriLabelling( )
42 {
43 }
44
45 // -------------------------------------------------------------------------
46 template< class _TInputImage, class _TLabelImage >
47 const itk::DataObject*
48 CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
49 _GetReferenceInput( ) const
50 {
51   return( this->GetInputLabels( ) );
52 }
53
54 // -------------------------------------------------------------------------
55 template< class _TInputImage, class _TLabelImage >
56 void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
57 _PostComputeOutputValue( TNode& n )
58 {
59   this->Superclass::_PostComputeOutputValue( n );
60   if( n.Value == this->GetInsideValue( ) )
61   {
62     const _TInputImage* input = this->GetInput( );
63     const TLabelImage* labels = this->GetInputLabels( );
64     double x = input->GetPixel( n.Vertex );
65     /* TODO
66        double a = std::fabs( x - double( this->m_Functor->GetUpperThreshold( ) ) );
67        double b = std::fabs( x - double( this->m_LastThreshold ) );
68     */
69     if( labels->GetPixel( n.Vertex ) == 0 /* && b < a*/ )
70       n.Value = 0;
71
72   } // fi
73 }
74
75 // -------------------------------------------------------------------------
76 namespace CTBronchi
77 {
78   template< class _TInputPtr, class _TOutputPtr, class _TInputValue >
79   void Label(
80     _TOutputPtr& output,
81     const _TInputPtr& input, const _TOutputPtr& input_labels,
82     const _TInputValue& last_thr,
83     std::map< std::string, std::string >& args
84     )
85   {
86     typedef typename _TInputPtr::ObjectType  _TInput;
87     typedef typename _TOutputPtr::ObjectType _TOutput;
88     typedef CTBronchi::MoriLabelling< _TInput, _TOutput > _TLabelling;
89
90     typename _TLabelling::Pointer labelling = _TLabelling::New( );
91     labelling->SetInput( input );
92     labelling->SetInputLabels( input_labels );
93     labelling->SetOutsideValue( 2 );
94     labelling->SetInsideValue( 1 );
95     labelling->SetUpperThreshold(
96       _TInputValue( std::atof( args[ "labelling_upper_threshold" ].c_str( ) ) )
97       );
98     labelling->SetLastThreshold( last_thr );
99     double t = MeasureTime( labelling );
100     std::cout << "Labelling executed in " << t << " s" << std::endl;
101     output = labelling->GetOutput( );
102     std::map< std::string, std::string >::const_iterator i =
103       args.find( "out_labels" );
104     if( i != args.end( ) )
105       WriteImage( output, i->second );
106     output->DisconnectPipeline( );
107   }
108
109 } // ecapseman
110
111 #endif // __CTBronchi__MoriLabelling__hxx__
112
113 // eof - $RCSfile$