Orfeo Toolbox  4.0
otbWriterWatcherBase.cxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12  Some parts of this code are derived from ITK. See ITKCopyright.txt
13  for details.
14 
15 
16  This software is distributed WITHOUT ANY WARRANTY; without even
17  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18  PURPOSE. See the above copyright notices for more information.
19 
20 =========================================================================*/
21 #include "otbWriterWatcherBase.h"
22 
23 namespace otb
24 {
25 
28 {
29  // Initialize state
30  m_Comment = "Not watching any object";
31  m_Process = 0;
32 }
33 
36  const char *comment)
37 {
38  // Initialize state
39  m_Process = process;
40  m_Comment = comment;
41 
42  // Create a series of commands
43  m_StartWriterCommand = CommandType::New();
44  m_EndWriterCommand = CommandType::New();
45  m_ProgressWriterCommand = CommandType::New();
46  m_StartFilterCommand = CommandType::New();
47  m_EndFilterCommand = CommandType::New();
48  m_ProgressFilterCommand = CommandType::New();
49 
50  // Assign the callbacks
51  m_StartFilterCommand->SetCallbackFunction(this,
53  m_EndFilterCommand->SetCallbackFunction(this,
55  m_ProgressFilterCommand->SetCallbackFunction(this,
57  m_StartWriterCommand->SetCallbackFunction(this,
59  m_EndWriterCommand->SetCallbackFunction(this,
61  m_ProgressWriterCommand->SetCallbackFunction(this,
63 
64  // Add the commands as observers
65  m_StartWriterTag = m_Process->AddObserver(itk::StartEvent(),
66  m_StartWriterCommand);
67 
68  m_EndWriterTag = m_Process->AddObserver(itk::EndEvent(),
69  m_EndWriterCommand);
70 
71  m_ProgressWriterTag = m_Process->AddObserver(itk::ProgressEvent(),
72  m_ProgressWriterCommand);
73 
74  // Try to get the filter that is wired to m_Process.
75  if (m_Process->GetInputs()[0]->GetSource())
76  {
77  m_SourceProcess = m_Process->GetInputs()[0]->GetSource();
78 
79  // Add the commands as observers
80  m_StartFilterTag = m_SourceProcess->AddObserver(itk::StartEvent(),
81  m_StartFilterCommand);
82 
83  m_EndFilterTag = m_SourceProcess->AddObserver(itk::EndEvent(),
84  m_EndFilterCommand);
85 
86  m_ProgressFilterTag = m_SourceProcess->AddObserver(itk::ProgressEvent(),
87  m_ProgressFilterCommand);
88  }
89 }
90 
93  const char *comment)
94 {
95  // Initialize state
96  m_Process = process;
97  m_Comment = comment;
98 
99  // Create a series of commands
100  m_StartWriterCommand = CommandType::New();
101  m_EndWriterCommand = CommandType::New();
102  m_ProgressWriterCommand = CommandType::New();
103  m_StartFilterCommand = CommandType::New();
104  m_EndFilterCommand = CommandType::New();
105  m_ProgressFilterCommand = CommandType::New();
106 
107  // Assign the callbacks
108  m_StartFilterCommand->SetCallbackFunction(this,
110  m_EndFilterCommand->SetCallbackFunction(this,
112  m_ProgressFilterCommand->SetCallbackFunction(this,
114  m_StartWriterCommand->SetCallbackFunction(this,
116  m_EndWriterCommand->SetCallbackFunction(this,
118  m_ProgressWriterCommand->SetCallbackFunction(this,
120 
121  // Add the commands as observers
122  m_StartWriterTag = m_Process->AddObserver(itk::StartEvent(),
123  m_StartWriterCommand);
124 
125  m_EndWriterTag = m_Process->AddObserver(itk::EndEvent(),
126  m_EndWriterCommand);
127 
128  m_ProgressWriterTag = m_Process->AddObserver(itk::ProgressEvent(),
129  m_ProgressWriterCommand);
130 
131  m_SourceProcess = source;
132 
133  // Add the commands as observers
134  m_StartFilterTag = m_SourceProcess->AddObserver(itk::StartEvent(),
135  m_StartFilterCommand);
136 
137  m_EndFilterTag = m_SourceProcess->AddObserver(itk::EndEvent(),
138  m_EndFilterCommand);
139 
140  m_ProgressFilterTag = m_SourceProcess->AddObserver(itk::ProgressEvent(),
141  m_ProgressFilterCommand);
142 }
143 
146 {
147  // Remove any observers we have on the old process object
148  if (m_Process)
149  {
150  if (m_StartWriterCommand)
151  {
152  m_Process->RemoveObserver(m_StartWriterTag);
153  }
154  if (m_EndWriterCommand)
155  {
156  m_Process->RemoveObserver(m_EndWriterTag);
157  }
158  if (m_ProgressWriterCommand)
159  {
160  m_Process->RemoveObserver(m_ProgressWriterTag);
161  }
162  }
163  if (m_SourceProcess)
164  {
165  if (m_StartFilterCommand)
166  {
167  m_SourceProcess->RemoveObserver(m_StartFilterTag);
168  }
169  if (m_EndFilterCommand)
170  {
171  m_SourceProcess->RemoveObserver(m_EndFilterTag);
172  }
173  if (m_ProgressFilterCommand)
174  {
175  m_SourceProcess->RemoveObserver(m_ProgressFilterTag);
176  }
177  }
178 
179  // Initialize state
180  m_TimeProbe = watch.m_TimeProbe;
181  m_Process = watch.m_Process;
182  m_SourceProcess = watch.m_SourceProcess;
183  m_Comment = watch.m_Comment;
184 
185  m_StartFilterTag = 0;
186  m_EndFilterTag = 0;
187  m_ProgressFilterTag = 0;
188  m_StartWriterTag = 0;
189  m_EndWriterTag = 0;
190  m_ProgressWriterTag = 0;
191 
192  // Create a series of commands
193  if (m_Process)
194  {
195  m_StartWriterCommand = CommandType::New();
196  m_EndWriterCommand = CommandType::New();
197  m_ProgressWriterCommand = CommandType::New();
198 
199  // Assign the callbacks
200  m_StartWriterCommand->SetCallbackFunction(this,
202  m_EndWriterCommand->SetCallbackFunction(this,
204  m_ProgressWriterCommand->SetCallbackFunction(this,
206 
207  // Add the commands as observers
208  m_StartWriterTag = m_Process->AddObserver(itk::StartEvent(), m_StartWriterCommand);
209  m_EndWriterTag = m_Process->AddObserver(itk::EndEvent(), m_EndWriterCommand);
210  m_ProgressWriterTag
211  = m_Process->AddObserver(itk::ProgressEvent(), m_ProgressWriterCommand);
212  }
213 
214  if (m_SourceProcess)
215  {
216  m_StartFilterCommand = CommandType::New();
217  m_EndFilterCommand = CommandType::New();
218  m_ProgressFilterCommand = CommandType::New();
219 
220  // Assign the callbacks
221  m_StartFilterCommand->SetCallbackFunction(this,
223  m_EndFilterCommand->SetCallbackFunction(this,
225  m_ProgressFilterCommand->SetCallbackFunction(this,
227 
228  // Add the commands as observers
229  m_StartFilterTag = m_SourceProcess->AddObserver(itk::StartEvent(), m_StartFilterCommand);
230  m_EndFilterTag = m_SourceProcess->AddObserver(itk::EndEvent(), m_EndFilterCommand);
231  m_ProgressFilterTag
232  = m_SourceProcess->AddObserver(itk::ProgressEvent(), m_ProgressFilterCommand);
233  }
234 }
235 
236 void
239 {
240 // Remove any observers we have on the old process object
241  if (m_Process)
242  {
243  if (m_StartWriterCommand)
244  {
245  m_Process->RemoveObserver(m_StartWriterTag);
246  }
247  if (m_EndWriterCommand)
248  {
249  m_Process->RemoveObserver(m_EndWriterTag);
250  }
251  if (m_ProgressWriterCommand)
252  {
253  m_Process->RemoveObserver(m_ProgressWriterTag);
254  }
255  }
256  if (m_SourceProcess)
257  {
258  if (m_StartFilterCommand)
259  {
260  m_SourceProcess->RemoveObserver(m_StartFilterTag);
261  }
262  if (m_EndFilterCommand)
263  {
264  m_SourceProcess->RemoveObserver(m_EndFilterTag);
265  }
266  if (m_ProgressFilterCommand)
267  {
268  m_SourceProcess->RemoveObserver(m_ProgressFilterTag);
269  }
270  }
271 
272  // Initialize state
273  m_TimeProbe = watch.m_TimeProbe;
274  m_Process = watch.m_Process;
275  m_SourceProcess = watch.m_SourceProcess;
276  m_Comment = watch.m_Comment;
277 
278  m_StartFilterTag = 0;
279  m_EndFilterTag = 0;
280  m_ProgressFilterTag = 0;
281  m_StartWriterTag = 0;
282  m_EndWriterTag = 0;
283  m_ProgressWriterTag = 0;
284 
285  // Create a series of commands
286  if (m_Process)
287  {
288  m_StartWriterCommand = CommandType::New();
289  m_EndWriterCommand = CommandType::New();
290  m_ProgressWriterCommand = CommandType::New();
291 
292  // Assign the callbacks
293  m_StartWriterCommand->SetCallbackFunction(this,
295  m_EndWriterCommand->SetCallbackFunction(this,
297  m_ProgressWriterCommand->SetCallbackFunction(this,
299 
300  // Add the commands as observers
301  m_StartWriterTag = m_Process->AddObserver(itk::StartEvent(), m_StartWriterCommand);
302  m_EndWriterTag = m_Process->AddObserver(itk::EndEvent(), m_EndWriterCommand);
303  m_ProgressWriterTag
304  = m_Process->AddObserver(itk::ProgressEvent(), m_ProgressWriterCommand);
305  }
306  if (m_SourceProcess)
307  {
308  m_StartFilterCommand = CommandType::New();
309  m_EndFilterCommand = CommandType::New();
310  m_ProgressFilterCommand = CommandType::New();
311 
312  // Assign the callbacks
313  m_StartFilterCommand->SetCallbackFunction(this,
315  m_EndFilterCommand->SetCallbackFunction(this,
317  m_ProgressFilterCommand->SetCallbackFunction(this,
319 
320  // Add the commands as observers
321  m_StartFilterTag = m_SourceProcess->AddObserver(itk::StartEvent(), m_StartFilterCommand);
322  m_EndFilterTag = m_SourceProcess->AddObserver(itk::EndEvent(), m_EndFilterCommand);
323  m_ProgressFilterTag
324  = m_SourceProcess->AddObserver(itk::ProgressEvent(), m_ProgressFilterCommand);
325  }
326 }
327 
330 {
331  // Remove any observers we have on the old process object
332  if (m_Process)
333  {
334  if (m_StartWriterCommand)
335  {
336  m_Process->RemoveObserver(m_StartWriterTag);
337  }
338  if (m_EndWriterCommand)
339  {
340  m_Process->RemoveObserver(m_EndWriterTag);
341  }
342  if (m_ProgressWriterCommand)
343  {
344  m_Process->RemoveObserver(m_ProgressWriterTag);
345  }
346  }
347  if (m_SourceProcess)
348  {
349  if (m_StartFilterCommand)
350  {
351  m_SourceProcess->RemoveObserver(m_StartFilterTag);
352  }
353  if (m_EndFilterCommand)
354  {
355  m_SourceProcess->RemoveObserver(m_EndFilterTag);
356  }
357  if (m_ProgressFilterCommand)
358  {
359  m_SourceProcess->RemoveObserver(m_ProgressFilterTag);
360  }
361  }
362 }
363 
364 } // end namespace otb

Generated at Sat Mar 8 2014 16:28:52 for Orfeo Toolbox with doxygen 1.8.3.1