]> Creatis software - FrontAlgorithms.git/blob - plugins/ImageAlgorithms/BaseFilter.h
...
[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/BaseObjects/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::BaseObjects::ProcessObject
15   {
16   public:
17     typedef BaseFilter                            Self;
18     typedef cpPlugins::BaseObjects::ProcessObject Superclass;
19     typedef itk::SmartPointer< Self >             Pointer;
20     typedef itk::SmartPointer< const Self >       ConstPointer;
21
22   public:
23     itkTypeMacro( BaseFilter, cpPlugins::BaseObjects::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 fpa::Image::Functors::SimpleNeighborhood< _TImage > _TSimpleNeigh;
60
61   // Simple configuration
62   filter->SetInput( image );
63   filter->SetStopAtOneFront( this->m_Parameters.GetBool( "StopAtOneFront" ) );
64
65   // Neighborhood function
66   auto neig = this->GetInputData< _TNeighborhood >( "Neighborhood" );
67   if( neig == NULL )
68   {
69     typename _TSimpleNeigh::Pointer sfunc = _TSimpleNeigh::New( );
70     sfunc->SetOrder( this->m_Parameters.GetUint( "NeighborhoodOrder" ) );
71     filter->SetNeighborhoodFunction( sfunc );
72   }
73   else
74     filter->SetNeighborhoodFunction( neig );
75
76   // Assign seeds
77   auto seeds = this->GetInputData< vtkPolyData >( "Seeds" );
78   if( seeds != NULL )
79   {
80     typename _TImage::PointType pnt;
81     typename _TImage::IndexType idx;
82     unsigned int dim =
83       ( _TImage::ImageDimension < 3 )? _TImage::ImageDimension: 3;
84
85     for( int i = 0; i < seeds->GetNumberOfPoints( ); ++i )
86     {
87       double buf[ 3 ];
88       seeds->GetPoint( i, buf );
89       pnt.Fill( 0 );
90       for( unsigned int d = 0; d < dim; ++d )
91         pnt[ d ] = buf[ d ];
92
93       if( image->TransformPhysicalPointToIndex( pnt, idx ) )
94         filter->AddSeed( idx, 0 );
95
96     } // rof
97
98   } // fi
99 }
100
101 #endif // __fpaPluginsImageAlgorithms__BaseFilter__h__
102
103 // eof - $RCSfile$