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 _TNode& n )
139 this->Superclass::_SetResult( v, n );
140 this->GetOutput( )->SetPixel( v, n.Result );
143 #endif // __FPA__IMAGE__ALGORITHM__HXX__