X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2Ffpa%2FImage%2FAlgorithm.hxx;h=5e8605dcdd04f117c077169a3852a457f5e87945;hb=6468f1fda5fed2788fbaef1a7925c91ecff83d13;hp=4a57bddef02b9f60eb44d604c3f4a14cc74d4478;hpb=d3bb16bf060b7249a9ed1a49e6b118ca9394a22a;p=FrontAlgorithms.git diff --git a/lib/fpa/Image/Algorithm.hxx b/lib/fpa/Image/Algorithm.hxx index 4a57bdd..5e8605d 100644 --- a/lib/fpa/Image/Algorithm.hxx +++ b/lib/fpa/Image/Algorithm.hxx @@ -2,68 +2,63 @@ #define __FPA__IMAGE__ALGORITHM__HXX__ #include -#include #include // ------------------------------------------------------------------------- -template< class I, class A, class CC > -fpa::Image::Algorithm< I, A, CC >:: +template< class I, class O, class A > +fpa::Image::Algorithm< I, O, A >:: Algorithm( ) : Superclass( ), m_NeighborhoodOrder( 1 ) { - this->m_CostConversion = TCostConversionFunction::New( ); } // ------------------------------------------------------------------------- -template< class I, class A, class CC > -fpa::Image::Algorithm< I, A, CC >:: +template< class I, class O, class A > +fpa::Image::Algorithm< I, O, A >:: ~Algorithm( ) { } // ------------------------------------------------------------------------- -template< class I, class A, class CC > -bool fpa::Image::Algorithm< I, A, CC >:: -_UpdateResult( _TNode& n ) +template< class I, class O, class A > +void fpa::Image::Algorithm< I, O, A >:: +_BeforeGenerateData( ) { - bool ret = this->Superclass::_UpdateResult( n ); - this->GetOutput( )->SetPixel( n.Vertex, n.Result ); - return( ret ); + this->Superclass::_BeforeGenerateData( ); + this->AllocateOutputs( ); } // ------------------------------------------------------------------------- -template< class I, class A, class CC > -unsigned long fpa::Image::Algorithm< I, A, CC >:: -_NumberOfVertices( ) const +template< class I, class O, class A > +void fpa::Image::Algorithm< I, O, A >:: +_AfterGenerateData( ) { - return( - this->GetInput( )->GetLargestPossibleRegion( ).GetNumberOfPixels( ) - ); + this->Superclass::_AfterGenerateData( ); + this->GetMinimumSpanningTree( )->SetCollisions( this->m_Collisions ); } // ------------------------------------------------------------------------- -template< class I, class A, class CC > -typename fpa::Image::Algorithm< I, A, CC >:: -TVertexValue fpa::Image::Algorithm< I, A, CC >:: -_Value( const TVertex& v ) const +template< class I, class O, class A > +unsigned long fpa::Image::Algorithm< I, O, A >:: +_NumberOfVertices( ) const { - return( this->GetInput( )->GetPixel( v ) ); + return( this->GetInput( )->GetRequestedRegion( ).GetNumberOfPixels( ) ); } // ------------------------------------------------------------------------- -template< class I, class A, class CC > -typename fpa::Image::Algorithm< I, A, CC >:: -TResult fpa::Image::Algorithm< I, A, CC >:: -_Result( const TVertex& v ) const +template< class I, class O, class A > +const typename fpa::Image::Algorithm< I, O, A >:: +TValue& fpa::Image::Algorithm< I, O, A >:: +_VertexValue( const TVertex& v ) const { - return( this->GetOutput( )->GetPixel( v ) ); + return( this->GetInput( )->GetPixel( v ) ); } // ------------------------------------------------------------------------- -template< class I, class A, class CC > -double fpa::Image::Algorithm< I, A, CC >:: -_Norm( const TVertex& a, const TVertex& b ) const +template< class I, class O, class A > +double fpa::Image::Algorithm< I, O, A >:: +_Distance( const TVertex& a, const TVertex& b ) const { typename I::PointType pa, pb; this->GetInput( )->TransformIndexToPhysicalPoint( a, pa ); @@ -72,9 +67,9 @@ _Norm( const TVertex& a, const TVertex& b ) const } // ------------------------------------------------------------------------- -template< class I, class A, class CC > -bool fpa::Image::Algorithm< I, A, CC >:: -_Edge( const TVertex& a, const TVertex& b ) const +template< class I, class O, class A > +bool fpa::Image::Algorithm< I, O, A >:: +_HasEdge( const TVertex& a, const TVertex& b ) const { unsigned long dist = 0; for( unsigned int d = 0; d < I::ImageDimension; d++ ) @@ -86,42 +81,23 @@ _Edge( const TVertex& a, const TVertex& b ) const } // ------------------------------------------------------------------------- -template< class I, class A, class CC > -typename fpa::Image::Algorithm< I, A, CC >:: -TCost fpa::Image::Algorithm< I, A, CC >:: -_Cost( const TVertex& a, const TVertex& b ) const -{ - static const TCost INF_COST = std::numeric_limits< TCost >::max( ); - if( this->_Edge( a, b ) ) - { - return( - this->m_CostConversion->Evaluate( this->GetInput( )->GetPixel( b ) ) - ); - } - else - return( INF_COST ); -} - -// ------------------------------------------------------------------------- -template< class I, class A, class CC > -void fpa::Image::Algorithm< I, A, CC >:: -_Neighs( const _TNode& n, _TNodes& N ) const +template< class I, class O, class A > +void fpa::Image::Algorithm< I, O, A >:: +_Neighborhood( _TVertices& neighborhood, const TVertex& v ) const { typename I::RegionType reg = this->GetInput( )->GetRequestedRegion( ); - N.clear( ); + neighborhood.clear( ); if( this->m_NeighborhoodOrder == 1 ) { for( unsigned int d = 0; d < I::ImageDimension; d++ ) { for( int i = -1; i <= 1; i += 2 ) { - TVertex v = n.Vertex; - v[ d ] += i; - if( reg.IsInside( v ) ) - N.push_back( _TNode( v, n.FrontId ) ); - else - N.push_back( n ); + TVertex n = v; + n[ d ] += i; + if( reg.IsInside( n ) ) + neighborhood.push_back( n ); } // rof @@ -134,15 +110,14 @@ _Neighs( const _TNode& n, _TNodes& N ) const nSize.Fill( 1 ); TNeighIt nIt( nSize, this->GetInput( ), reg ); - nIt.SetLocation( n.Vertex ); + nIt.SetLocation( v ); for( unsigned int i = 0; i < nIt.Size( ); i++ ) { - TVertex idxN = nIt.GetIndex( i ); - if( idxN == n.Vertex ) - continue; - if( !reg.IsInside( idxN ) ) + TVertex n = nIt.GetIndex( i ); + if( n == v ) continue; - N.push_back( _TNode( idxN, n.FrontId ) ); + if( reg.IsInside( n ) ) + neighborhood.push_back( n ); } // rof @@ -150,28 +125,28 @@ _Neighs( const _TNode& n, _TNodes& N ) const } // ------------------------------------------------------------------------- -template< class I, class A, class CC > -void fpa::Image::Algorithm< I, A, CC >:: -_NeighsInDim( const _TNode& n, const unsigned int& d, _TNodes& N ) +template< class I, class O, class A > +void fpa::Image::Algorithm< I, O, A >:: +_InitResults( ) { - typename I::RegionType reg = this->GetInput( )->GetRequestedRegion( ); - - N.clear( ); - for( int i = -1; i <= 1; i += 2 ) - { - TVertex v = n.Vertex; - v[ d ] += i; - if( reg.IsInside( v ) ) - N.push_back( _TNode( v, n.FrontId ) ); +} - } // rof +// ------------------------------------------------------------------------- +template< class I, class O, class A > +const typename fpa::Image::Algorithm< I, O, A >:: +TResult& fpa::Image::Algorithm< I, O, A >:: +_Result( const TVertex& v ) const +{ + return( this->GetOutput( )->GetPixel( v ) ); } // ------------------------------------------------------------------------- -template< class I, class A, class CC > -void fpa::Image::Algorithm< I, A, CC >:: -_InitializeResults( ) +template< class I, class O, class A > +void fpa::Image::Algorithm< I, O, A >:: +_SetResult( const TVertex& v, const _TNode& n ) { + this->GetOutput( )->SetPixel( v, n.Result ); + this->GetMinimumSpanningTree( )->SetParent( v, n.Parent, n.FrontId ); } #endif // __FPA__IMAGE__ALGORITHM__HXX__