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

itkProgressReporter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkProgressReporter.h,v $
00005   Language:  C++
00006   Date:      $Date: 2006/07/24 11:41:15 $
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 __itkProgressReporter_h
00018 #define __itkProgressReporter_h
00019 
00020 #include "itkProcessObject.h"
00021 
00022 namespace itk
00023 {
00024 
00058 class ITKCommon_EXPORT ProgressReporter
00059 {
00060 public:
00062   ProgressReporter(ProcessObject* filter, int threadId,
00063                    unsigned long numberOfPixels,
00064                    unsigned long numberOfUpdates = 100,
00065                    float initialProgress = 0.0f,
00066                    float progressWeight  = 1.0f );
00067 
00069   ~ProgressReporter();
00070 
00072   void CompletedPixel()
00073     {
00074     // Inline implementation for efficiency.
00075     if(--m_PixelsBeforeUpdate == 0)
00076       {
00077       m_PixelsBeforeUpdate = m_PixelsPerUpdate;
00078       m_CurrentPixel += m_PixelsPerUpdate;
00079       // only thread 0 should update the progress of the filter
00080       if (m_ThreadId == 0)
00081         {
00082         m_Filter->UpdateProgress(
00083           m_CurrentPixel * m_InverseNumberOfPixels * m_ProgressWeight + m_InitialProgress);
00084         }
00085       // all threads needs to check the abort flag
00086       if( m_Filter->GetAbortGenerateData() )
00087         {
00088         std::string msg;
00089         ProcessAborted e(__FILE__, __LINE__);
00090         msg += "Object " + std::string(m_Filter->GetNameOfClass()) + ": AbortGenerateDataOn";
00091         e.SetDescription(msg);
00092         throw e;
00093         }
00094       }
00095     }
00097 
00098 protected:
00099   ProcessObject* m_Filter;
00100   int m_ThreadId;
00101   float m_InverseNumberOfPixels;
00102   unsigned long m_CurrentPixel;
00103   unsigned long m_PixelsPerUpdate;
00104   unsigned long m_PixelsBeforeUpdate;
00105   float  m_InitialProgress;
00106   float  m_ProgressWeight;
00107 
00108 private:
00109   ProgressReporter(); //purposely not implemented
00110 
00111 };
00112 
00113 } // end namespace itk
00114 
00115 #endif
00116 

Generated at Sun Sep 23 13:55:27 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000