]> Creatis software - FrontAlgorithms.git/blobdiff - lib/fpa/Image/Algorithm.hxx
...
[FrontAlgorithms.git] / lib / fpa / Image / Algorithm.hxx
index 5e8605dcdd04f117c077169a3852a457f5e87945..43ebeb0af9da0affc72c892300b2d5ee6e7b3f9d 100644 (file)
-#ifndef __FPA__IMAGE__ALGORITHM__HXX__
-#define __FPA__IMAGE__ALGORITHM__HXX__
+// =========================================================================
+// @author Leonardo Florez Valencia
+// @email florez-l@javeriana.edu.co
+// =========================================================================
 
-#include <cmath>
-#include <itkConstNeighborhoodIterator.h>
+#ifndef __fpa__Image__Algorithm__hxx__
+#define __fpa__Image__Algorithm__hxx__
 
 // -------------------------------------------------------------------------
-template< class I, class O, class A >
-fpa::Image::Algorithm< I, O, A >::
-Algorithm( )
-  : Superclass( ),
-    m_NeighborhoodOrder( 1 )
+template< class _TTraits >
+typename fpa::Image::Algorithm< _TTraits >::TMarks*
+fpa::Image::Algorithm< _TTraits >::
+GetMarks( )
 {
+  return(
+    dynamic_cast< TMarks* >(
+      this->itk::ProcessObject::GetOutput( this->m_MarksIdx )
+      )
+    );
 }
 
 // -------------------------------------------------------------------------
-template< class I, class O, class A >
-fpa::Image::Algorithm< I, O, A >::
-~Algorithm( )
+template< class _TTraits >
+const typename fpa::Image::Algorithm< _TTraits >::TMarks*
+fpa::Image::Algorithm< _TTraits >::
+GetMarks( ) const
 {
+  return(
+    dynamic_cast< const TMarks* >(
+      this->itk::ProcessObject::GetOutput( this->m_MarksIdx )
+      )
+    );
 }
 
 // -------------------------------------------------------------------------
-template< class I, class O, class A >
-void fpa::Image::Algorithm< I, O, A >::
-_BeforeGenerateData( )
+template< class _TTraits >
+fpa::Image::Algorithm< _TTraits >::
+Algorithm( )
+  : Superclass( ),
+    m_NeigborhoodOrder( 1 )
 {
-  this->Superclass::_BeforeGenerateData( );
-  this->AllocateOutputs( );
+  this->m_MarksIdx = this->GetNumberOfRequiredOutputs( );
+  this->itk::ProcessObject::SetNumberOfRequiredOutputs( this->m_MarksIdx + 1 );
+  this->SetNthOutput( this->m_MarksIdx, TMarks::New( ) );
 }
 
 // -------------------------------------------------------------------------
-template< class I, class O, class A >
-void fpa::Image::Algorithm< I, O, A >::
-_AfterGenerateData( )
+template< class _TTraits >
+fpa::Image::Algorithm< _TTraits >::
+~Algorithm( )
 {
-  this->Superclass::_AfterGenerateData( );
-  this->GetMinimumSpanningTree( )->SetCollisions( this->m_Collisions );
 }
 
 // -------------------------------------------------------------------------
-template< class I, class O, class A >
-unsigned long fpa::Image::Algorithm< I, O, A >::
-_NumberOfVertices( ) const
+template< class _TTraits >
+typename fpa::Image::Algorithm< _TTraits >::TNodes
+fpa::Image::Algorithm< _TTraits >::
+_UnifySeeds( )
 {
-  return( this->GetInput( )->GetRequestedRegion( ).GetNumberOfPixels( ) );
-}
+  const TInputImage* input = this->GetInput( );
+  typename TInputImage::RegionType region = input->GetRequestedRegion( );
+  TSeeds& seeds = this->GetSeeds( );
+  TNodes nodes;
 
-// -------------------------------------------------------------------------
-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 ) );
+  typename TSeeds::iterator sIt = seeds.begin( );
+  for( ; sIt != seeds.end( ); ++sIt )
+  {
+    TNode node;
+    if( sIt->IsPoint )
+      input->TransformPhysicalPointToIndex( sIt->Point, sIt->Vertex );
+    else
+      input->TransformIndexToPhysicalPoint( sIt->Vertex, sIt->Point );
+    if( region.IsInside( sIt->Vertex ) )
+    {
+      sIt->IsUnified = true;
+      node.Vertex = sIt->Vertex;
+      node.Parent = node.Vertex;
+      if( sIt->FrontId == 0 )
+        node.FrontId = nodes.size( ) + 1;
+      else
+        node.FrontId = sIt->FrontId;
+      nodes.insert( node );
+    }
+    else
+      sIt->IsUnified = false;
+
+  } // rof
+
+  return( nodes );
 }
 
 // -------------------------------------------------------------------------
