]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/Algorithms/MacheteImageFilter.hxx
Machete filter example added
[cpPlugins.git] / lib / cpExtensions / Algorithms / MacheteImageFilter.hxx
diff --git a/lib/cpExtensions/Algorithms/MacheteImageFilter.hxx b/lib/cpExtensions/Algorithms/MacheteImageFilter.hxx
new file mode 100644 (file)
index 0000000..4da9428
--- /dev/null
@@ -0,0 +1,64 @@
+#ifndef __CPEXTENSIONS__ALGORITHMS__MACHETEIMAGEFILTER__HXX__
+#define __CPEXTENSIONS__ALGORITHMS__MACHETEIMAGEFILTER__HXX__
+
+#include <cpExtensions/Algorithms/MacheteImageFilter.h>
+
+//filter stuff
+#include "itkObjectFactory.h"
+#include "itkImageRegionIterator.h"
+#include "itkImageRegionConstIterator.h"
+
+//typedef itk::Image<unsigned char, 2>  ImageType;
+
+template< class I, class O>
+void cpExtensions::Algorithms::MacheteImageFilter<  I, O>
+::GenerateData()
+{
+  typename I::ConstPointer input = this->GetInput();
+
+  typename O::Pointer output = this->GetOutput();
+  output->SetRegions(input->GetLargestPossibleRegion());
+  output->Allocate();
+
+  itk::ImageRegionIterator<I> outputIterator(output, output->GetLargestPossibleRegion());
+  itk::ImageRegionConstIterator<O> inputIterator(input, input->GetLargestPossibleRegion());
+
+  while (!outputIterator.IsAtEnd())
+  {
+    auto p0 = inputIterator.GetIndex();
+    itk::Point<double, 3> otherPoint;
+    otherPoint[0] = p0[0];
+    otherPoint[1] = p0[1];
+    otherPoint[2] = p0[2];
+    otherPoint[2] = this->point[2]; // TODO : Solve this hammer
+
+    double dist = this->point.EuclideanDistanceTo(otherPoint);
+    if (dist <= this->radius)
+    {
+      outputIterator.Set(0);
+    }
+    else
+    {
+      outputIterator.Set(inputIterator.Get());
+    }
+
+    ++inputIterator;
+    ++outputIterator;
+  }
+
+}
+
+template< class I, class O>
+void cpExtensions::Algorithms::MacheteImageFilter< I, O>::SetRadius(double rad){
+  this->radius = rad;
+}
+
+template< class I, class O>
+void cpExtensions::Algorithms::MacheteImageFilter< I, O>::SetPoint(itk::Point<double, 3> point){
+  this->point = point;
+}
+
+
+
+
+#endif
\ No newline at end of file