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: 2006/05/19 13:26:23 $
00007   Version:   $Revision: 1.7 $
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 
00063 class ITKCommon_EXPORT SimpleFilterWatcher
00064 {
00065 public:
00067   friend class XMLFilterWatcher;
00068 
00071   SimpleFilterWatcher(itk::ProcessObject* o, const char *comment="");
00072 
00074   SimpleFilterWatcher(const SimpleFilterWatcher& );
00075 
00078   SimpleFilterWatcher();
00079 
00081   void operator=(const SimpleFilterWatcher& );
00082 
00084   virtual ~SimpleFilterWatcher();
00085 
00088   const char *GetNameOfClass ()
00089     {
00090       return (m_Process.GetPointer() ? m_Process->GetNameOfClass() : "None");
00091     }
00092 
00095   void QuietOn() {m_Quiet = true;};
00096   void QuietOff() {m_Quiet = false;};
00098 
00102   void TestAbortOn() {m_TestAbort = true;};
00103   void TestAbortOff() {m_TestAbort = false;};
00105 
00106   
00107 protected:
00108 
00110   virtual void ShowProgress()
00111   {
00112     if (m_Process)
00113       {
00114       m_Steps++;
00115       if (!m_Quiet)
00116         {
00117         std::cout << " | " << m_Process->GetProgress() << std::flush;
00118         if ((m_Steps % 10) == 0)
00119           {
00120           std::cout << std::endl;
00121           }
00122         }
00123       if (m_TestAbort)
00124         {
00125         if (m_Process->GetProgress() > .03)
00126           {
00127           m_Process->AbortGenerateDataOn();
00128           }
00129         }
00130       }
00131   }
00133 
00135   virtual void ShowAbort()
00136   {
00137     std::cout << std::endl << "      ABORT" << std::endl << std::flush;
00138   }
00139 
00141   virtual void ShowIteration()
00142   {
00143     std::cout << " # " << std::flush;
00144     m_Iterations++;
00145   }
00146 
00148   virtual void StartFilter()
00149   {
00150     m_Steps = 0;
00151     m_Iterations = 0;
00152     m_TimeProbe.Start();
00153     std::cout << "-------- Start "
00154               << (m_Process.GetPointer() ? m_Process->GetNameOfClass() : "None")
00155               << " \"" << m_Comment << "\" ";
00156     if (!m_Quiet)
00157       {
00158       if (m_Process)
00159         {
00160         std::cout << m_Process;
00161         }
00162       else
00163         {
00164         std::cout << "Null";
00165         }
00166       }
00167     std::cout << (m_Quiet ? "Progress Quiet " : "Progress ")
00168               << std::flush;
00169   }
00171 
00173   virtual void EndFilter()
00174   {
00175     m_TimeProbe.Stop();
00176     std::cout << std::endl << "Filter took "
00177               << m_TimeProbe.GetMeanTime()
00178               << " seconds.";
00179     std::cout << std::endl
00180               << "-------- End "
00181               << (m_Process.GetPointer() ? m_Process->GetNameOfClass() : "None")
00182               << " \"" << m_Comment << "\" " << std::endl;
00183     if (!m_Quiet)
00184       {
00185       if (m_Process)
00186         {
00187         std::cout << m_Process;
00188         }
00189       else
00190         {
00191         std::cout << "None";
00192         }
00193       std::cout << std::flush;
00194       }
00195     if (m_Steps < 1)
00196       {
00197       itkExceptionMacro ("Filter does not have progress.");
00198       }
00199     }
00201 
00202 private:
00203   TimeProbe m_TimeProbe;
00204   int m_Steps;
00205   int m_Iterations;
00206   bool m_Quiet;
00207   bool m_TestAbort;
00208   std::string m_Comment;
00209   itk::ProcessObject::Pointer m_Process;
00210 
00211   typedef SimpleMemberCommand<SimpleFilterWatcher> CommandType;
00212   CommandType::Pointer m_StartFilterCommand;
00213   CommandType::Pointer m_EndFilterCommand;
00214   CommandType::Pointer m_ProgressFilterCommand;
00215   CommandType::Pointer m_IterationFilterCommand;
00216   CommandType::Pointer m_AbortFilterCommand;
00217 
00218   unsigned long m_StartTag;
00219   unsigned long m_EndTag;
00220   unsigned long m_ProgressTag;
00221   unsigned long m_IterationTag;
00222   unsigned long m_AbortTag;
00223 };
00224 
00225 } // end namespace itk
00226 
00227 #endif
00228 

Generated at Fri Sep 8 04:07:35 2006 for ITK by doxygen 1.4.7 written by Dimitri van Heesch, © 1997-2000