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