]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/Algorithms/MacheteImageFilter.hxx
yet another refactoring
[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..a984df1
--- /dev/null
@@ -0,0 +1,92 @@
+#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()
+{
+  //const typename Superclass::OutputImageRegionType& region;
+
+  typename I::ConstPointer input = this->GetInput();
+
+  typename O::Pointer output = this->GetOutput();
+  output->SetRegions(input->GetLargestPossibleRegion());
+  output->Allocate();
+
+  itk::ImageRegionIterator<O> outputIterator(output, output->GetLargestPossibleRegion());
+  itk::ImageRegionConstIterator<I> 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->m_Radius)
+    {
+      outputIterator.Set(0);
+    }
+    else
+    {
+      outputIterator.Set(inputIterator.Get());
+    }
+
+    ++inputIterator;
+    ++outputIterator;
+  }
+
+  
+}
+
+template< class I, class O>
+void cpExtensions::Algorithms::MacheteImageFilter< I, O>::SetRadius(const RadiusType & rad)
+{
+  if (this->m_Radius != rad)
+  {
+    this->m_Radius = rad;
+    this->Modified();
+  }
+}
+
+//template< class I, class O>
+//void cpExtensions::Algorithms::MacheteImageFilter< I, O>::SetRadius(const RadiusValueType & rad)
+//{
+//  RadiusType r;
+//  r.Fill(rad);
+//  this->SetRadius(r);
+//}
+
+template< class I, class O>
+void cpExtensions::Algorithms::MacheteImageFilter< I, O>::SetPoint(itk::Point<double, 3> & p){
+  if (point != p)
+  {
+    this->point = p;
+    this->Modified();
+  }
+}
+
+template< class I, class O>
+void cpExtensions::Algorithms::MacheteImageFilter< I, O>::SetPoint(const double & x, const double & y, const double & z)
+{
+  this->point[0] = x;
+  this->point[1] = y;
+  this->point[2] = z;
+  this->Modified();
+}
+
+
+
+#endif
\ No newline at end of file