]> Creatis software - FrontAlgorithms.git/blobdiff - appli/CTBronchi/MoriLabelling.hxx
...
[FrontAlgorithms.git] / appli / CTBronchi / MoriLabelling.hxx
index 228ed2d96f58b629a14e2d70866a633650f23f34..e654b09278e67537e2ac0b25e3e633d7c29237e1 100644 (file)
 #ifndef __CTBronchi__MoriLabelling__hxx__
 #define __CTBronchi__MoriLabelling__hxx__
 
-/* TODO
-   #include <itkImageRegionConstIteratorWithIndex.h>
-
-   // -------------------------------------------------------------------------
-   template< class _TInputImage, class _TLabelImage, class _TTraits >
-   const typename CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
-   TLabelImage* CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
-   GetInputLabelImage( ) const
-   {
-   return( this->GetLabels( ) );
-   }
-
-   // -------------------------------------------------------------------------
-   template< class _TInputImage, class _TLabelImage, class _TTraits >
-   void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
-   SetInputLabelImage( TLabelImage* image )
-   {
-   this->SetLabels( image );
-   }
-
-   // -------------------------------------------------------------------------
-   template< class _TInputImage, class _TLabelImage, class _TTraits >
-   const typename CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
-   TInputImage* CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
-   GetInputRawImage( ) const
-   {
-   return( this->GetInput( ) );
-   }
-
-   // -------------------------------------------------------------------------
-   template< class _TInputImage, class _TLabelImage, class _TTraits >
-   void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
-   SetInputRawImage( TInputImage* image )
-   {
-   this->SetInput( image );
-   }
-
-   // -------------------------------------------------------------------------
-   template< class _TInputImage, class _TLabelImage, class _TTraits >
-   typename CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
-   TInputValue CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
-   GetUpperThreshold( ) const
-   {
-   const TThresholdFunction* func =
-   dynamic_cast< const TThresholdFunction* >( this->GetValuePredicate( ) );
-   if( func != NULL )
-   return( func->GetUpper( ) );
-   else
-   return( TInputValue( 0 ) );
-   }
-
-   // -------------------------------------------------------------------------
-   template< class _TInputImage, class _TLabelImage, class _TTraits >
-   void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
-   SetUpperThreshold( TInputValue t )
-   {
-   TThresholdFunction* func =
-   dynamic_cast< TThresholdFunction* >( this->GetValuePredicate( ) );
-   if( func != NULL )
-   func->SetUpper( t );
-   }
-
-   // -------------------------------------------------------------------------
-   template< class _TInputImage, class _TLabelImage, class _TTraits >
-   typename CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
-   TOutputValue CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
-   GetOutsideValue( ) const
-   {
-   return( this->GetInitValue( ) );
-   }
-
-   // -------------------------------------------------------------------------
-   template< class _TInputImage, class _TLabelImage, class _TTraits >
-   void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
-   SetOutsideLabel( TOutputValue o )
-   {
-   this->SetInitValue( o );
-   }
-
-   // -------------------------------------------------------------------------
-   template< class _TInputImage, class _TLabelImage, class _TTraits >
-   CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
-   MoriLabelling( )
-   : Superclass( ),
-   m_InsideLabel( TOutputValue( 0 ) )
-   {
-   typename TThresholdFunction::Pointer func = TThresholdFunction::New( );
-   this->SetPredicate( func );
-   }
-
-   // -------------------------------------------------------------------------
-   template< class _TInputImage, class _TLabelImage, class _TTraits >
-   CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
-   ~MoriLabelling( )
-   {
-   }
-
-   // -------------------------------------------------------------------------
-   template< class _TInputImage, class _TLabelImage, class _TTraits >
-   typename CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
-   TNodes CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
-   _UnifySeeds( )
-   {
-   this->m_Seeds.clear( );
-   const TLabelImage* lbl = this->GetLabels( );
-   if( lbl == NULL )
-   {
-   std::ostringstream msg;
-   msg << "itk::ERROR: CTBronchi::MoriLabelling (" << this
-   << "): Labelled image not defined.";
-   ::itk::ExceptionObject e(
-   __FILE__, __LINE__, msg.str( ).c_str( ), ITK_LOCATION
-   );
-   throw e;
-
-   } // fi
-
-   // Iterate over labels
-   typename TLabelImage::RegionType reg = lbl->GetRequestedRegion( );
-   itk::ImageRegionConstIteratorWithIndex< TLabelImage > lIt( lbl, reg );
-   for( lIt.GoToBegin( ); !lIt.IsAtEnd( ); ++lIt )
-   {
-   if( lIt.Get( ) > 0 )
-   {
-   bool is_seed = false;
-   for( unsigned int d = 0; d < TLabelImage::ImageDimension; ++d )
-   {
-   for( int s = -1; s <= 1; s += 2 )
-   {
-   TVertex neigh = lIt.GetIndex( );
-   neigh[ d ] += s;
-   if( reg.IsInside( neigh ) )
-   is_seed |= ( lbl->GetPixel( neigh ) == 0 );
-
-   } // rof
-
-   } // rof
-
-   if( !is_seed )
-   {
-   typename TSeedsInterface::TNode node;
-   node.Vertex = lIt.GetIndex( );
-   node.Parent = lIt.GetIndex( );
-   node.FrontId = lIt.Get( );
-   node.Value = this->m_InsideLabel;
-   this->_Mark( node.Vertex, node.FrontId );
-   this->_UpdateOutputValue( node );
-   }
-   else
-   {
-   typename TSeedsInterface::TSeed seed;
-   seed.Vertex = lIt.GetIndex( );
-   seed.IsPoint = false;
-   seed.FrontId = lIt.Get( );
-   this->m_Seeds.push_back( seed );
-
-   } // fi
-
-   } // fi
-
-   } // rof
-
-   // Ok, finish initialization
-   return( this->Superclass::_UnifySeeds( ) );
-   }
-
-   // -------------------------------------------------------------------------
-   template< class _TInputImage, class _TLabelImage, class _TTraits >
-   void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage, _TTraits >::
-   _UpdateOutputValue( TNode& n )
-   {
-   const TLabelImage* input_labels = this->GetInputLabelImage( );
-
-   this->Superclass::_UpdateOutputValue( n );
-   if( n.FrontId != 0 )
-   {
-   if( input_labels->GetPixel( n.Vertex ) == this->GetInsideValue( ) )
-   n.Value = this->GetInsideLabel( );
-   else
-   n.Value = TOutputValue( 0 );
-   this->TAlgorithm::_UpdateOutputValue( n );
-
-   } // fi
-   }
-*/
+// -------------------------------------------------------------------------
+template< class _TInputImage, class _TLabelImage >
+typename CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
+TInputValue CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
+GetUpperThreshold( ) const
+{
+  return( this->m_LabelFunctor->GetUpperThreshold( ) );
+}
+
+// -------------------------------------------------------------------------
+template< class _TInputImage, class _TLabelImage >
+void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
+SetUpperThreshold( TInputValue t )
+{
+  this->m_LabelFunctor->SetUpperThreshold( t );
+}
+
+// -------------------------------------------------------------------------
+template< class _TInputImage, class _TLabelImage >
+CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
+MoriLabelling( )
+  : Superclass( )
+{
+  this->m_LabelFunctor = TLabelFunctor::New( );
+  this->SetPredicate( this->m_LabelFunctor );
+}
+
+// -------------------------------------------------------------------------
+template< class _TInputImage, class _TLabelImage >
+CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
+~MoriLabelling( )
+{
+}
+
+// -------------------------------------------------------------------------
+template< class _TInputImage, class _TLabelImage >
+void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
+_UpdateOutputValue( TNode& n )
+{
+  this->Superclass::_UpdateOutputValue( n );
+  if( n.FrontId != 0 )
+  {
+    const TLabelImage* input_labels = this->GetInputLabels( );
+    if( input_labels->GetPixel( n.Vertex ) == this->GetInsideValue( ) )
+      n.Value = TOutputValue( 1 ); // this->GetInsideLabel( );
+    else
+      n.Value = TOutputValue( 0 );
+    /* TODO
+       if( input_labels->GetPixel( n.Vertex ) == this->GetInsideValue( ) )
+    */
+  } // fi
+}
 
 #endif // __CTBronchi__MoriLabelling__hxx__