]> Creatis software - FrontAlgorithms.git/blob - plugins/fpa/ImageRegionGrow.cxx
8ee71cabc001bdc21a1d4a3d12285985f64d8b40
[FrontAlgorithms.git] / plugins / fpa / ImageRegionGrow.cxx
1 #include "ImageRegionGrow.h"
2
3 #include <cpPlugins/Image.h>
4 #include <fpa_Instances/Filters.h>
5
6 // -------------------------------------------------------------------------
7 fpaPlugins::ImageRegionGrow::
8 ImageRegionGrow( )
9   : Superclass( )
10 {
11   this->_AddInput( "GrowFunctor", false );
12   this->m_Parameters.ConfigureAsUint( "InsideValue" );
13   this->m_Parameters.ConfigureAsUint( "OutsideValue" );
14   this->m_Parameters.SetUint( "InsideValue", 1 );
15   this->m_Parameters.SetUint( "OutsideValue", 0 );
16 }
17
18 // -------------------------------------------------------------------------
19 fpaPlugins::ImageRegionGrow::
20 ~ImageRegionGrow( )
21 {
22 }
23
24 // -------------------------------------------------------------------------
25 std::string fpaPlugins::ImageRegionGrow::
26 _GenerateData( )
27 {
28   auto image = this->GetInputData( "Input" )->GetITK< itk::DataObject >( );
29   std::string   cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 2 );
30   if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 3 );
31   return( r );
32 }
33
34 // -------------------------------------------------------------------------
35 template< class _TImage >
36 std::string fpaPlugins::ImageRegionGrow::
37 _GD0( _TImage* image )
38 {
39   typedef unsigned short _TPixel;
40   typedef itk::Image< _TPixel, _TImage::ImageDimension > _TOutImage;
41   typedef fpa::Image::RegionGrow< _TImage, _TOutImage >  _TFilter;
42   typedef typename _TFilter::TGrowingFunction            _TGrowFunctor;
43   typedef typename _TFilter::TResult                     _TResult;
44
45   if( image == NULL )
46     return( "fpaPlugins::ImageRegionGrow: Invalid image type." );
47
48   // Create filter
49   _TFilter* filter = this->_ConfigureFilter< _TFilter >( );
50
51   typename _TGrowFunctor::Pointer functor;
52   auto wrap_functor = this->GetInputData( "GrowFunctor" );
53   if( wrap_functor != NULL )
54     functor = wrap_functor->GetITK< _TGrowFunctor >( );
55   if( functor.IsNull( ) )
56     filter->SetGrowingFunction( functor );
57   filter->SetInsideValue(
58     _TResult( this->m_Parameters.GetUint( "InsideValue" ) )
59     );
60   filter->SetOutsideValue(
61     _TResult( this->m_Parameters.GetUint( "OutsideValue" ) )
62     );
63
64   // Go!!!
65   this->_ExecuteFilter( filter );
66
67   // Connect remaining output
68   this->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) );
69   return( "" );
70 }
71
72 // eof - $RCSfile$