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( ) )
80 if( i->second.GetPointer( ) != port.GetPointer( ) )
92 // -------------------------------------------------------------------------
93 void cpPlugins::Interface::ProcessObject::
96 auto i = this->m_Inputs.begin( );
97 for( ; i != this->m_Inputs.end( ); ++i )
102 // -------------------------------------------------------------------------
103 void cpPlugins::Interface::ProcessObject::
106 auto i = this->m_Outputs.begin( );
107 for( ; i != this->m_Outputs.end( ); ++i )
108 if( i->second.IsValid( ) )
109 i->second->DisconnectPipeline( );
113 // -------------------------------------------------------------------------
114 void cpPlugins::Interface::ProcessObject::
117 this->DisconnectInputs( );
118 this->DisconnectOutputs( );
121 // -------------------------------------------------------------------------
122 itk::ModifiedTimeType cpPlugins::Interface::ProcessObject::
125 auto params_time = this->m_Parameters->GetMTime( );
126 auto filter_time = this->Superclass::GetMTime( );
127 auto ipobj = this->GetITK< itk::ProcessObject >( );
130 auto vpobj = this->GetVTK< vtkAlgorithm >( );
132 filter_time = ( const_cast< vtkAlgorithm* >( vpobj ) )->GetMTime( );
135 filter_time = ipobj->GetMTime( );
136 return( ( params_time < filter_time )? filter_time: params_time );
139 // -------------------------------------------------------------------------
140 std::string cpPlugins::Interface::ProcessObject::
145 // Force upstream updates
146 _TDataContainer::iterator i = this->m_Inputs.begin( );
147 bool need_to_update = false;
148 for( ; i != this->m_Inputs.end( ) && r == ""; ++i )
150 if( i->second.IsValid( ) )
152 Self* src = dynamic_cast< Self* >( i->second->GetSource( ) );
155 need_to_update |= ( this->m_LastExecutionTime < src->GetMTime( ) );
161 r = "cpPlugins::Interface::ProcessObject: No input connected.";
168 if( this->m_LastExecutionTime < this->GetMTime( ) || need_to_update )
170 r = this->_GenerateData( );
171 this->m_LastExecutionTime = this->GetMTime( );
177 // Return error description, if any
181 // -------------------------------------------------------------------------
182 cpPlugins::Interface::ProcessObject::
185 m_LastExecutionTime( 0 ),
186 m_ParametersDialog( NULL ),
189 this->m_Parameters = TParameters::New( );
190 this->m_Parameters->SetProcessObject( this );
192 #ifdef cpPlugins_Interface_QT4
193 if( QApplication::instance( ) != NULL )
195 this->m_ParametersDialog = new ParametersQtDialog( );
196 this->m_ParametersDialog->setParameters( this->m_Parameters );
199 #endif // cpPlugins_Interface_QT4
202 // -------------------------------------------------------------------------
203 cpPlugins::Interface::ProcessObject::
207 if( this->m_ParametersDialog != NULL )
208 delete this->m_ParametersDialog;
211 // -------------------------------------------------------------------------
212 void cpPlugins::Interface::ProcessObject::
213 _AddInput( const std::string& name )
215 typedef typename _TDataContainer::value_type _TValue;
216 auto i = this->m_Inputs.find( name );
217 if( i == this->m_Inputs.end( ) )
219 i = this->m_Inputs.insert( _TValue( name, NULL ) ).first;