]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Algorithms/MacheteImageFilter.hxx
yet another refactoring
[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   //const typename Superclass::OutputImageRegionType& region;
18
19   typename I::ConstPointer input = this->GetInput();
20
21   typename O::Pointer output = this->GetOutput();
22   output->SetRegions(input->GetLargestPossibleRegion());
23   output->Allocate();
24
25   itk::ImageRegionIterator<O> outputIterator(output, output->GetLargestPossibleRegion());
26   itk::ImageRegionConstIterator<I> inputIterator(input, input->GetLargestPossibleRegion());
27
28   while (!outputIterator.IsAtEnd())
29   {
30     auto p0 = inputIterator.GetIndex();
31     itk::Point<double, 3> otherPoint;
32     otherPoint[0] = p0[0];
33     otherPoint[1] = p0[1];
34     otherPoint[2] = p0[2];
35     //otherPoint[2] = this->point[2]; // TODO : Solve this hammer
36
37     double dist = this->point.EuclideanDistanceTo(otherPoint);
38     if (dist <= this->m_Radius)
39     {
40       outputIterator.Set(0);
41     }
42     else
43     {
44       outputIterator.Set(inputIterator.Get());
45     }
46
47     ++inputIterator;
48     ++outputIterator;
49   }
50
51   
52 }
53
54 template< class I, class O>
55 void cpExtensions::Algorithms::MacheteImageFilter< I, O>::SetRadius(const RadiusType & rad)
56 {
57   if (this->m_Radius != rad)
58   {
59     this->m_Radius = rad;
60     this->Modified();
61   }
62 }
63
64 //template< class I, class O>
65 //void cpExtensions::Algorithms::MacheteImageFilter< I, O>::SetRadius(const RadiusValueType & rad)
66 //{
67 //  RadiusType r;
68 //  r.Fill(rad);
69 //  this->SetRadius(r);
70 //}
71
72 template< class I, class O>
73 void cpExtensions::Algorithms::MacheteImageFilter< I, O>::SetPoint(itk::Point<double, 3> & p){
74   if (point != p)
75   {
76     this->point = p;
77     this->Modified();
78   }
79 }
80
81 template< class I, class O>
82 void cpExtensions::Algorithms::MacheteImageFilter< I, O>::SetPoint(const double & x, const double & y, const double & z)
83 {
84   this->point[0] = x;
85   this->point[1] = y;
86   this->point[2] = z;
87   this->Modified();
88 }
89
90
91
92 #endif