1 #ifndef __FPA__IMAGE__ALGORITHM__HXX__
2 #define __FPA__IMAGE__ALGORITHM__HXX__
5 #include <itkConstNeighborhoodIterator.h>
7 // -------------------------------------------------------------------------
8 template< class I, class O, class A >
9 fpa::Image::Algorithm< I, O, A >::
12 m_NeighborhoodOrder( 1 )
16 // -------------------------------------------------------------------------
17 template< class I, class O, class A >
18 fpa::Image::Algorithm< I, O, A >::
23 // -------------------------------------------------------------------------
24 template< class I, class O, class A >
25 void fpa::Image::Algorithm< I, O, A >::
26 _BeforeGenerateData( )
28 this->Superclass::_BeforeGenerateData( );
29 this->AllocateOutputs( );
32 // -------------------------------------------------------------------------
33 template< class I, class O, class A >
34 unsigned long fpa::Image::Algorithm< I, O, A >::
35 _NumberOfVertices( ) const
37 return( this->GetInput( )->GetRequestedRegion( ).GetNumberOfPixels( ) );
40 // -------------------------------------------------------------------------
41 template< class I, class O, class A >
42 const typename fpa::Image::Algorithm< I, O, A >::
43 TValue& fpa::Image::Algorithm< I, O, A >::
44 _VertexValue( const TVertex& v ) const
46 return( this->GetInput( )->GetPixel( v ) );
49 // -------------------------------------------------------------------------
50 template< class I, class O, class A >
51 double fpa::Image::Algorithm< I, O, A >::
52 _Distance( const TVertex& a, const TVertex& b ) const
54 typename I::PointType pa, pb;
55 this->GetInput( )->TransformIndexToPhysicalPoint( a, pa );
56 this->GetInput( )->TransformIndexToPhysicalPoint( b, pb );
57 return( double( pa.EuclideanDistanceTo( pb ) ) );
60 // -------------------------------------------------------------------------
61 template< class I, class O, class A >
62 bool fpa::Image::Algorithm< I, O, A >::
63 _HasEdge( const TVertex& a, const TVertex& b ) const
65 unsigned long dist = 0;
66 for( unsigned int d = 0; d < I::ImageDimension; d++ )
67 dist += std::abs( long( a[ d ] ) - long( b[ d ] ) );
68 if( this->m_NeighborhoodOrder == 1 )
71 return( dist <= I::ImageDimension );
74 // -------------------------------------------------------------------------
75 template< class I, class O, class A >
76 void fpa::Image::Algorithm< I, O, A >::
77 _Neighborhood( _TVertices& neighborhood, const TVertex& v ) const
79 typename I::RegionType reg = this->GetInput( )->GetRequestedRegion( );
81 neighborhood.clear( );
82 if( this->m_NeighborhoodOrder == 1 )
84 for( unsigned int d = 0; d < I::ImageDimension; d++ )
86 for( int i = -1; i <= 1; i += 2 )
90 if( reg.IsInside( n ) )
91 neighborhood.push_back( n );
99 typedef itk::ConstNeighborhoodIterator< I > TNeighIt;
100 typename I::SizeType nSize;
103 TNeighIt nIt( nSize, this->GetInput( ), reg );
104 nIt.SetLocation( v );
105 for( unsigned int i = 0; i < nIt.Size( ); i++ )
107 TVertex n = nIt.GetIndex( i );
110 if( reg.IsInside( n ) )
111 neighborhood.push_back( n );
118 // -------------------------------------------------------------------------
119 template< class I, class O, class A >
120 void fpa::Image::Algorithm< I, O, A >::
125 // -------------------------------------------------------------------------
126 template< class I, class O, class A >
127 const typename fpa::Image::Algorithm< I, O, A >::
128 TResult& fpa::Image::Algorithm< I, O, A >::
129 _Result( const TVertex& v ) const
131 return( this->GetOutput( )->GetPixel( v ) );
134 // -------------------------------------------------------------------------
135 template< class I, class O, class A >
136 void fpa::Image::Algorithm< I, O, A >::
137 _SetResult( const TVertex& v, const TResult& r )
139 this->GetOutput( )->SetPixel( v, r );
142 // -------------------------------------------------------------------------
143 template< class I, class O, class A >
144 const typename fpa::Image::Algorithm< I, O, A >::
145 _TNode& fpa::Image::Algorithm< I, O, A >::
146 _Node( const TVertex& v ) const
148 return( this->m_Marks->GetPixel( v ) );
151 // -------------------------------------------------------------------------
152 template< class I, class O, class A >
153 void fpa::Image::Algorithm< I, O, A >::
156 const I* in = this->GetInput( );
158 this->m_Marks = _TMarks::New( );
159 this->m_Marks->SetLargestPossibleRegion( in->GetLargestPossibleRegion( ) );
160 this->m_Marks->SetRequestedRegion( in->GetRequestedRegion( ) );
161 this->m_Marks->SetBufferedRegion( in->GetBufferedRegion( ) );
162 this->m_Marks->SetOrigin( in->GetOrigin( ) );
163 this->m_Marks->SetSpacing( in->GetSpacing( ) );
164 this->m_Marks->SetDirection( in->GetDirection( ) );
165 this->m_Marks->Allocate( );
168 far_node.Label = Self::FarLabel;
169 this->m_Marks->FillBuffer( far_node );
172 // -------------------------------------------------------------------------
173 template< class I, class O, class A >
174 void fpa::Image::Algorithm< I, O, A >::
175 _Mark( const _TNode& node )
177 this->m_Marks->SetPixel( node.Vertex, node );
180 #endif // __FPA__IMAGE__ALGORITHM__HXX__