+typedef short TPixel;
+typedef unsigned char TLabel;
+typedef itk::NumericTraits< TPixel >::RealType TScalar;
+typedef itk::Image< TPixel, Dim > TImage;
+typedef itk::Image< TLabel, Dim > TLabels;
+typedef itk::Image< TScalar, Dim > TScalarImage;
+
+/**
+ */
+class MoriLabellingTraits
+ : public fpa::Filters::Image::DefaultTraits< TImage, TLabels, TLabel >
+{
+public:
+ typedef fpa::Filters::Image::DefaultTraits< TImage, TLabels, TLabel > 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;
+};
+
+/**
+ */
+class MoriLabelling
+ : public fpa::Filters::Image::RegionGrow< TImage, TLabels, TLabel, MoriLabellingTraits >
+{
+public:
+ typedef MoriLabellingTraits TTraits;
+ fpaTraitsMacro( 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 fpa::Functors::RegionGrow::BinaryThreshold< TInputValue > TFunctor;
+
+public:
+ itkNewMacro( Self );
+ itkTypeMacro( MoriLabelling, fpa::Filters::Image::RegionGrow );
+
+ itkGetConstMacro( LastThreshold, TInputValue );
+ itkSetMacro( LastThreshold, TInputValue );
+
+ itkGetConstMacro( MinVertex, TVertex );
+ itkGetConstMacro( MaxVertex, TVertex );
+
+ fpaFilterInputMacro( InputLabels, TLabels );
+ fpaFilterInputMacro( InputVesselness, TScalarImage );
+
+public:
+ TInputValue GetUpperThreshold( ) const
+ {
+ return( this->m_Functor->GetUpperThreshold( ) );
+ }
+ void SetUpperThreshold( TInputValue t )
+ {
+ this->m_Functor->SetUpperThreshold( t );
+ }
+
+protected:
+ MoriLabelling( )
+ : Superclass( ),
+ m_LastThreshold( TInputValue( 0 ) ),
+ m_VesselnessThr( TScalar( 0.05 ) )
+ {
+ fpaFilterInputConfigureMacro( InputLabels, TLabels );
+ fpaFilterInputConfigureMacro( 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_FirstVertex = true;
+
+ typedef itk::MinimumMaximumImageCalculator< TScalarImage > _TMinMax;
+ _TMinMax::Pointer minMax = _TMinMax::New( );
+ minMax->SetImage( this->GetInputVesselness( ) );
+ minMax->Compute( );
+ this->m_MaxVesselness = ( 1.0 - this->m_VesselnessThr ) * minMax->GetMaximum( );
+ }
+
+ virtual void _PostComputeOutputValue( TNode& n ) override
+ {
+ this->Superclass::_PostComputeOutputValue( n );
+ if( n.Value == this->GetInsideValue( ) )
+ {
+ const TImage* input = this->GetInput( );
+ const TLabels* labels = this->GetInputLabels( );
+ const TScalarImage* vesselness = this->GetInputVesselness( );
+ 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 )
+ {
+ if( vesselness->GetPixel( n.Vertex ) > this->m_MaxVesselness )
+ n.Value = this->GetInsideValue( );
+ else
+ n.Value = 0;
+
+ } // fi
+
+ if( !( this->m_FirstVertex ) )
+ {
+ for( unsigned int d = 0; d < TImage::ImageDimension; ++d )
+ {
+ if( n.Vertex[ d ] < this->m_MinVertex[ d ] )
+ this->m_MinVertex[ d ] = n.Vertex[ d ];
+ if( this->m_MaxVertex[ d ] < n.Vertex[ d ] )
+ this->m_MaxVertex[ d ] = n.Vertex[ d ];
+
+ } // rof
+ }
+ else
+ {
+ this->m_MinVertex = n.Vertex;
+ this->m_MaxVertex = n.Vertex;
+ this->m_FirstVertex = false;
+
+ } // fi
+
+ } // fi
+ }
+
+private:
+ // Purposely not implemented.
+ MoriLabelling( const Self& other );
+ Self& operator=( const Self& other );
+
+protected:
+ TFunctor::Pointer m_Functor;
+ TInputValue m_LastThreshold;
+ bool m_FirstVertex;
+ TVertex m_MinVertex;
+ TVertex m_MaxVertex;
+
+ TScalar m_MaxVesselness;
+ TScalar m_VesselnessThr;
+};