]> Creatis software - FrontAlgorithms.git/blobdiff - lib/fpa/Image/Algorithm.hxx
Refactoring: gaussian model estimator
[FrontAlgorithms.git] / lib / fpa / Image / Algorithm.hxx
index 0d83b035e6f821ccb52fe9d3bc0a843f0c72ebe7..a5b1f8548e5e4dd481a93eb1fbb3e3f6561d4ff4 100644 (file)
@@ -4,6 +4,42 @@
 #include <cmath>
 #include <itkConstNeighborhoodIterator.h>
 
+// -------------------------------------------------------------------------
+template< class I, class O, class A >
+typename fpa::Image::Algorithm< I, O, A >::
+TMinimumSpanningTree* fpa::Image::Algorithm< I, O, A >::
+GetMinimumSpanningTree( )
+{
+  return(
+    dynamic_cast< TMinimumSpanningTree* >(
+      this->itk::ProcessObject::GetOutput( 1 )
+      )
+    );
+}
+
+// -------------------------------------------------------------------------
+template< class I, class O, class A >
+const typename fpa::Image::Algorithm< I, O, A >::
+TMinimumSpanningTree* fpa::Image::Algorithm< I, O, A >::
+GetMinimumSpanningTree( ) const
+{
+  return(
+    dynamic_cast< const TMinimumSpanningTree* >(
+      this->itk::ProcessObject::GetOutput( 1 )
+      )
+    );
+}
+
+// -------------------------------------------------------------------------
+template< class I, class O, class A >
+void fpa::Image::Algorithm< I, O, A >::
+GraftMinimumSpanningTree( itk::DataObject* obj )
+{
+  TMinimumSpanningTree* mst = dynamic_cast< TMinimumSpanningTree* >( obj );
+  if( mst != NULL )
+    this->GraftNthOutput( 1, mst );
+}
+
 // -------------------------------------------------------------------------
 template< class I, class O, class A >
 fpa::Image::Algorithm< I, O, A >::
@@ -11,6 +47,9 @@ Algorithm( )
   : Superclass( ),
     m_NeighborhoodOrder( 1 )
 {
+  this->itk::ProcessObject::SetNumberOfRequiredOutputs( 2 );
+  this->itk::ProcessObject::SetNthOutput( 0, O::New( ) );
+  this->itk::ProcessObject::SetNthOutput( 1, TMinimumSpanningTree::New( ) );
 }
 
 // -------------------------------------------------------------------------
@@ -29,6 +68,15 @@ _BeforeGenerateData( )
   this->AllocateOutputs( );
 }
 
+// -------------------------------------------------------------------------
+template< class I, class O, class A >
+void fpa::Image::Algorithm< I, O, A >::
+_AfterGenerateData( )
+{
+  this->Superclass::_AfterGenerateData( );
+  this->GetMinimumSpanningTree( )->SetCollisions( this->m_Collisions );
+}
+
 // -------------------------------------------------------------------------
 template< class I, class O, class A >
 unsigned long fpa::Image::Algorithm< I, O, A >::
@@ -145,7 +193,7 @@ 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 ) );
+  return( this->GetMinimumSpanningTree( )->GetPixel( v ) );
 }
 
 // -------------------------------------------------------------------------
@@ -153,20 +201,9 @@ 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 );
+  this->GetMinimumSpanningTree( )->FillBuffer( far_node );
 }
 
 // -------------------------------------------------------------------------
@@ -174,7 +211,7 @@ 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 );
+  this->GetMinimumSpanningTree( )->SetPixel( node.Vertex, node );
 }
 
 #endif // __FPA__IMAGE__ALGORITHM__HXX__