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 OutputProcessObjectPort& cpPlugins::Interface::ProcessObject::
47 GetOutput( const std::string& id )
49 static OutputProcessObjectPort null_port;
50 auto i = this->m_Outputs.find( id );
51 if( i == this->m_Outputs.end( ) )
60 // -------------------------------------------------------------------------
61 const cpPlugins::Interface::
62 OutputProcessObjectPort& cpPlugins::Interface::ProcessObject::
63 GetOutput( const std::string& id ) const
65 static const OutputProcessObjectPort 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 OutputProcessObjectPort& 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->DisconnectFromPipeline( );
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 return( ( params_time < filter_time )? params_time: filter_time );
130 // -------------------------------------------------------------------------
131 std::string cpPlugins::Interface::ProcessObject::
136 // Force upstream updates
137 auto i = this->m_Inputs.begin( );
138 bool need_to_update = false;
139 for( ; i != this->m_Inputs.end( ) && r == ""; ++i )
141 if( i->second.IsValid( ) )
143 Self* src = dynamic_cast< Self* >( i->second->GetSource( ) );
146 need_to_update |= ( this->m_LastExecutionTime < src->GetMTime( ) );
158 if( this->m_LastExecutionTime < this->GetMTime( ) || need_to_update )
160 r = this->_GenerateData( );
161 this->m_LastExecutionTime = this->GetMTime( );
167 // Return error description, if any
171 // -------------------------------------------------------------------------
172 cpPlugins::Interface::ProcessObject::
175 m_LastExecutionTime( 0 ),
176 m_ParametersDialog( NULL ),
179 this->m_Parameters = TParameters::New( );
180 this->m_Parameters->SetProcessObject( this );
182 #ifdef cpPlugins_Interface_QT4
183 if( QApplication::instance( ) != NULL )
185 this->m_ParametersDialog = new ParametersQtDialog( );
186 this->m_ParametersDialog->setParameters( this->m_Parameters );
189 #endif // cpPlugins_Interface_QT4
192 // -------------------------------------------------------------------------
193 cpPlugins::Interface::ProcessObject::
197 if( this->m_ParametersDialog != NULL )
198 delete this->m_ParametersDialog;
201 // -------------------------------------------------------------------------
202 void cpPlugins::Interface::ProcessObject::
203 _AddInput( const std::string& name, bool required )
205 auto i = this->m_Inputs.find( name );
206 if( i == this->m_Inputs.end( ) )
208 InputProcessObjectPort new_port( required );
209 this->m_Inputs[ name ] = new_port;