]> Creatis software - FrontAlgorithms.git/blob - plugins/ImageAlgorithms/MoriRegionGrow.cxx
cda89792a19c53d3baaff57471b4cdc441ab557a
[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   /* TODO
65      typedef
66      itk::Image< _TOutputPixel, _TInputImage::ImageDimension >
67      _TOutputImage;
68      typedef fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage > _TFilter;
69
70      auto filter = this->_CreateITK< _TFilter >( );
71      filter->SetInput( image );
72      filter->SetInsideValue( this->m_Parameters.GetInt( "InsideValue" ) );
73      filter->SetOutsideValue( this->m_Parameters.GetInt( "OutsideValue" ) );
74      filter->SetStep( this->m_Parameters.GetReal( "Step" ) );
75      filter->SetLower( this->m_Parameters.GetReal( "Lower" ) );
76      filter->SetUpper( this->m_Parameters.GetReal( "Upper" ) );
77
78      // Assign seed
79      auto seeds = this->GetInputData< vtkPolyData >( "Seed" );
80      if( seeds != NULL )
81      {
82      typename _TInputImage::PointType pnt;
83      typename _TInputImage::IndexType idx;
84      unsigned int dim =
85      ( _TInputImage::ImageDimension < 3 )? _TInputImage::ImageDimension: 3;
86      if( seeds->GetNumberOfPoints( ) > 0 )
87      {
88      double buf[ 3 ];
89      seeds->GetPoint( 0, buf );
90      pnt.Fill( 0 );
91      for( unsigned int d = 0; d < dim; ++d )
92      pnt[ d ] = buf[ d ];
93
94      if( image->TransformPhysicalPointToIndex( pnt, idx ) )
95      filter->SetSeed( idx );
96      }
97      else
98      this->_Error( "No given seeds." );
99      }
100      else
101      this->_Error( "No given seeds." );
102
103      filter->Update( );
104      this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
105      this->GetOutput( "AuxiliaryOutput" )->SetITK( filter->GetAuxiliaryImage( ) );
106   */
107 }
108
109 // eof - $RCSfile$