]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/BasicFilters/MacheteImageFilter.cxx
...
[cpPlugins.git] / lib / cpPlugins / Plugins / BasicFilters / MacheteImageFilter.cxx
1 #include "MacheteImageFilter.h"
2 #include <cpPlugins/Interface/Image.h>
3
4 //#include <MacheteImageFilter.h>
5 #include <itkImage.h>
6 #include <itkBinaryBallStructuringElement.h>
7
8 #include <cpExtensions/Algorithms/MacheteImageFilter.h>
9
10 // -------------------------------------------------------------------------
11 cpPlugins::BasicFilters::MacheteImageFilter::
12 MacheteImageFilter()
13 : Superclass()
14 {
15   this->_AddInput( "Input" );
16   this->_AddOutput< cpPlugins::Interface::Image >("Output");
17
18   this->m_Parameters->ConfigureAsReal("Radius");
19   //this->m_Parameters->ConfigureAsPoint("Point", 3, 3);
20   this->m_Parameters->ConfigureAsReal("X");
21   this->m_Parameters->ConfigureAsReal("Y");
22   this->m_Parameters->ConfigureAsReal("Z");
23
24   this->m_Parameters->SetReal("Radius", 20);
25   //this->m_Parameters->SetPoint("Point", 3, 3);
26   this->m_Parameters->SetReal("X", 30);
27   this->m_Parameters->SetReal("Y", 30);
28   this->m_Parameters->SetReal("Z", 30);
29 }
30
31 // -------------------------------------------------------------------------
32 cpPlugins::BasicFilters::MacheteImageFilter::
33 ~MacheteImageFilter()
34 {
35 }
36
37 // -------------------------------------------------------------------------
38 std::string cpPlugins::BasicFilters::MacheteImageFilter::
39 _GenerateData()
40 {
41   auto image = this->GetInputData< cpPlugins::Interface::Image >("Input");
42   if (image == NULL)
43     return("MacheteImageFilter: No input image.");
44
45   itk::DataObject* itk_image = NULL;
46   std::string r = "";
47   cpPlugins_Image_Demangle_AllScalarTypes(2, image, itk_image, r, _GD0);
48   else cpPlugins_Image_Demangle_AllScalarTypes(3, image, itk_image, r, _GD0);
49   else cpPlugins_Image_Demangle_AllScalarTypes(4, image, itk_image, r, _GD0);
50   else r = "MacheteImageFilter: Input image type not supported.";
51   return(r);
52 }
53
54 // -------------------------------------------------------------------------
55 template< class I >
56 std::string cpPlugins::BasicFilters::MacheteImageFilter::
57 _GD0(itk::DataObject* image)
58 {
59   return(
60     this->_RealGD< I, itk::Image< unsigned char, I::ImageDimension > >(
61     image
62     )
63     );
64 }
65
66 // -------------------------------------------------------------------------
67 template< class I, class O >
68 inline std::string cpPlugins::BasicFilters::MacheteImageFilter::
69 _RealGD(itk::DataObject* image)
70 {
71   typedef cpExtensions::Algorithms::MacheteImageFilter< I, O > _F;
72   typedef typename I::PixelType _RT;
73
74   // Get parameters
75
76   _RT rad_val = _RT(this->m_Parameters->GetReal("Radius"));
77   
78   double pointx = this->m_Parameters->GetReal("X");
79   double pointy = this->m_Parameters->GetReal("Y");
80   double pointz = this->m_Parameters->GetReal("Z");
81
82   // Configure filter
83     _F* filter = this->_CreateITK< _F >();
84   filter->SetInput(dynamic_cast<I*>(image));
85   filter->SetRadius(rad_val);
86    
87   filter->SetPoint(pointx, pointy, pointz);
88
89   filter->Update();
90
91   // Connect output
92   auto out = this->GetOutputData< cpPlugins::Interface::Image >("Output");
93   if (out != NULL)
94   {
95     out->SetITK< O >( filter->GetOutput( ) );
96     return("");
97   }
98   else
99     return("MacheteImageFilter: output not correctly created.");
100 }
101
102 // eof - $RCSfile$