1 #include <cpPlugins/ProcessObject.h>
2 #include <cpPlugins/ParametersQtDialog.h>
3 #include <itkProcessObject.h>
6 // -------------------------------------------------------------------------
7 cpPlugins::Parameters* cpPlugins::ProcessObject::
10 return( &( this->m_Parameters ) );
13 // -------------------------------------------------------------------------
14 const cpPlugins::Parameters* cpPlugins::ProcessObject::
15 GetParameters( ) const
17 return( &( this->m_Parameters ) );
20 // -------------------------------------------------------------------------
21 void cpPlugins::ProcessObject::
22 SetITK( itk::LightObject* o )
24 // Polymorphism: do nothing -> this is a filter!!!
27 // -------------------------------------------------------------------------
28 void cpPlugins::ProcessObject::
29 SetVTK( vtkObjectBase* o )
31 // Polymorphism: do nothing -> this is a filter!!!
34 // -------------------------------------------------------------------------
35 std::set< std::string > cpPlugins::ProcessObject::
36 GetInputsNames( ) const
38 std::set< std::string > names;
39 for( auto i = this->m_Inputs.begin( ); i != this->m_Inputs.end( ); ++i )
40 names.insert( i->first );
44 // -------------------------------------------------------------------------
45 std::set< std::string > cpPlugins::ProcessObject::
46 GetOutputsNames( ) const
48 std::set< std::string > names;
49 for( auto i = this->m_Outputs.begin( ); i != this->m_Outputs.end( ); ++i )
50 names.insert( i->first );
54 // -------------------------------------------------------------------------
55 unsigned int cpPlugins::ProcessObject::
56 GetNumberOfInputs( ) const
58 return( this->m_Inputs.size( ) );
61 // -------------------------------------------------------------------------
62 unsigned int cpPlugins::ProcessObject::
63 GetNumberOfOutputs( ) const
65 return( this->m_Outputs.size( ) );
68 // -------------------------------------------------------------------------
70 OutputPort& cpPlugins::ProcessObject::
71 GetOutput( const std::string& id )
73 static OutputPort null_port;
74 auto i = this->m_Outputs.find( id );
75 if( i == this->m_Outputs.end( ) )
84 // -------------------------------------------------------------------------
86 OutputPort& cpPlugins::ProcessObject::
87 GetOutput( const std::string& id ) const
89 static const OutputPort null_port;
90 auto i = this->m_Outputs.find( id );
91 if( i == this->m_Outputs.end( ) )
97 // -------------------------------------------------------------------------
99 DataObject* cpPlugins::ProcessObject::
100 GetInputData( const std::string& id )
102 auto i = this->m_Inputs.find( id );
103 if( i != this->m_Inputs.end( ) )
104 return( dynamic_cast< DataObject* >( i->second.GetPointer( ) ) );
109 // -------------------------------------------------------------------------
111 DataObject* cpPlugins::ProcessObject::
112 GetInputData( const std::string& id ) const
114 auto i = this->m_Inputs.find( id );
115 if( i != this->m_Inputs.end( ) )
116 return( dynamic_cast< const DataObject* >( i->second.GetPointer( ) ) );
121 // -------------------------------------------------------------------------
123 DataObject* cpPlugins::ProcessObject::
124 GetOutputData( const std::string& id )
126 auto i = this->m_Outputs.find( id );
127 if( i != this->m_Outputs.end( ) )
128 return( dynamic_cast< DataObject* >( i->second.GetPointer( ) ) );
133 // -------------------------------------------------------------------------
135 DataObject* cpPlugins::ProcessObject::
136 GetOutputData( const std::string& id ) const
138 auto i = this->m_Outputs.find( id );
139 if( i != this->m_Outputs.end( ) )
140 return( dynamic_cast< const DataObject* >( i->second.GetPointer( ) ) );
145 // -------------------------------------------------------------------------
146 bool cpPlugins::ProcessObject::
147 SetInput( const std::string& id, const OutputPort& port )
149 auto i = this->m_Inputs.find( id );
150 if( i != this->m_Inputs.end( ) )
152 if( i->second.GetPointer( ) != port.GetPointer( ) )
164 // -------------------------------------------------------------------------
165 void cpPlugins::ProcessObject::
168 auto i = this->m_Inputs.begin( );
169 for( ; i != this->m_Inputs.end( ); ++i )
174 // -------------------------------------------------------------------------
175 void cpPlugins::ProcessObject::
178 auto i = this->m_Outputs.begin( );
179 for( ; i != this->m_Outputs.end( ); ++i )
180 if( i->second.IsValid( ) )
181 i->second->DisconnectFromPipeline( );
185 // -------------------------------------------------------------------------
186 void cpPlugins::ProcessObject::
189 this->DisconnectInputs( );
190 this->DisconnectOutputs( );
193 // -------------------------------------------------------------------------
194 itk::ModifiedTimeType cpPlugins::ProcessObject::
197 auto params_time = this->m_Parameters.GetMTime( );
198 auto filter_time = this->Superclass::GetMTime( );
199 return( ( params_time > filter_time )? params_time: filter_time );
202 // -------------------------------------------------------------------------
203 std::string cpPlugins::ProcessObject::
208 // Force upstream updates
209 auto i = this->m_Inputs.begin( );
210 bool need_to_update = false;
211 for( ; i != this->m_Inputs.end( ) && r == ""; ++i )
213 bool iv = i->second.IsValid( );
214 bool ir = i->second.IsRequired( );
217 "ProcessObject: Required input \"" +
218 i->first + "@" + this->GetClassName( ) +
219 "\" is not valid (=NULL).";
222 Self* src = dynamic_cast< Self* >( i->second->GetSource( ) );
225 need_to_update |= ( this->m_LastExecutionTime < src->GetMTime( ) );
237 if( this->m_LastExecutionTime < this->GetMTime( ) || need_to_update )
240 << "cpPlugins: Updating \""
241 << this->GetClassName( ) << ":" << this->GetClassCategory( )
245 std::chrono::duration_cast< std::chrono::milliseconds >(
246 std::chrono::system_clock::now( ).time_since_epoch( )
248 r = this->_GenerateData( );
250 std::chrono::duration_cast< std::chrono::milliseconds >(
251 std::chrono::system_clock::now( ).time_since_epoch( )
253 this->m_LastExecutionTime = this->GetMTime( );
254 std::cout << "done in " << ( ( end - start ) / 1000 ) << "s!" << std::endl;
260 // Return error description, if any
264 // -------------------------------------------------------------------------
265 cpPlugins::ParametersQtDialog* cpPlugins::ProcessObject::
269 ParametersQtDialog* dlg = NULL;
270 if( QApplication::instance( ) != NULL )
272 dlg = new ParametersQtDialog( );
273 dlg->setProcessObject( this );
277 #else // cpPlugins_QT4
279 #endif // cpPlugins_QT4
282 // -------------------------------------------------------------------------
283 bool cpPlugins::ProcessObject::
289 // -------------------------------------------------------------------------
290 void cpPlugins::ProcessObject::
291 SetInteractionObjects( const std::vector< void* >& objs )
296 // -------------------------------------------------------------------------
297 cpPlugins::ProcessObject::
300 m_LastExecutionTime( 0 )
304 // -------------------------------------------------------------------------
305 cpPlugins::ProcessObject::
310 // -------------------------------------------------------------------------
311 void cpPlugins::ProcessObject::
312 _AddInput( const std::string& name, bool required )
314 auto i = this->m_Inputs.find( name );
315 if( i == this->m_Inputs.end( ) )
317 this->m_Inputs[ name ] = InputPort( required );