From bd53dc3e11a665706fd8082bef218786a9d0669c Mon Sep 17 00:00:00 2001 From: Jose Luis Guzman Date: Mon, 19 Oct 2015 19:19:37 +0200 Subject: [PATCH] Machete filter example added --- appli/examples/CMakeLists.txt | 1 + appli/examples/example_MacheteFilter.cxx | 83 +++++++++++++++++++ .../Algorithms/MacheteImageFilter.h | 62 ++++++++++++++ .../Algorithms/MacheteImageFilter.hxx | 64 ++++++++++++++ 4 files changed, 210 insertions(+) create mode 100644 appli/examples/example_MacheteFilter.cxx create mode 100644 lib/cpExtensions/Algorithms/MacheteImageFilter.h create mode 100644 lib/cpExtensions/Algorithms/MacheteImageFilter.hxx diff --git a/appli/examples/CMakeLists.txt b/appli/examples/CMakeLists.txt index e12dfa5..35353a0 100644 --- a/appli/examples/CMakeLists.txt +++ b/appli/examples/CMakeLists.txt @@ -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 index 0000000..983c0f8 --- /dev/null +++ b/appli/examples/example_MacheteFilter.cxx @@ -0,0 +1,83 @@ +#include +#include +#include "itkImageFileWriter.h" +#include + +#include + +//#include "MacheteImageFilter.h" +#include "itkObjectFactory.h" +#include "itkImageRegionIterator.h" +#include "itkImageRegionConstIterator.h" + +#include + + +int main(int, char*[]) +{ + std::cout << "Machete image filter"; + + // 1. work with the filter + typedef itk::Image ImageType; + ImageType::Pointer image; + + typedef itk::ImageFileReader ReaderType; + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName("c://img//lung.jpg"); + image = reader->GetOutput(); + + typedef cpExtensions::Algorithms::MacheteImageFilter FilterType; + + FilterType::Pointer filter = FilterType::New(); + filter->SetInput(image); + filter->SetRadius(151); + + itk::Point 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 actor = + vtkSmartPointer::New(); +#if VTK_MAJOR_VERSION <= 5 + actor->SetInput(connector->GetOutput()); +#else + connector->Update(); + actor->GetMapper()->SetInputData(connector->GetOutput()); +#endif + vtkSmartPointer renderer = + vtkSmartPointer::New(); + renderer->AddActor(actor); + renderer->ResetCamera(); + + vtkSmartPointer renderWindow = + vtkSmartPointer::New(); + renderWindow->AddRenderer(renderer); + + vtkSmartPointer renderWindowInteractor = + vtkSmartPointer::New(); + vtkSmartPointer style = + vtkSmartPointer::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 index 0000000..4dde2dc --- /dev/null +++ b/lib/cpExtensions/Algorithms/MacheteImageFilter.h @@ -0,0 +1,62 @@ +// ------------------------------------------------------------------------- +// @author Jose Luis Guzman (cycopepe@gmail.com) +// ------------------------------------------------------------------------- + + +#ifndef __CPEXTENSIONS__ALGORITHMS__MACHETEIMAGEFILTER__H__ +#define __CPEXTENSIONS__ALGORITHMS__MACHETEIMAGEFILTER__H__ + +#include + +#include + +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 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 point; + }; + + } // ecapseman + +} // ecapseman + + +#ifndef ITK_MANUAL_INSTANTIATION +#include +#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 index 0000000..4da9428 --- /dev/null +++ b/lib/cpExtensions/Algorithms/MacheteImageFilter.hxx @@ -0,0 +1,64 @@ +#ifndef __CPEXTENSIONS__ALGORITHMS__MACHETEIMAGEFILTER__HXX__ +#define __CPEXTENSIONS__ALGORITHMS__MACHETEIMAGEFILTER__HXX__ + +#include + +//filter stuff +#include "itkObjectFactory.h" +#include "itkImageRegionIterator.h" +#include "itkImageRegionConstIterator.h" + +//typedef itk::Image 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 outputIterator(output, output->GetLargestPossibleRegion()); + itk::ImageRegionConstIterator inputIterator(input, input->GetLargestPossibleRegion()); + + while (!outputIterator.IsAtEnd()) + { + auto p0 = inputIterator.GetIndex(); + itk::Point 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 point){ + this->point = point; +} + + + + +#endif \ No newline at end of file -- 2.47.1