]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Algorithms/RasterContourFilter.h
...
[cpPlugins.git] / lib / cpExtensions / Algorithms / RasterContourFilter.h
1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
4
5 #ifndef __cpExtensions__Algorithms__RasterContourFilter__h__
6 #define __cpExtensions__Algorithms__RasterContourFilter__h__
7
8 #include <cpExtensions/Config.h>
9 #include <itkImageSource.h>
10 #include <deque>
11
12 // -------------------------------------------------------------------------
13 namespace cpExtensions
14 {
15   namespace Algorithms
16   {
17     /**
18      */
19     template< class _TImage >
20     class RasterContourFilter
21       : public itk::ImageSource< _TImage >
22     {
23     public:
24       // Basic types
25       typedef RasterContourFilter             Self;
26       typedef itk::ImageSource< _TImage >     Superclass;
27       typedef itk::SmartPointer< Self >       Pointer;
28       typedef itk::SmartPointer< const Self > ConstPointer;
29
30       typedef _TImage TImage;
31       typedef typename _TImage::IndexType  TIndex;
32       typedef typename _TImage::PixelType  TPixel;
33       typedef typename _TImage::PointType  TPoint;
34       typedef typename _TImage::RegionType TRegion;
35       typedef itk::ImageBase< 2 > TImageBase;
36
37     public:
38       itkNewMacro( Self );
39       itkTypeMacro( RasterContourFilter, itk::ImageSource );
40
41       itkGetConstObjectMacro( Template, TImageBase );
42       itkGetConstMacro( InsideValue, TPixel );
43       itkGetConstMacro( OutsideValue, TPixel );
44
45       itkSetConstObjectMacro( Template, TImageBase );
46       itkSetMacro( InsideValue, TPixel );
47       itkSetMacro( OutsideValue, TPixel );
48
49     public:
50       void AddPoint( double x, double y );
51       void AddPoint( double p[ 2 ] );
52       template< class _TPoint >
53         inline void AddPoint( const _TPoint& p );
54       void ClearPoints( );
55
56     protected:
57       RasterContourFilter( );
58       virtual ~RasterContourFilter( );
59
60       virtual void AllocateOutputs( ) cpExtensions_OVERRIDE;
61       virtual void BeforeThreadedGenerateData( ) cpExtensions_OVERRIDE;
62       virtual void AfterThreadedGenerateData( ) cpExtensions_OVERRIDE;
63       virtual void ThreadedGenerateData(
64         const TRegion& region, itk::ThreadIdType id
65         ) cpExtensions_OVERRIDE;
66
67     private:
68       // Purposely not implemented
69       RasterContourFilter( const Self& );
70       void operator=( const Self& );
71
72     protected:
73       std::deque< TPoint > m_Contour;
74       std::deque< TIndex > m_Polygon;
75       TRegion m_ROI;
76       typename TImageBase::ConstPointer m_Template;
77       TPixel m_InsideValue;
78       TPixel m_OutsideValue;
79     };
80
81   } // ecapseman
82
83 } // ecapseman
84
85 // -------------------------------------------------------------------------
86 template< class _TImage >
87 template< class _TPoint >
88 void cpExtensions::Algorithms::RasterContourFilter< _TImage >::
89 AddPoint( const _TPoint& p )
90 {
91   TPoint pnt;
92   pnt[ 0 ] = p[ 0 ];
93   pnt[ 1 ] = p[ 2 ];
94   this->m_Contour.push_back( pnt );
95   this->Modified( );
96 }
97
98 // -------------------------------------------------------------------------
99 #ifndef ITK_MANUAL_INSTANTIATION
100 #  include <cpExtensions/Algorithms/RasterContourFilter.hxx>
101 #endif // ITK_MANUAL_INSTANTIATION
102
103 #endif // __cpExtensions__Algorithms__RasterContourFilter__h__
104
105 // eof - $RCSfile$