itkSimpleFilterWatcher.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkSimpleFilterWatcher_h
00018 #define __itkSimpleFilterWatcher_h
00019
00020 #include "itkCommand.h"
00021 #include "itkProcessObject.h"
00022 #include "itkTimeProbe.h"
00023
00024
00025 namespace itk
00026 {
00027
00063 class ITKCommon_EXPORT SimpleFilterWatcher
00064 {
00065 public:
00068 SimpleFilterWatcher(itk::ProcessObject* o, const char *comment="");
00069
00071 SimpleFilterWatcher(const SimpleFilterWatcher& );
00072
00075 SimpleFilterWatcher();
00076
00078 void operator=(const SimpleFilterWatcher& );
00079
00081 virtual ~SimpleFilterWatcher();
00082
00085 const char *GetNameOfClass ()
00086 {
00087 return (m_Process.GetPointer() ? m_Process->GetNameOfClass() : "None");
00088 }
00089
00092 void QuietOn() {m_Quiet = true;}
00093 void QuietOff() {m_Quiet = false;}
00095
00099 void TestAbortOn() {m_TestAbort = true;}
00100 void TestAbortOff() {m_TestAbort = false;}
00102
00106 ProcessObject *GetProcess () {return m_Process.GetPointer();}
00107
00109 void SetSteps(int val) {m_Steps=val;}
00110 int GetSteps() {return m_Steps;}
00112
00114 void SetIterations(int val) {m_Iterations=val;}
00115 int GetIterations() {return m_Iterations;}
00117
00120 void SetQuiet(bool val) {m_Quiet=val;}
00121 bool GetQuiet() {return m_Quiet;}
00123
00125 std::string GetComment() {return m_Comment;}
00126
00128 TimeProbe &GetTimeProbe() {return m_TimeProbe;}
00129
00130 protected:
00131
00133 virtual void ShowProgress()
00134 {
00135 if (m_Process)
00136 {
00137 m_Steps++;
00138 if (!m_Quiet)
00139 {
00140 std::cout << " | " << m_Process->GetProgress() << std::flush;
00141 if ((m_Steps % 10) == 0)
00142 {
00143 std::cout << std::endl;
00144 }
00145 }
00146 if (m_TestAbort)
00147 {
00148 if (m_Process->GetProgress() > .03)
00149 {
00150 m_Process->AbortGenerateDataOn();
00151 }
00152 }
00153 }
00154 }
00156
00158 virtual void ShowAbort()
00159 {
00160 std::cout << std::endl << "-------Aborted" << std::endl << std::flush;
00161 }
00162
00164 virtual void ShowIteration()
00165 {
00166 std::cout << " # " << std::flush;
00167 m_Iterations++;
00168 }
00169
00171 virtual void StartFilter()
00172 {
00173 m_Steps = 0;
00174 m_Iterations = 0;
00175 m_TimeProbe.Start();
00176 std::cout << "-------- Start "
00177 << (m_Process.GetPointer() ? m_Process->GetNameOfClass() : "None")
00178 << " \"" << m_Comment << "\" ";
00179 if (!m_Quiet)
00180 {
00181 if (m_Process)
00182 {
00183 std::cout << m_Process;
00184 }
00185 else
00186 {
00187 std::cout << "Null";
00188 }
00189 }
00190 std::cout << (m_Quiet ? "Progress Quiet " : "Progress ")
00191 << std::flush;
00192 }
00194
00196 virtual void EndFilter()
00197 {
00198 m_TimeProbe.Stop();
00199 std::cout << std::endl << "Filter took "
00200 << m_TimeProbe.GetMeanTime()
00201 << " seconds.";
00202 std::cout << std::endl
00203 << "-------- End "
00204 << (m_Process.GetPointer() ? m_Process->GetNameOfClass() : "None")
00205 << " \"" << m_Comment << "\" " << std::endl;
00206 if (!m_Quiet)
00207 {
00208 if (m_Process)
00209 {
00210 std::cout << m_Process;
00211 }
00212 else
00213 {
00214 std::cout << "None";
00215 }
00216 std::cout << std::flush;
00217 }
00218 if (m_Steps < 1)
00219 {
00220 itkExceptionMacro ("Filter does not have progress.");
00221 }
00222 }
00224
00225 private:
00226 TimeProbe m_TimeProbe;
00227 int m_Steps;
00228 int m_Iterations;
00229 bool m_Quiet;
00230 bool m_TestAbort;
00231 std::string m_Comment;
00232 itk::ProcessObject::Pointer m_Process;
00233
00234 typedef SimpleMemberCommand<SimpleFilterWatcher> CommandType;
00235 CommandType::Pointer m_StartFilterCommand;
00236 CommandType::Pointer m_EndFilterCommand;
00237 CommandType::Pointer m_ProgressFilterCommand;
00238 CommandType::Pointer m_IterationFilterCommand;
00239 CommandType::Pointer m_AbortFilterCommand;
00240
00241 unsigned long m_StartTag;
00242 unsigned long m_EndTag;
00243 unsigned long m_ProgressTag;
00244 unsigned long m_IterationTag;
00245 unsigned long m_AbortTag;
00246 };
00247
00248 }
00249
00250 #endif
00251