]> Creatis software - cpPlugins.git/commitdiff
Machete filter example added
authorJose Luis Guzman <cycopepe@gmail.com>
Mon, 19 Oct 2015 17:19:37 +0000 (19:19 +0200)
committerJose Luis Guzman <cycopepe@gmail.com>
Mon, 19 Oct 2015 17:19:37 +0000 (19:19 +0200)
appli/examples/CMakeLists.txt
appli/examples/example_MacheteFilter.cxx [new file with mode: 0644]
lib/cpExtensions/Algorithms/MacheteImageFilter.h [new file with mode: 0644]
lib/cpExtensions/Algorithms/MacheteImageFilter.hxx [new file with mode: 0644]

index e12dfa53d429cdc22313510d7920a6b3c5ffce86..35353a0b0504349c2489557a7901d416a5907844 100644 (file)
@@ -58,6 +58,7 @@ SET(
   example_BaseInteractorStyle
   example_ContourWidget
   example_Test_async
+  ## example_MacheteFilter
   ## example_Test_DoubleClick
   ## example_ExtractDICOMSeries
   ## example_ImageGaussianModelEstimator
diff --git a/appli/examples/example_MacheteFilter.cxx b/appli/examples/example_MacheteFilter.cxx
new file mode 100644 (file)
index 0000000..983c0f8
--- /dev/null
@@ -0,0 +1,83 @@
+#include <itkImage.h>
+#include <itkImageFileReader.h>
+#include "itkImageFileWriter.h"
+#include <itkRescaleIntensityImageFilter.h>
+
+#include <iostream>
+
+//#include "MacheteImageFilter.h"
+#include "itkObjectFactory.h"
+#include "itkImageRegionIterator.h"
+#include "itkImageRegionConstIterator.h"
+
+#include <cpExtensions/Algorithms/MacheteImageFilter.h>
+
+
+int main(int, char*[])
+{
+  std::cout << "Machete image filter";
+  
+  // 1. work with the filter
+  typedef itk::Image<unsigned char, 2>  ImageType;
+  ImageType::Pointer image;
+
+  typedef itk::ImageFileReader<ImageType> ReaderType;
+  ReaderType::Pointer reader = ReaderType::New();
+  reader->SetFileName("c://img//lung.jpg");
+  image = reader->GetOutput();
+
+  typedef cpExtensions::Algorithms::MacheteImageFilter<ImageType, ImageType>  FilterType;
+
+  FilterType::Pointer filter = FilterType::New();
+  filter->SetInput(image);
+  filter->SetRadius(151);
+
+  itk::Point<double, 3> p0;
+  p0[0] = 250.0;
+  p0[1] = 250.0;
+  p0[2] = 0.0;
+
+  filter->SetPoint(p0);
+  filter->Update();
+
+  // 2. write result
+
+  typedef  itk::ImageFileWriter< ImageType  > WriterType;
+  WriterType::Pointer writer = WriterType::New();
+  writer->SetFileName("c://img//out.jpg");
+  writer->SetInput(filter->GetOutput());
+  writer->Update();
+
+  // 3.display result visualization
+
+ /* vtkSmartPointer<vtkImageActor> actor =
+    vtkSmartPointer<vtkImageActor>::New();
+#if VTK_MAJOR_VERSION <= 5
+  actor->SetInput(connector->GetOutput());
+#else
+  connector->Update();
+  actor->GetMapper()->SetInputData(connector->GetOutput());
+#endif
+  vtkSmartPointer<vtkRenderer> renderer =
+    vtkSmartPointer<vtkRenderer>::New();
+  renderer->AddActor(actor);
+  renderer->ResetCamera();
+
+  vtkSmartPointer<vtkRenderWindow> renderWindow =
+    vtkSmartPointer<vtkRenderWindow>::New();
+  renderWindow->AddRenderer(renderer);
+
+  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
+    vtkSmartPointer<vtkRenderWindowInteractor>::New();
+  vtkSmartPointer<vtkInteractorStyleImage> style =
+    vtkSmartPointer<vtkInteractorStyleImage>::New();
+
+  renderWindowInteractor->SetInteractorStyle(style);
+
+  renderWindowInteractor->SetRenderWindow(renderWindow);
+  renderWindowInteractor->Initialize();
+
+  renderWindowInteractor->Start();*/
+
+  return 0;
+}
\ No newline at end of file
diff --git a/lib/cpExtensions/Algorithms/MacheteImageFilter.h b/lib/cpExtensions/Algorithms/MacheteImageFilter.h
new file mode 100644 (file)
index 0000000..4dde2dc
--- /dev/null
@@ -0,0 +1,62 @@
+// -------------------------------------------------------------------------
+// @author Jose Luis Guzman (cycopepe@gmail.com)
+// -------------------------------------------------------------------------
+
+
+#ifndef __CPEXTENSIONS__ALGORITHMS__MACHETEIMAGEFILTER__H__
+#define __CPEXTENSIONS__ALGORITHMS__MACHETEIMAGEFILTER__H__
+
+#include <cpExtensions/cpExtensions_Export.h>
+
+#include <itkImageToImageFilter.h>
+
+namespace cpExtensions
+{
+  namespace Algorithms
+  {
+    template< class I, class O>
+    class MacheteImageFilter :public itk::ImageToImageFilter < I, O >
+    {
+    public:
+      /** Standard class typedefs. */
+      typedef MacheteImageFilter             Self;
+
+      typedef itk::ImageToImageFilter< I, O > Superclass;
+      typedef itk::SmartPointer< Self >        Pointer;
+
+      /** Method for creation through the object factory. */
+      itkNewMacro(Self);
+
+      /** Run-time type information (and related methods). */
+      itkTypeMacro(MacheteImageFilter, ImageToImageFilter);
+
+      void SetRadius(double radius);
+      void SetPoint(itk::Point<double, 3> point);
+
+    protected:
+      MacheteImageFilter(){}
+      ~MacheteImageFilter(){}
+
+      /** Does the real work. */
+      virtual void GenerateData();
+
+
+    private:
+      MacheteImageFilter(const Self &); //purposely not implemented
+      void operator=(const Self &);  //purposely not implemented
+
+      double radius;
+      itk::Point<double, 3> point;
+    };
+
+  } // ecapseman
+
+} // ecapseman
+
+
+#ifndef ITK_MANUAL_INSTANTIATION
+#include <cpExtensions/Algorithms/MacheteImageFilter.hxx>
+#endif
+
+
+#endif // __CPEXTENSIONS__ALGORITHMS__MACHETEIMAGEFILTER__H__
\ No newline at end of file
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