]> Creatis software - FrontAlgorithms.git/blobdiff - lib/fpa/Image/Algorithm.hxx
Major refactoring
[FrontAlgorithms.git] / lib / fpa / Image / Algorithm.hxx
index 4a57bddef02b9f60eb44d604c3f4a14cc74d4478..0d83b035e6f821ccb52fe9d3bc0a843f0c72ebe7 100644 (file)
@@ -2,68 +2,54 @@
 #define __FPA__IMAGE__ALGORITHM__HXX__
 
 #include <cmath>
-#include <limits>
 #include <itkConstNeighborhoodIterator.h>
 
 // -------------------------------------------------------------------------
-template< class I, class A, class CC >
-fpa::Image::Algorithm< I, A, CC >::
+template< class I, class O, class A >
+fpa::Image::Algorithm< I, O, A >::
 Algorithm( )
   : Superclass( ),
     m_NeighborhoodOrder( 1 )
 {
-  this->m_CostConversion = TCostConversionFunction::New( );
 }
 
 // -------------------------------------------------------------------------
-template< class I, class A, class CC >
-fpa::Image::Algorithm< I, A, CC >::
+template< class I, class O, class A >
+fpa::Image::Algorithm< I, O, A >::
 ~Algorithm( )
 {
 }
 
 // -------------------------------------------------------------------------
-template< class I, class A, class CC >
-bool fpa::Image::Algorithm< I, A, CC >::
-_UpdateResult( _TNode& n )
+template< class I, class O, class A >
+void fpa::Image::Algorithm< I, O, A >::
+_BeforeGenerateData( )
 {
-  bool ret = this->Superclass::_UpdateResult( n );
-  this->GetOutput( )->SetPixel( n.Vertex, n.Result );
-  return( ret );
+  this->Superclass::_BeforeGenerateData( );
+  this->AllocateOutputs( );
 }
 
 // -------------------------------------------------------------------------
-template< class I, class A, class CC >
-unsigned long fpa::Image::Algorithm< I, A, CC >::
+template< class I, class O, class A >
+unsigned long fpa::Image::Algorithm< I, O, A >::
 _NumberOfVertices( ) const
 {
-  return(
-    this->GetInput( )->GetLargestPossibleRegion( ).GetNumberOfPixels( )
-    );
+  return( this->GetInput( )->GetRequestedRegion( ).GetNumberOfPixels( ) );
 }
 
 // -------------------------------------------------------------------------
-template< class I, class A, class CC >
-typename fpa::Image::Algorithm< I, A, CC >::
-TVertexValue fpa::Image::Algorithm< I, A, CC >::
-_Value( const TVertex& v ) const
+template< class I, class O, class A >
+const typename fpa::Image::Algorithm< I, O, A >::
+TValue& fpa::Image::Algorithm< I, O, A >::
+_VertexValue( const TVertex& v ) const
 {
   return( this->GetInput( )->GetPixel( v ) );
 }
 
 // -------------------------------------------------------------------------
-template< class I, class A, class CC >
-typename fpa::Image::Algorithm< I, A, CC >::
-TResult fpa::Image::Algorithm< I, A, CC >::
-_Result( const TVertex& v ) const
-{
-  return( this->GetOutput( )->GetPixel( v ) );
-}
-
-// -------------------------------------------------------------------------
-template< class I, class A, class CC >
-double fpa::Image::Algorithm< I, A, CC >::
-_Norm( const TVertex& a, const TVertex& b ) const
+template< class I, class O, class A >
+double fpa::Image::Algorithm< I, O, A >::
+_Distance( const TVertex& a, const TVertex& b ) const
 {
   typename I::PointType pa, pb;
   this->GetInput( )->TransformIndexToPhysicalPoint( a, pa );
@@ -72,9 +58,9 @@ _Norm( const TVertex& a, const TVertex& b ) const
 }
 
 // -------------------------------------------------------------------------
-template< class I, class A, class CC >
-bool fpa::Image::Algorithm< I, A, CC >::
-_Edge( const TVertex& a, const TVertex& b ) const
+template< class I, class O, class A >
+bool fpa::Image::Algorithm< I, O, A >::
+_HasEdge( const TVertex& a, const TVertex& b ) const
 {
   unsigned long dist = 0;
   for( unsigned int d = 0; d < I::ImageDimension; d++ )
@@ -86,42 +72,23 @@ _Edge( const TVertex& a, const TVertex& b ) const
 }
 
 // -------------------------------------------------------------------------
