]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Interface/ProcessObject.cxx
Integration of new functionalities into ProcessObject and DataObject
[cpPlugins.git] / lib / cpPlugins / Interface / ProcessObject.cxx
1 #include <cpPlugins/Interface/ProcessObject.h>
2 #include <cpPlugins/Interface/DataObject.h>
3
4 // -------------------------------------------------------------------------
5 cpPlugins::Interface::ProcessObject::
6 ProcessObject( )
7   : Superclass( ),
8     m_OutputsDisconnected( false )
9 {
10 }
11
12 // -------------------------------------------------------------------------
13 cpPlugins::Interface::ProcessObject::
14 ~ProcessObject( )
15 {
16   this->_DeleteOutputs( );
17 }
18
19 // -------------------------------------------------------------------------
20 std::string cpPlugins::Interface::ProcessObject::
21 GetClassName( ) const
22 {
23   return( "cpPlugins::Interface::ProcessObject" );
24 }
25
26 // -------------------------------------------------------------------------
27 const cpPlugins::Interface::ProcessObject::
28 TParameters& cpPlugins::Interface::ProcessObject::
29 GetDefaultParameters( ) const
30 {
31   return( this->m_DefaultParameters );
32 }
33
34 // -------------------------------------------------------------------------
35 void cpPlugins::Interface::ProcessObject::
36 SetParameters( const TParameters& params )
37 {
38   this->m_Parameters = params;
39 }
40
41 // -------------------------------------------------------------------------
42 unsigned int cpPlugins::Interface::ProcessObject::
43 GetNumberOfInputs( ) const
44 {
45   return( this->m_Inputs.size( ) );
46 }
47
48 // -------------------------------------------------------------------------
49 unsigned int cpPlugins::Interface::ProcessObject::
50 GetNumberOfOutputs( ) const
51 {
52   return( this->m_Outputs.size( ) );
53 }
54
55 // -------------------------------------------------------------------------
56 void cpPlugins::Interface::ProcessObject::
57 SetNumberOfInputs( unsigned int n )
58 {
59   this->m_Inputs.clear( );
60   this->m_Inputs.resize( n, NULL );
61 }
62
63 // -------------------------------------------------------------------------
64 void cpPlugins::Interface::ProcessObject::
65 SetNumberOfOutputs( unsigned int n )
66 {
67   this->_DeleteOutputs( );
68   this->m_Outputs.clear( );
69   this->m_Outputs.resize( n, NULL );
70   this->m_OutputsDisconnected = false;
71 }
72
73 // -------------------------------------------------------------------------
74 void cpPlugins::Interface::ProcessObject::
75 SetInput(
76   unsigned int idx, const cpPlugins::Interface::DataObject* dobj
77   )
78 {
79   if( idx < this->m_Inputs.size( ) )
80     this->m_Inputs[ idx ] = dobj;
81 }
82
83 // -------------------------------------------------------------------------
84 cpPlugins::Interface::DataObject* cpPlugins::Interface::ProcessObject::
85 GetOutput( unsigned int idx )
86 {
87   if( idx < this->m_Outputs.size( ) )
88     return( this->m_Outputs[ idx ] );
89   else
90     return( NULL );
91 }
92
93 // -------------------------------------------------------------------------
94 std::string cpPlugins::Interface::ProcessObject::
95 Update( )
96 {
97   // Force upstream updates
98   for( unsigned int idx = 0; idx < this->m_Inputs.size( ); ++idx )
99     this->m_Inputs[ idx ]->GetSource( )->Update( );
100
101   // Current update
102   std::string ret = this->_GenerateData( );
103   this->m_OutputsDisconnected = false;
104
105   // Return error description, if any
106   return( ret );
107 }
108
109 // -------------------------------------------------------------------------
110 void cpPlugins::Interface::ProcessObject::
111 DisconnectOutputs( )
112 {
113   this->m_OutputsDisconnected = true;
114   for( unsigned int idx = 0; idx < this->m_Outputs.size( ); ++idx )
115     if( this->m_Outputs[ idx ] != NULL )
116       this->m_Outputs[ idx ]->GetDataObject( )->DisconnectPipeline( );
117 }
118
119 // -------------------------------------------------------------------------
120 itk::DataObject* cpPlugins::Interface::ProcessObject::
121 _GetInput( unsigned int idx )
122 {
123   if( idx < this->m_Inputs.size( ) )
124     return( this->m_Inputs[ idx ]->GetDataObject( ) );
125   else
126     return( NULL );
127 }
128
129 // -------------------------------------------------------------------------
130 void cpPlugins::Interface::ProcessObject::
131 _SetOutput( unsigned int idx, itk::DataObject* dobj )
132 {
133   if( idx < this->m_Outputs.size( ) )
134     if( this->m_Outputs[ idx ] != NULL )
135       this->m_Outputs[ idx ]->SetDataObject( dobj );
136 }
137
138 // -------------------------------------------------------------------------
139 void cpPlugins::Interface::ProcessObject::
140 _DeleteOutputs( )
141 {
142   if( !( this->m_OutputsDisconnected ) )
143     for( unsigned int idx = 0; idx < this->m_Outputs.size( ); ++idx )
144       if( this->m_Outputs[ idx ] != NULL )
145         delete this->m_Outputs[ idx ];
146 }
147
148 // eof - $RCSfile$