]> Creatis software - FrontAlgorithms.git/blobdiff - appli/CTBronchi/MoriLabelling.hxx
...
[FrontAlgorithms.git] / appli / CTBronchi / MoriLabelling.hxx
index bc38389ad4dae540286b88954d1977dfd1dca075..b6f982a5f4f8e2b31cf542939d154d2be3d0f896 100644 (file)
@@ -6,54 +6,13 @@
 #ifndef __CTBronchi__MoriLabelling__hxx__
 #define __CTBronchi__MoriLabelling__hxx__
 
-#include <itkImageRegionConstIteratorWithIndex.h>
-
-// -------------------------------------------------------------------------
-template< class _TInputImage, class _TLabelImage >
-const typename CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
-TLabelImage* CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
-GetInputLabelImage( ) const
-{
-  return( this->GetLabels( ) );
-}
-
-// -------------------------------------------------------------------------
-template< class _TInputImage, class _TLabelImage >
-void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
-SetInputLabelImage( TLabelImage* image )
-{
-  this->SetLabels( image );
-}
-
-// -------------------------------------------------------------------------
-template< class _TInputImage, class _TLabelImage >
-const typename CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
-TInputImage* CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
-GetInputRawImage( ) const
-{
-  return( this->GetInput( ) );
-}
-
-// -------------------------------------------------------------------------
-template< class _TInputImage, class _TLabelImage >
-void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
-SetInputRawImage( TInputImage* image )
-{
-  this->SetInput( image );
-}
-
 // -------------------------------------------------------------------------
 template< class _TInputImage, class _TLabelImage >
 typename CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
 TInputValue CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
 GetUpperThreshold( ) const
 {
-  const TThresholdFunction* func =
-    dynamic_cast< const TThresholdFunction* >( this->GetValuePredicate( ) );
-  if( func != NULL )
-    return( func->GetUpper( ) );
-  else
-    return( TInputValue( 0 ) );
+  return( this->m_Functor->GetUpperThreshold( ) );
 }
 
 // -------------------------------------------------------------------------
@@ -61,10 +20,7 @@ template< class _TInputImage, class _TLabelImage >
 void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
 SetUpperThreshold( TInputValue t )
 {
-  TThresholdFunction* func =
-    dynamic_cast< TThresholdFunction* >( this->GetValuePredicate( ) );
-  if( func != NULL )
-    func->SetUpper( t );
+  this->m_Functor->SetUpperThreshold( t );
 }
 
 // -------------------------------------------------------------------------
@@ -72,11 +28,11 @@ template< class _TInputImage, class _TLabelImage >
 CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
 MoriLabelling( )
   : Superclass( ),
-    m_InsideLabel( TOutputValue( 0 ) ),
-    m_OutsideLabel( TOutputValue( 0 ) )
+    m_LastThreshold( TInputValue( 0 ) )
 {
-  typename TThresholdFunction::Pointer func = TThresholdFunction::New( );
-  this->SetPredicate( func );
+  fpaFilterInputConfigureMacro( InputLabels, TLabelImage );
+  this->m_Functor = TFunctor::New( );
+  this->SetPredicate( this->m_Functor );
 }
 
 // -------------------------------------------------------------------------
@@ -88,193 +44,69 @@ CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
 
 // -------------------------------------------------------------------------
 template< class _TInputImage, class _TLabelImage >
