1 #include <cpPlugins/ProcessObject.h>
2 #include <cpPlugins/ParametersQDialog.h>
3 #include <itkProcessObject.h>
4 #include <itkExceptionObject.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 GetOutputPort( 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 GetOutputPort( 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 // -------------------------------------------------------------------------
98 bool cpPlugins::ProcessObject::
99 SetInputPort( const std::string& id, const OutputPort& port )
101 auto i = this->m_Inputs.find( id );
102 if( i != this->m_Inputs.end( ) )
104 if( i->second.GetPointer( ) != port.GetPointer( ) )
116 // -------------------------------------------------------------------------
117 void cpPlugins::ProcessObject::
120 auto i = this->m_Inputs.begin( );
121 for( ; i != this->m_Inputs.end( ); ++i )
126 // -------------------------------------------------------------------------
127 void cpPlugins::ProcessObject::
130 auto i = this->m_Outputs.begin( );
131 for( ; i != this->m_Outputs.end( ); ++i )
132 if( i->second.IsValid( ) )
133 i->second->DisconnectFromPipeline( );
137 // -------------------------------------------------------------------------
138 void cpPlugins::ProcessObject::
141 this->DisconnectInputs( );
142 this->DisconnectOutputs( );
145 // -------------------------------------------------------------------------
146 void cpPlugins::ProcessObject::
149 this->Superclass::Modified( );
150 this->m_LastExecutionSpan = -1;
153 // -------------------------------------------------------------------------
154 itk::ModifiedTimeType cpPlugins::ProcessObject::
157 auto params_time = this->m_Parameters.GetMTime( );
158 auto filter_time = this->Superclass::GetMTime( );
159 return( ( params_time > filter_time )? params_time: filter_time );
162 // -------------------------------------------------------------------------
163 void cpPlugins::ProcessObject::
166 // Force upstream updates
167 auto i = this->m_Inputs.begin( );
168 bool need_to_update = this->m_CouldHaveExplicitReExecution;
169 need_to_update &= this->m_ExplicitReExecution;
170 for( ; i != this->m_Inputs.end( ); ++i )
172 bool iv = i->second.IsValid( );
173 bool ir = i->second.IsRequired( );
176 std::string( "Required input \"" ) + i->first +
177 std::string( "\" is not valid." )
181 Self* src = dynamic_cast< Self* >( i->second->GetSource( ) );
184 need_to_update |= ( this->m_LastExecutionTime < src->GetMTime( ) );
194 if( this->m_LastExecutionTime < this->GetMTime( ) || need_to_update )
196 if( this->m_PrintExecution && this->m_PrintExecutionStream != NULL )
198 *( this->m_PrintExecutionStream )
199 << "cpPlugins: Updating \""
200 << this->GetName( ) << " ("
201 << this->GetClassCategory( ) << ":" << this->GetClassName( )
203 this->m_PrintExecutionStream->flush( );
207 auto t_start = cpPlugins_CHRONO;
208 this->_GenerateData( );
209 auto t_end = cpPlugins_CHRONO;
210 this->m_LastExecutionSpan = long( t_end - t_start );
211 this->m_LastExecutionTime = this->GetMTime( );
213 if( this->m_PrintExecution && this->m_PrintExecutionStream != NULL )
215 *( this->m_PrintExecutionStream )
217 << double( this->m_LastExecutionSpan ) / double( 1000 )
218 << " s." << std::endl;
225 // -------------------------------------------------------------------------
226 QDialog* cpPlugins::ProcessObject::
230 ParametersQDialog* dlg = NULL;
231 if( QApplication::instance( ) != NULL )
233 dlg = new ParametersQDialog( );
234 dlg->setProcessObject( this );
238 #else // cpPlugins_QT4
240 #endif // cpPlugins_QT4
243 // -------------------------------------------------------------------------
244 bool cpPlugins::ProcessObject::
250 // -------------------------------------------------------------------------
251 void cpPlugins::ProcessObject::
252 SetInteractionObjects( const std::vector< void* >& objs )
257 // -------------------------------------------------------------------------
258 cpPlugins::ProcessObject::
263 m_CouldHaveExplicitReExecution( false ),
264 m_ExplicitReExecution( false ),
265 m_LastExecutionTime( 0 ),
266 m_LastExecutionSpan( -1 ),
267 m_PrintExecution( false ),
268 m_PrintExecutionStream( &( std::cout ) )
272 // -------------------------------------------------------------------------
273 cpPlugins::ProcessObject::
278 // -------------------------------------------------------------------------
279 void cpPlugins::ProcessObject::
280 _AddInput( const std::string& name, bool required )
282 auto i = this->m_Inputs.find( name );
283 if( i == this->m_Inputs.end( ) )
285 this->m_Inputs[ name ] = InputPort( required );
291 // -------------------------------------------------------------------------
292 void cpPlugins::ProcessObject::
293 _Error( const std::string& error )
298 "Error: \"" << this->GetClassCategory( ) << "::" <<
299 this->GetClassName( ) << "\": " << error