]> Creatis software - FrontAlgorithms.git/commitdiff
...
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Tue, 18 Oct 2016 04:21:10 +0000 (23:21 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Tue, 18 Oct 2016 04:21:10 +0000 (23:21 -0500)
appli/examples/ImageDijkstra.cxx
lib/fpa/Image/Functors/SimpleNeighborhood.h
lib/fpa/Image/Functors/SimpleNeighborhood.hxx

index 1b562636724ce0376872875cf8a07021f5683610..2dede622dd4b7f3b2d26aa18755ba8d1ce0ceab7 100644 (file)
@@ -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 );
index 30745990c7c9d7ab0802db8f17c25cdbbc28df6f..1fd854757003c21efe03231c5d230429c2785b1d 100644 (file)
@@ -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
index ce5fcc5c5ca7ce6957e34c3600bc1d5d3bff9697..a09dab8a130f9cc1c1b2fd9dbf8cde142f368bd7 100644 (file)
@@ -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$