]> Creatis software - FrontAlgorithms.git/blobdiff - appli/CTBronchi/MoriLabelling.h
...
[FrontAlgorithms.git] / appli / CTBronchi / MoriLabelling.h
index d4eea090eec3e1a9ad02d6229d885ed439afaf77..f9adb5ce8ea9de58bd51f22a3dcd9b293bd31372 100644 (file)
@@ -5,10 +5,10 @@
 #ifndef __CTBronchi__MoriLabelling__h__
 #define __CTBronchi__MoriLabelling__h__
 
+#include <itkMinimumMaximumImageCalculator.h>
+#include <fpa/Filters/BaseMarksInterface.h>
+#include <fpa/Filters/Image/SeedsFromLabelsInterface.h>
 #include <fpa/Filters/Image/DefaultTraits.h>
-#include <fpa/Filters/MarksInterface.h>
-#include <fpa/Filters/Image/LabelsSeedFilter.h>
-#include <fpa/Filters/Image/LabelsSeedInterface.h>
 #include <fpa/Filters/Image/RegionGrow.h>
 #include <fpa/Functors/RegionGrow/BinaryThreshold.h>
 
@@ -16,58 +16,103 @@ namespace CTBronchi
 {
   /**
    */
-  template< class _TInputImage, class _TLabelImage >
+  template< class _TImage, class _TLabels >
   class MoriLabellingTraits
-        : public fpa::Filters::Image::DefaultTraits< _TInputImage, _TLabelImage, typename _TLabelImage::PixelType >
+    : public fpa::Filters::Image::DefaultTraits< _TImage, _TLabels, typename _TLabels::PixelType >
   {
   public:
-    typedef _TInputImage TInputImage;
-    typedef _TLabelImage TLabelImage;
-    typedef fpa::Filters::Image::DefaultTraits< TInputImage, TLabelImage, typename TLabelImage::PixelType > Superclass;
-
-    typedef typename Superclass::TInternalTraits TInternalTraits;
-    typedef typename Superclass::TFilter TFilter;
-    typedef fpa::Filters::MarksInterface< TInternalTraits >  TMarksInterface;
-    typedef fpa::Filters::Image::LabelsSeedInterface< TInternalTraits > TSeedsInterface;
+    typedef fpa::Filters::Image::DefaultTraits< _TImage, _TLabels, typename _TLabels::PixelType > Superclass;
+    typedef typename Superclass::TInternalTraits  TInternalTraits;
+    typedef typename Superclass::TMarksImage      TMarksImage;
+    typedef typename Superclass::TFilterInterface TFilterInterface;
+
+    typedef fpa::Filters::BaseMarksInterface< TInternalTraits >  TMarksInterface;
+    typedef fpa::Filters::Image::SeedsFromLabelsInterface< TInternalTraits > TSeedsInterface;
   };
 
   /**
    */
-  template< class _TInputImage, class _TLabelImage >
+  template< class _TImage, class _TLabels, class _TScalarImage >
   class MoriLabelling
-    : public fpa::Filters::Image::LabelsSeedFilter< fpa::Filters::Image::Algorithm< fpa::Filters::RegionGrow< CTBronchi::MoriLabellingTraits< _TInputImage, _TLabelImage > > >, _TLabelImage >
+    : public fpa::Filters::Image::RegionGrow< _TImage, _TLabels, typename _TLabels::PixelType, CTBronchi::MoriLabellingTraits< _TImage, _TLabels > >
   {
   public:
-    typedef _TInputImage TInputImage;
-    typedef _TLabelImage TLabelImage;
-    typedef CTBronchi::MoriLabellingTraits< TInputImage, TLabelImage > TTraits;
-    fpaTraitsMacro( typename, TTraits );
-
-    typedef fpa::Filters::RegionGrow< TTraits > TBase;
-    typedef fpa::Filters::Image::Algorithm< TBase > TAlgorithm;
-    typedef fpa::Filters::Image::LabelsSeedFilter< TAlgorithm, _TLabelImage > Superclass;
+    typedef CTBronchi::MoriLabellingTraits< _TImage, _TLabels > TTraits;
+    fpaTraitsMacro( typename TTraits );
+
+    typedef fpa::Filters::Image::RegionGrow< _TImage, _TLabels, TMark, TTraits > Superclass;
     typedef MoriLabelling Self;
-    typedef itk::SmartPointer< Self >        Pointer;
-    typedef itk::SmartPointer< const Self >  ConstPointer;
+    typedef itk::SmartPointer< Self > Pointer;
+    typedef itk::SmartPointer< const Self > ConstPointer;
 
-    typedef fpa::Functors::RegionGrow::BinaryThreshold< TInputValue > TLabelFunctor;
+    typedef fpa::Functors::RegionGrow::BinaryThreshold< TInputValue > TFunctor;
 
   public:
     itkNewMacro( Self );
-    itkTypeMacro( CTBronchi::MoriLabelling, fpa::Filters::Image::RegionGrow );
+    itkTypeMacro( MoriLabelling, fpa::Filters::Image::RegionGrow );
 
-    itkGetConstMacro( InputInsideValue, TInputValue );
-    itkSetMacro( InputInsideValue, TInputValue );
+    itkGetConstMacro( VesselnessThreshold, double );
+    itkSetMacro( VesselnessThreshold, double );
 
-  public:
-    TInputValue GetUpperThreshold( ) const;
-    void SetUpperThreshold( TInputValue t );
+    itkGetConstMacro( UpperThreshold, TInputValue );
+    itkSetMacro( UpperThreshold, TInputValue );
 
-  protected:
-    MoriLabelling( );
-    virtual ~MoriLabelling( );
+    ivqITKInputMacro( InputLabels, _TLabels );
+    ivqITKInputMacro( InputVesselness, _TScalarImage );
 
-    virtual void _UpdateOutputValue( TNode& n ) override;
+  protected:
+    MoriLabelling( )
+      : Superclass( ),
+        m_VesselnessThreshold( 5 ),
+        m_UpperThreshold( -650 )
+      {
+        ivqITKInputConfigureMacro( InputLabels, _TLabels );
+        ivqITKInputConfigureMacro( InputVesselness, _TScalarImage );
+        this->m_Functor = TFunctor::New( );
+        this->SetPredicate( this->m_Functor );
+      }
+
+    virtual ~MoriLabelling( )
+      {
+      }
+
+    virtual const itk::DataObject* _GetReferenceInput( ) const override
+      {
+        return( this->GetInputLabels( ) );
+      }
+    virtual void _BeforeGenerateData( ) override
+      {
+        this->Superclass::_BeforeGenerateData( );
+
+        this->m_Functor->SetUpperThreshold( this->m_UpperThreshold );
+
+        typedef itk::MinimumMaximumImageCalculator< _TScalarImage > _TMinMax;
+        typename _TMinMax::Pointer minMax = _TMinMax::New( );
+        minMax->SetImage( this->GetInputVesselness( ) );
+        minMax->Compute( );
+        this->m_MinVesselness =
+          ( 1.0  - ( this->m_VesselnessThreshold / double( 100 ) ) ) *
+          double( minMax->GetMaximum( ) );
+      }
+
+    virtual void _PostComputeOutputValue( TNode& n ) override
+      {
+        this->Superclass::_PostComputeOutputValue( n );
+        if( n.Value == this->GetInsideValue( ) )
+        {
+          const _TLabels* labels = this->GetInputLabels( );
+          const _TScalarImage* vesselness = this->GetInputVesselness( );
+          if( labels->GetPixel( n.Vertex ) == 0 )
+          {
+            if( this->m_MinVesselness < vesselness->GetPixel( n.Vertex ) )
+              n.Value = this->GetInsideValue( );
+            else
+              n.Value = 0;
+
+          } // fi
+
+        } // fi
+      }
 
   private:
     // Purposely not implemented.
@@ -75,16 +120,14 @@ namespace CTBronchi
     Self& operator=( const Self& other );
 
   protected:
-    typename TLabelFunctor::Pointer m_LabelFunctor;
-    TInputValue m_InputInsideValue;
+    typename TFunctor::Pointer m_Functor;
+    double m_VesselnessThreshold;
+    double m_MinVesselness;
+    TInputValue m_UpperThreshold;
   };
 
 } // ecapseman
 
-#ifndef ITK_MANUAL_INSTANTIATION
-#  include <CTBronchi/MoriLabelling.hxx>
-#endif // ITK_MANUAL_INSTANTIATION
-
-#endif // __CTBronchi__MoriLabelling__h__
+#endif // __CTBronchi__Functions__h__
 
 // eof - $RCSfile$