-template< class I, class O, class A >
-double fpa::Image::Algorithm< I, O, A >::
-_Distance( const TVertex& a, const TVertex& b ) const
+template< class _TTraits >
+void fpa::Image::Algorithm< _TTraits >::
+_ConfigureOutput( const TOutputValue& v )
 {
-  typename I::PointType pa, pb;
-  this->GetInput( )->TransformIndexToPhysicalPoint( a, pa );
-  this->GetInput( )->TransformIndexToPhysicalPoint( b, pb );
-  return( double( pa.EuclideanDistanceTo( pb ) ) );
+  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( v );
+
+  TMarks* 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( TFrontId( 0 ) );
 }
 
 // -------------------------------------------------------------------------
-template< class I, class O, class A >
-bool fpa::Image::Algorithm< I, O, A >::
-_HasEdge( const TVertex& a, const TVertex& b ) const
+template< class _TTraits >
+typename fpa::Image::Algorithm< _TTraits >::TNeighborhood
+fpa::Image::Algorithm< _TTraits >::
+_GetNeighbors( const TVertex& v ) const
 {
-  unsigned long dist = 0;
-  for( unsigned int d = 0; d < I::ImageDimension; d++ )
-    dist += std::abs( long( a[ d ] ) - long( b[ d ] ) );
-  if( this->m_NeighborhoodOrder == 1 )
-    return( dist <= 1 );
+  typename TInputImage::RegionType region =
+    this->GetInput( )->GetRequestedRegion( );
+  TNeighborhood neighborhood;
+  if( this->m_NeigborhoodOrder != 1 )
+  {
+    // TODO
+  }
   else
-    return( dist <= I::ImageDimension );
-}
-
-// -------------------------------------------------------------------------
-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( );
-
-  neighborhood.clear( );
-  if( this->m_NeighborhoodOrder == 1 )
   {
-    for( unsigned int d = 0; d < I::ImageDimension; d++ )
+    for( unsigned int d = 0; d < TInputImage::ImageDimension; ++d )
     {
-      for( int i = -1; i <= 1; i += 2 )
+      for( int s = -1; s <= 1; s += 2 )
       {
         TVertex n = v;
-        n[ d ] += i;
-        if( reg.IsInside( n ) )
+        n[ d ] += s;
+        if( region.IsInside( n ) )
           neighborhood.push_back( n );
 
       } // rof
 
     } // rof
-  }
-  else
-  {
-    typedef itk::ConstNeighborhoodIterator< I > TNeighIt;
-    typename I::SizeType nSize;
-    nSize.Fill( 1 );
-
-    TNeighIt nIt( nSize, this->GetInput( ), reg );
-    nIt.SetLocation( v );
-    for( unsigned int i = 0; i < nIt.Size( ); i++ )
-    {
-      TVertex n = nIt.GetIndex( i );
-      if( n == v )
-        continue;
-      if( reg.IsInside( n ) )
-        neighborhood.push_back( n );
-
-    } // rof
 
   } // fi
+  return( neighborhood );
 }
 
 // -------------------------------------------------------------------------
-template< class I, class O, class A >
-void fpa::Image::Algorithm< I, O, A >::
-_InitResults( )
+template< class _TTraits >
+typename fpa::Image::Algorithm< _TTraits >::TInputValue
+fpa::Image::Algorithm< _TTraits >::
+_GetInputValue( const TVertex& v ) const
 {
+  return( this->GetInput( )->GetPixel( v ) );
 }
 
 // -------------------------------------------------------------------------
-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
+template< class _TTraits >
+typename fpa::Image::Algorithm< _TTraits >::TOutputValue
+fpa::Image::Algorithm< _TTraits >::
+_GetOutputValue( 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 _TNode& n )
+template< class _TTraits >
+void fpa::Image::Algorithm< _TTraits >::
+_UpdateOutputValue( TNode& n )
+{
+  this->GetOutput( )->SetPixel( n.Vertex, n.Value );
+}
+
+// -------------------------------------------------------------------------
+template< class _TTraits >
+bool fpa::Image::Algorithm< _TTraits >::
+_IsMarked( const TVertex& v ) const
+{
+  return( this->GetMarks( )->GetPixel( v ) > 0 );
+}
+
+// -------------------------------------------------------------------------
+template< class _TTraits >
+unsigned long fpa::Image::Algorithm< _TTraits >::
+_GetMark( const TVertex& v ) const
+{
+  return( ( unsigned long )( this->GetMarks( )->GetPixel( v ) ) );
+}
+
+// -------------------------------------------------------------------------
+template< class _TTraits >
+void fpa::Image::Algorithm< _TTraits >::
+_Mark( const TVertex& v, unsigned long frontId )
 {
-  this->GetOutput( )->SetPixel( v, n.Result );
-  this->GetMinimumSpanningTree( )->SetParent( v, n.Parent, n.FrontId );
+  this->GetMarks( )->SetPixel( v, TFrontId( frontId ) );
 }
 
-#endif // __FPA__IMAGE__ALGORITHM__HXX__
+#endif // __fpa__Image__Algorithm__hxx__
 
 // eof - $RCSfile$