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 cpPlugins::Interface::
89 DataObject* cpPlugins::Interface::ProcessObject::
90 GetInputData( const std::string& id )
92 auto i = this->m_Inputs.find( id );
93 if( i != this->m_Inputs.end( ) )
94 return( dynamic_cast< DataObject* >( i->second.GetPointer( ) ) );
99 // -------------------------------------------------------------------------
100 const cpPlugins::Interface::
101 DataObject* cpPlugins::Interface::ProcessObject::
102 GetInputData( const std::string& id ) const
104 auto i = this->m_Inputs.find( id );
105 if( i != this->m_Inputs.end( ) )
106 return( dynamic_cast< const DataObject* >( i->second.GetPointer( ) ) );
111 // -------------------------------------------------------------------------
112 cpPlugins::Interface::
113 DataObject* cpPlugins::Interface::ProcessObject::
114 GetOutputData( const std::string& id )
116 auto i = this->m_Outputs.find( id );
117 if( i != this->m_Outputs.end( ) )
118 return( dynamic_cast< DataObject* >( i->second.GetPointer( ) ) );
123 // -------------------------------------------------------------------------
124 const cpPlugins::Interface::
125 DataObject* cpPlugins::Interface::ProcessObject::
126 GetOutputData( const std::string& id ) const
128 auto i = this->m_Outputs.find( id );
129 if( i != this->m_Outputs.end( ) )
130 return( dynamic_cast< const DataObject* >( i->second.GetPointer( ) ) );
135 // -------------------------------------------------------------------------
136 bool cpPlugins::Interface::ProcessObject::
137 SetInput( const std::string& id, const OutputProcessObjectPort& port )
139 auto i = this->m_Inputs.find( id );
140 if( i != this->m_Inputs.end( ) )
142 if( i->second.GetPointer( ) != port.GetPointer( ) )
154 // -------------------------------------------------------------------------
155 void cpPlugins::Interface::ProcessObject::
158 auto i = this->m_Inputs.begin( );
159 for( ; i != this->m_Inputs.end( ); ++i )
164 // -------------------------------------------------------------------------
165 void cpPlugins::Interface::ProcessObject::
168 auto i = this->m_Outputs.begin( );
169 for( ; i != this->m_Outputs.end( ); ++i )
170 if( i->second.IsValid( ) )
171 i->second->DisconnectFromPipeline( );
175 // -------------------------------------------------------------------------
176 void cpPlugins::Interface::ProcessObject::
179 this->DisconnectInputs( );
180 this->DisconnectOutputs( );
183 // -------------------------------------------------------------------------
184 itk::ModifiedTimeType cpPlugins::Interface::ProcessObject::
187 auto params_time = this->m_Parameters->GetMTime( );
188 auto filter_time = this->Superclass::GetMTime( );
189 return( ( params_time < filter_time )? params_time: filter_time );
192 // -------------------------------------------------------------------------
193 std::string cpPlugins::Interface::ProcessObject::
198 // Force upstream updates
199 auto i = this->m_Inputs.begin( );
200 bool need_to_update = false;
201 for( ; i != this->m_Inputs.end( ) && r == ""; ++i )
203 bool iv = i->second.IsValid( );
204 bool ir = i->second.IsRequired( );
207 "ProcessObject: Required input \"" +
208 i->first + "@" + this->GetClassName( ) +
209 "\" is not valid (=NULL).";
212 Self* src = dynamic_cast< Self* >( i->second->GetSource( ) );
215 need_to_update |= ( this->m_LastExecutionTime < src->GetMTime( ) );
227 if( this->m_LastExecutionTime < this->GetMTime( ) || need_to_update )
229 r = this->_GenerateData( );
230 this->m_LastExecutionTime = this->GetMTime( );
236 // Return error description, if any
240 // -------------------------------------------------------------------------
241 cpPlugins::Interface::ProcessObject::
244 m_LastExecutionTime( 0 ),
245 m_ParametersDialog( NULL ),
248 this->m_Parameters = TParameters::New( );
249 this->m_Parameters->SetProcessObject( this );
251 #ifdef cpPlugins_Interface_QT4
252 if( QApplication::instance( ) != NULL )
254 this->m_ParametersDialog = new ParametersQtDialog( );
255 this->m_ParametersDialog->setParameters( this->m_Parameters );
258 #endif // cpPlugins_Interface_QT4
261 // -------------------------------------------------------------------------
262 cpPlugins::Interface::ProcessObject::
266 if( this->m_ParametersDialog != NULL )
267 delete this->m_ParametersDialog;
270 // -------------------------------------------------------------------------
271 void cpPlugins::Interface::ProcessObject::
272 _AddInput( const std::string& name, bool required )
274 auto i = this->m_Inputs.find( name );
275 if( i == this->m_Inputs.end( ) )
277 this->m_Inputs[ name ] = InputProcessObjectPort( required );