-template< class I, class A, class CC >
-typename fpa::Image::Algorithm< I, A, CC >::
-TCost fpa::Image::Algorithm< I, A, CC >::
-_Cost( const TVertex& a, const TVertex& b ) const
-{
-  static const TCost INF_COST = std::numeric_limits< TCost >::max( );
-  if( this->_Edge( a, b ) )
-  {
-    return(
-      this->m_CostConversion->Evaluate( this->GetInput( )->GetPixel( b ) )
-      );
-  }
-  else
-    return( INF_COST );
-}
-
-// -------------------------------------------------------------------------
-template< class I, class A, class CC >
-void fpa::Image::Algorithm< I, A, CC >::
-_Neighs( const _TNode& n, _TNodes& N ) const
+template< class I, class O, class A >
+void fpa::Image::Algorithm< I, O, A >::
+_Neighborhood( _TVertices& neighborhood, const TVertex& v ) const
 {
   typename I::RegionType reg = this->GetInput( )->GetRequestedRegion( );
 
-  N.clear( );
+  neighborhood.clear( );
   if( this->m_NeighborhoodOrder == 1 )
   {
     for( unsigned int d = 0; d < I::ImageDimension; d++ )
     {
       for( int i = -1; i <= 1; i += 2 )
       {
-        TVertex v = n.Vertex;
-        v[ d ] += i;
-        if( reg.IsInside( v ) )
-          N.push_back( _TNode( v, n.FrontId ) );
-        else
-          N.push_back( n );
+        TVertex n = v;
+        n[ d ] += i;
+        if( reg.IsInside( n ) )
+          neighborhood.push_back( n );
 
       } // rof
 
@@ -134,15 +101,14 @@ _Neighs( const _TNode& n, _TNodes& N ) const
     nSize.Fill( 1 );
 
     TNeighIt nIt( nSize, this->GetInput( ), reg );
-    nIt.SetLocation( n.Vertex );
+    nIt.SetLocation( v );
     for( unsigned int i = 0; i < nIt.Size( ); i++ )
     {
-      TVertex idxN = nIt.GetIndex( i );
-      if( idxN == n.Vertex )
-        continue;
-      if( !reg.IsInside( idxN ) )
+      TVertex n = nIt.GetIndex( i );
+      if( n == v )
         continue;
-      N.push_back( _TNode( idxN, n.FrontId ) );
+      if( reg.IsInside( n ) )
+        neighborhood.push_back( n );
 
     } // rof
 
@@ -150,28 +116,65 @@ _Neighs( const _TNode& n, _TNodes& N ) const
 }
 
 // -------------------------------------------------------------------------
-template< class I, class A, class CC >
-void fpa::Image::Algorithm< I, A, CC >::
-_NeighsInDim( const _TNode& n, const unsigned int& d, _TNodes& N )
+template< class I, class O, class A >
+void fpa::Image::Algorithm< I, O, A >::
+_InitResults( )
 {
-  typename I::RegionType reg = this->GetInput( )->GetRequestedRegion( );
+}
 
-  N.clear( );
-  for( int i = -1; i <= 1; i += 2 )
-  {
-    TVertex v = n.Vertex;
-    v[ d ] += i;
-    if( reg.IsInside( v ) )
-      N.push_back( _TNode( v, n.FrontId ) );
+// -------------------------------------------------------------------------
+template< class I, class O, class A >
+const typename fpa::Image::Algorithm< I, O, A >::
+TResult& fpa::Image::Algorithm< I, O, A >::
+_Result( const TVertex& v ) const
+{
+  return( this->GetOutput( )->GetPixel( v ) );
+}
+
+// -------------------------------------------------------------------------
+template< class I, class O, class A >
+void fpa::Image::Algorithm< I, O, A >::
+_SetResult( const TVertex& v, const TResult& r )
+{
+  this->GetOutput( )->SetPixel( v, r );
+}
+
+// -------------------------------------------------------------------------
+template< class I, class O, class A >
+const typename fpa::Image::Algorithm< I, O, A >::
+_TNode& fpa::Image::Algorithm< I, O, A >::
+_Node( const TVertex& v ) const
+{
+  return( this->m_Marks->GetPixel( v ) );
+}
 
-  } // rof
+// -------------------------------------------------------------------------
+template< class I, class O, class A >
+void fpa::Image::Algorithm< I, O, A >::
+_InitMarks( )
+{
+  const I* in = this->GetInput( );
+
+  this->m_Marks = _TMarks::New( );
+  this->m_Marks->SetLargestPossibleRegion( in->GetLargestPossibleRegion( ) );
+  this->m_Marks->SetRequestedRegion( in->GetRequestedRegion( ) );
+  this->m_Marks->SetBufferedRegion( in->GetBufferedRegion( ) );
+  this->m_Marks->SetOrigin( in->GetOrigin( ) );
+  this->m_Marks->SetSpacing( in->GetSpacing( ) );
+  this->m_Marks->SetDirection( in->GetDirection( ) );
+  this->m_Marks->Allocate( );
+
+  _TNode far_node;
+  far_node.Label = Self::FarLabel;
+  this->m_Marks->FillBuffer( far_node );
 }
 
 // -------------------------------------------------------------------------
-template< class I, class A, class CC >
-void fpa::Image::Algorithm< I, A, CC >::
-_InitializeResults( )
+template< class I, class O, class A >
+void fpa::Image::Algorithm< I, O, A >::
+_Mark( const _TNode& node )
 {
+  this->m_Marks->SetPixel( node.Vertex, node );
 }
 
 #endif // __FPA__IMAGE__ALGORITHM__HXX__