1 #ifndef __FPA__IMAGE__ALGORITHM__HXX__
2 #define __FPA__IMAGE__ALGORITHM__HXX__
6 #include <itkConstNeighborhoodIterator.h>
8 // -------------------------------------------------------------------------
9 template< class I, class A >
10 fpa::Image::Algorithm< I, A >::
13 m_NeighborhoodOrder( 1 )
17 // -------------------------------------------------------------------------
18 template< class I, class A >
19 fpa::Image::Algorithm< I, A >::
24 // -------------------------------------------------------------------------
25 template< class I, class A >
26 bool fpa::Image::Algorithm< I, A >::
27 _UpdateResult( _TNode& n )
29 bool ret = this->Superclass::_UpdateResult( n );
30 this->GetOutput( )->SetPixel( n.Vertex, n.Result );
34 // -------------------------------------------------------------------------
35 template< class I, class A >
36 unsigned long fpa::Image::Algorithm< I, A >::
37 _NumberOfVertices( ) const
40 this->GetInput( )->GetLargestPossibleRegion( ).GetNumberOfPixels( )
44 // -------------------------------------------------------------------------
45 template< class I, class A >
46 typename fpa::Image::Algorithm< I, A >::
47 TVertexValue fpa::Image::Algorithm< I, A >::
48 _Value( const TVertex& v ) const
50 return( this->GetInput( )->GetPixel( v ) );
53 // -------------------------------------------------------------------------
54 template< class I, class A >
55 typename fpa::Image::Algorithm< I, A >::
56 TResult fpa::Image::Algorithm< I, A >::
57 _Result( const TVertex& v ) const
59 return( this->GetOutput( )->GetPixel( v ) );
62 // -------------------------------------------------------------------------
63 template< class I, class A >
64 double fpa::Image::Algorithm< I, A >::
65 _Norm( const TVertex& a, const TVertex& b ) const
67 typename I::PointType pa, pb;
68 this->GetInput( )->TransformIndexToPhysicalPoint( a, pa );
69 this->GetInput( )->TransformIndexToPhysicalPoint( b, pb );
70 return( double( pa.EuclideanDistanceTo( pb ) ) );
73 // -------------------------------------------------------------------------
74 template< class I, class A >
75 bool fpa::Image::Algorithm< I, A >::
76 _Edge( const TVertex& a, const TVertex& b ) const
78 unsigned long dist = 0;
79 for( unsigned int d = 0; d < I::ImageDimension; d++ )
80 dist += std::abs( long( a[ d ] ) - long( b[ d ] ) );
81 if( this->m_NeighborhoodOrder == 1 )
82 return( dist == 0 || dist == 1 );
84 return( dist == 0 || dist == 1 || dist == 2 );
87 // -------------------------------------------------------------------------
88 template< class I, class A >
89 typename fpa::Image::Algorithm< I, A >::
90 TCost fpa::Image::Algorithm< I, A >::
91 _Cost( const TVertex& a, const TVertex& b ) const
93 static const TCost INF_COST = std::numeric_limits< TCost >::max( );
94 if( this->_Edge( a, b ) )
96 TCost c = TCost( this->GetInput( )->GetPixel( b ) );
97 if( this->m_CostConversion.IsNotNull( ) )
98 return( this->m_CostConversion->Evaluate( c ) );
106 // -------------------------------------------------------------------------
107 template< class I, class A >
108 void fpa::Image::Algorithm< I, A >::
109 _Neighs( const _TNode& n, _TNodes& N ) const
111 typename I::RegionType reg = this->GetInput( )->GetRequestedRegion( );
114 if( this->m_NeighborhoodOrder == 1 )
116 for( unsigned int d = 0; d < I::ImageDimension; d++ )
118 for( int i = -1; i <= 1; i += 2 )
120 TVertex v = n.Vertex;
122 if( reg.IsInside( v ) )
123 N.push_back( _TNode( v, n.FrontId ) );
133 typedef itk::ConstNeighborhoodIterator< I > TNeighIt;
134 typename I::SizeType nSize;
137 TNeighIt nIt( nSize, this->GetInput( ), reg );
138 nIt.SetLocation( n.Vertex );
139 for( unsigned int i = 0; i < nIt.Size( ); i++ )
141 TVertex idxN = nIt.GetIndex( i );
142 if( idxN == n.Vertex )
144 if( !reg.IsInside( idxN ) )
146 N.push_back( _TNode( idxN, n.FrontId ) );
153 // -------------------------------------------------------------------------
154 template< class I, class A >
155 void fpa::Image::Algorithm< I, A >::
156 _NeighsInDim( const _TNode& n, const unsigned int& d, _TNodes& N )
158 typename I::RegionType reg = this->GetInput( )->GetRequestedRegion( );
161 for( int i = -1; i <= 1; i += 2 )
163 TVertex v = n.Vertex;
165 if( reg.IsInside( v ) )
166 N.push_back( _TNode( v, n.FrontId ) );
171 // -------------------------------------------------------------------------
172 template< class I, class A >
173 void fpa::Image::Algorithm< I, A >::
174 _InitializeResults( )
178 #endif // __FPA__IMAGE__ALGORITHM__HXX__