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: 2009-10-02 12:39:50 $
00007   Version:   $Revision: 1.11 $
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 "itkTimeProbe.h"
00023 
00024 
00025 namespace itk
00026 {
00027 
00064 class ITKCommon_EXPORT SimpleFilterWatcher
00065 {
00066 public:
00069   SimpleFilterWatcher(itk::ProcessObject* o, const char *comment="");
00070 
00072   SimpleFilterWatcher(const SimpleFilterWatcher& );
00073 
00076   SimpleFilterWatcher();
00077 
00079   void operator=(const SimpleFilterWatcher& );
00080 
00082   virtual ~SimpleFilterWatcher();
00083 
00086   const char *GetNameOfClass ()
00087     {
00088     return (m_Process.GetPointer() ? m_Process->GetNameOfClass() : "None");
00089     }
00090 
00093   void QuietOn() {m_Quiet = true;}
00094   void QuietOff() {m_Quiet = false;}
00096 
00100   void TestAbortOn() {m_TestAbort = true;}
00101   void TestAbortOff() {m_TestAbort = false;}
00103 
00107   ProcessObject *GetProcess () {return m_Process.GetPointer();}
00108 
00110   void SetSteps(int val) {m_Steps=val;}
00111   int GetSteps() {return m_Steps;}
00113 
00115   void SetIterations(int val) {m_Iterations=val;}
00116   int GetIterations() {return m_Iterations;}
00118 
00121   void SetQuiet(bool val) {m_Quiet=val;}
00122   bool GetQuiet() {return m_Quiet;}
00124 
00126   std::string GetComment() {return m_Comment;}
00127 
00129   TimeProbe &GetTimeProbe() {return m_TimeProbe;}
00130 
00131 protected:
00132 
00134   virtual void ShowProgress()
00135     {
00136     if (m_Process)
00137       {
00138       m_Steps++;
00139       if (!m_Quiet)
00140         {
00141         std::cout << " | " << m_Process->GetProgress() << std::flush;
00142         if ((m_Steps % 10) == 0)
00143           {
00144           std::cout << std::endl;
00145           }
00146         }
00147       if (m_TestAbort)
00148         {
00149         if (m_Process->GetProgress() > .03)
00150           {
00151           m_Process->AbortGenerateDataOn();
00152           }
00153         }
00154       }
00155     }
00157 
00159   virtual void ShowAbort()
00160     {
00161     std::cout << std::endl << "-------Aborted" << std::endl << std::flush;
00162     }
00163 
00165   virtual void ShowIteration()
00166     {
00167     std::cout << " # " << std::flush;
00168     m_Iterations++;
00169     }
00170 
00172   virtual void StartFilter()
00173     {
00174     m_Steps = 0;
00175     m_Iterations = 0;
00176     m_TimeProbe.Start();
00177     std::cout << "-------- Start "
00178               << (m_Process.GetPointer() ? m_Process->GetNameOfClass() : "None")
00179               << " \"" << m_Comment << "\" ";
00180     if (!m_Quiet)
00181       {
00182       if (m_Process)
00183         {
00184         std::cout << m_Process;
00185         }
00186       else
00187         {
00188         std::cout << "Null";
00189         }
00190       }
00191     std::cout << (m_Quiet ? "Progress Quiet " : "Progress ")
00192               << std::flush;
00193     }
00195 
00197   virtual void EndFilter()
00198     {
00199     m_TimeProbe.Stop();
00200     std::cout << std::endl << "Filter took "
00201               << m_TimeProbe.GetMeanTime()
00202               << " seconds.";
00203     std::cout << std::endl
00204               << "-------- End "
00205               << (m_Process.GetPointer() ? m_Process->GetNameOfClass() : "None")
00206               << " \"" << m_Comment << "\" " << std::endl;
00207     if (!m_Quiet)
00208       {
00209       if (m_Process)
00210         {
00211         std::cout << m_Process;
00212         }
00213       else
00214         {
00215         std::cout << "None";
00216         }
00217       std::cout << std::flush;
00218       }
00219     if (m_Steps < 1)
00220       {
00221       itkExceptionMacro ("Filter does not have progress.");
00222       }
00223     }
00225 
00226 private:
00227   TimeProbe                   m_TimeProbe;
00228   int                         m_Steps;
00229   int                         m_Iterations;
00230   bool                        m_Quiet;
00231   bool                        m_TestAbort;
00232   std::string                 m_Comment;
00233   itk::ProcessObject::Pointer m_Process;
00234 
00235   typedef SimpleMemberCommand<SimpleFilterWatcher> CommandType;
00236   CommandType::Pointer m_StartFilterCommand;
00237   CommandType::Pointer m_EndFilterCommand;
00238   CommandType::Pointer m_ProgressFilterCommand;
00239   CommandType::Pointer m_IterationFilterCommand;
00240   CommandType::Pointer m_AbortFilterCommand;
00241 
00242   unsigned long m_StartTag;
00243   unsigned long m_EndTag;
00244   unsigned long m_ProgressTag;
00245   unsigned long m_IterationTag;
00246   unsigned long m_AbortTag;
00247 };
00248 
00249 } // end namespace itk
00250 
00251 #endif
00252 

Generated at Fri Apr 16 19:42:05 2010 for ITK by doxygen 1.6.1 written by Dimitri van Heesch, © 1997-2000