ITK  4.3.0
Insight Segmentation and Registration Toolkit
itkProgressReporter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkProgressReporter_h
19 #define __itkProgressReporter_h
20 
21 #include "itkIntTypes.h"
22 #include "itkProcessObject.h"
23 
24 namespace itk
25 {
60 class ITKCommon_EXPORT ProgressReporter
61 {
62 public:
65  SizeValueType numberOfPixels,
66  SizeValueType numberOfUpdates = 100,
67  float initialProgress = 0.0f,
68  float progressWeight = 1.0f);
69 
72 
74  void CompletedPixel()
75  {
76  // Inline implementation for efficiency.
77  if ( --m_PixelsBeforeUpdate == 0 )
78  {
79  m_PixelsBeforeUpdate = m_PixelsPerUpdate;
80  m_CurrentPixel += m_PixelsPerUpdate;
81  // only thread 0 should update the progress of the filter
82  if ( m_ThreadId == 0 )
83  {
84  m_Filter->UpdateProgress(
85  m_CurrentPixel * m_InverseNumberOfPixels * m_ProgressWeight + m_InitialProgress);
86  }
87  // all threads needs to check the abort flag
88  if ( m_Filter->GetAbortGenerateData() )
89  {
90  std::string msg;
91  ProcessAborted e(__FILE__, __LINE__);
92  msg += "Object " + std::string( m_Filter->GetNameOfClass() ) + ": AbortGenerateDataOn";
93  e.SetDescription(msg);
94  throw e;
95  }
96  }
97  }
99 
100 protected:
109 
110 private:
111  ProgressReporter(); //purposely not implemented
112 };
113 } // end namespace itk
114 
115 #endif
116