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;
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 );
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;
SimpleNeighborhood( );
virtual ~SimpleNeighborhood( );
+ void _1stCombination( ) const;
+ void _2ndCombination( ) const;
+
private:
// Purposely not implemented
SimpleNeighborhood( const Self& other );
protected:
unsigned int m_Order;
+ mutable std::vector< TOffset > m_Offsets;
};
} // ecapseman
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 );
}
{
}
+// -------------------------------------------------------------------------
+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$