]> Creatis software - FrontAlgorithms.git/commitdiff
...
authorLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Wed, 5 Jul 2017 20:36:41 +0000 (15:36 -0500)
committerLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Wed, 5 Jul 2017 20:36:41 +0000 (15:36 -0500)
lib/fpa/Base/Mori.h
lib/fpa/Base/Mori.hxx [new file with mode: 0644]

index 430ff03ae5bc222da3ac1547efab3e0074554006..d9277845fd365a80541769d891c7bbceda872aa0 100644 (file)
@@ -66,6 +66,8 @@ namespace fpa
       Mori( );
       virtual ~Mori( );
 
+      virtual void _BeforeGenerateData( ) override;
+      virtual void _AfterGenerateData( ) override;
       virtual TOutputValue _ComputeOutputValue( const TNode& n ) override;
       virtual void _QueueClear( ) override;
       virtual TNode _QueuePop( ) override;
@@ -91,11 +93,9 @@ namespace fpa
 
 } // ecapseman
 
-/* TODO
-   #ifndef ITK_MANUAL_INSTANTIATION
-   #  include <fpa/Base/Mori.hxx>
-   #endif // ITK_MANUAL_INSTANTIATION
-*/
+#ifndef ITK_MANUAL_INSTANTIATION
+#  include <fpa/Base/Mori.hxx>
+#endif // ITK_MANUAL_INSTANTIATION
 
 #endif // __fpa__Base__Mori__h__
 
