]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Filters/Image/Algorithm.hxx
5095992770ae9b394999764a0ff8b113e1b7dd63
[FrontAlgorithms.git] / lib / fpa / Filters / Image / Algorithm.hxx
1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5 #ifndef __fpa__Filters__Image__Algorithm__hxx__
6 #define __fpa__Filters__Image__Algorithm__hxx__
7
8 // -------------------------------------------------------------------------
9 template< class _TBaseAlgorithm >
10 fpa::Filters::Image::Algorithm< _TBaseAlgorithm >::
11 Algorithm( )
12   : Superclass( ),
13     m_NeighborhoodOrder( 1 )
14 {
15   fpaFilterOutputConfigureMacro( Marks, TMarksImage );
16 }
17
18 // -------------------------------------------------------------------------
19 template< class _TBaseAlgorithm >
20 fpa::Filters::Image::Algorithm< _TBaseAlgorithm >::
21 ~Algorithm( )
22 {
23 }
24
25 // -------------------------------------------------------------------------
26 template< class _TBaseAlgorithm >
27 void fpa::Filters::Image::Algorithm< _TBaseAlgorithm >::
28 _ConfigureOutputs( )
29 {
30   const TInputImage* in = this->GetInput( );
31
32   TOutputImage* out = this->GetOutput( );
33   out->SetLargestPossibleRegion( in->GetLargestPossibleRegion( ) );
34   out->SetRequestedRegion( in->GetRequestedRegion( ) );
35   out->SetBufferedRegion( in->GetBufferedRegion( ) );
36   out->SetSpacing( in->GetSpacing( ) );
37   out->SetOrigin( in->GetOrigin( ) );
38   out->SetDirection( in->GetDirection( ) );
39   out->Allocate( );
40   out->FillBuffer( this->GetInitValue( ) );
41
42   TMarksImage* marks = this->GetMarks( );
43   marks->SetLargestPossibleRegion( in->GetLargestPossibleRegion( ) );
44   marks->SetRequestedRegion( in->GetRequestedRegion( ) );
45   marks->SetBufferedRegion( in->GetBufferedRegion( ) );
46   marks->SetSpacing( in->GetSpacing( ) );
47   marks->SetOrigin( in->GetOrigin( ) );
48   marks->SetDirection( in->GetDirection( ) );
49   marks->Allocate( );
50   marks->FillBuffer( TMark( 0 ) );
51 }
52
53 // -------------------------------------------------------------------------
54 template< class _TBaseAlgorithm >
55 typename fpa::Filters::Image::Algorithm< _TBaseAlgorithm >::
56 TInputValue fpa::Filters::Image::Algorithm< _TBaseAlgorithm >::
57 _GetInputValue( const TVertex& v ) const
58 {
59   return( this->GetInput( )->GetPixel( v ) );
60 }
61
62 // -------------------------------------------------------------------------
63 template< class _TBaseAlgorithm >
64 typename fpa::Filters::Image::Algorithm< _TBaseAlgorithm >::
65 TOutputValue fpa::Filters::Image::Algorithm< _TBaseAlgorithm >::
66 _GetOutputValue( const TVertex& v ) const
67 {
68   return( this->GetOutput( )->GetPixel( v ) );
69 }
70
71 // -------------------------------------------------------------------------
72 template< class _TBaseAlgorithm >
73 typename fpa::Filters::Image::Algorithm< _TBaseAlgorithm >::
74 TNeighborhood fpa::Filters::Image::Algorithm< _TBaseAlgorithm >::
75 _GetNeighbors( const TVertex& v ) const
76 {
77   typename TInputImage::RegionType region =
78     this->GetInput( )->GetRequestedRegion( );
79   TNeighborhood neighborhood;
80   if( this->m_NeighborhoodOrder == 1 )
81   {
82     for( unsigned int d = 0; d < Self::Dimension; ++d )
83     {
84       for( int s = -1; s <= 1; s += 2 )
85       {
86         TVertex n = v;
87         n[ d ] += s;
88         if( region.IsInside( n ) )
89           neighborhood.push_back( n );
90
91       } // rof
92
93     } // rof
94   }
95   else if( this->m_NeighborhoodOrder == 2 )
96   {
97     // TODO
98
99   } // fi
100   return( neighborhood );
101 }
102
103 // -------------------------------------------------------------------------
104 template< class _TBaseAlgorithm >
105 void fpa::Filters::Image::Algorithm< _TBaseAlgorithm >::
106 _UpdateOutputValue( TNode& n )
107 {
108   this->Superclass::_UpdateOutputValue( n );
109   this->GetOutput( )->SetPixel( n.Vertex, n.Value );
110 }
111
112 // -------------------------------------------------------------------------
113 template< class _TBaseAlgorithm >
114 unsigned long fpa::Filters::Image::Algorithm< _TBaseAlgorithm >::
115 _GetMark( const TVertex& v ) const
116 {
117   return( ( unsigned long )( this->GetMarks( )->GetPixel( v ) ) );
118 }
119
120 // -------------------------------------------------------------------------
121 template< class _TBaseAlgorithm >
122 bool fpa::Filters::Image::Algorithm< _TBaseAlgorithm >::
123 _IsMarked( const TVertex& v ) const
124 {
125   return( this->GetMarks( )->GetPixel( v ) != TMark( 0 ) );
126 }
127
128 // -------------------------------------------------------------------------
129 template< class _TBaseAlgorithm >
130 void fpa::Filters::Image::Algorithm< _TBaseAlgorithm >::
131 _Mark( const TVertex& v, unsigned long m )
132 {
133   this->GetMarks( )->SetPixel( v, TMark( m ) );
134 }
135
136 #endif // __fpa__Filters__Image__Algorithm__hxx__
137 // eof - $RCSfile$