]> Creatis software - FrontAlgorithms.git/blob - plugins/Functors/Inverse.cxx
...
[FrontAlgorithms.git] / plugins / Functors / Inverse.cxx
1 #include "Inverse.h"
2
3 #include <cpInstances/DataObjects/Image.h>
4
5 #include <itkImage.h>
6 #include <fpa/Base/Functors/Inverse.h>
7
8 // -------------------------------------------------------------------------
9 void fpaPlugins_Functors::Inverse::
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_Functors::Inverse::
32 Inverse( )
33   : Superclass( )
34 {
35   this->_ConfigureOutput< cpPlugins::Pipeline::DataObject >( "Functor" );
36   this->m_Parameters.ConfigureAsReal( "NegativeValue", -1 );
37   this->GetOutput( "Functor" )->SetITK( this );
38 }
39
40 // -------------------------------------------------------------------------
41 fpaPlugins_Functors::Inverse::
42 ~Inverse( )
43 {
44 }
45
46 // -------------------------------------------------------------------------
47 void fpaPlugins_Functors::Inverse::
48 _GenerateData( )
49 {
50 }
51
52 // -------------------------------------------------------------------------
53 template< class _TInput >
54 void fpaPlugins_Functors::Inverse::
55 _GD0( _TInput* input, itk::ProcessObject* filter )
56 {
57   auto outputs = filter->GetOutputs( );
58   if( outputs.size( ) > 0 )
59   {
60     cpPlugins_Demangle_Image_RealPixels_3(
61       outputs[ 0 ].GetPointer( ), _GD1, _TInput::ImageDimension, input, filter
62       )
63       this->_Error( "Invalid output data." );
64   }
65   else
66     this->_Error( "Not enough outputs." );
67 }
68
69 // -------------------------------------------------------------------------
70 template< class _TInput, class _TOutput >
71 void fpaPlugins_Functors::Inverse::
72 _GD1( _TOutput* output, _TInput* input, itk::ProcessObject* filter )
73 {
74   typedef typename _TInput::PixelType  _TIValue;
75   typedef typename _TOutput::PixelType _TOValue;
76   typedef fpa::Base::Functors::Inverse< _TIValue, _TOValue > _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->SetNegativeValue( this->m_Parameters.GetReal( "NegativeValue" ) );
87 }
88
89 // eof - $RCSfile$