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