]> Creatis software - FrontAlgorithms.git/blob - plugins/fpa/InvertCostFunction.cxx
3664bfa64689fa10f7210eca0b38714c6b09a154
[FrontAlgorithms.git] / plugins / fpa / InvertCostFunction.cxx
1 #include "InvertCostFunction.h"
2
3 #include <cpPlugins/Image.h>
4 #include <fpa/Base/Functors/InvertCostFunction.h>
5
6 // -------------------------------------------------------------------------
7 fpaPlugins::InvertCostFunction::
8 InvertCostFunction( )
9   : Superclass( )
10 {
11   this->_AddOutput< cpPlugins::DataObject >( "Output" );
12
13   this->m_Parameters.ConfigureAsReal( "Alpha" );
14   this->m_Parameters.ConfigureAsReal( "Beta" );
15
16   std::vector< std::string > choices;
17   choices.push_back( "float" );
18   choices.push_back( "double" );
19   this->m_Parameters.ConfigureAsChoices( "ScalarType", choices );
20
21   this->m_Parameters.SetReal( "Alpha", 1 );
22   this->m_Parameters.SetReal( "Beta", 1 );
23   this->m_Parameters.SetSelectedChoice( "ScalarType", "float" );
24 }
25
26 // -------------------------------------------------------------------------
27 fpaPlugins::InvertCostFunction::
28 ~InvertCostFunction( )
29 {
30 }
31
32 // -------------------------------------------------------------------------
33 void fpaPlugins::InvertCostFunction::
34 _GenerateData( )
35 {
36   auto choice = this->m_Parameters.GetSelectedChoice( "ScalarType" );
37   if     ( choice == "float" )  this->_GD0< float >( );
38   else if( choice == "double" ) this->_GD0< double >( );
39   else this->_Error( "Invalid scalar type." );
40 }
41
42 // -------------------------------------------------------------------------
43 template< class _TScalar >
44 void fpaPlugins::InvertCostFunction::
45 _GD0( )
46 {
47   typedef fpa::Base::Functors::InvertCostFunction< _TScalar > _TFunctor;
48   auto out = this->GetOutput( "Output" );
49   auto f = out->GetITK< _TFunctor >( );
50   if( f == NULL )
51   {
52     typename _TFunctor::Pointer ptr_f = _TFunctor::New( );
53     f = ptr_f.GetPointer( );
54     out->SetITK( f );
55
56   } // fi
57   f->SetAlpha( this->m_Parameters.GetReal( "Alpha" ) );
58   f->SetBeta( this->m_Parameters.GetReal( "Beta" ) );
59 }
60
61 // eof - $RCSfile$