]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Image/Functors/SimpleNeighborhood.hxx
...
[FrontAlgorithms.git] / lib / fpa / Image / Functors / SimpleNeighborhood.hxx
1 #ifndef __fpa__Image__Functors__SimpleNeighborhood__hxx__
2 #define __fpa__Image__Functors__SimpleNeighborhood__hxx__
3
4 // -------------------------------------------------------------------------
5 template< unsigned int _VDim >
6 typename fpa::Image::Functors::SimpleNeighborhood< _VDim >::
7 TOutput fpa::Image::Functors::SimpleNeighborhood< _VDim >::
8 Evaluate( const TIndex& center ) const
9 {
10   if( this->m_Offsets.size( ) == 0 )
11   {
12     if( this->m_Order == 1 )
13       this->_1stCombination( );
14     else
15       this->_2ndCombination( );
16
17   } // fi
18
19   TOutput res;
20   typename TImage::RegionType reg = this->m_Image->GetRequestedRegion( );
21   for( int i = 0; i < this->m_Offsets.size( ); ++i )
22   {
23     TIndex idx = center + this->m_Offsets[ i ];
24     if( reg.IsInside( idx ) && idx != center )
25       res.push_back( idx );
26
27   } // rof
28   return( res );
29 }
30
31 // -------------------------------------------------------------------------
32 template< unsigned int _VDim >
33 fpa::Image::Functors::SimpleNeighborhood< _VDim >::
34 SimpleNeighborhood( )
35   : Superclass( ),
36     m_Order( 1 )
37 {
38 }
39
40 // -------------------------------------------------------------------------
41 template< unsigned int _VDim >
42  fpa::Image::Functors::SimpleNeighborhood< _VDim >::
43 ~SimpleNeighborhood( )
44 {
45 }
46
47 // -------------------------------------------------------------------------
48 template< unsigned int _VDim >
49 void fpa::Image::Functors::SimpleNeighborhood< _VDim >::
50 _1stCombination( ) const
51 {
52   for( int d = 0; d < TImage::ImageDimension; ++d )
53   {
54     typename TIndex::OffsetType off;
55     off.Fill( 0 );
56     for( int i = -1; i <= 1; i += 2 )
57     {
58       off[ d ] = i;
59       this->m_Offsets.push_back( off );
60
61     } // rof
62
63   } // rof
64 }
65
66 // -------------------------------------------------------------------------
67 template< unsigned int _VDim >
68 void fpa::Image::Functors::SimpleNeighborhood< _VDim >::
69 _2ndCombination( ) const
70 {
71   std::vector< std::vector< std::vector< int > > > M;
72   M.push_back( std::vector< std::vector< int > >( ) );
73
74   std::vector< int > base;
75   base.push_back( -1 );
76   base.push_back(  0 );
77   base.push_back(  1 );
78   int dim = TImage::ImageDimension;
79
80   M.push_back( std::vector< std::vector< int > >( ) );
81   for( int j = 0; j < base.size( ); ++j )
82     M[ 1 ].push_back( std::vector< int >( 1, base[ j ] ) );
83
84   for( int i = 2; i <= dim; ++i )
85   {
86     M.push_back( std::vector< std::vector< int > >( ) );
87     for( int j = 0; j < base.size( ); ++j )
88     {
89       for( int k = 0; k < M[ i - 1 ].size( ); ++k )
90       {
91         M[ i ].push_back( std::vector< int >( 1, base[ j ] ) );
92         for( int l = 0; l < M[ i - 1 ][ k ].size( ); ++l )
93           M[ i ].back( ).push_back( M[ i - 1 ][ k ][ l ] );
94
95       } // rof
96
97     } // rof
98
99   } // rof
100
101   for( int i = 0; i < M[ dim ].size( ); ++i )
102   {
103     TOffset off;
104     for( int j = 0; j < M[ dim ][ i ].size( ); ++j )
105       off[ j ] = M[ dim ][ i ][ j ];
106     this->m_Offsets.push_back( off );
107
108   } // rof
109 }
110
111 #endif // __fpa__Image__Functors__SimpleNeighborhood__hxx__
112
113 // eof - $RCSfile$