1 #ifndef __FPA__IMAGE__ALGORITHM__HXX__
2 #define __FPA__IMAGE__ALGORITHM__HXX__
6 #include <itkConstNeighborhoodIterator.h>
8 // -------------------------------------------------------------------------
9 template< class I, class A, class CC >
10 fpa::Image::Algorithm< I, A, CC >::
13 m_NeighborhoodOrder( 1 )
15 this->m_CostConversion = TCostConversionFunction::New( );
18 // -------------------------------------------------------------------------
19 template< class I, class A, class CC >
20 fpa::Image::Algorithm< I, A, CC >::
25 // -------------------------------------------------------------------------
26 template< class I, class A, class CC >
27 bool fpa::Image::Algorithm< I, A, CC >::
28 _UpdateResult( _TNode& n )
30 bool ret = this->Superclass::_UpdateResult( n );
31 this->GetOutput( )->SetPixel( n.Vertex, n.Result );
35 // -------------------------------------------------------------------------
36 template< class I, class A, class CC >
37 unsigned long fpa::Image::Algorithm< I, A, CC >::
38 _NumberOfVertices( ) const
41 this->GetInput( )->GetLargestPossibleRegion( ).GetNumberOfPixels( )
45 // -------------------------------------------------------------------------
46 template< class I, class A, class CC >
47 typename fpa::Image::Algorithm< I, A, CC >::
48 TVertexValue fpa::Image::Algorithm< I, A, CC >::
49 _Value( const TVertex& v ) const
51 return( this->GetInput( )->GetPixel( v ) );
54 // -------------------------------------------------------------------------
55 template< class I, class A, class CC >
56 typename fpa::Image::Algorithm< I, A, CC >::
57 TResult fpa::Image::Algorithm< I, A, CC >::
58 _Result( const TVertex& v ) const
60 return( this->GetOutput( )->GetPixel( v ) );
63 // -------------------------------------------------------------------------
64 template< class I, class A, class CC >
65 double fpa::Image::Algorithm< I, A, CC >::
66 _Norm( const TVertex& a, const TVertex& b ) const
68 typename I::PointType pa, pb;
69 this->GetInput( )->TransformIndexToPhysicalPoint( a, pa );
70 this->GetInput( )->TransformIndexToPhysicalPoint( b, pb );
71 return( double( pa.EuclideanDistanceTo( pb ) ) );
74 // -------------------------------------------------------------------------
75 template< class I, class A, class CC >
76 bool fpa::Image::Algorithm< I, A, CC >::
77 _Edge( const TVertex& a, const TVertex& b ) const
79 unsigned long dist = 0;
80 for( unsigned int d = 0; d < I::ImageDimension; d++ )
81 dist += std::abs( long( a[ d ] ) - long( b[ d ] ) );
82 if( this->m_NeighborhoodOrder == 1 )
85 return( dist <= I::ImageDimension );
88 // -------------------------------------------------------------------------
89 template< class I, class A, class CC >
90 typename fpa::Image::Algorithm< I, A, CC >::
91 TCost fpa::Image::Algorithm< I, A, CC >::
92 _Cost( const TVertex& a, const TVertex& b ) const
94 static const TCost INF_COST = std::numeric_limits< TCost >::max( );
95 if( this->_Edge( a, b ) )
98 this->m_CostConversion->Evaluate( this->GetInput( )->GetPixel( b ) )
105 // -------------------------------------------------------------------------
106 template< class I, class A, class CC >
107 void fpa::Image::Algorithm< I, A, CC >::
108 _Neighs( const _TNode& n, _TNodes& N ) const
110 typename I::RegionType reg = this->GetInput( )->GetRequestedRegion( );
113 if( this->m_NeighborhoodOrder == 1 )
115 for( unsigned int d = 0; d < I::ImageDimension; d++ )
117 for( int i = -1; i <= 1; i += 2 )
119 TVertex v = n.Vertex;
121 if( reg.IsInside( v ) )
122 N.push_back( _TNode( v, n.FrontId ) );
132 typedef itk::ConstNeighborhoodIterator< I > TNeighIt;
133 typename I::SizeType nSize;
136 TNeighIt nIt( nSize, this->GetInput( ), reg );
137 nIt.SetLocation( n.Vertex );
138 for( unsigned int i = 0; i < nIt.Size( ); i++ )
140 TVertex idxN = nIt.GetIndex( i );
141 if( idxN == n.Vertex )
143 if( !reg.IsInside( idxN ) )
145 N.push_back( _TNode( idxN, n.FrontId ) );
152 // -------------------------------------------------------------------------
153 template< class I, class A, class CC >
154 void fpa::Image::Algorithm< I, A, CC >::
155 _NeighsInDim( const _TNode& n, const unsigned int& d, _TNodes& N )
157 typename I::RegionType reg = this->GetInput( )->GetRequestedRegion( );
160 for( int i = -1; i <= 1; i += 2 )
162 TVertex v = n.Vertex;
164 if( reg.IsInside( v ) )
165 N.push_back( _TNode( v, n.FrontId ) );
170 // -------------------------------------------------------------------------
171 template< class I, class A, class CC >
172 void fpa::Image::Algorithm< I, A, CC >::
173 _InitializeResults( )
177 #endif // __FPA__IMAGE__ALGORITHM__HXX__