ITK  5.2.0
Insight Toolkit
itkTotalProgressReporter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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 itkTotalProgressReporter_h
19 #define itkTotalProgressReporter_h
20 
21 #include "itkIntTypes.h"
22 #include "itkProcessObject.h"
23 
24 namespace itk
25 {
40 class ITKCommon_EXPORT TotalProgressReporter
41 {
42 public:
43  ITK_DISALLOW_COPY_AND_MOVE(TotalProgressReporter);
44 
53  SizeValueType totalNumberOfPixels,
54  SizeValueType numberOfUpdates = 100,
55  float progressWeight = 1.0f);
56 
59 
63  void
65  {
66  // all threads needs to check the abort flag
67  if (m_Filter && m_Filter->GetAbortGenerateData())
68  {
69  std::string msg;
70  ProcessAborted e(__FILE__, __LINE__);
71  msg += "Object " + std::string(m_Filter->GetNameOfClass()) + ": AbortGenerateDataOn";
72  e.SetDescription(msg);
73  throw e;
74  }
75  }
77 
79  void
81  {
82  // Inline implementation for efficiency.
83  if (--m_PixelsBeforeUpdate == 0)
84  {
85  m_PixelsBeforeUpdate = m_PixelsPerUpdate;
86  m_CurrentPixel += m_PixelsPerUpdate;
88 
89  if (m_Filter)
90  {
91  m_Filter->IncrementProgress(m_PixelsPerUpdate * m_InverseNumberOfPixels * m_ProgressWeight);
92 
93  this->CheckAbortGenerateData();
94  }
95  }
96  }
97 
98 
100  void
102  {
103 
104  if (count >= m_PixelsBeforeUpdate)
105  {
106  SizeValueType total = static_cast<SizeValueType>(m_PixelsPerUpdate - m_PixelsBeforeUpdate) + count;
107  SizeValueType numberOfUpdates = total / m_PixelsPerUpdate;
108 
109  m_PixelsBeforeUpdate = m_PixelsPerUpdate - total % m_PixelsPerUpdate;
110  m_CurrentPixel += numberOfUpdates * m_PixelsPerUpdate;
111 
112  if (m_Filter)
113  {
114  m_Filter->IncrementProgress(numberOfUpdates * m_PixelsPerUpdate * m_InverseNumberOfPixels * m_ProgressWeight);
115 
116  this->CheckAbortGenerateData();
117  }
118  }
119  else
120  {
121  m_PixelsBeforeUpdate -= count;
122  }
123  }
124 
125 protected:
132 };
133 } // end namespace itk
134 
135 #endif
itk::TotalProgressReporter::m_Filter
ProcessObject * m_Filter
Definition: itkTotalProgressReporter.h:126
itk::TotalProgressReporter::Completed
void Completed(SizeValueType count)
Definition: itkTotalProgressReporter.h:101
itk::TotalProgressReporter::m_PixelsBeforeUpdate
SizeValueType m_PixelsBeforeUpdate
Definition: itkTotalProgressReporter.h:130
itk::TotalProgressReporter::m_InverseNumberOfPixels
float m_InverseNumberOfPixels
Definition: itkTotalProgressReporter.h:127
itkProcessObject.h
itk::TotalProgressReporter::m_CurrentPixel
SizeValueType m_CurrentPixel
Definition: itkTotalProgressReporter.h:128
itk::TotalProgressReporter::CheckAbortGenerateData
void CheckAbortGenerateData()
Definition: itkTotalProgressReporter.h:64
itkIntTypes.h
itk::TotalProgressReporter::CompletedPixel
void CompletedPixel()
Definition: itkTotalProgressReporter.h:80
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::TotalProgressReporter
A progress reporter for concurrent threads.
Definition: itkTotalProgressReporter.h:40
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:138
itk::TotalProgressReporter::m_ProgressWeight
float m_ProgressWeight
Definition: itkTotalProgressReporter.h:131
itk::Math::e
static constexpr double e
Definition: itkMath.h:54
itk::TotalProgressReporter::m_PixelsPerUpdate
SizeValueType m_PixelsPerUpdate
Definition: itkTotalProgressReporter.h:129
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83