ITK  4.9.0
Insight Segmentation and Registration Toolkit
itkSimpleFilterWatcher.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkSimpleFilterWatcher_h
19 #define itkSimpleFilterWatcher_h
20 
21 #include "itkCommand.h"
22 #include "itkProcessObject.h"
23 #include "itkTimeProbe.h"
24 
25 namespace itk
26 {
67 class ITKCommon_EXPORT SimpleFilterWatcher
68 {
69 public:
72  SimpleFilterWatcher(itk::ProcessObject *o, const char *comment = "");
73 
76 
80 
82  SimpleFilterWatcher & operator=(const SimpleFilterWatcher &);
83 
85  virtual ~SimpleFilterWatcher();
86 
89  const char * GetNameOfClass()
90  {
91  return ( m_Process.GetPointer() ? m_Process->GetNameOfClass() : "None" );
92  }
93 
96  void QuietOn() { m_Quiet = true; }
97  void QuietOff() { m_Quiet = false; }
99 
103  void TestAbortOn() { m_TestAbort = true; }
104  void TestAbortOff() { m_TestAbort = false; }
106 
110  ProcessObject * GetProcess() { return m_Process.GetPointer(); }
111 
113  void SetSteps(int val) { m_Steps = val; }
114  int GetSteps() { return m_Steps; }
116 
118  void SetIterations(int val) { m_Iterations = val; }
119  int GetIterations() { return m_Iterations; }
121 
124  void SetQuiet(bool val) { m_Quiet = val; }
125  bool GetQuiet() { return m_Quiet; }
127 
129  std::string GetComment() { return m_Comment; }
130 
132  TimeProbe & GetTimeProbe() { return m_TimeProbe; }
133 
134 protected:
135 
137  virtual void ShowProgress()
138  {
139  if ( m_Process )
140  {
141  m_Steps++;
142  if ( !m_Quiet )
143  {
144  std::cout << " | " << m_Process->GetProgress() << std::flush;
145  if ( ( m_Steps % 10 ) == 0 )
146  {
147  std::cout << std::endl;
148  }
149  }
150  if ( m_TestAbort )
151  {
152  if ( m_Process->GetProgress() > .03 )
153  {
154  m_Process->AbortGenerateDataOn();
155  }
156  }
157  }
158  }
160 
162  virtual void ShowAbort()
163  {
164  std::cout << std::endl << "-------Aborted" << std::endl << std::flush;
165  }
166 
168  virtual void ShowIteration()
169  {
170  std::cout << " #" << std::flush;
171  m_Iterations++;
172  }
173 
175  virtual void StartFilter()
176  {
177  m_Steps = 0;
178  m_Iterations = 0;
179  m_TimeProbe.Start();
180  std::cout << "-------- Start "
181  << ( m_Process.GetPointer() ? m_Process->GetNameOfClass() : "None" )
182  << " \"" << m_Comment << "\" ";
183  if ( !m_Quiet )
184  {
185  if ( m_Process )
186  {
187  std::cout << m_Process;
188  }
189  else
190  {
191  std::cout << "Null";
192  }
193  }
194  std::cout << ( m_Quiet ? "Progress Quiet " : "Progress " )
195  << std::flush;
196  }
198 
200  virtual void EndFilter()
201  {
202  m_TimeProbe.Stop();
203  std::cout << std::endl << "Filter took "
204  << m_TimeProbe.GetMean()
205  << " seconds.";
206  std::cout << std::endl
207  << "-------- End "
208  << ( m_Process.GetPointer() ? m_Process->GetNameOfClass() : "None" )
209  << " \"" << m_Comment << "\" " << std::endl;
210  if ( !m_Quiet )
211  {
212  if ( m_Process )
213  {
214  std::cout << m_Process;
215  }
216  else
217  {
218  std::cout << "None";
219  }
220  std::cout << std::flush;
221  }
222  if ( m_Steps < 1 )
223  {
224  itkExceptionMacro ("Filter does not have progress.");
225  }
226  }
228 
229 private:
231  int m_Steps;
233  bool m_Quiet;
235  std::string m_Comment;
237 
244 
245  unsigned long m_StartTag;
246  unsigned long m_EndTag;
247  unsigned long m_ProgressTag;
248  unsigned long m_IterationTag;
249  unsigned long m_AbortTag;
250 };
251 } // end namespace itk
252 
253 #endif
CommandType::Pointer m_EndFilterCommand
Computes the time passed between two points in code.
Definition: itkTimeProbe.h:44
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
CommandType::Pointer m_IterationFilterCommand
CommandType::Pointer m_ProgressFilterCommand
A Command subclass that calls a pointer to a member function.
Definition: itkCommand.h:239
CommandType::Pointer m_StartFilterCommand
SimpleMemberCommand< SimpleFilterWatcher > CommandType
itk::ProcessObject::Pointer m_Process
Simple mechanism for monitoring the pipeline events of a filter and reporting these events to std::co...
CommandType::Pointer m_AbortFilterCommand