]> Creatis software - cpPlugins.git/blob - plugins/ITKLevelSetFilters/ThresholdSegmentationLevelSetImageFilter.cxx
053c92207b61ffca6ba32e30afb4f14af1e8ff56
[cpPlugins.git] / plugins / ITKLevelSetFilters / ThresholdSegmentationLevelSetImageFilter.cxx
1 #include <ITKLevelSetFilters/ThresholdSegmentationLevelSetImageFilter.h>
2 #include <cpInstances/Image.h>
3
4 #include <itkThresholdSegmentationLevelSetImageFilter.h>
5
6 // -------------------------------------------------------------------------
7 cpPluginsITKLevelSetFilters::ThresholdSegmentationLevelSetImageFilter::
8 ThresholdSegmentationLevelSetImageFilter( )
9   : Superclass( )
10 {
11   this->_ConfigureInput< cpInstances::Image >( "Input", true, false );
12   this->_ConfigureInput< cpInstances::Image >( "Feature", true, false );
13   this->_ConfigureOutput< cpInstances::Image >( "Output" );
14
15   this->m_Parameters.ConfigureAsReal( "PropagationScaling", 1 );
16   this->m_Parameters.ConfigureAsReal( "CurvatureScaling", 1 );
17   this->m_Parameters.ConfigureAsReal( "MaximumRMSError", 0.02 );
18   this->m_Parameters.ConfigureAsReal( "UpperThreshold", 1 );
19   this->m_Parameters.ConfigureAsReal( "LowerThreshold", 0 );
20   this->m_Parameters.ConfigureAsReal( "IsoSurfaceValue", 0 );
21   this->m_Parameters.ConfigureAsUint( "NumberOfIterations", 100 );
22 }
23
24 // -------------------------------------------------------------------------
25 cpPluginsITKLevelSetFilters::ThresholdSegmentationLevelSetImageFilter::
26 ~ThresholdSegmentationLevelSetImageFilter( )
27 {
28 }
29
30 // -------------------------------------------------------------------------
31 void cpPluginsITKLevelSetFilters::ThresholdSegmentationLevelSetImageFilter::
32 _GenerateData( )
33 {
34   auto o = this->GetInputData( "Input" );
35   cpPlugins_Demangle_Image_RealPixels_AllDims_1( o, _GD0 )
36     this->_Error( "Invalid input image dimension." );
37 }
38
39 // -------------------------------------------------------------------------
40 template< class _TImage >
41 void cpPluginsITKLevelSetFilters::ThresholdSegmentationLevelSetImageFilter::
42 _GD0( _TImage* image )
43 {
44   auto f = this->GetInputData( "Feature" );
45   cpPlugins_Demangle_Image_RealPixels_2( f, _GD1, _TImage::ImageDimension, image )
46     this->_Error( "Invalid feature image." );
47 }
48
49 // -------------------------------------------------------------------------
50 template< class _TFeature, class _TImage >
51 void cpPluginsITKLevelSetFilters::ThresholdSegmentationLevelSetImageFilter::
52 _GD1( _TFeature* feature, _TImage* image )
53 {
54   typedef typename _TFeature::PixelType _TScalar;
55   typedef
56     itk::ThresholdSegmentationLevelSetImageFilter< _TImage, _TFeature, _TScalar >
57     _TFilter;
58
59   // Configure filter
60   _TFilter* filter = this->_CreateITK< _TFilter >( );
61   filter->SetInput( image );
62   filter->SetFeatureImage( feature );
63   filter->SetPropagationScaling( this->m_Parameters.GetReal( "PropagationScaling" ) );
64   filter->SetCurvatureScaling( this->m_Parameters.GetReal( "CurvatureScaling" ) );
65   filter->SetMaximumRMSError( this->m_Parameters.GetReal( "MaximumRMSError" ) );
66   filter->SetUpperThreshold( this->m_Parameters.GetReal( "UpperThreshold" ) );
67   filter->SetLowerThreshold( this->m_Parameters.GetReal( "LowerThreshold" ) );
68   filter->SetIsoSurfaceValue( this->m_Parameters.GetReal( "IsoSurfaceValue" ) );
69   filter->SetNumberOfIterations( this->m_Parameters.GetUint( "NumberOfIterations" ) );
70   filter->Update( );
71
72   // Connect output
73   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
74 }
75
76 // eof - $RCSfile$