]> Creatis software - FrontAlgorithms.git/blob - plugins/ImageFunctors/BinaryThreshold.cxx
4d4589e72c78ec3480b5a95750a0a6b59d63468b
[FrontAlgorithms.git] / plugins / ImageFunctors / BinaryThreshold.cxx
1 #include "BinaryThreshold.h"
2
3 #include <cpInstances/DataObjects/Image.h>
4
5 #include <itkImage.h>
6 #include <fpa/Image/Functors/RegionGrow/BinaryThreshold.h>
7
8 // -------------------------------------------------------------------------
9 void fpaPlugins_ImageFunctors::BinaryThreshold::
10 Instantiate( itk::LightObject* filter )
11 {
12   auto itk_filter = dynamic_cast< itk::ProcessObject* >( filter );
13   if( itk_filter != NULL )
14   {
15     auto inputs = itk_filter->GetInputs( );
16     if( inputs.size( ) > 0 )
17     {
18       cpPlugins_Demangle_Image_ScalarPixels_AllDims_2(
19         inputs[ 0 ].GetPointer( ), _GD0, itk_filter
20         )
21         this->_Error( "Invalid input data." );
22     }
23     else
24       this->_Error( "Not enough inputs." );
25   }
26   else
27     this->_Error( "Invalid instantiation filter." );
28 }
29
30 // -------------------------------------------------------------------------
31 fpaPlugins_ImageFunctors::BinaryThreshold::
32 BinaryThreshold( )
33   : Superclass( )
34 {
35   this->_ConfigureOutput< cpPlugins::Pipeline::DataObject >( "Functor" );
36   this->GetOutput( "Functor" )->SetITK( this );
37   this->m_Parameters.ConfigureAsReal( "Lower", 0 );
38   this->m_Parameters.ConfigureAsReal( "Upper", 1 );
39 }
40
41 // -------------------------------------------------------------------------
42 fpaPlugins_ImageFunctors::BinaryThreshold::
43 ~BinaryThreshold( )
44 {
45 }
46
47 // -------------------------------------------------------------------------
48 void fpaPlugins_ImageFunctors::BinaryThreshold::
49 _GenerateData( )
50 {
51 }
52
53 // -------------------------------------------------------------------------
54 template< class _TInput >
55 void fpaPlugins_ImageFunctors::BinaryThreshold::
56 _GD0( _TInput* input, itk::ProcessObject* filter )
57 {
58   auto outputs = filter->GetOutputs( );
59   if( outputs.size( ) > 0 )
60   {
61     cpPlugins_Demangle_Image_IntPixels_3(
62       outputs[ 0 ].GetPointer( ), _GD1, _TInput::ImageDimension, input, filter
63       )
64       this->_Error( "Invalid output data." );
65   }
66   else
67     this->_Error( "Not enough outputs." );
68 }
69
70 // -------------------------------------------------------------------------
71 template< class _TInput, class _TOutput >
72 void fpaPlugins_ImageFunctors::BinaryThreshold::
73 _GD1( _TOutput* output, _TInput* input, itk::ProcessObject* filter )
74 {
75   typedef typename _TOutput::PixelType _TValue;
76   typedef fpa::Image::Functors::RegionGrow::BinaryThreshold< _TInput, _TValue > _TFunctor;
77
78   auto f = dynamic_cast< _TFunctor* >( this->m_Functor.GetPointer( ) );
79   if( f == NULL )
80   {
81     typename _TFunctor::Pointer ptr_f = _TFunctor::New( );
82     f = ptr_f.GetPointer( );
83     this->m_Functor = f;
84
85   } // fi
86   f->SetLower( this->m_Parameters.GetReal( "Lower" ) );
87   f->SetUpper( this->m_Parameters.GetReal( "Upper" ) );
88 }
89
90 // eof - $RCSfile$