]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Algorithms/MacheteImageFilter.hxx
Machete filter example added
[cpPlugins.git] / lib / cpExtensions / Algorithms / MacheteImageFilter.hxx
1 #ifndef __CPEXTENSIONS__ALGORITHMS__MACHETEIMAGEFILTER__HXX__
2 #define __CPEXTENSIONS__ALGORITHMS__MACHETEIMAGEFILTER__HXX__
3
4 #include <cpExtensions/Algorithms/MacheteImageFilter.h>
5
6 //filter stuff
7 #include "itkObjectFactory.h"
8 #include "itkImageRegionIterator.h"
9 #include "itkImageRegionConstIterator.h"
10
11 //typedef itk::Image<unsigned char, 2>  ImageType;
12
13 template< class I, class O>
14 void cpExtensions::Algorithms::MacheteImageFilter<  I, O>
15 ::GenerateData()
16 {
17   typename I::ConstPointer input = this->GetInput();
18
19   typename O::Pointer output = this->GetOutput();
20   output->SetRegions(input->GetLargestPossibleRegion());
21   output->Allocate();
22
23   itk::ImageRegionIterator<I> outputIterator(output, output->GetLargestPossibleRegion());
24   itk::ImageRegionConstIterator<O> inputIterator(input, input->GetLargestPossibleRegion());
25
26   while (!outputIterator.IsAtEnd())
27   {
28     auto p0 = inputIterator.GetIndex();
29     itk::Point<double, 3> otherPoint;
30     otherPoint[0] = p0[0];
31     otherPoint[1] = p0[1];
32     otherPoint[2] = p0[2];
33     otherPoint[2] = this->point[2]; // TODO : Solve this hammer
34
35     double dist = this->point.EuclideanDistanceTo(otherPoint);
36     if (dist <= this->radius)
37     {
38       outputIterator.Set(0);
39     }
40     else
41     {
42       outputIterator.Set(inputIterator.Get());
43     }
44
45     ++inputIterator;
46     ++outputIterator;
47   }
48
49 }
50
51 template< class I, class O>
52 void cpExtensions::Algorithms::MacheteImageFilter< I, O>::SetRadius(double rad){
53   this->radius = rad;
54 }
55
56 template< class I, class O>
57 void cpExtensions::Algorithms::MacheteImageFilter< I, O>::SetPoint(itk::Point<double, 3> point){
58   this->point = point;
59 }
60
61
62
63
64 #endif