]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Filter.cxx
Moved to version 1.0
[cpPlugins.git] / lib / cpPlugins / Filter.cxx
diff --git a/lib/cpPlugins/Filter.cxx b/lib/cpPlugins/Filter.cxx
new file mode 100644 (file)
index 0000000..84dcc6f
--- /dev/null
@@ -0,0 +1,163 @@
+// =========================================================================
+// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
+// =========================================================================
+
+#include <cpPlugins/Filter.h>
+
+// -------------------------------------------------------------------------
+void cpPlugins::Filter::
+SetFunctor( const std::string& name, cpPlugins::Functor* functor )
+{
+  TFunctors::iterator i = this->m_Functors.find( name );
+  if( i != this->m_Functors.end( ) )
+  {
+    if( !( i->second.Set( functor ) ) )
+      cpPluginsErrorMacro(
+        this, << "Functor \"" << name << "\" does not match to input data."
+        );
+  }
+  else
+    cpPluginsErrorMacro(
+      this, << "Functor \"" << name << "\" does not belong to this filter."
+      );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::DataObject* cpPlugins::Filter::
+GetOutput( const std::string& name )
+{
+  TOutputs::iterator i = this->m_Outputs.find( name );
+  if( i != this->m_Outputs.end( ) )
+    return( i->second.Get( ) );
+  else
+    cpPluginsErrorMacro(
+      this, << "Output \"" << name << "\" does not belong to this filter."
+      );
+}
+
+// -------------------------------------------------------------------------
+const cpPlugins::DataObject* cpPlugins::Filter::
+GetOutput( const std::string& name ) const
+{
+  TOutputs::const_iterator i = this->m_Outputs.find( name );
+  if( i != this->m_Outputs.end( ) )
+    return( i->second.Get( ) );
+  else
+    cpPluginsErrorMacro(
+      this, << "Output \"" << name << "\" does not belong to this filter."
+      );
+}
+
+// -------------------------------------------------------------------------
+bool cpPlugins::Filter::
+HasOutput( const std::string& name ) const
+{
+  TOutputs::const_iterator i = this->m_Outputs.find( name );
+  return( i != this->m_Outputs.end( ) );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Functor* cpPlugins::Filter::
+GetFunctor( const std::string& name )
+{
+  TFunctors::iterator i = this->m_Functors.find( name );
+  if( i != this->m_Functors.end( ) )
+    return( i->second.Get( ) );
+  else
+    cpPluginsErrorMacro(
+      this, << "Functor \"" << name << "\" does not belong to this filter."
+      );
+}
+
+// -------------------------------------------------------------------------
+const cpPlugins::Functor* cpPlugins::Filter::
+GetFunctor( const std::string& name ) const
+{
+  TFunctors::const_iterator i = this->m_Functors.find( name );
+  if( i != this->m_Functors.end( ) )
+    return( i->second.Get( ) );
+  else
+    cpPluginsErrorMacro(
+      this, << "Functor \"" << name << "\" does not belong to this filter."
+      );
+}
+
+// -------------------------------------------------------------------------
+std::set< std::string > cpPlugins::Filter::
+GetOutputsNames( ) const
+{
+  std::set< std::string > n;
+  TOutputs::const_iterator i = this->m_Outputs.begin( );
+  for( ; i != this->m_Outputs.end( ); ++i )
+    n.insert( i->first );
+  return( n );
+}
+
+// -------------------------------------------------------------------------
+std::set< std::string > cpPlugins::Filter::
+GetFunctorsNames( ) const
+{
+  std::set< std::string > n;
+  TFunctors::const_iterator i = this->m_Functors.begin( );
+  for( ; i != this->m_Functors.end( ); ++i )
+    n.insert( i->first );
+  return( n );
+}
+
+// -------------------------------------------------------------------------
+std::set< std::string > cpPlugins::Filter::
+GetAllInputsNames( ) const
+{
+  std::set< std::string > r = this->Superclass::GetAllInputsNames( );
+  std::set< std::string > iFunctors = this->GetFunctorsNames( );
+  for( const std::string& s: iFunctors )
+    r.insert( s );
+  return( r );
+}
+
+// -------------------------------------------------------------------------
+std::set< std::string > cpPlugins::Filter::
+GetAllOutputsNames( ) const
+{
+  std::set< std::string > r = this->Superclass::GetAllOutputsNames( );
+  std::set< std::string > oNames = this->GetOutputsNames( );
+  for( const std::string& s: oNames )
+    r.insert( s );
+  return( r );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Filter::
+Filter( )
+  : Superclass( )
+{
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Filter::
+~Filter( )
+{
+}
+
+// -------------------------------------------------------------------------
+bool cpPlugins::Filter::
+_BeforeUpdate( )
+{
+  bool is_updated = this->Superclass::_BeforeUpdate( );
+  for( TFunctors::value_type& fIt: this->m_Functors )
+  {
+    cpPlugins::Functor* f = fIt.second.Get( )->Cast< cpPlugins::Functor >( );
+    if( f != NULL )
+    {
+      if( !( f->IsUpdated( ) ) )
+      {
+        f->Update( );
+        is_updated = false;
+
+      } // end if
+    } // end if
+  } // end for
+  return( is_updated );
+}
+
+// eof - $RCSfile$