Orfeo Toolbox  4.0
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; }
98 
102  void TestAbortOn() { m_TestAbort = true; }
103  void TestAbortOff() { m_TestAbort = false; }
104 
107  ProcessObject * GetProcess() { return m_Process.GetPointer(); }
108 
110  void SetSteps(int val) { m_Steps = val; }
111  int GetSteps() { return m_Steps; }
112 
114  void SetIterations(int val) { m_Iterations = val; }
115  int GetIterations() { return m_Iterations; }
116 
119  void SetQuiet(bool val) { m_Quiet = val; }
120  bool GetQuiet() { return m_Quiet; }
121 
123  std::string GetComment() { return m_Comment; }
124 
126  TimeProbe & GetTimeProbe() { return m_TimeProbe; }
127 
128 protected:
129 
131  virtual void ShowProgress()
132  {
133  if ( m_Process )
134  {
135  m_Steps++;
136  if ( !m_Quiet )
137  {
138  std::cout << " | " << m_Process->GetProgress() << std::flush;
139  if ( ( m_Steps % 10 ) == 0 )
140  {
141  std::cout << std::endl;
142  }
143  }
144  if ( m_TestAbort )
145  {
146  if ( m_Process->GetProgress() > .03 )
147  {
148  m_Process->AbortGenerateDataOn();
149  }
150  }
151  }
152  }
153 
155  virtual void ShowAbort()
156  {
157  std::cout << std::endl << "-------Aborted" << std::endl << std::flush;
158  }
159 
161  virtual void ShowIteration()
162  {
163  std::cout << " #" << std::flush;
164  m_Iterations++;
165  }
166 
168  virtual void StartFilter()
169  {
170  m_Steps = 0;
171  m_Iterations = 0;
172  m_TimeProbe.Start();
173  std::cout << "-------- Start "
174  << ( m_Process.GetPointer() ? m_Process->GetNameOfClass() : "None" )
175  << " \"" << m_Comment << "\" ";
176  if ( !m_Quiet )
177  {
178  if ( m_Process )
179  {
180  std::cout << m_Process;
181  }
182  else
183  {
184  std::cout << "Null";
185  }
186  }
187  std::cout << ( m_Quiet ? "Progress Quiet " : "Progress " )
188  << std::flush;
189  }
190 
192  virtual void EndFilter()
193  {
194  m_TimeProbe.Stop();
195  std::cout << std::endl << "Filter took "
196  << m_TimeProbe.GetMean()
197  << " seconds.";
198  std::cout << std::endl
199  << "-------- End "
200  << ( m_Process.GetPointer() ? m_Process->GetNameOfClass() : "None" )
201  << " \"" << m_Comment << "\" " << std::endl;
202  if ( !m_Quiet )
203  {
204  if ( m_Process )
205  {
206  std::cout << m_Process;
207  }
208  else
209  {
210  std::cout << "None";
211  }
212  std::cout << std::flush;
213  }
214  if ( m_Steps < 1 )
215  {
216  itkExceptionMacro ("Filter does not have progress.");
217  }
218  }
219 
220 private:
222  int m_Steps;
224  bool m_Quiet;
226  std::string m_Comment;
228 
235 
236  unsigned long m_StartTag;
237  unsigned long m_EndTag;
238  unsigned long m_ProgressTag;
239  unsigned long m_IterationTag;
240  unsigned long m_AbortTag;
241 };
242 } // end namespace itk
243 
244 #endif

Generated at Sat Mar 8 2014 15:33:30 for Orfeo Toolbox with doxygen 1.8.3.1