Orfeo Toolbox  3.16
itkSimpleFilterWatcher.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkSimpleFilterWatcher.h,v $
5  Language: C++
6  Date: $Date: 2009-10-02 12:39:50 $
7  Version: $Revision: 1.11 $
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  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkSimpleFilterWatcher_h
18 #define __itkSimpleFilterWatcher_h
19 
20 #include "itkCommand.h"
21 #include "itkProcessObject.h"
22 #include "itkTimeProbe.h"
23 
24 
25 namespace itk
26 {
27 
65 {
66 public:
69  SimpleFilterWatcher(itk::ProcessObject* o, const char *comment="");
70 
73 
77 
79  void operator=(const SimpleFilterWatcher& );
80 
82  virtual ~SimpleFilterWatcher();
83 
86  const char *GetNameOfClass ()
87  {
88  return (m_Process.GetPointer() ? m_Process->GetNameOfClass() : "None");
89  }
90 
93  void QuietOn() {m_Quiet = true;}
94  void QuietOff() {m_Quiet = false;}
95 
99  void TestAbortOn() {m_TestAbort = true;}
100  void TestAbortOff() {m_TestAbort = false;}
101 
104  ProcessObject *GetProcess () {return m_Process.GetPointer();}
105 
107  void SetSteps(int val) {m_Steps=val;}
108  int GetSteps() {return m_Steps;}
109 
111  void SetIterations(int val) {m_Iterations=val;}
112  int GetIterations() {return m_Iterations;}
113 
116  void SetQuiet(bool val) {m_Quiet=val;}
117  bool GetQuiet() {return m_Quiet;}
118 
120  std::string GetComment() {return m_Comment;}
121 
123  TimeProbe &GetTimeProbe() {return m_TimeProbe;}
124 
125 protected:
126 
128  virtual void ShowProgress()
129  {
130  if (m_Process)
131  {
132  m_Steps++;
133  if (!m_Quiet)
134  {
135  std::cout << " | " << m_Process->GetProgress() << std::flush;
136  if ((m_Steps % 10) == 0)
137  {
138  std::cout << std::endl;
139  }
140  }
141  if (m_TestAbort)
142  {
143  if (m_Process->GetProgress() > .03)
144  {
145  m_Process->AbortGenerateDataOn();
146  }
147  }
148  }
149  }
150 
152  virtual void ShowAbort()
153  {
154  std::cout << std::endl << "-------Aborted" << std::endl << std::flush;
155  }
156 
158  virtual void ShowIteration()
159  {
160  std::cout << " # " << std::flush;
161  m_Iterations++;
162  }
163 
165  virtual void StartFilter()
166  {
167  m_Steps = 0;
168  m_Iterations = 0;
169  m_TimeProbe.Start();
170  std::cout << "-------- Start "
171  << (m_Process.GetPointer() ? m_Process->GetNameOfClass() : "None")
172  << " \"" << m_Comment << "\" ";
173  if (!m_Quiet)
174  {
175  if (m_Process)
176  {
177  std::cout << m_Process;
178  }
179  else
180  {
181  std::cout << "Null";
182  }
183  }
184  std::cout << (m_Quiet ? "Progress Quiet " : "Progress ")
185  << std::flush;
186  }
187 
189  virtual void EndFilter()
190  {
191  m_TimeProbe.Stop();
192  std::cout << std::endl << "Filter took "
193  << m_TimeProbe.GetMeanTime()
194  << " seconds.";
195  std::cout << std::endl
196  << "-------- End "
197  << (m_Process.GetPointer() ? m_Process->GetNameOfClass() : "None")
198  << " \"" << m_Comment << "\" " << std::endl;
199  if (!m_Quiet)
200  {
201  if (m_Process)
202  {
203  std::cout << m_Process;
204  }
205  else
206  {
207  std::cout << "None";
208  }
209  std::cout << std::flush;
210  }
211  if (m_Steps < 1)
212  {
213  itkExceptionMacro ("Filter does not have progress.");
214  }
215  }
216 
217 private:
219  int m_Steps;
221  bool m_Quiet;
223  std::string m_Comment;
225 
232 
233  unsigned long m_StartTag;
234  unsigned long m_EndTag;
235  unsigned long m_ProgressTag;
236  unsigned long m_IterationTag;
237  unsigned long m_AbortTag;
238 };
239 
240 } // end namespace itk
241 
242 #endif

Generated at Sun Feb 3 2013 00:07:18 for Orfeo Toolbox with doxygen 1.8.1.1