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