1 #include <cpPlugins/BaseObjects/ProcessObject.h>
2 #include <cpPlugins/QT/ParametersDialog.h>
3 #include <cpPlugins/Utility.h>
4 #include <itkProcessObject.h>
5 #include <itkExceptionObject.h>
7 // -------------------------------------------------------------------------
8 cpPlugins::BaseObjects::Parameters*
9 cpPlugins::BaseObjects::ProcessObject::
12 return( &( this->m_Parameters ) );
15 // -------------------------------------------------------------------------
16 const cpPlugins::BaseObjects::Parameters*
17 cpPlugins::BaseObjects::ProcessObject::
18 GetParameters( ) const
20 return( &( this->m_Parameters ) );
23 // -------------------------------------------------------------------------
24 void cpPlugins::BaseObjects::ProcessObject::
25 SetITK( itk::LightObject* o )
27 // Polymorphism: do nothing -> this is a filter!!!
30 // -------------------------------------------------------------------------
31 void cpPlugins::BaseObjects::ProcessObject::
32 SetVTK( vtkObjectBase* o )
34 // Polymorphism: do nothing -> this is a filter!!!
37 // -------------------------------------------------------------------------
38 std::set< std::string > cpPlugins::BaseObjects::ProcessObject::
39 GetInputsNames( ) const
41 std::set< std::string > names;
42 for( auto i = this->m_Inputs.begin( ); i != this->m_Inputs.end( ); ++i )
43 names.insert( i->first );
47 // -------------------------------------------------------------------------
48 std::set< std::string > cpPlugins::BaseObjects::ProcessObject::
49 GetOutputsNames( ) const
51 std::set< std::string > names;
52 for( auto i = this->m_Outputs.begin( ); i != this->m_Outputs.end( ); ++i )
53 names.insert( i->first );
57 // -------------------------------------------------------------------------
58 unsigned int cpPlugins::BaseObjects::ProcessObject::
59 GetNumberOfInputs( ) const
61 return( this->m_Inputs.size( ) );
64 // -------------------------------------------------------------------------
65 unsigned int cpPlugins::BaseObjects::ProcessObject::
66 GetNumberOfOutputs( ) const
68 return( this->m_Outputs.size( ) );
71 // -------------------------------------------------------------------------
72 unsigned int cpPlugins::BaseObjects::ProcessObject::
73 GetInputSize( const std::string& n ) const
75 auto it = this->m_Inputs.find( n );
76 if( it != this->m_Inputs.end( ) )
77 return( it->second->Size( ) );
82 // -------------------------------------------------------------------------
83 bool cpPlugins::BaseObjects::ProcessObject::
84 IsInputMultiple( const std::string& n ) const
86 auto i = this->m_Inputs.find( n );
87 if( i != this->m_Inputs.end( ) )
88 return( dynamic_cast< MultipleInputsPort* >( i->second ) != NULL );
93 // -------------------------------------------------------------------------
94 void cpPlugins::BaseObjects::ProcessObject::
95 AddInput( const std::string& n, cpPlugins::BaseObjects::DataObject* o )
97 auto it = this->m_Inputs.find( n );
98 if( it != this->m_Inputs.end( ) )
102 // -------------------------------------------------------------------------
103 void cpPlugins::BaseObjects::ProcessObject::
104 SetInput( const std::string& n, cpPlugins::BaseObjects::DataObject* o )
106 this->AddInput( n, o );
109 // -------------------------------------------------------------------------
110 void cpPlugins::BaseObjects::ProcessObject::
113 for( auto i = this->m_Inputs.begin( ); i != this->m_Inputs.end( ); ++i )
118 // -------------------------------------------------------------------------
119 void cpPlugins::BaseObjects::ProcessObject::
122 for( auto i = this->m_Outputs.begin( ); i != this->m_Outputs.end( ); ++i )
123 if( i->second->IsValid( ) )
124 i->second->Get( )->DisconnectFromPipeline( );
128 // -------------------------------------------------------------------------
129 void cpPlugins::BaseObjects::ProcessObject::
132 this->DisconnectInputs( );
133 this->DisconnectOutputs( );
136 // -------------------------------------------------------------------------
137 void cpPlugins::BaseObjects::ProcessObject::
140 this->Superclass::Modified( );
141 this->m_LastExecutionSpan = -1;
144 // -------------------------------------------------------------------------
145 itk::ModifiedTimeType cpPlugins::BaseObjects::ProcessObject::
148 auto params_time = this->m_Parameters.GetMTime( );
149 auto filter_time = this->Superclass::GetMTime( );
150 return( ( params_time > filter_time )? params_time: filter_time );
153 // -------------------------------------------------------------------------
154 void cpPlugins::BaseObjects::ProcessObject::
157 // Force upstream updates
158 bool need_to_update = this->m_ExplicitExecution;
159 for( auto i = this->m_Inputs.begin( ); i != this->m_Inputs.end( ); ++i )
161 bool iv = i->second->IsValid( );
162 bool ir = i->second->IsRequired( );
165 std::string( "Required input \"" ) + i->first +
166 std::string( "\" is not valid." )
170 unsigned int n = i->second->Size( );
171 for( unsigned int j = 0; j < n; ++j )
173 Self* src = i->second->Get( j )->GetSource( );
176 need_to_update |= ( this->m_LastExecutionTime < src->GetMTime( ) );
188 if( this->m_LastExecutionTime < this->GetMTime( ) || need_to_update )
190 if( this->m_PrintExecution && this->m_PrintExecutionStream != NULL )
192 *( this->m_PrintExecutionStream )
193 << "cpPlugins: Updating \""
194 << this->GetName( ) << " ("
195 << this->GetClassCategory( ) << ":" << this->GetClassName( )
197 this->m_PrintExecutionStream->flush( );
201 auto t_start = cpPlugins_CHRONO;
202 this->_GenerateData( );
203 auto t_end = cpPlugins_CHRONO;
204 this->m_LastExecutionSpan = long( t_end - t_start );
205 this->m_LastExecutionTime = this->GetMTime( );
207 if( this->m_PrintExecution && this->m_PrintExecutionStream != NULL )
209 *( this->m_PrintExecutionStream )
211 << double( this->m_LastExecutionSpan ) / double( 1000 )
212 << " s." << std::endl;
219 // -------------------------------------------------------------------------
220 QDialog* cpPlugins::BaseObjects::ProcessObject::
224 cpPlugins::QT::ParametersDialog* dlg = NULL;
225 if( QApplication::instance( ) != NULL )
227 dlg = new cpPlugins::QT::ParametersDialog( );
228 dlg->setProcessObject( this );
232 #else // cpPlugins_QT4
234 #endif // cpPlugins_QT4
237 // -------------------------------------------------------------------------
238 void cpPlugins::BaseObjects::ProcessObject::
239 AddInteractor( vtkRenderWindowInteractor* i )
241 if( this->m_Interactors.insert( i ).second )
245 // -------------------------------------------------------------------------
246 bool cpPlugins::BaseObjects::ProcessObject::
252 // -------------------------------------------------------------------------
253 cpPlugins::BaseObjects::ProcessObject::
258 m_ExplicitExecution( false ),
259 m_LastExecutionTime( 0 ),
260 m_LastExecutionSpan( -1 ),
261 m_PrintExecution( false ),
262 m_PrintExecutionStream( &( std::cout ) )
266 // -------------------------------------------------------------------------
267 cpPlugins::BaseObjects::ProcessObject::
270 for( auto i = this->m_Inputs.begin( ); i != this->m_Inputs.end( ); ++i )
272 for( auto o = this->m_Outputs.begin( ); o != this->m_Outputs.end( ); ++o )
275 this->m_Inputs.clear( );
276 this->m_Outputs.clear( );
279 // -------------------------------------------------------------------------
280 void cpPlugins::BaseObjects::ProcessObject::
281 _Error( const std::string& error )
286 "Error: \"" << this->GetClassCategory( ) << "::" <<
287 this->GetClassName( ) << "\": " << error