]> Creatis software - FrontAlgorithms.git/blobdiff - plugins/ImageAlgorithms/RegionGrow.cxx
...
[FrontAlgorithms.git] / plugins / ImageAlgorithms / RegionGrow.cxx
index e1aff3e3effc67bfea2eef7da2dd1e8fee73b2b3..bd0fc747d0afa3ca78e6c049c30693e2d42ad1e4 100644 (file)
@@ -1,29 +1,31 @@
-#include <ImageAlgorithms/RegionGrow.h>
+#include "RegionGrow.h"
+#include <cpPlugins/Pipeline/Functor.h>
 #include <cpInstances/DataObjects/Image.h>
 
 #include <fpa/Image/RegionGrow.h>
 
 // -------------------------------------------------------------------------
-fpaPluginsImageAlgorithms::RegionGrow::
+fpaPlugins_ImageAlgorithms::RegionGrow::
 RegionGrow( )
   : Superclass( )
 {
-  typedef cpPlugins::Pipeline::DataObject _TData;
+  typedef cpPlugins::Pipeline::DataObject _TFunctor;
+  typedef cpInstances::DataObjects::Image _TMST;
 
-  this->_ConfigureInput< _TData >( "GrowFunction", true, false );
+  this->_ConfigureInput< _TFunctor >( "GrowFunction", true, false );
   this->m_Parameters.ConfigureAsInt( "InsideValue", 1 );
   this->m_Parameters.ConfigureAsInt( "OutsideValue", 0 );
   this->m_Parameters.ConfigureAsIntTypesChoices( "ResultType" );
 }
 
 // -------------------------------------------------------------------------
-fpaPluginsImageAlgorithms::RegionGrow::
+fpaPlugins_ImageAlgorithms::RegionGrow::
 ~RegionGrow( )
 {
 }
 
 // -------------------------------------------------------------------------
-void fpaPluginsImageAlgorithms::RegionGrow::
+void fpaPlugins_ImageAlgorithms::RegionGrow::
 _GenerateData( )
 {
   auto o = this->GetInputData( "Input" );
@@ -33,7 +35,7 @@ _GenerateData( )
 
 // -------------------------------------------------------------------------
 template< class _TImage >
-void fpaPluginsImageAlgorithms::RegionGrow::
+void fpaPlugins_ImageAlgorithms::RegionGrow::
 _GD0( _TImage* image )
 {
   auto rtype = this->m_Parameters.GetSelectedChoice( "ResultType" );
@@ -50,27 +52,34 @@ _GD0( _TImage* image )
 
 // -------------------------------------------------------------------------
 template< class _TInputImage, class _TOutputPixel >
-void fpaPluginsImageAlgorithms::RegionGrow::
+void fpaPlugins_ImageAlgorithms::RegionGrow::
 _GD1( _TInputImage* image )
 {
-  typedef
-    itk::Image< _TOutputPixel, _TInputImage::ImageDimension >
-    _TOutputImage;
+  typedef cpPlugins::Pipeline::Functor _TFunctor;
+  typedef itk::Image< _TOutputPixel, _TInputImage::ImageDimension > _TOutputImage;
   typedef fpa::Image::RegionGrow< _TInputImage, _TOutputImage > _TFilter;
-  typedef typename _TFilter::TGrowFunction                      _TGrow;
-
-  _TOutputPixel i_val = _TOutputPixel( this->m_Parameters.GetInt( "InsideValue" ) );
-  _TOutputPixel o_val = _TOutputPixel( this->m_Parameters.GetInt( "OutsideValue" ) );
+  typedef typename _TFilter::TGrowFunction _TGrowFunction;
 
+  // Create filter
   auto filter = this->_CreateITK< _TFilter >( );
   std::vector< typename _TInputImage::IndexType > seeds;
   this->_ConfigureFilter( filter, image, seeds );
+
+  // Instantiate functors
+  auto growfunc = this->GetInputData< _TFunctor >( "GrowFunction" );
+  if( growfunc != NULL )
+  {
+    growfunc->Instantiate( filter );
+    auto growfunc_functor = growfunc->GetFunctor< _TGrowFunction >( );
+    if( growfunc_functor != NULL )
+      filter->SetGrowFunction( growfunc_functor );
+
+  } // fi
+
+  // Finish filter's configuration
   filter->ClearSeeds( );
   for( auto seed : seeds )
-    filter->AddSeed( seed, i_val );
-  filter->SetGrowFunction( this->GetInputData< _TGrow >( "GrowFunction" ) );
-  filter->SetInsideValue( i_val );
-  filter->SetOutsideValue( o_val );
+    filter->AddSeed( seed, ( typename _TOutputImage::PixelType )( 0 ) );
   filter->Update( );
   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
 }