From: Leonardo Florez-Valencia Date: Tue, 18 Oct 2016 04:21:10 +0000 (-0500) Subject: ... X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=a7f37699808cd8cd56110607b03b84288628a690;p=FrontAlgorithms.git ... --- diff --git a/appli/examples/ImageDijkstra.cxx b/appli/examples/ImageDijkstra.cxx index 1b56263..2dede62 100644 --- a/appli/examples/ImageDijkstra.cxx +++ b/appli/examples/ImageDijkstra.cxx @@ -16,7 +16,7 @@ typedef itk::Image< TScalar, VDim > TOutputImage; typedef itk::RandomImageSource< TInputImage > TImageSource; typedef itk::ImageFileWriter< TOutputImage > TImageWriter; -typedef fpa::Image::Functors::SimpleNeighborhood< TInputImage > TNeighFunction; +typedef fpa::Image::Functors::SimpleNeighborhood< itk::ImageBase< VDim > > TNeighFunction; typedef fpa::Image::Functors::SimpleDijkstraCost< TInputImage, TScalar > TCostFunction; typedef fpa::Base::Functors::Inverse< TScalar, TScalar > TCostConversionFunction; @@ -28,7 +28,7 @@ int main( int argc, char* argv[] ) static const unsigned long SIZE = 100; unsigned long size[] = { SIZE, SIZE }; - unsigned int neigh_order = 1; + unsigned int neigh_order = 2; TInputImage::IndexType seed0, seed1; seed0.Fill( 0 ); diff --git a/lib/fpa/Image/Functors/SimpleNeighborhood.h b/lib/fpa/Image/Functors/SimpleNeighborhood.h index 3074599..1fd8547 100644 --- a/lib/fpa/Image/Functors/SimpleNeighborhood.h +++ b/lib/fpa/Image/Functors/SimpleNeighborhood.h @@ -20,6 +20,7 @@ namespace fpa public: typedef _TImage TImage; typedef typename TImage::IndexType TIndex; + typedef typename TIndex::OffsetType TOffset; typedef std::vector< TIndex > TOutput; typedef itk::FunctionBase< TIndex, TOutput > TBaseFunctor; typedef fpa::Image::Functors::Base< TImage, TBaseFunctor > Superclass; @@ -41,6 +42,9 @@ namespace fpa SimpleNeighborhood( ); virtual ~SimpleNeighborhood( ); + void _1stCombination( ) const; + void _2ndCombination( ) const; + private: // Purposely not implemented SimpleNeighborhood( const Self& other ); @@ -48,6 +52,7 @@ namespace fpa protected: unsigned int m_Order; + mutable std::vector< TOffset > m_Offsets; }; } // ecapseman diff --git a/lib/fpa/Image/Functors/SimpleNeighborhood.hxx b/lib/fpa/Image/Functors/SimpleNeighborhood.hxx index ce5fcc5..a09dab8 100644 --- a/lib/fpa/Image/Functors/SimpleNeighborhood.hxx +++ b/lib/fpa/Image/Functors/SimpleNeighborhood.hxx @@ -7,28 +7,24 @@ typename fpa::Image::Functors::SimpleNeighborhood< _TImage >:: TOutput fpa::Image::Functors::SimpleNeighborhood< _TImage >:: Evaluate( const TIndex& center ) const { - TOutput res; - typename _TImage::RegionType reg = this->m_Image->GetRequestedRegion( ); - if( this->m_Order == 1 ) + if( this->m_Offsets.size( ) == 0 ) { - for( unsigned int d = 0; d < _TImage::ImageDimension; ++d ) - { - for( int o = -1; o <= 1; o += 2 ) - { - TIndex idx = center; - idx[ d ] += o; - if( reg.IsInside( idx ) ) - res.push_back( idx ); + if( this->m_Order == 1 ) + this->_1stCombination( ); + else + this->_2ndCombination( ); - } // rof + } // fi - } // rof - } - else + TOutput res; + typename _TImage::RegionType reg = this->m_Image->GetRequestedRegion( ); + for( int i = 0; i < this->m_Offsets.size( ); ++i ) { - // TODO!!! + TIndex idx = center + this->m_Offsets[ i ]; + if( reg.IsInside( idx ) && idx != center ) + res.push_back( idx ); - } // fi + } // rof return( res ); } @@ -48,6 +44,70 @@ template< class _TImage > { } +// ------------------------------------------------------------------------- +template< class _TImage > +void fpa::Image::Functors::SimpleNeighborhood< _TImage >:: +_1stCombination( ) const +{ + for( int d = 0; d < _TImage::ImageDimension; ++d ) + { + typename TIndex::OffsetType off; + off.Fill( 0 ); + for( int i = -1; i <= 1; i += 2 ) + { + off[ d ] = i; + this->m_Offsets.push_back( off ); + + } // rof + + } // rof +} + +// ------------------------------------------------------------------------- +template< class _TImage > +void fpa::Image::Functors::SimpleNeighborhood< _TImage >:: +_2ndCombination( ) const +{ + std::vector< std::vector< std::vector< int > > > M; + M.push_back( std::vector< std::vector< int > >( ) ); + + std::vector< int > base; + base.push_back( -1 ); + base.push_back( 0 ); + base.push_back( 1 ); + int dim = _TImage::ImageDimension; + + M.push_back( std::vector< std::vector< int > >( ) ); + for( int j = 0; j < base.size( ); ++j ) + M[ 1 ].push_back( std::vector< int >( 1, base[ j ] ) ); + + for( int i = 2; i <= dim; ++i ) + { + M.push_back( std::vector< std::vector< int > >( ) ); + for( int j = 0; j < base.size( ); ++j ) + { + for( int k = 0; k < M[ i - 1 ].size( ); ++k ) + { + M[ i ].push_back( std::vector< int >( 1, base[ j ] ) ); + for( int l = 0; l < M[ i - 1 ][ k ].size( ); ++l ) + M[ i ].back( ).push_back( M[ i - 1 ][ k ][ l ] ); + + } // rof + + } // rof + + } // rof + + for( int i = 0; i < M[ dim ].size( ); ++i ) + { + TOffset off; + for( int j = 0; j < M[ dim ][ i ].size( ); ++j ) + off[ j ] = M[ dim ][ i ][ j ]; + this->m_Offsets.push_back( off ); + + } // rof +} + #endif // __fpa__Image__Functors__SimpleNeighborhood__hxx__ // eof - $RCSfile$