itkPluginFilterWatcher.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkPluginFilterWatcher.h,v $
00005   Language:  C++
00006   Date:      $Date: 2007/04/09 02:26:30 $
00007   Version:   $Revision: 1.1 $
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 __itkPluginFilterWatcher_h
00018 #define __itkPluginFilterWatcher_h
00019 
00020 #include "itkSimpleFilterWatcher.h"
00021 #include "ModuleProcessInformation.h"
00022 
00023 namespace itk
00024 {
00025 
00031 class PluginFilterWatcher: public SimpleFilterWatcher
00032 {
00033 public:
00034   PluginFilterWatcher(itk::ProcessObject* o,
00035                       const char *comment="",
00036                       ModuleProcessInformation *inf=0,
00037                       double fraction = 1.0,
00038                       double start = 0.0)
00039     : SimpleFilterWatcher(o, comment)
00040   {
00041     m_ProcessInformation = inf;
00042     m_Fraction = fraction;
00043     m_Start = start;
00044   };
00045 
00046 protected:
00047 
00049 virtual void ShowProgress()
00050 {
00051   if (this->GetProcess())
00052     {
00053     this->SetSteps( this->GetSteps()+1 );
00054     if (!this->GetQuiet())
00055       {
00056       if (m_ProcessInformation)
00057         {
00058         strncpy(m_ProcessInformation->ProgressMessage,
00059                 this->GetComment().c_str(), 1023);
00060         m_ProcessInformation->Progress = 
00061           (this->GetProcess()->GetProgress() * m_Fraction + m_Start);
00062         if (m_Fraction != 1.0)
00063           {
00064           m_ProcessInformation->StageProgress = this->GetProcess()->GetProgress();
00065           }
00066 
00067         this->GetTimeProbe().Stop();
00068         m_ProcessInformation->ElapsedTime
00069           = this->GetTimeProbe().GetMeanTime()
00070           * this->GetTimeProbe().GetNumberOfStops();
00071         this->GetTimeProbe().Start();
00072 
00073         if (m_ProcessInformation->Abort)
00074           {
00075           this->GetProcess()->AbortGenerateDataOn();
00076           m_ProcessInformation->Progress = 0;
00077           m_ProcessInformation->StageProgress = 0;
00078           }
00079 
00080         if (m_ProcessInformation->ProgressCallbackFunction
00081             && m_ProcessInformation->ProgressCallbackClientData)
00082           {
00083           (*(m_ProcessInformation->ProgressCallbackFunction))(m_ProcessInformation->ProgressCallbackClientData);
00084           }
00085         }
00086       else
00087         {
00088         std::cout << "<filter-progress>"
00089                   << (this->GetProcess()->GetProgress() * m_Fraction) + m_Start
00090                   << "</filter-progress>"
00091                   << std::endl;
00092         if (m_Fraction != 1.0)
00093           {
00094           std::cout << "<filter-stage-progress>"
00095                     << this->GetProcess()->GetProgress() 
00096                     << "</filter-stage-progress>"
00097                     << std::endl;
00098           }
00099         std::cout << std::flush;
00100         }
00101       }
00102     }
00103 }
00104 
00106 virtual void StartFilter()
00107 {
00108   this->SetSteps(0);
00109   this->SetIterations(0);
00110   this->GetTimeProbe().Start();
00111   if (!this->GetQuiet())
00112     {
00113     if (m_ProcessInformation)
00114       {
00115       m_ProcessInformation->Progress = 0;
00116       m_ProcessInformation->StageProgress = 0;
00117       strncpy(m_ProcessInformation->ProgressMessage,
00118               this->GetComment().c_str(), 1023);
00119       
00120       if (m_ProcessInformation->ProgressCallbackFunction
00121           && m_ProcessInformation->ProgressCallbackClientData)
00122         {
00123         (*(m_ProcessInformation->ProgressCallbackFunction))(m_ProcessInformation->ProgressCallbackClientData);
00124         }
00125       }
00126     else
00127       {
00128       std::cout << "<filter-start>"
00129                 << std::endl;
00130       std::cout << "<filter-name>"
00131                 << (this->GetProcess()
00132                     ? this->GetProcess()->GetNameOfClass() : "None")
00133                 << "</filter-name>"
00134                 << std::endl;
00135       std::cout << "<filter-comment>"
00136                 << " \"" << this->GetComment() << "\" "
00137                 << "</filter-comment>"
00138                 << std::endl;
00139       std::cout << "</filter-start>"
00140                 << std::endl;
00141       std::cout << std::flush;
00142       }
00143     }
00144 }
00145 
00147 virtual void EndFilter()
00148 {
00149   this->GetTimeProbe().Stop();
00150   if (!this->GetQuiet())
00151     {
00152     if (m_ProcessInformation)
00153       {
00154       m_ProcessInformation->Progress = 0;
00155       m_ProcessInformation->StageProgress = 0;
00156 
00157       m_ProcessInformation->ElapsedTime
00158         = this->GetTimeProbe().GetMeanTime()
00159         * this->GetTimeProbe().GetNumberOfStops();
00160       
00161       if (m_ProcessInformation->ProgressCallbackFunction
00162           && m_ProcessInformation->ProgressCallbackClientData)
00163         {
00164         (*(m_ProcessInformation->ProgressCallbackFunction))(m_ProcessInformation->ProgressCallbackClientData);
00165         }
00166       }
00167     else
00168       {
00169       std::cout << "<filter-end>"
00170                 << std::endl;
00171       std::cout << "<filter-name>"
00172                 << (this->GetProcess()
00173                     ? this->GetProcess()->GetNameOfClass() : "None")
00174                 << "</filter-name>"
00175                 << std::endl;
00176       std::cout << "<filter-time>"
00177                 << this->GetTimeProbe().GetMeanTime()
00178                 << "</filter-time>"
00179                 << std::endl;
00180       std::cout << "</filter-end>";
00181       std::cout << std::flush;
00182       }
00183     }
00184 }
00185 
00186 
00187   ModuleProcessInformation *m_ProcessInformation;
00188   double m_Fraction;
00189   double m_Start;
00190 };
00191 
00192 } // end namespace itk
00193 
00194 #endif

Generated on 6 Apr 2011 for Slicer3 by  doxygen 1.6.1