]> Creatis software - cpPlugins.git/commitdiff
Merge branch 'master' of ssh://git.creatis.insa-lyon.fr/cpPlugins
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Tue, 20 Oct 2015 21:03:51 +0000 (16:03 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Tue, 20 Oct 2015 21:03:51 +0000 (16:03 -0500)
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]
lib/cpPlugins/Plugins/BasicFilters/MacheteImageFilter.cxx [new file with mode: 0644]
lib/cpPlugins/Plugins/BasicFilters/MacheteImageFilter.h [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..4a38149
--- /dev/null
@@ -0,0 +1,66 @@
+#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->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
diff --git a/lib/cpPlugins/Plugins/BasicFilters/MacheteImageFilter.cxx b/lib/cpPlugins/Plugins/BasicFilters/MacheteImageFilter.cxx
new file mode 100644 (file)
index 0000000..ff4e03a
--- /dev/null
@@ -0,0 +1,93 @@
+#include "MacheteImageFilter.h"
+#include <cpPlugins/Interface/Image.h>
+
+//#include <MacheteImageFilter.h>
+#include <itkImage.h>
+#include <itkBinaryBallStructuringElement.h>
+
+#include <cpExtensions/Algorithms/MacheteImageFilter.h>
+
+// -------------------------------------------------------------------------
+cpPlugins::BasicFilters::MacheteImageFilter::
+MacheteImageFilter( )
+  : Superclass( )
+{
+  this->_AddInput( "Input" );
+  this->_MakeOutput< cpPlugins::Interface::Image >( "Output" );
+
+  this->m_Parameters->ConfigureAsUint( "Radius", 2 );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::BasicFilters::MacheteImageFilter::
+~MacheteImageFilter( )
+{
+}
+
+// -------------------------------------------------------------------------
+std::string cpPlugins::BasicFilters::MacheteImageFilter::
+_GenerateData( )
+{
+  cpPlugins::Interface::Image* image =
+    this->GetInput< cpPlugins::Interface::Image >( "Input" );
+  if( image == NULL )
+    return( "MacheteImageFilter: No input image." );
+
+  itk::DataObject* itk_image = NULL;
+  std::string r = "";
+  cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _GD0 );
+  else cpPlugins_Image_Demangle_AllScalarTypes( 3, image, itk_image, r, _GD0 );
+  else cpPlugins_Image_Demangle_AllScalarTypes( 4, image, itk_image, r, _GD0 );
+  else r = "MacheteImageFilter: Input image type not supported.";
+  return( r );
+}
+
+// -------------------------------------------------------------------------
+template< class I >
+std::string cpPlugins::BasicFilters::MacheteImageFilter::
+_GD0( itk::DataObject* image )
+{
+  return(
+    this->_RealGD< I, itk::Image< unsigned char, I::ImageDimension > >(
+      image
+      )
+    );
+}
+
+// -------------------------------------------------------------------------
+template< class I, class O >
+inline std::string cpPlugins::BasicFilters::MacheteImageFilter::
+_RealGD( itk::DataObject* image )
+{
+  typedef cpExtensions::Algorithms::MacheteImageFilter< I, O > _F;
+  //typedef typename _F::radius _RT;
+
+  // Get parameters
+  //_RT rad_val;
+  //rad_val.Fill( this->m_Parameters->GetUint( "Radius" ) );
+
+  // Configure filter
+
+  _F* filter = this->_CreateITK< _F >();
+  filter->SetInput(dynamic_cast< I* >(image));
+  filter->SetRadius(this->m_Parameters->GetUint("Radius"));
+  filter->Update();
+
+  //_F* filter = this->_CreateITK< _F >( );
+  //filter->SetInput( dynamic_cast< I* >( image ) );
+  //filter->Update( );
+
+  // Connect output
+  cpPlugins::Interface::Image* out =
+    this->GetOutput< cpPlugins::Interface::Image >( "Output" );
+  if( out != NULL )
+  {
+    //out->SetITK< O >( filter->GetOutput( ) );
+    return( "" );
+  }
+  else
+    return( "MacheteImageFilter: output not correctly created." );
+}
+
+// eof - $RCSfile$
diff --git a/lib/cpPlugins/Plugins/BasicFilters/MacheteImageFilter.h b/lib/cpPlugins/Plugins/BasicFilters/MacheteImageFilter.h
new file mode 100644 (file)
index 0000000..ab7a6e9
--- /dev/null
@@ -0,0 +1,60 @@
+#ifndef __CPPLUGINS__PLUGINS__MACHETEIMAGEFILTER__H__
+#define __CPPLUGINS__PLUGINS__MACHETEIMAGEFILTER__H__
+
+#include <cpPlugins/BasicFilters/cpPluginsBasicFilters_Export.h>
+#include <cpPlugins/Interface/BaseProcessObjects.h>
+
+namespace cpPlugins
+{
+  namespace BasicFilters
+  {
+    /**
+     */
+    class cpPluginsBasicFilters_EXPORT MacheteImageFilter
+      : public cpPlugins::Interface::ImageToImageFilter
+    {
+    public:
+      typedef MacheteImageFilter                        Self;
+      typedef cpPlugins::Interface::ImageToImageFilter Superclass;
+      typedef itk::SmartPointer< Self >                Pointer;
+      typedef itk::SmartPointer< const Self >          ConstPointer;
+
+    public:
+      itkNewMacro( Self );
+      itkTypeMacro(
+        MacheteImageFilter,
+        cpPluginsInterfaceImageToImageFilter
+        );
+      cpPlugins_Id_Macro(
+        cpPlugins::BasicFilters::MacheteImageFilter,
+        "ImageToImageFilter"
+        );
+
+    protected:
+      MacheteImageFilter( );
+      virtual ~MacheteImageFilter( );
+
+      virtual std::string _GenerateData( );
+
+      template< class I >
+        inline std::string _GD0( itk::DataObject* image );
+
+      template< class I, class O >
+        inline std::string _RealGD( itk::DataObject* image );
+
+    private:
+      // Purposely not implemented
+      MacheteImageFilter( const Self& );
+      Self& operator=( const Self& );
+    };
+
+    // ---------------------------------------------------------------------
+    CPPLUGINS_INHERIT_PROVIDER( MacheteImageFilter );
+
+  } // ecapseman
+
+} // ecapseman
+
+#endif // __CPPLUGINS__PLUGINS__MacheteImageFilter__H__
+
+// eof - $RCSfile$