X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FFilter.cxx;fp=lib%2FcpPlugins%2FFilter.cxx;h=84dcc6fa1b28b0f779848536742068553bc6c58b;hb=2e142df11d6f312a2a2b5097b8da73571ed523e8;hp=0000000000000000000000000000000000000000;hpb=61b3659afe961ed248f30e26f9ca8f28fcfafddc;p=cpPlugins.git diff --git a/lib/cpPlugins/Filter.cxx b/lib/cpPlugins/Filter.cxx new file mode 100644 index 0000000..84dcc6f --- /dev/null +++ b/lib/cpPlugins/Filter.cxx @@ -0,0 +1,163 @@ +// ========================================================================= +// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co) +// ========================================================================= + +#include + +// ------------------------------------------------------------------------- +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$