ITK  6.0.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 * https://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
24namespace itk
25{
40class ITKCommon_EXPORT TotalProgressReporter
41{
42public:
43 ITK_DISALLOW_COPY_AND_MOVE(TotalProgressReporter);
44
54 SizeValueType totalNumberOfPixels,
55 SizeValueType numberOfUpdates = 100,
56 float progressWeight = 1.0f);
57
60
64 void
66 {
67 // all threads needs to check the abort flag
68 if (m_Filter && m_Filter->GetAbortGenerateData())
69 {
70 std::string msg;
71 ProcessAborted e(__FILE__, __LINE__);
72 msg += "Object " + std::string(m_Filter->GetNameOfClass()) + ": AbortGenerateDataOn";
73 e.SetDescription(msg);
74 throw e;
75 }
76 }
80 void
82 {
83 // Inline implementation for efficiency.
84 if (--m_PixelsBeforeUpdate == 0)
85 {
86 m_PixelsBeforeUpdate = m_PixelsPerUpdate;
87 m_CurrentPixel += m_PixelsPerUpdate;
90 if (m_Filter)
91 {
92 m_Filter->IncrementProgress(m_PixelsPerUpdate * m_InverseNumberOfPixels * m_ProgressWeight);
93
94 this->CheckAbortGenerateData();
95 }
96 }
97 }
98
99
101 void
103 {
104
105 if (count >= m_PixelsBeforeUpdate)
106 {
107 SizeValueType total = static_cast<SizeValueType>(m_PixelsPerUpdate - m_PixelsBeforeUpdate) + count;
108 SizeValueType numberOfUpdates = total / m_PixelsPerUpdate;
109
110 m_PixelsBeforeUpdate = m_PixelsPerUpdate - total % m_PixelsPerUpdate;
111 m_CurrentPixel += numberOfUpdates * m_PixelsPerUpdate;
112
113 if (m_Filter)
114 {
115 m_Filter->IncrementProgress(numberOfUpdates * m_PixelsPerUpdate * m_InverseNumberOfPixels * m_ProgressWeight);
116
117 this->CheckAbortGenerateData();
118 }
119 }
120 else
121 {
122 m_PixelsBeforeUpdate -= count;
123 }
124 }
125
126protected:
133};
134} // end namespace itk
135
136#endif
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
A progress reporter for concurrent threads.
void Completed(SizeValueType count)
TotalProgressReporter(ProcessObject *filter, SizeValueType totalNumberOfPixels, SizeValueType numberOfUpdates=100, float progressWeight=1.0f)
Construct a TotalProgressReporter.
static constexpr double e
Definition: itkMath.h:56
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition: itkIntTypes.h:86