1 #include <cpPlugins/ProcessObject.h>
2 #include <cpPlugins/ParametersQtDialog.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 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 void cpPlugins::ProcessObject::
197 this->Superclass::Modified( );
198 this->m_LastExecutionSpan = -1;
201 // -------------------------------------------------------------------------
202 itk::ModifiedTimeType cpPlugins::ProcessObject::
205 auto params_time = this->m_Parameters.GetMTime( );
206 auto filter_time = this->Superclass::GetMTime( );
207 return( ( params_time > filter_time )? params_time: filter_time );
210 // -------------------------------------------------------------------------
211 void cpPlugins::ProcessObject::
214 // Force upstream updates
215 auto i = this->m_Inputs.begin( );
216 bool need_to_update = false;
217 for( ; i != this->m_Inputs.end( ); ++i )
219 bool iv = i->second.IsValid( );
220 bool ir = i->second.IsRequired( );
223 std::string( "Required input \"" ) + i->first +
224 std::string( "\" is not valid." )
228 Self* src = dynamic_cast< Self* >( i->second->GetSource( ) );
231 need_to_update |= ( this->m_LastExecutionTime < src->GetMTime( ) );
241 if( this->m_LastExecutionTime < this->GetMTime( ) || need_to_update )
243 if( this->m_PrintExecution && this->m_PrintExecutionStream != NULL )
245 *( this->m_PrintExecutionStream )
246 << "cpPlugins: Updating \""
247 << this->GetClassCategory( ) << ":" << this->GetClassName( )
249 this->m_PrintExecutionStream->flush( );
253 auto t_start = cpPlugins_CHRONO;
254 this->_GenerateData( );
255 auto t_end = cpPlugins_CHRONO;
256 this->m_LastExecutionSpan = long( t_end - t_start );
257 this->m_LastExecutionTime = this->GetMTime( );
259 if( this->m_PrintExecution && this->m_PrintExecutionStream != NULL )
261 *( this->m_PrintExecutionStream )
263 << double( this->m_LastExecutionSpan ) / double( 1000 )
264 << " s." << std::endl;
271 // -------------------------------------------------------------------------
272 cpPlugins::ParametersQtDialog* cpPlugins::ProcessObject::
276 ParametersQtDialog* dlg = NULL;
277 if( QApplication::instance( ) != NULL )
279 dlg = new ParametersQtDialog( );
280 dlg->setProcessObject( this );
284 #else // cpPlugins_QT4
286 #endif // cpPlugins_QT4
289 // -------------------------------------------------------------------------
290 bool cpPlugins::ProcessObject::
296 // -------------------------------------------------------------------------
297 void cpPlugins::ProcessObject::
298 SetInteractionObjects( const std::vector< void* >& objs )
303 // -------------------------------------------------------------------------
304 cpPlugins::ProcessObject::
307 m_LastExecutionTime( 0 ),
308 m_LastExecutionSpan( -1 ),
309 m_PrintExecution( false ),
310 m_PrintExecutionStream( &( std::cout ) )
314 // -------------------------------------------------------------------------
315 cpPlugins::ProcessObject::
320 // -------------------------------------------------------------------------
321 void cpPlugins::ProcessObject::
322 _AddInput( const std::string& name, bool required )
324 auto i = this->m_Inputs.find( name );
325 if( i == this->m_Inputs.end( ) )
327 this->m_Inputs[ name ] = InputPort( required );
333 // -------------------------------------------------------------------------
334 void cpPlugins::ProcessObject::
335 _Error( const std::string& error )
340 "Error: \"" << this->GetClassCategory( ) << "::" <<
341 this->GetClassName( ) << "\": " << error