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