| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkSimpleFilterWatcher.cxx.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:47 $ |
| 7 |
|
Version: $Revision: 1.4 $ |
| 8 |
|
|
| 9 |
|
Copyright (c) Insight Software Consortium. All rights reserved. |
| 10 |
|
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. |
| 11 |
|
|
| 12 |
|
Portions of this code are covered under the VTK copyright. |
| 13 |
|
See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details. |
| 14 |
|
|
| 15 |
|
This software is distributed WITHOUT ANY WARRANTY; without even |
| 16 |
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 17 |
IND |
*****PURPOSE. See the above copyright notices for more information. |
| 18 |
|
|
| 19 |
DEF |
=========================================================================*/ |
| 20 |
|
|
| 21 |
|
#include "itkSimpleFilterWatcher.h" |
| 22 |
|
|
| 23 |
|
namespace itk |
| 24 |
|
{ |
| 25 |
|
|
| 26 |
|
SimpleFilterWatcher |
| 27 |
|
::SimpleFilterWatcher(ProcessObject* o, const char *comment) |
| 28 |
|
{ |
| 29 |
|
// Initialize state |
| 30 |
|
m_Process = o; |
| 31 |
|
m_Steps = 0; |
| 32 |
|
m_Comment = comment; |
| 33 |
|
m_TestAbort = false; |
| 34 |
|
#if defined(_COMPILER_VERSION) && (_COMPILER_VERSION == 730) |
| 35 |
|
m_Quiet = true; |
| 36 |
IND |
#else |
| 37 |
|
m_Quiet = false; |
| 38 |
|
#endif |
| 39 |
|
|
| 40 |
|
// Create a series of commands |
| 41 |
|
m_StartFilterCommand = CommandType::New(); |
| 42 |
|
m_EndFilterCommand = CommandType::New(); |
| 43 |
|
m_ProgressFilterCommand = CommandType::New(); |
| 44 |
|
m_IterationFilterCommand = CommandType::New(); |
| 45 |
|
m_AbortFilterCommand = CommandType::New(); |
| 46 |
|
|
| 47 |
|
// Assign the callbacks |
| 48 |
|
m_StartFilterCommand->SetCallbackFunction(this, |
| 49 |
|
&SimpleFilterWatcher::StartFilter); |
| 50 |
|
m_EndFilterCommand->SetCallbackFunction(this, |
| 51 |
|
&SimpleFilterWatcher::EndFilter); |
| 52 |
|
m_ProgressFilterCommand->SetCallbackFunction(this, |
| 53 |
|
&SimpleFilterWatcher::ShowProgress); |
| 54 |
|
m_IterationFilterCommand->SetCallbackFunction(this, |
| 55 |
|
&SimpleFilterWatcher::ShowIteration); |
| 56 |
|
m_AbortFilterCommand->SetCallbackFunction(this, |
| 57 |
|
&SimpleFilterWatcher::ShowAbort); |
| 58 |
|
|
| 59 |
|
|
| 60 |
|
// Add the commands as observers |
| 61 |
|
m_StartTag = m_Process->AddObserver(StartEvent(), m_StartFilterCommand); |
| 62 |
|
m_EndTag = m_Process->AddObserver(EndEvent(), m_EndFilterCommand); |
| 63 |
|
m_ProgressTag |
| 64 |
IND |
****= m_Process->AddObserver(ProgressEvent(), m_ProgressFilterCommand); |
| 65 |
|
m_IterationTag |
| 66 |
IND |
****= m_Process->AddObserver(IterationEvent(), m_IterationFilterCommand); |
| 67 |
|
m_AbortTag |
| 68 |
IND |
****= m_Process->AddObserver(AbortEvent(), m_AbortFilterCommand); |
| 69 |
|
} |
| 70 |
|
|
| 71 |
|
|
| 72 |
|
SimpleFilterWatcher |
| 73 |
|
::SimpleFilterWatcher() |
| 74 |
|
{ |
| 75 |
|
// Initialize state |
| 76 |
|
m_Steps = 0; |
| 77 |
|
m_Comment = "Not watching an object"; |
| 78 |
|
m_TestAbort = false; |
| 79 |
|
#if defined(_COMPILER_VERSION) && (_COMPILER_VERSION == 730) |
| 80 |
|
m_Quiet = true; |
| 81 |
IND |
#else |
| 82 |
|
m_Quiet = false; |
| 83 |
|
#endif |
| 84 |
|
|
| 85 |
|
m_Process = 0; |
| 86 |
|
} |
| 87 |
|
|
| 88 |
|
SimpleFilterWatcher |
| 89 |
|
::SimpleFilterWatcher(const SimpleFilterWatcher &watch) |
| 90 |
|
{ |
| 91 |
|
// Remove any observers we have on the old process object |
| 92 |
|
if (m_Process) |
| 93 |
|
{ |
| 94 |
|
if (m_StartFilterCommand) |
| 95 |
|
{ |
| 96 |
|
m_Process->RemoveObserver(m_StartTag); |
| 97 |
|
} |
| 98 |
|
if (m_EndFilterCommand) |
| 99 |
|
{ |
| 100 |
|
m_Process->RemoveObserver(m_EndTag); |
| 101 |
|
} |
| 102 |
|
if (m_ProgressFilterCommand) |
| 103 |
|
{ |
| 104 |
|
m_Process->RemoveObserver(m_ProgressTag); |
| 105 |
|
} |
| 106 |
|
if (m_IterationFilterCommand) |
| 107 |
|
{ |
| 108 |
|
m_Process->RemoveObserver(m_IterationTag); |
| 109 |
|
} |
| 110 |
|
if (m_AbortFilterCommand) |
| 111 |
|
{ |
| 112 |
|
m_Process->RemoveObserver(m_AbortTag); |
| 113 |
|
} |
| 114 |
|
} |
| 115 |
|
|
| 116 |
|
// Initialize state |
| 117 |
|
m_TimeProbe = watch.m_TimeProbe; |
| 118 |
|
m_Process = watch.m_Process; |
| 119 |
|
m_Steps = watch.m_Steps; |
| 120 |
|
m_Comment = watch.m_Comment; |
| 121 |
|
m_TestAbort = watch.m_TestAbort; |
| 122 |
|
m_Quiet = watch.m_Quiet; |
| 123 |
|
|
| 124 |
|
m_StartTag = 0; |
| 125 |
|
m_EndTag = 0; |
| 126 |
|
m_ProgressTag = 0; |
| 127 |
|
m_IterationTag = 0; |
| 128 |
|
m_AbortTag = 0; |
| 129 |
|
|
| 130 |
|
// Create a series of commands |
| 131 |
|
if (m_Process) |
| 132 |
|
{ |
| 133 |
|
m_StartFilterCommand = CommandType::New(); |
| 134 |
|
m_EndFilterCommand = CommandType::New(); |
| 135 |
|
m_ProgressFilterCommand = CommandType::New(); |
| 136 |
|
m_IterationFilterCommand = CommandType::New(); |
| 137 |
|
m_AbortFilterCommand = CommandType::New(); |
| 138 |
|
|
| 139 |
|
// Assign the callbacks |
| 140 |
|
m_StartFilterCommand->SetCallbackFunction(this, |
| 141 |
|
&SimpleFilterWatcher::StartFilter); |
| 142 |
|
m_EndFilterCommand->SetCallbackFunction(this, |
| 143 |
|
&SimpleFilterWatcher::EndFilter); |
| 144 |
|
m_ProgressFilterCommand->SetCallbackFunction(this, |
| 145 |
|
&SimpleFilterWatcher::ShowProgress); |
| 146 |
|
m_IterationFilterCommand->SetCallbackFunction(this, |
| 147 |
|
&SimpleFilterWatcher::ShowIteration); |
| 148 |
|
m_AbortFilterCommand->SetCallbackFunction(this, |
| 149 |
|
&SimpleFilterWatcher::ShowAbort); |
| 150 |
|
|
| 151 |
|
|
| 152 |
|
// Add the commands as observers |
| 153 |
|
m_StartTag = m_Process->AddObserver(StartEvent(), m_StartFilterCommand); |
| 154 |
|
m_EndTag = m_Process->AddObserver(EndEvent(), m_EndFilterCommand); |
| 155 |
|
m_ProgressTag |
| 156 |
IND |
******= m_Process->AddObserver(ProgressEvent(), m_ProgressFilterCommand); |
| 157 |
|
m_IterationTag |
| 158 |
IND |
******= m_Process->AddObserver(IterationEvent(), m_IterationFilterCommand); |
| 159 |
|
m_AbortTag = m_Process->AddObserver(AbortEvent(), m_AbortFilterCommand); |
| 160 |
|
} |
| 161 |
|
} |
| 162 |
|
|
| 163 |
|
|
| 164 |
|
void |
| 165 |
|
SimpleFilterWatcher |
| 166 |
|
::operator=(const SimpleFilterWatcher &watch) |
| 167 |
|
{ |
| 168 |
|
// Remove any observers we have on the old process object |
| 169 |
|
if (m_Process) |
| 170 |
|
{ |
| 171 |
|
if (m_StartFilterCommand) |
| 172 |
|
{ |
| 173 |
|
m_Process->RemoveObserver(m_StartTag); |
| 174 |
|
} |
| 175 |
|
if (m_EndFilterCommand) |
| 176 |
|
{ |
| 177 |
|
m_Process->RemoveObserver(m_EndTag); |
| 178 |
|
} |
| 179 |
|
if (m_ProgressFilterCommand) |
| 180 |
|
{ |
| 181 |
|
m_Process->RemoveObserver(m_ProgressTag); |
| 182 |
|
} |
| 183 |
|
if (m_IterationFilterCommand) |
| 184 |
|
{ |
| 185 |
|
m_Process->RemoveObserver(m_IterationTag); |
| 186 |
|
} |
| 187 |
|
if (m_AbortFilterCommand) |
| 188 |
|
{ |
| 189 |
|
m_Process->RemoveObserver(m_AbortTag); |
| 190 |
|
} |
| 191 |
|
} |
| 192 |
|
|
| 193 |
|
// Initialize state |
| 194 |
|
m_TimeProbe = watch.m_TimeProbe; |
| 195 |
|
m_Process = watch.m_Process; |
| 196 |
|
m_Steps = watch.m_Steps; |
| 197 |
|
m_Comment = watch.m_Comment; |
| 198 |
|
m_TestAbort = watch.m_TestAbort; |
| 199 |
|
m_Quiet = watch.m_Quiet; |
| 200 |
|
|
| 201 |
|
m_StartTag = 0; |
| 202 |
|
m_EndTag = 0; |
| 203 |
|
m_ProgressTag = 0; |
| 204 |
|
m_IterationTag = 0; |
| 205 |
|
m_AbortTag = 0; |
| 206 |
|
|
| 207 |
|
// Create a series of commands |
| 208 |
|
if (m_Process) |
| 209 |
|
{ |
| 210 |
|
m_StartFilterCommand = CommandType::New(); |
| 211 |
|
m_EndFilterCommand = CommandType::New(); |
| 212 |
|
m_ProgressFilterCommand = CommandType::New(); |
| 213 |
|
m_IterationFilterCommand = CommandType::New(); |
| 214 |
|
m_AbortFilterCommand = CommandType::New(); |
| 215 |
|
|
| 216 |
|
// Assign the callbacks |
| 217 |
|
m_StartFilterCommand->SetCallbackFunction(this, |
| 218 |
|
&SimpleFilterWatcher::StartFilter); |
| 219 |
|
m_EndFilterCommand->SetCallbackFunction(this, |
| 220 |
|
&SimpleFilterWatcher::EndFilter); |
| 221 |
|
m_ProgressFilterCommand->SetCallbackFunction(this, |
| 222 |
|
&SimpleFilterWatcher::ShowProgress); |
| 223 |
|
m_IterationFilterCommand->SetCallbackFunction(this, |
| 224 |
|
&SimpleFilterWatcher::ShowIteration); |
| 225 |
|
m_AbortFilterCommand->SetCallbackFunction(this, |
| 226 |
|
&SimpleFilterWatcher::ShowAbort); |
| 227 |
|
|
| 228 |
|
|
| 229 |
|
// Add the commands as observers |
| 230 |
|
m_StartTag = m_Process->AddObserver(StartEvent(), m_StartFilterCommand); |
| 231 |
|
m_EndTag = m_Process->AddObserver(EndEvent(), m_EndFilterCommand); |
| 232 |
|
m_ProgressTag |
| 233 |
IND |
******= m_Process->AddObserver(ProgressEvent(), m_ProgressFilterCommand); |
| 234 |
|
m_IterationTag |
| 235 |
IND |
******= m_Process->AddObserver(IterationEvent(), m_IterationFilterCommand); |
| 236 |
|
m_AbortTag = m_Process->AddObserver(AbortEvent(), m_AbortFilterCommand); |
| 237 |
|
} |
| 238 |
|
} |
| 239 |
|
|
| 240 |
|
SimpleFilterWatcher |
| 241 |
|
::~SimpleFilterWatcher() |
| 242 |
|
{ |
| 243 |
|
// Remove any observers we have on the old process object |
| 244 |
|
if (m_Process) |
| 245 |
|
{ |
| 246 |
|
if (m_StartFilterCommand) |
| 247 |
|
{ |
| 248 |
|
m_Process->RemoveObserver(m_StartTag); |
| 249 |
|
} |
| 250 |
|
if (m_EndFilterCommand) |
| 251 |
|
{ |
| 252 |
|
m_Process->RemoveObserver(m_EndTag); |
| 253 |
|
} |
| 254 |
|
if (m_ProgressFilterCommand) |
| 255 |
|
{ |
| 256 |
|
m_Process->RemoveObserver(m_ProgressTag); |
| 257 |
|
} |
| 258 |
|
if (m_IterationFilterCommand) |
| 259 |
|
{ |
| 260 |
|
m_Process->RemoveObserver(m_IterationTag); |
| 261 |
|
} |
| 262 |
|
if (m_AbortFilterCommand) |
| 263 |
|
{ |
| 264 |
|
m_Process->RemoveObserver(m_AbortTag); |
| 265 |
|
} |
| 266 |
|
} |
| 267 |
|
} |
| 268 |
|
|
| 269 |
|
} // end namespace itk |
| 270 |
|
|
| 271 |
EOF |
|