1 #include <cpPlugins/Interface/ProcessObject.h>
2 #include <itkProcessObject.h>
4 #ifdef cpPlugins_Interface_QT4
5 #include <QApplication>
6 #include <cpPlugins/Interface/ParametersQtDialog.h>
7 #include <cpPlugins/Interface/SimpleMPRWidget.h>
8 #endif // cpPlugins_Interface_QT4
10 // -------------------------------------------------------------------------
11 std::set< std::string > cpPlugins::Interface::ProcessObject::
12 GetInputsNames( ) const
14 std::set< std::string > names;
15 for( auto i = this->m_Inputs.begin( ); i != this->m_Inputs.end( ); ++i )
16 names.insert( i->first );
20 // -------------------------------------------------------------------------
21 std::set< std::string > cpPlugins::Interface::ProcessObject::
22 GetOutputsNames( ) const
24 std::set< std::string > names;
25 for( auto i = this->m_Outputs.begin( ); i != this->m_Outputs.end( ); ++i )
26 names.insert( i->first );
30 // -------------------------------------------------------------------------
31 unsigned int cpPlugins::Interface::ProcessObject::
32 GetNumberOfInputs( ) const
34 return( this->m_Inputs.size( ) );
37 // -------------------------------------------------------------------------
38 unsigned int cpPlugins::Interface::ProcessObject::
39 GetNumberOfOutputs( ) const
41 return( this->m_Outputs.size( ) );
44 // -------------------------------------------------------------------------
45 cpPlugins::Interface::
46 ProcessObjectPort& cpPlugins::Interface::ProcessObject::
47 GetOutput( const std::string& id )
49 static ProcessObjectPort null_port;
50 auto i = this->m_Outputs.find( id );
51 if( i == this->m_Outputs.end( ) )
60 // -------------------------------------------------------------------------
61 const cpPlugins::Interface::
62 ProcessObjectPort& cpPlugins::Interface::ProcessObject::
63 GetOutput( const std::string& id ) const
65 static const ProcessObjectPort null_port;
66 auto i = this->m_Outputs.find( id );
67 if( i == this->m_Outputs.end( ) )
73 // -------------------------------------------------------------------------
74 bool cpPlugins::Interface::ProcessObject::
75 SetInput( const std::string& id, const ProcessObjectPort& port )
77 auto i = this->m_Inputs.find( id );
78 if( i != this->m_Inputs.end( ) )
88 // -------------------------------------------------------------------------
89 void cpPlugins::Interface::ProcessObject::
92 auto i = this->m_Inputs.begin( );
93 for( ; i != this->m_Inputs.end( ); ++i )
98 // -------------------------------------------------------------------------
99 void cpPlugins::Interface::ProcessObject::
102 auto i = this->m_Outputs.begin( );
103 for( ; i != this->m_Outputs.end( ); ++i )
104 if( i->second.IsValid( ) )
105 i->second->DisconnectPipeline( );
109 // -------------------------------------------------------------------------
110 void cpPlugins::Interface::ProcessObject::
113 this->DisconnectInputs( );
114 this->DisconnectOutputs( );
117 // -------------------------------------------------------------------------
118 itk::ModifiedTimeType cpPlugins::Interface::ProcessObject::
121 auto params_time = this->m_Parameters->GetMTime( );
122 auto filter_time = this->Superclass::GetMTime( );
123 auto ipobj = this->GetITK< itk::ProcessObject >( );
126 auto vpobj = this->GetVTK< vtkAlgorithm >( );
128 filter_time = ( const_cast< vtkAlgorithm* >( vpobj ) )->GetMTime( );
131 filter_time = ipobj->GetMTime( );
132 return( ( params_time < filter_time )? filter_time: params_time );
135 // -------------------------------------------------------------------------
136 std::string cpPlugins::Interface::ProcessObject::
142 // Force upstream updates
143 _TDataContainer::iterator i = this->m_Inputs.begin( );
144 bool need_to_update = false;
145 for( ; i != this->m_Inputs.end( ) && r == ""; ++i )
147 if( i->second.IsValid( ) )
149 Self* src = dynamic_cast< Self* >( i->second->GetSource( ) );
152 need_to_update |= ( this->m_LastExecutionTime < src->GetMTime( ) );
158 r = "cpPlugins::Interface::ProcessObject: No input connected.";
165 if( this->m_LastExecutionTime < this->GetMTime( ) || need_to_update )
167 r = this->_GenerateData( );
168 this->m_LastExecutionTime = this->GetMTime( );
174 // Return error description, if any
178 // -------------------------------------------------------------------------
179 cpPlugins::Interface::ProcessObject::
182 m_LastExecutionTime( 0 ),
183 m_ParametersDialog( NULL ),
186 this->m_Parameters = TParameters::New( );
187 this->m_Parameters->SetProcessObject( this );
189 #ifdef cpPlugins_Interface_QT4
190 if( QApplication::instance( ) != NULL )
192 this->m_ParametersDialog = new ParametersQtDialog( );
193 this->m_ParametersDialog->setParameters( this->m_Parameters );
196 #endif // cpPlugins_Interface_QT4
199 // -------------------------------------------------------------------------
200 cpPlugins::Interface::ProcessObject::
204 if( this->m_ParametersDialog != NULL )
205 delete this->m_ParametersDialog;
208 // -------------------------------------------------------------------------
209 void cpPlugins::Interface::ProcessObject::
210 _AddInput( const std::string& name )
212 typedef typename _TDataContainer::value_type _TValue;
213 auto i = this->m_Inputs.find( name );
214 if( i == this->m_Inputs.end( ) )
215 i = this->m_Inputs.insert( _TValue( name, NULL ) ).first;