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