]> Creatis software - FrontAlgorithms.git/blob - lib/fpaPlugins/ThresholdImageGrowFunctionSource.cxx
eabd396be9dcb5dc20679952fbb1f576f37f4d45
[FrontAlgorithms.git] / lib / fpaPlugins / ThresholdImageGrowFunctionSource.cxx
1 #include "ThresholdImageGrowFunctionSource.h"
2
3 #include <cpPlugins/Interface/BaseProcessObjects.h>
4 #include <cpPlugins/Interface/Image.h>
5 #include <fpaPlugins/GrowFunction.h>
6 #include <fpa/Image/Functors/RegionGrowThresholdFunction.h>
7
8 // -------------------------------------------------------------------------
9 fpaPlugins::ThresholdImageGrowFunctionSource::
10 ThresholdImageGrowFunctionSource( )
11   : Superclass( )
12 {
13   this->_AddInput( "ReferenceImage" );
14   this->_AddOutput< GrowFunction >( "Output" );
15
16   this->m_Parameters->ConfigureAsReal( "LowerThreshold" );
17   this->m_Parameters->ConfigureAsReal( "UpperThreshold" );
18
19   this->m_Parameters->SetReal( "LowerThreshold", 0 );
20   this->m_Parameters->SetReal( "UpperThreshold", 0 );
21 }
22
23 // -------------------------------------------------------------------------
24 fpaPlugins::ThresholdImageGrowFunctionSource::
25 ~ThresholdImageGrowFunctionSource( )
26 {
27 }
28
29 // -------------------------------------------------------------------------
30 std::string fpaPlugins::ThresholdImageGrowFunctionSource::
31 _GenerateData( )
32 {
33   auto image =
34     this->GetInputData< cpPlugins::Interface::Image >( "ReferenceImage" );
35   if( image == NULL )
36     return( "fpaPlugins::ThresholdImageGrowFunctionSource: No input reference image." );
37
38   itk::DataObject* itk_image = NULL;
39   std::string r = "";
40   cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _GD0 );
41   else cpPlugins_Image_Demangle_AllScalarTypes( 3, image, itk_image, r, _GD0 );
42   else r = "fpaPlugins::ThresholdImageGrowFunctionSource: no valid reference image.";
43
44   return( r );
45 }
46
47 // -------------------------------------------------------------------------
48 template< class I >
49 std::string fpaPlugins::ThresholdImageGrowFunctionSource::
50 _GD0( itk::DataObject* data )
51 {
52   typedef fpa::Image::Functors::RegionGrowThresholdFunction< I > _F;
53   typename _F::Pointer f = _F::New( );
54   f->SetLowerThreshold( this->m_Parameters->GetReal( "LowerThreshold" ) );
55   f->SetUpperThreshold( this->m_Parameters->GetReal( "UpperThreshold" ) );
56
57   // Connect output
58   auto out = this->GetOutputData< GrowFunction >( "Output" );
59   if( out != NULL )
60   {
61     out->SetITK< _F >( f );
62     return( "" );
63   }
64   else
65     return( "fpaPlugins::ThresholdImageGrowFunctionSource: output not correctly created." );
66 }
67
68 // eof - $RCSfile$