-typename CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
-TNodes CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
-_UnifySeeds( )
-{
-  this->m_Seeds.clear( );
-  const TLabelImage* lbl = this->GetLabels( );
-  if( lbl == NULL )
-  {
-    std::ostringstream msg;
-    msg << "itk::ERROR: CTBronchi::MoriLabelling (" << this
-        << "): Labelled image not defined.";
-    ::itk::ExceptionObject e(
-      __FILE__, __LINE__, msg.str( ).c_str( ), ITK_LOCATION
-      );
-    throw e;
-
-  } // fi
-
-  // Iterate over labels
-  typename TLabelImage::RegionType reg = lbl->GetRequestedRegion( );
-  itk::ImageRegionConstIteratorWithIndex< TLabelImage > lIt( lbl, reg );
-  for( lIt.GoToBegin( ); !lIt.IsAtEnd( ); ++lIt )
-  {
-    if( lIt.Get( ) > 0 )
-    {
-      bool is_seed = false;
-      for( unsigned int d = 0; d < TLabelImage::ImageDimension; ++d )
-      {
-        for( int s = -1; s <= 1; s += 2 )
-        {
-          TVertex neigh = lIt.GetIndex( );
-          neigh[ d ] += s;
-          if( reg.IsInside( neigh ) )
-            is_seed |= ( lbl->GetPixel( neigh ) == 0 );
-
-        } // rof
-
-      } // rof
-
-      if( !is_seed )
-      {
-        typename TSeedsInterface::TNode node;
-        node.Vertex = lIt.GetIndex( );
-        node.Parent = lIt.GetIndex( );
-        node.FrontId = lIt.Get( );
-        node.Value = this->m_InsideLabel;
-        this->_Mark( node.Vertex, node.FrontId );
-        this->_UpdateOutputValue( node );
-      }
-      else
-      {
-        typename TSeedsInterface::TSeed seed;
-        seed.Vertex = lIt.GetIndex( );
-        seed.IsPoint = false;
-        seed.FrontId = lIt.Get( );
-        this->m_Seeds.push_back( seed );
-
-      } // fi
-
-    } // fi
-
-  } // rof
-
-  // Ok, finish initialization
-  return( this->Superclass::_UnifySeeds( ) );
-}
-
-// -------------------------------------------------------------------------
-template< class _TInputImage, class _TLabelImage >
-void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
-_UpdateOutputValue( TNode& n )
-{
-  const TInputImage* input = this->GetInputRawImage( );
-  const TLabelImage* labels = this->GetInputLabelImage( );
-}
-
-
-/* TODO
-   TOutputValue m_InsideValue;
-   TOutputValue m_InsideLabel;
-   TOutputValue m_OutsideLabel;
-*/
-
-
-
-
-
-
-
-
-
-
-/* TODO
-#include <itkImageRegionConstIterator.h>
-#include <itkImageRegionIterator.h>
-
-// -------------------------------------------------------------------------
-template< class _TInputImage, class _TLabelImage >
-const _TLabelImage*
+const itk::DataObject*
 CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
-GetInputLabelImage( ) const
+_GetReferenceInput( ) const
 {
-  return( this->GetInput( ) );
+  return( this->GetInputLabels( ) );
 }
 
 // -------------------------------------------------------------------------
 template< class _TInputImage, class _TLabelImage >
 void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
-SetInputLabelImage( TLabelImage* image )
-{
-  this->SetInput( image );
-}
-
-// -------------------------------------------------------------------------
-template< class _TInputImage, class _TLabelImage >
-const _TInputImage*
-CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
-GetInputRawImage( ) const
+_PostComputeOutputValue( TNode& n )
 {
-  return(
-    dynamic_cast< const TInputImage* >(
-      this->itk::ProcessObject::GetInput( 1 )
-      )
-    );
-}
-
-// -------------------------------------------------------------------------
-template< class _TInputImage, class _TLabelImage >
-void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
-SetInputRawImage( TInputImage* image )
-{
-  this->itk::ProcessObject::SetNthInput( 1, image );
-}
-
-// -------------------------------------------------------------------------
-template< class _TInputImage, class _TLabelImage >
-CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
-MoriLabelling( )
-  : Superclass( ),
-    m_UpperThreshold( TOutputValue( 0 ) ),
-    m_InsideValue( TOutputValue( 0 ) ),
-    m_InsideLabel( TOutputValue( 0 ) ),
-    m_OutsideLabel( TOutputValue( 0 ) )
-{
-  this->SetNumberOfRequiredInputs( 2 );
-}
+  this->Superclass::_PostComputeOutputValue( n );
+  if( 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;
 
-// -------------------------------------------------------------------------
-template< class _TInputImage, class _TLabelImage >
-CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
-~MoriLabelling( )
-{
+  } // fi
 }
 
 // -------------------------------------------------------------------------
-template< class _TInputImage, class _TLabelImage >
-void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
-ThreadedGenerateData( const TRegion& region, itk::ThreadIdType threadId )
+namespace CTBronchi
 {
-  itk::ImageRegionConstIterator< TLabelImage >
-    lIt( this->GetInputLabelImage( ), region );
-  itk::ImageRegionConstIterator< TInputImage >
-    iIt( this->GetInputRawImage( ), region );
-  itk::ImageRegionIterator< TLabelImage >
-    oIt( this->GetOutput( ), region );
-
-  lIt.GoToBegin( );
-  iIt.GoToBegin( );
-  oIt.GoToBegin( );
-  while( !( lIt.IsAtEnd( ) || iIt.IsAtEnd( ) || oIt.IsAtEnd( ) ) )
+  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
+    )
   {
-    if( lIt.Get( ) != this->m_InsideValue )
-    {
-      if( this->m_UpperThreshold < iIt.Get( ) )
-        oIt.Set( this->m_OutsideLabel );
-      else
-        oIt.Set( TOutputValue( 0 ) );
-    }
-    else
-      oIt.Set( this->m_InsideLabel );
-    ++lIt;
-    ++iIt;
-    ++oIt;
-
-  } // elihw
-}
-*/
+    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__