]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Filter.cxx
Moved to version 1.0
[cpPlugins.git] / lib / cpPlugins / Filter.cxx
1 // =========================================================================
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // =========================================================================
4
5 #include <cpPlugins/Filter.h>
6
7 // -------------------------------------------------------------------------
8 void cpPlugins::Filter::
9 SetFunctor( const std::string& name, cpPlugins::Functor* functor )
10 {
11   TFunctors::iterator i = this->m_Functors.find( name );
12   if( i != this->m_Functors.end( ) )
13   {
14     if( !( i->second.Set( functor ) ) )
15       cpPluginsErrorMacro(
16         this, << "Functor \"" << name << "\" does not match to input data."
17         );
18   }
19   else
20     cpPluginsErrorMacro(
21       this, << "Functor \"" << name << "\" does not belong to this filter."
22       );
23 }
24
25 // -------------------------------------------------------------------------
26 cpPlugins::DataObject* cpPlugins::Filter::
27 GetOutput( const std::string& name )
28 {
29   TOutputs::iterator i = this->m_Outputs.find( name );
30   if( i != this->m_Outputs.end( ) )
31     return( i->second.Get( ) );
32   else
33     cpPluginsErrorMacro(
34       this, << "Output \"" << name << "\" does not belong to this filter."
35       );
36 }
37
38 // -------------------------------------------------------------------------
39 const cpPlugins::DataObject* cpPlugins::Filter::
40 GetOutput( const std::string& name ) const
41 {
42   TOutputs::const_iterator i = this->m_Outputs.find( name );
43   if( i != this->m_Outputs.end( ) )
44     return( i->second.Get( ) );
45   else
46     cpPluginsErrorMacro(
47       this, << "Output \"" << name << "\" does not belong to this filter."
48       );
49 }
50
51 // -------------------------------------------------------------------------
52 bool cpPlugins::Filter::
53 HasOutput( const std::string& name ) const
54 {
55   TOutputs::const_iterator i = this->m_Outputs.find( name );
56   return( i != this->m_Outputs.end( ) );
57 }
58
59 // -------------------------------------------------------------------------
60 cpPlugins::Functor* cpPlugins::Filter::
61 GetFunctor( const std::string& name )
62 {
63   TFunctors::iterator i = this->m_Functors.find( name );
64   if( i != this->m_Functors.end( ) )
65     return( i->second.Get( ) );
66   else
67     cpPluginsErrorMacro(
68       this, << "Functor \"" << name << "\" does not belong to this filter."
69       );
70 }
71
72 // -------------------------------------------------------------------------
73 const cpPlugins::Functor* cpPlugins::Filter::
74 GetFunctor( const std::string& name ) const
75 {
76   TFunctors::const_iterator i = this->m_Functors.find( name );
77   if( i != this->m_Functors.end( ) )
78     return( i->second.Get( ) );
79   else
80     cpPluginsErrorMacro(
81       this, << "Functor \"" << name << "\" does not belong to this filter."
82       );
83 }
84
85 // -------------------------------------------------------------------------
86 std::set< std::string > cpPlugins::Filter::
87 GetOutputsNames( ) const
88 {
89   std::set< std::string > n;
90   TOutputs::const_iterator i = this->m_Outputs.begin( );
91   for( ; i != this->m_Outputs.end( ); ++i )
92     n.insert( i->first );
93   return( n );
94 }
95
96 // -------------------------------------------------------------------------
97 std::set< std::string > cpPlugins::Filter::
98 GetFunctorsNames( ) const
99 {
100   std::set< std::string > n;
101   TFunctors::const_iterator i = this->m_Functors.begin( );
102   for( ; i != this->m_Functors.end( ); ++i )
103     n.insert( i->first );
104   return( n );
105 }
106
107 // -------------------------------------------------------------------------
108 std::set< std::string > cpPlugins::Filter::
109 GetAllInputsNames( ) const
110 {
111   std::set< std::string > r = this->Superclass::GetAllInputsNames( );
112   std::set< std::string > iFunctors = this->GetFunctorsNames( );
113   for( const std::string& s: iFunctors )
114     r.insert( s );
115   return( r );
116 }
117
118 // -------------------------------------------------------------------------
119 std::set< std::string > cpPlugins::Filter::
120 GetAllOutputsNames( ) const
121 {
122   std::set< std::string > r = this->Superclass::GetAllOutputsNames( );
123   std::set< std::string > oNames = this->GetOutputsNames( );
124   for( const std::string& s: oNames )
125     r.insert( s );
126   return( r );
127 }
128
129 // -------------------------------------------------------------------------
130 cpPlugins::Filter::
131 Filter( )
132   : Superclass( )
133 {
134 }
135
136 // -------------------------------------------------------------------------
137 cpPlugins::Filter::
138 ~Filter( )
139 {
140 }
141
142 // -------------------------------------------------------------------------
143 bool cpPlugins::Filter::
144 _BeforeUpdate( )
145 {
146   bool is_updated = this->Superclass::_BeforeUpdate( );
147   for( TFunctors::value_type& fIt: this->m_Functors )
148   {
149     cpPlugins::Functor* f = fIt.second.Get( )->Cast< cpPlugins::Functor >( );
150     if( f != NULL )
151     {
152       if( !( f->IsUpdated( ) ) )
153       {
154         f->Update( );
155         is_updated = false;
156
157       } // end if
158     } // end if
159   } // end for
160   return( is_updated );
161 }
162
163 // eof - $RCSfile$