1 #include <cpPlugins/Interface/ProcessObject.h>
2 #include <itkProcessObject.h>
4 #ifdef cpPlugins_Interface_QT4
5 #include <QApplication>
6 #include <cpPlugins/Interface/ParametersQtDialog.h>
7 #include <cpPlugins/Interface/SimpleMPRWidget.h>
8 #endif // cpPlugins_Interface_QT4
10 // -------------------------------------------------------------------------
11 void cpPlugins::Interface::ProcessObject::
12 SetITK( itk::LightObject* o )
14 // Polymorphism: do nothing -> this is a filter!!!
17 // -------------------------------------------------------------------------
18 void cpPlugins::Interface::ProcessObject::
19 SetVTK( vtkObjectBase* o )
21 // Polymorphism: do nothing -> this is a filter!!!
24 // -------------------------------------------------------------------------
25 std::set< std::string > cpPlugins::Interface::ProcessObject::
26 GetInputsNames( ) const
28 std::set< std::string > names;
29 for( auto i = this->m_Inputs.begin( ); i != this->m_Inputs.end( ); ++i )
30 names.insert( i->first );
34 // -------------------------------------------------------------------------
35 std::set< std::string > cpPlugins::Interface::ProcessObject::
36 GetOutputsNames( ) const
38 std::set< std::string > names;
39 for( auto i = this->m_Outputs.begin( ); i != this->m_Outputs.end( ); ++i )
40 names.insert( i->first );
44 // -------------------------------------------------------------------------
45 unsigned int cpPlugins::Interface::ProcessObject::
46 GetNumberOfInputs( ) const
48 return( this->m_Inputs.size( ) );
51 // -------------------------------------------------------------------------
52 unsigned int cpPlugins::Interface::ProcessObject::
53 GetNumberOfOutputs( ) const
55 return( this->m_Outputs.size( ) );
58 // -------------------------------------------------------------------------
59 cpPlugins::Interface::
60 OutputProcessObjectPort& cpPlugins::Interface::ProcessObject::
61 GetOutput( const std::string& id )
63 static OutputProcessObjectPort null_port;
64 auto i = this->m_Outputs.find( id );
65 if( i == this->m_Outputs.end( ) )
74 // -------------------------------------------------------------------------
75 const cpPlugins::Interface::
76 OutputProcessObjectPort& cpPlugins::Interface::ProcessObject::
77 GetOutput( const std::string& id ) const
79 static const OutputProcessObjectPort null_port;
80 auto i = this->m_Outputs.find( id );
81 if( i == this->m_Outputs.end( ) )
87 // -------------------------------------------------------------------------
88 bool cpPlugins::Interface::ProcessObject::
89 SetInput( const std::string& id, const OutputProcessObjectPort& port )
91 auto i = this->m_Inputs.find( id );
92 if( i != this->m_Inputs.end( ) )
94 if( i->second.GetPointer( ) != port.GetPointer( ) )
106 // -------------------------------------------------------------------------
107 void cpPlugins::Interface::ProcessObject::
110 auto i = this->m_Inputs.begin( );
111 for( ; i != this->m_Inputs.end( ); ++i )
116 // -------------------------------------------------------------------------
117 void cpPlugins::Interface::ProcessObject::
120 auto i = this->m_Outputs.begin( );
121 for( ; i != this->m_Outputs.end( ); ++i )
122 if( i->second.IsValid( ) )
123 i->second->DisconnectFromPipeline( );
127 // -------------------------------------------------------------------------
128 void cpPlugins::Interface::ProcessObject::
131 this->DisconnectInputs( );
132 this->DisconnectOutputs( );
135 // -------------------------------------------------------------------------
136 itk::ModifiedTimeType cpPlugins::Interface::ProcessObject::
139 auto params_time = this->m_Parameters->GetMTime( );
140 auto filter_time = this->Superclass::GetMTime( );
141 return( ( params_time < filter_time )? params_time: filter_time );
144 // -------------------------------------------------------------------------
145 std::string cpPlugins::Interface::ProcessObject::
150 // Force upstream updates
151 auto i = this->m_Inputs.begin( );
152 bool need_to_update = false;
153 for( ; i != this->m_Inputs.end( ) && r == ""; ++i )
155 bool iv = i->second.IsValid( );
156 bool ir = i->second.IsRequired( );
159 Self* src = dynamic_cast< Self* >( i->second->GetSource( ) );
162 need_to_update |= ( this->m_LastExecutionTime < src->GetMTime( ) );
169 "ProcessObject: Required input \"" +
170 i->first + "@" + this->GetClassName( ) +
171 "\" is not valid (=NULL).";
178 if( this->m_LastExecutionTime < this->GetMTime( ) || need_to_update )
180 r = this->_GenerateData( );
181 this->m_LastExecutionTime = this->GetMTime( );
187 // Return error description, if any
191 // -------------------------------------------------------------------------
192 cpPlugins::Interface::ProcessObject::
195 m_LastExecutionTime( 0 ),
196 m_ParametersDialog( NULL ),
199 this->m_Parameters = TParameters::New( );
200 this->m_Parameters->SetProcessObject( this );
202 #ifdef cpPlugins_Interface_QT4
203 if( QApplication::instance( ) != NULL )
205 this->m_ParametersDialog = new ParametersQtDialog( );
206 this->m_ParametersDialog->setParameters( this->m_Parameters );
209 #endif // cpPlugins_Interface_QT4
212 // -------------------------------------------------------------------------
213 cpPlugins::Interface::ProcessObject::
217 if( this->m_ParametersDialog != NULL )
218 delete this->m_ParametersDialog;
221 // -------------------------------------------------------------------------
222 void cpPlugins::Interface::ProcessObject::
223 _AddInput( const std::string& name, bool required )
225 auto i = this->m_Inputs.find( name );
226 if( i == this->m_Inputs.end( ) )
228 InputProcessObjectPort new_port( required );
229 this->m_Inputs[ name ] = new_port;