]> Creatis software - FrontAlgorithms.git/blob - plugins/ImageAlgorithms/MoriRegionGrow.cxx
f8e323c1509b5b437d479af86af7559975f4ef9c
[FrontAlgorithms.git] / plugins / ImageAlgorithms / MoriRegionGrow.cxx
1 #include <ImageAlgorithms/MoriRegionGrow.h>
2 #include <cpInstances/DataObjects/Image.h>
3
4 #include <fpa/Image/MoriRegionGrow.h>
5
6 // -------------------------------------------------------------------------
7 fpaPluginsImageAlgorithms::MoriRegionGrow::
8 MoriRegionGrow( )
9   : Superclass( )
10 {
11   typedef cpPlugins::Pipeline::DataObject _TData;
12   typedef cpInstances::DataObjects::Image _TImage;
13
14   this->_ConfigureInput< _TImage >( "Input", true, false );
15   this->_ConfigureInput< _TData >( "Seed", true, false );
16   this->_ConfigureOutput< _TImage >( "Output" );
17   this->_ConfigureOutput< _TImage >( "AuxiliaryOutput" );
18
19   this->m_Parameters.ConfigureAsInt( "InsideValue", 1 );
20   this->m_Parameters.ConfigureAsInt( "OutsideValue", 0 );
21   this->m_Parameters.ConfigureAsReal( "Step", 1 );
22   this->m_Parameters.ConfigureAsReal( "Lower", 0 );
23   this->m_Parameters.ConfigureAsReal( "Upper", 1 );
24   this->m_Parameters.ConfigureAsIntTypesChoices( "ResultType" );
25 }
26
27 // -------------------------------------------------------------------------
28 fpaPluginsImageAlgorithms::MoriRegionGrow::
29 ~MoriRegionGrow( )
30 {
31 }
32
33 // -------------------------------------------------------------------------
34 void fpaPluginsImageAlgorithms::MoriRegionGrow::
35 _GenerateData( )
36 {
37   auto o = this->GetInputData( "Input" );
38   cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 )
39     this->_Error( "Invalid input image." );
40 }
41
42 // -------------------------------------------------------------------------
43 template< class _TImage >
44 void fpaPluginsImageAlgorithms::MoriRegionGrow::
45 _GD0( _TImage* image )
46 {
47   auto rtype = this->m_Parameters.GetSelectedChoice( "ResultType" );
48   if( rtype == "char" )        this->_GD1< _TImage, char >( image );
49   else if( rtype == "uchar" )  this->_GD1< _TImage, unsigned char >( image );
50   else if( rtype == "short" )  this->_GD1< _TImage, short >( image );
51   else if( rtype == "ushort" ) this->_GD1< _TImage, unsigned short >( image );
52   else if( rtype == "int" )    this->_GD1< _TImage, int >( image );
53   else if( rtype == "uint" )   this->_GD1< _TImage, unsigned int >( image );
54   else if( rtype == "long" )   this->_GD1< _TImage, long >( image );
55   else if( rtype == "ulong" )  this->_GD1< _TImage, unsigned long >( image );
56   else                         this->_GD1< _TImage, char >( image );
57 }
58
59 // -------------------------------------------------------------------------
60 template< class _TInputImage, class _TOutputPixel >
61 void fpaPluginsImageAlgorithms::MoriRegionGrow::
62 _GD1( _TInputImage* image )
63 {
64   typedef
65     itk::Image< _TOutputPixel, _TInputImage::ImageDimension >
66     _TOutputImage;
67   typedef fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage > _TFilter;
68
69   auto filter = this->_CreateITK< _TFilter >( );
70   filter->SetInput( image );
71   filter->SetInsideValue( this->m_Parameters.GetInt( "InsideValue" ) );
72   filter->SetOutsideValue( this->m_Parameters.GetInt( "OutsideValue" ) );
73   filter->SetStep( this->m_Parameters.GetReal( "Step" ) );
74   filter->SetLower( this->m_Parameters.GetReal( "Lower" ) );
75   filter->SetUpper( this->m_Parameters.GetReal( "Upper" ) );
76
77   // Assign seed
78   auto seeds = this->GetInputData< vtkPolyData >( "Seed" );
79   if( seeds != NULL )
80   {
81     typename _TInputImage::PointType pnt;
82     typename _TInputImage::IndexType idx;
83     unsigned int dim =
84       ( _TInputImage::ImageDimension < 3 )? _TInputImage::ImageDimension: 3;
85     if( seeds->GetNumberOfPoints( ) > 0 )
86     {
87       double buf[ 3 ];
88       seeds->GetPoint( 0, buf );
89       pnt.Fill( 0 );
90       for( unsigned int d = 0; d < dim; ++d )
91         pnt[ d ] = buf[ d ];
92
93       if( image->TransformPhysicalPointToIndex( pnt, idx ) )
94         filter->SetSeed( idx );
95     }
96     else
97       this->_Error( "No given seeds." );
98   }
99   else
100     this->_Error( "No given seeds." );
101
102   filter->Update( );
103   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
104   this->GetOutput( "AuxiliaryOutput" )->SetITK( filter->GetAuxiliaryImage( ) );
105 }
106
107 // eof - $RCSfile$