]> Creatis software - FrontAlgorithms.git/blob - plugins/ImageAlgorithms/BaseFilter.h
0b871a5f4cf06a1f0c6db17ea65446a4457791a3
[FrontAlgorithms.git] / plugins / ImageAlgorithms / BaseFilter.h
1 #ifndef __fpaPluginsImageAlgorithms__BaseFilter__h__
2 #define __fpaPluginsImageAlgorithms__BaseFilter__h__
3
4 #include <fpaPluginsImageAlgorithms_Export.h>
5
6 #include <vtkPolyData.h>
7 #include <cpPlugins/Pipeline/ProcessObject.h>
8
9 #define ITK_MANUAL_INSTANTIATION
10 #include <fpa/Image/Functors/SimpleNeighborhood.h>
11
12 namespace fpaPluginsImageAlgorithms
13 {
14   /**
15    */
16   class fpaPluginsImageAlgorithms_EXPORT BaseFilter
17     : public cpPlugins::Pipeline::ProcessObject
18   {
19   public:
20     typedef BaseFilter                         Self;
21     typedef cpPlugins::Pipeline::ProcessObject Superclass;
22     typedef itk::SmartPointer< Self >          Pointer;
23     typedef itk::SmartPointer< const Self >    ConstPointer;
24
25   public:
26     itkTypeMacro( BaseFilter, cpPlugins::Pipeline::ProcessObject );
27     cpPlugins_Id_Macro( BaseFilter, fpaImageAlgorithm );
28
29   protected:
30     BaseFilter( );
31     virtual ~BaseFilter( );
32
33     template< class _TFilter, class _TImage >
34     inline void _ConfigureFilter(
35       _TFilter* filter, _TImage* image,
36       std::vector< typename _TImage::IndexType >& seeds
37       );
38
39   private:
40     // Purposely not implemented.
41     BaseFilter( const Self& other );
42     Self& operator=( const Self& other );
43   };
44
45 } // ecapseman
46
47 // -------------------------------------------------------------------------
48 template< class _TFilter, class _TImage >
49 void fpaPluginsImageAlgorithms::BaseFilter::
50 _ConfigureFilter(
51   _TFilter* filter, _TImage* image,
52   std::vector< typename _TImage::IndexType >& seeds
53   )
54 {
55   typedef typename _TFilter::TNeighborhoodFunction _TNeighborhood;
56   typedef
57     fpa::Image::Functors::SimpleNeighborhood< _TImage::ImageDimension >
58     _TSimpleNeigh;
59
60   // Simple configuration
61   filter->SetInput( image );
62   filter->SetStopAtOneFront( this->m_Parameters.GetBool( "StopAtOneFront" ) );
63
64   // Neighborhood function
65   typename _TSimpleNeigh::Pointer sfunc = _TSimpleNeigh::New( );
66   sfunc->SetOrder( this->m_Parameters.GetUint( "NeighborhoodOrder" ) );
67   filter->SetNeighborhoodFunction( sfunc );
68
69   // Assign seeds
70   seeds.clear( );
71   auto pnt_seeds = this->GetInputData< vtkPolyData >( "Seeds" );
72   if( pnt_seeds != NULL )
73   {
74     typename _TImage::PointType pnt;
75     typename _TImage::IndexType idx;
76     unsigned int dim =
77       ( _TImage::ImageDimension < 3 )? _TImage::ImageDimension: 3;
78
79     for( int i = 0; i < pnt_seeds->GetNumberOfPoints( ); ++i )
80     {
81       double buf[ 3 ];
82       pnt_seeds->GetPoint( i, buf );
83       pnt.Fill( 0 );
84       for( unsigned int d = 0; d < dim; ++d )
85         pnt[ d ] = buf[ d ];
86
87       if( image->TransformPhysicalPointToIndex( pnt, idx ) )
88         seeds.push_back( idx );
89
90     } // rof
91
92   } // fi
93 }
94
95 #endif // __fpaPluginsImageAlgorithms__BaseFilter__h__
96
97 // eof - $RCSfile$