1 #include <cpPlugins/BaseObjects/ProcessObject.h>
2 #include <cpPlugins/QT/ParametersDialog.h>
3 #include <cpExtensions/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 void cpPlugins::BaseObjects::ProcessObject::
84 AddInput( const std::string& n, cpPlugins::BaseObjects::DataObject* o )
86 auto it = this->m_Inputs.find( n );
87 if( it != this->m_Inputs.end( ) )
91 // -------------------------------------------------------------------------
92 void cpPlugins::BaseObjects::ProcessObject::
93 SetInput( const std::string& n, cpPlugins::BaseObjects::DataObject* o )
95 this->AddInput( n, o );
98 // -------------------------------------------------------------------------
99 void cpPlugins::BaseObjects::ProcessObject::
102 for( auto i = this->m_Inputs.begin( ); i != this->m_Inputs.end( ); ++i )
107 // -------------------------------------------------------------------------
108 void cpPlugins::BaseObjects::ProcessObject::
111 for( auto i = this->m_Outputs.begin( ); i != this->m_Outputs.end( ); ++i )
112 if( i->second->IsValid( ) )
113 i->second->Get( )->DisconnectFromPipeline( );
117 // -------------------------------------------------------------------------
118 void cpPlugins::BaseObjects::ProcessObject::
121 this->DisconnectInputs( );
122 this->DisconnectOutputs( );
125 // -------------------------------------------------------------------------
126 void cpPlugins::BaseObjects::ProcessObject::
129 this->Superclass::Modified( );
130 this->m_LastExecutionSpan = -1;
133 // -------------------------------------------------------------------------
134 itk::ModifiedTimeType cpPlugins::BaseObjects::ProcessObject::
137 auto params_time = this->m_Parameters.GetMTime( );
138 auto filter_time = this->Superclass::GetMTime( );
139 return( ( params_time > filter_time )? params_time: filter_time );
142 // -------------------------------------------------------------------------
143 void cpPlugins::BaseObjects::ProcessObject::
146 // Force upstream updates
147 bool need_to_update = this->m_ExplicitExecution;
148 for( auto i = this->m_Inputs.begin( ); i != this->m_Inputs.end( ); ++i )
150 bool iv = i->second->IsValid( );
151 bool ir = i->second->IsRequired( );
154 std::string( "Required input \"" ) + i->first +
155 std::string( "\" is not valid." )
159 unsigned int n = i->second->Size( );
160 for( unsigned int j = 0; j < n; ++j )
162 Self* src = i->second->Get( j )->GetSource( );
165 need_to_update |= ( this->m_LastExecutionTime < src->GetMTime( ) );
177 if( this->m_LastExecutionTime < this->GetMTime( ) || need_to_update )
179 if( this->m_PrintExecution && this->m_PrintExecutionStream != NULL )
181 *( this->m_PrintExecutionStream )
182 << "cpPlugins: Updating \""
183 << this->GetName( ) << " ("
184 << this->GetClassCategory( ) << ":" << this->GetClassName( )
186 this->m_PrintExecutionStream->flush( );
190 auto t_start = cpExtensions_CHRONO;
191 this->_GenerateData( );
192 auto t_end = cpExtensions_CHRONO;
193 this->m_LastExecutionSpan = long( t_end - t_start );
194 this->m_LastExecutionTime = this->GetMTime( );
196 if( this->m_PrintExecution && this->m_PrintExecutionStream != NULL )
198 *( this->m_PrintExecutionStream )
200 << double( this->m_LastExecutionSpan ) / double( 1000 )
201 << " s." << std::endl;
208 // -------------------------------------------------------------------------
209 QDialog* cpPlugins::BaseObjects::ProcessObject::
213 cpPlugins::QT::ParametersDialog* dlg = NULL;
214 if( QApplication::instance( ) != NULL )
216 dlg = new cpPlugins::QT::ParametersDialog( );
217 dlg->setProcessObject( this );
221 #else // cpPlugins_QT4
223 #endif // cpPlugins_QT4
226 // -------------------------------------------------------------------------
227 void cpPlugins::BaseObjects::ProcessObject::
228 AddInteractor( vtkRenderWindowInteractor* i )
230 if( this->m_Interactors.insert( i ).second )
234 // -------------------------------------------------------------------------
235 bool cpPlugins::BaseObjects::ProcessObject::
241 // -------------------------------------------------------------------------
242 cpPlugins::BaseObjects::ProcessObject::
247 m_ExplicitExecution( false ),
248 m_LastExecutionTime( 0 ),
249 m_LastExecutionSpan( -1 ),
250 m_PrintExecution( false ),
251 m_PrintExecutionStream( &( std::cout ) )
255 // -------------------------------------------------------------------------
256 cpPlugins::BaseObjects::ProcessObject::
259 for( auto i = this->m_Inputs.begin( ); i != this->m_Inputs.end( ); ++i )
261 for( auto o = this->m_Outputs.begin( ); o != this->m_Outputs.end( ); ++o )
264 this->m_Inputs.clear( );
265 this->m_Outputs.clear( );
268 // -------------------------------------------------------------------------
269 void cpPlugins::BaseObjects::ProcessObject::
270 _Error( const std::string& error )
275 "Error: \"" << this->GetClassCategory( ) << "::" <<
276 this->GetClassName( ) << "\": " << error