Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkSimpleFilterWatcher.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkSimpleFilterWatcher.h,v $
00005   Language:  C++
00006   Date:      $Date: 2004/11/10 19:22:12 $
00007   Version:   $Revision: 1.4 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef _itkSimpleFilterWatcher_h
00018 #define _itkSimpleFilterWatcher_h
00019 
00020 #include "itkCommand.h"
00021 #include "itkProcessObject.h"
00022 #include <time.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;};
00094 
00098   void TestAbortOn() {m_TestAbort = true;};
00099   void TestAbortOff() {m_TestAbort = false;};
00100 
00101   
00102 protected:
00103 
00105   virtual void ShowProgress()
00106   {
00107     if (m_Process)
00108       {
00109       m_Steps++;
00110       if (!m_Quiet)
00111         {
00112         std::cout << " | " << m_Process->GetProgress() << std::flush;
00113         if ((m_Steps % 10) == 0)
00114           {
00115           std::cout << std::endl;
00116           }
00117         }
00118       if (m_TestAbort)
00119         {
00120         if (m_Process->GetProgress() > .03)
00121           {
00122           m_Process->AbortGenerateDataOn();
00123           }
00124         }
00125       }
00126   }
00127 
00129   virtual void ShowAbort()
00130   {
00131     std::cout << std::endl << "      ABORT" << std::endl << std::flush;
00132   }
00133 
00135   virtual void ShowIteration()
00136   {
00137     std::cout << " # " << std::flush;
00138     m_Iterations++;
00139   }
00140 
00142   virtual void StartFilter()
00143   {
00144     m_Steps = 0;
00145     m_Iterations = 0;
00146     m_Start = ::clock();
00147     std::cout << "-------- Start "
00148               << (m_Process.GetPointer() ? m_Process->GetNameOfClass() : "None")
00149               << " \"" << m_Comment << "\" ";
00150     if (m_Process)
00151       {
00152       std::cout << m_Process;
00153       }
00154     else
00155       {
00156       std::cout << "Null";
00157       }
00158     std::cout << (m_Quiet ? "Progress Quiet " : "Progress ")
00159               << std::flush;
00160   }
00161 
00163   virtual void EndFilter()
00164   {
00165     m_End = ::clock();
00166     std::cout << std::endl << "Filter took "
00167               << static_cast<double>(m_End - m_Start) / CLOCKS_PER_SEC
00168               << " seconds.";
00169     std::cout << std::endl << std::endl
00170               << "-------- End "
00171               << (m_Process.GetPointer() ? m_Process->GetNameOfClass() : "None")
00172               << " \"" << m_Comment << "\" ";
00173     if (m_Process)
00174       {
00175       std::cout << m_Process;
00176       }
00177     else
00178       {
00179       std::cout << "None";
00180       }
00181     std::cout << std::flush;
00182     if (m_Steps < 1)
00183       {
00184       itkExceptionMacro ("Filter does not have progress.");
00185       }
00186     }
00187 
00188 private:
00189   clock_t m_Start;
00190   clock_t m_End;
00191   int m_Steps;
00192   int m_Iterations;
00193   bool m_Quiet;
00194   bool m_TestAbort;
00195   std::string m_Comment;
00196   itk::ProcessObject::Pointer m_Process;
00197 
00198   typedef SimpleMemberCommand<SimpleFilterWatcher> CommandType;
00199   CommandType::Pointer m_StartFilterCommand;
00200   CommandType::Pointer m_EndFilterCommand;
00201   CommandType::Pointer m_ProgressFilterCommand;
00202   CommandType::Pointer m_IterationFilterCommand;
00203   CommandType::Pointer m_AbortFilterCommand;
00204 
00205   unsigned long m_StartTag;
00206   unsigned long m_EndTag;
00207   unsigned long m_ProgressTag;
00208   unsigned long m_IterationTag;
00209   unsigned long m_AbortTag;
00210 };
00211 
00212 } // end namespace itk
00213 
00214 #endif

Generated at Thu May 25 00:04:18 2006 for ITK by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2000