diff --git a/lib/fpa/Base/Mori.hxx b/lib/fpa/Base/Mori.hxx
new file mode 100644 (file)
index 0000000..cff5fe8
--- /dev/null
@@ -0,0 +1,182 @@
+// =========================================================================
+// @author Leonardo Florez Valencia
+// @email florez-l@javeriana.edu.co
+// =========================================================================
+
+#ifndef __fpa__Base__Mori__hxx__
+#define __fpa__Base__Mori__hxx__
+
+// -------------------------------------------------------------------------
+template< class _TAlgorithm >
+itk::ModifiedTimeType fpa::Base::Mori< _TAlgorithm >::
+GetMTime( ) const
+{
+  itk::ModifiedTimeType t = this->Superclass::GetMTime( );
+  itk::ModifiedTimeType q = this->m_Predicate->GetMTime( );
+  return( ( q < t )? q: t );
+}
+
+// -------------------------------------------------------------------------
+template< class _TAlgorithm >
+typename fpa::Base::Mori< _TAlgorithm >::
+TOutputValue fpa::Base::Mori< _TAlgorithm >::
+GetOutsideValue( ) const
+{
+  return( this->GetInitValue( ) );
+}
+
+// -------------------------------------------------------------------------
+template< class _TAlgorithm >
+void fpa::Base::Mori< _TAlgorithm >::
+SetOutsideValue( const TOutputValue& v )
+{
+  this->SetInitValue( v );
+}
+
+// -------------------------------------------------------------------------
+template< class _TAlgorithm >
+void fpa::Base::Mori< _TAlgorithm >::
+ClearThresholds( )
+{
+  this->m_Thresholds.clear( );
+  this->Modified( );
+}
+
+// -------------------------------------------------------------------------
+template< class _TAlgorithm >
+void fpa::Base::Mori< _TAlgorithm >::
+AddThreshold( const TInputValue& thr )
+{
+  if( this->m_Thresholds.insert( thr ).second )
+    this->Modified( );
+}
+
+// -------------------------------------------------------------------------
+template< class _TAlgorithm >
+void fpa::Base::Mori< _TAlgorithm >::
+SetThresholds(
+  const TInputValue& init,
+  const TInputValue& end,
+  unsigned long number_of_thresholds
+  )
+{
+  double i = double( init );
+  double e = double( end );
+  double n = double( number_of_thresholds );
+  double d = ( e - i ) / n;
+  for( unsigned long c = 0; c <= number_of_thresholds; ++c )
+    this->AddThreshold( TInputValue( i + ( d * double( c ) ) ) );
+}
+
+// -------------------------------------------------------------------------
+template< class _TAlgorithm >
+fpa::Base::Mori< _TAlgorithm >::
+Mori( )
+  : Superclass( ),
+    m_InsideValue( TOutputValue( 1 ) )
+{
+  this->SetInitValue( TOutputValue( 0 ) );
+  this->m_Predicate = TPredicate::New( );
+}
+
+// -------------------------------------------------------------------------
+template< class _TAlgorithm >
+fpa::Base::Mori< _TAlgorithm >::
+~Mori( )
+{
+}
+
+// -------------------------------------------------------------------------
+template< class _TAlgorithm >
+void fpa::Base::Mori< _TAlgorithm >::
+_BeforeGenerateData( )
+{
+  this->Superclass::_BeforeGenerateData( );
+
+  this->_QueueClear( );
+  this->m_CurrentQueue = 0;
+}
+
+// -------------------------------------------------------------------------
+template< class _TAlgorithm >
+void fpa::Base::Mori< _TAlgorithm >::
+_AfterGenerateData( )
+{
+  this->Superclass::_AfterGenerateData( );
+}
+
+// -------------------------------------------------------------------------
+template< class _TAlgorithm >
+typename fpa::Base::Mori< _TAlgorithm >::
+TOutputValue fpa::Base::Mori< _TAlgorithm >::
+_ComputeOutputValue( const TNode& n )
+{
+  TInputValue value = this->_GetInputValue( n.Vertex );
+  bool inside = this->m_Predicate->Evaluate( value );
+  if( !inside )
+  {
+    // TODO: Update new queue
+    return( this->m_InitValue );
+  }
+  else
+    return( this->m_InsideValue );
+}
+  
+// -------------------------------------------------------------------------
+template< class _TAlgorithm >
+void fpa::Base::Mori< _TAlgorithm >::
+_QueueClear( )
+{
+  this->m_Queues[ 0 ].clear( );
+  this->m_Queues[ 1 ].clear( );
+}
+
+// -------------------------------------------------------------------------
+template< class _TAlgorithm >
+typename fpa::Base::Mori< _TAlgorithm >::
+TNode fpa::Base::Mori< _TAlgorithm >::
+_QueuePop( )
+{
+  TNode n = this->m_Queues[ this->m_CurrentQueue ].front( );
+  this->m_Queues[ this->m_CurrentQueue ].pop_front( );
+  return( n );
+}
+
+// -------------------------------------------------------------------------
+template< class _TAlgorithm >
+void fpa::Base::Mori< _TAlgorithm >::
+_QueuePush( const TNode& node )
+{
+  // TODO: Update mark
+  this->m_Queues[ this->m_CurrentQueue ].push_back( node );
+}
+
+// -------------------------------------------------------------------------
+template< class _TAlgorithm >
+unsigned long fpa::Base::Mori< _TAlgorithm >::
+_QueueSize( ) const
+{
+  return( this->m_Queues[ this->m_CurrentQueue ].size( ) );
+}
+
+// -------------------------------------------------------------------------
+template< class _TAlgorithm >
+void fpa::Base::Mori< _TAlgorithm >::
+_PrepareSeeds( TNodes& nodes )
+{
+  typename TNodes::iterator nIt = nodes.begin( );
+  for( ; nIt != nodes.end( ); ++nIt )
+    nIt->Value = this->m_InsideValue;
+}
+
+/* TODO
+   typename TPredicate::Pointer m_Predicate;
+   TThresholds m_Thresholds;
+   TQueue m_Queues[ 2 ];
+   unsigned int m_CurrentQueue;
+   TOutputValue m_InsideValue;
+*/
+
+#endif // __fpa__Base__Mori__hxx__
+
+// eof - $RCSfile$