]> Creatis software - FrontAlgorithms.git/blobdiff - appli/CTBronchi/MoriLabelling.hxx
...
[FrontAlgorithms.git] / appli / CTBronchi / MoriLabelling.hxx
index 7963416db6fea8d16a5142af48a41834f3a0dc81..b6f982a5f4f8e2b31cf542939d154d2be3d0f896 100644 (file)
@@ -12,7 +12,7 @@ typename CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
 TInputValue CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
 GetUpperThreshold( ) const
 {
-  return( this->m_LabelFunctor->GetUpperThreshold( ) );
+  return( this->m_Functor->GetUpperThreshold( ) );
 }
 
 // -------------------------------------------------------------------------
@@ -20,17 +20,19 @@ template< class _TInputImage, class _TLabelImage >
 void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
 SetUpperThreshold( TInputValue t )
 {
-  this->m_LabelFunctor->SetUpperThreshold( t );
+  this->m_Functor->SetUpperThreshold( t );
 }
 
 // -------------------------------------------------------------------------
 template< class _TInputImage, class _TLabelImage >
 CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
 MoriLabelling( )
-  : Superclass( )
+  : Superclass( ),
+    m_LastThreshold( TInputValue( 0 ) )
 {
-  this->m_LabelFunctor = TLabelFunctor::New( );
-  this->SetPredicate( this->m_LabelFunctor );
+  fpaFilterInputConfigureMacro( InputLabels, TLabelImage );
+  this->m_Functor = TFunctor::New( );
+  this->SetPredicate( this->m_Functor );
 }
 
 // -------------------------------------------------------------------------
@@ -40,24 +42,72 @@ CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
 {
 }
 
+// -------------------------------------------------------------------------
+template< class _TInputImage, class _TLabelImage >
+const itk::DataObject*
+CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
+_GetReferenceInput( ) const
+{
+  return( this->GetInputLabels( ) );
+}
+
 // -------------------------------------------------------------------------
 template< class _TInputImage, class _TLabelImage >
 void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
-_UpdateOutputValue( TNode& n )
+_PostComputeOutputValue( TNode& n )
 {
-  this->TBase::_UpdateOutputValue( n );
-  if( n.FrontId != 0 )
+  this->Superclass::_PostComputeOutputValue( n );
+  if( n.Value == this->GetInsideValue( ) )
   {
-    const TLabelImage* input_labels = this->GetInputLabels( );
-    if( input_labels->GetPixel( n.Vertex ) != this->GetInputInsideValue( ) )
-      n.Value = TOutputValue( 0 );
-    else
-      n.Value = this->GetInsideValue( );
+    const _TInputImage* input = this->GetInput( );
+    const TLabelImage* labels = this->GetInputLabels( );
+    double x = input->GetPixel( n.Vertex );
+    /* TODO
+       double a = std::fabs( x - double( this->m_Functor->GetUpperThreshold( ) ) );
+       double b = std::fabs( x - double( this->m_LastThreshold ) );
+    */
+    if( labels->GetPixel( n.Vertex ) == 0 /* && b < a*/ )
+      n.Value = 0;
 
   } // fi
-  this->GetOutput( )->SetPixel( n.Vertex, n.Value );
 }
 
+// -------------------------------------------------------------------------
+namespace CTBronchi
+{
+  template< class _TInputPtr, class _TOutputPtr, class _TInputValue >
+  void Label(
+    _TOutputPtr& output,
+    const _TInputPtr& input, const _TOutputPtr& input_labels,
+    const _TInputValue& last_thr,
+    std::map< std::string, std::string >& args
+    )
+  {
+    typedef typename _TInputPtr::ObjectType  _TInput;
+    typedef typename _TOutputPtr::ObjectType _TOutput;
+    typedef CTBronchi::MoriLabelling< _TInput, _TOutput > _TLabelling;
+
+    typename _TLabelling::Pointer labelling = _TLabelling::New( );
+    labelling->SetInput( input );
+    labelling->SetInputLabels( input_labels );
+    labelling->SetOutsideValue( 2 );
+    labelling->SetInsideValue( 1 );
+    labelling->SetUpperThreshold(
+      _TInputValue( std::atof( args[ "labelling_upper_threshold" ].c_str( ) ) )
+      );
+    labelling->SetLastThreshold( last_thr );
+    double t = MeasureTime( labelling );
+    std::cout << "Labelling executed in " << t << " s" << std::endl;
+    output = labelling->GetOutput( );
+    std::map< std::string, std::string >::const_iterator i =
+      args.find( "out_labels" );
+    if( i != args.end( ) )
+      WriteImage( output, i->second );
+    output->DisconnectPipeline( );
+  }
+
+} // ecapseman
+
 #endif // __CTBronchi__MoriLabelling__hxx__
 
 // eof - $RCSfile$