X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2Ffpa%2FFilters%2FImage%2FAlgorithm.hxx;fp=lib%2Ffpa%2FFilters%2FImage%2FAlgorithm.hxx;h=5095992770ae9b394999764a0ff8b113e1b7dd63;hb=2047276c8f1a02432fbcc7014722d460d6c1e60f;hp=0000000000000000000000000000000000000000;hpb=3c639e5da479c7216a0a302ffa156ac6762caeed;p=FrontAlgorithms.git diff --git a/lib/fpa/Filters/Image/Algorithm.hxx b/lib/fpa/Filters/Image/Algorithm.hxx new file mode 100644 index 0000000..5095992 --- /dev/null +++ b/lib/fpa/Filters/Image/Algorithm.hxx @@ -0,0 +1,137 @@ +// ========================================================================= +// @author Leonardo Florez Valencia +// @email florez-l@javeriana.edu.co +// ========================================================================= +#ifndef __fpa__Filters__Image__Algorithm__hxx__ +#define __fpa__Filters__Image__Algorithm__hxx__ + +// ------------------------------------------------------------------------- +template< class _TBaseAlgorithm > +fpa::Filters::Image::Algorithm< _TBaseAlgorithm >:: +Algorithm( ) + : Superclass( ), + m_NeighborhoodOrder( 1 ) +{ + fpaFilterOutputConfigureMacro( Marks, TMarksImage ); +} + +// ------------------------------------------------------------------------- +template< class _TBaseAlgorithm > +fpa::Filters::Image::Algorithm< _TBaseAlgorithm >:: +~Algorithm( ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TBaseAlgorithm > +void fpa::Filters::Image::Algorithm< _TBaseAlgorithm >:: +_ConfigureOutputs( ) +{ + const TInputImage* in = this->GetInput( ); + + TOutputImage* out = this->GetOutput( ); + out->SetLargestPossibleRegion( in->GetLargestPossibleRegion( ) ); + out->SetRequestedRegion( in->GetRequestedRegion( ) ); + out->SetBufferedRegion( in->GetBufferedRegion( ) ); + out->SetSpacing( in->GetSpacing( ) ); + out->SetOrigin( in->GetOrigin( ) ); + out->SetDirection( in->GetDirection( ) ); + out->Allocate( ); + out->FillBuffer( this->GetInitValue( ) ); + + TMarksImage* marks = this->GetMarks( ); + marks->SetLargestPossibleRegion( in->GetLargestPossibleRegion( ) ); + marks->SetRequestedRegion( in->GetRequestedRegion( ) ); + marks->SetBufferedRegion( in->GetBufferedRegion( ) ); + marks->SetSpacing( in->GetSpacing( ) ); + marks->SetOrigin( in->GetOrigin( ) ); + marks->SetDirection( in->GetDirection( ) ); + marks->Allocate( ); + marks->FillBuffer( TMark( 0 ) ); +} + +// ------------------------------------------------------------------------- +template< class _TBaseAlgorithm > +typename fpa::Filters::Image::Algorithm< _TBaseAlgorithm >:: +TInputValue fpa::Filters::Image::Algorithm< _TBaseAlgorithm >:: +_GetInputValue( const TVertex& v ) const +{ + return( this->GetInput( )->GetPixel( v ) ); +} + +// ------------------------------------------------------------------------- +template< class _TBaseAlgorithm > +typename fpa::Filters::Image::Algorithm< _TBaseAlgorithm >:: +TOutputValue fpa::Filters::Image::Algorithm< _TBaseAlgorithm >:: +_GetOutputValue( const TVertex& v ) const +{ + return( this->GetOutput( )->GetPixel( v ) ); +} + +// ------------------------------------------------------------------------- +template< class _TBaseAlgorithm > +typename fpa::Filters::Image::Algorithm< _TBaseAlgorithm >:: +TNeighborhood fpa::Filters::Image::Algorithm< _TBaseAlgorithm >:: +_GetNeighbors( const TVertex& v ) const +{ + typename TInputImage::RegionType region = + this->GetInput( )->GetRequestedRegion( ); + TNeighborhood neighborhood; + if( this->m_NeighborhoodOrder == 1 ) + { + for( unsigned int d = 0; d < Self::Dimension; ++d ) + { + for( int s = -1; s <= 1; s += 2 ) + { + TVertex n = v; + n[ d ] += s; + if( region.IsInside( n ) ) + neighborhood.push_back( n ); + + } // rof + + } // rof + } + else if( this->m_NeighborhoodOrder == 2 ) + { + // TODO + + } // fi + return( neighborhood ); +} + +// ------------------------------------------------------------------------- +template< class _TBaseAlgorithm > +void fpa::Filters::Image::Algorithm< _TBaseAlgorithm >:: +_UpdateOutputValue( TNode& n ) +{ + this->Superclass::_UpdateOutputValue( n ); + this->GetOutput( )->SetPixel( n.Vertex, n.Value ); +} + +// ------------------------------------------------------------------------- +template< class _TBaseAlgorithm > +unsigned long fpa::Filters::Image::Algorithm< _TBaseAlgorithm >:: +_GetMark( const TVertex& v ) const +{ + return( ( unsigned long )( this->GetMarks( )->GetPixel( v ) ) ); +} + +// ------------------------------------------------------------------------- +template< class _TBaseAlgorithm > +bool fpa::Filters::Image::Algorithm< _TBaseAlgorithm >:: +_IsMarked( const TVertex& v ) const +{ + return( this->GetMarks( )->GetPixel( v ) != TMark( 0 ) ); +} + +// ------------------------------------------------------------------------- +template< class _TBaseAlgorithm > +void fpa::Filters::Image::Algorithm< _TBaseAlgorithm >:: +_Mark( const TVertex& v, unsigned long m ) +{ + this->GetMarks( )->SetPixel( v, TMark( m ) ); +} + +#endif // __fpa__Filters__Image__Algorithm__hxx__ +// eof - $RCSfile$