]> Creatis software - cpPlugins.git/blob - plugins/cpPluginsImageFilters/MultiScaleGaussianImageFilter.cxx
bbdaa987de191fcf0baa67d1efb7dc288a26d200
[cpPlugins.git] / plugins / cpPluginsImageFilters / MultiScaleGaussianImageFilter.cxx
1 #include <cpPluginsImageFilters/MultiScaleGaussianImageFilter.h>
2 #include <cpPlugins/Image.h>
3 #include <cpPlugins_Instances/GaussianImageFilters.h>
4
5 // -------------------------------------------------------------------------
6 cpPluginsImageFilters::MultiScaleGaussianImageFilter::
7 MultiScaleGaussianImageFilter( )
8   : Superclass( )
9 {
10   this->_AddInput( "Input" );
11   this->_AddOutput< cpPlugins::Image >( "Output" );
12
13   this->m_Parameters.ConfigureAsRealList( "Sigmas" );
14
15   std::vector< std::string > choices;
16   choices.push_back( "float" );
17   choices.push_back( "double" );
18   this->m_Parameters.ConfigureAsChoices( "ScalarType", choices );
19   this->m_Parameters.SetSelectedChoice( "ScalarType", "float" );
20 }
21
22 // -------------------------------------------------------------------------
23 cpPluginsImageFilters::MultiScaleGaussianImageFilter::
24 ~MultiScaleGaussianImageFilter( )
25 {
26 }
27
28 // -------------------------------------------------------------------------
29 void cpPluginsImageFilters::MultiScaleGaussianImageFilter::
30 _GenerateData( )
31 {
32   auto image = this->GetInputData< itk::DataObject >( "Input" );
33   cpPlugins_Image_Demangle_Pixel_AllScalars     ( _GD0, image, 2 );
34   else cpPlugins_Image_Demangle_Pixel_AllScalars( _GD0, image, 3 );
35   else this->_Error( "No valid input image." );
36 }
37
38 // -------------------------------------------------------------------------
39 template< class _TImage >
40 void cpPluginsImageFilters::MultiScaleGaussianImageFilter::
41 _GD0( _TImage* image )
42 {
43   if( image != NULL )
44   {
45     auto choice = this->m_Parameters.GetSelectedChoice( "ScalarType" );
46     if     ( choice == "float" )  this->_GD1< _TImage, float >( image );
47     else if( choice == "double" ) this->_GD1< _TImage, double >( image );
48     else                          this->_Error( "No valid scalar type." );
49   }
50   else
51     this->_Error( "No valid input image." );
52 }
53
54 // -------------------------------------------------------------------------
55 template< class _TImage, class _TScalar >
56 void cpPluginsImageFilters::MultiScaleGaussianImageFilter::
57 _GD1( _TImage* image )
58 {
59   typedef itk::CovariantVector< _TScalar, _TImage::ImageDimension > _TVector;
60   typedef itk::Image< _TVector, _TImage::ImageDimension > _TGradient;
61   typedef
62     cpExtensions::Algorithms::MultiScaleGaussianImageFilter< _TImage, _TGradient >
63     _TFilter;
64
65   auto sigmas = this->m_Parameters.GetRealList( "Sigmas" );
66   if( sigmas.size( ) == 0 )
67     this->_Error( "No given sigmas." );
68
69   // Configure filter
70   _TFilter* filter = this->_CreateITK< _TFilter >( );
71   filter->SetInput( image );
72   for( auto sIt = sigmas.begin( ); sIt != sigmas.end( ); ++sIt )
73     filter->AddScale( *sIt );
74   filter->Update( );
75
76   // Connect output
77   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
78 }
79
80 // eof - $RCSfile$