ITK  5.4.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 
24 namespace itk
25 {
40 class ITKCommon_EXPORT TotalProgressReporter
41 {
42 public:
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 
126 protected:
133 };
134 } // end namespace itk
135 
136 #endif
itk::TotalProgressReporter::m_Filter
ProcessObject * m_Filter
Definition: itkTotalProgressReporter.h:127
itk::TotalProgressReporter::Completed
void Completed(SizeValueType count)
Definition: itkTotalProgressReporter.h:102
itk::TotalProgressReporter::m_PixelsBeforeUpdate
SizeValueType m_PixelsBeforeUpdate
Definition: itkTotalProgressReporter.h:131
itk::TotalProgressReporter::m_InverseNumberOfPixels
float m_InverseNumberOfPixels
Definition: itkTotalProgressReporter.h:128
itkProcessObject.h
itk::TotalProgressReporter::m_CurrentPixel
SizeValueType m_CurrentPixel
Definition: itkTotalProgressReporter.h:129
itk::TotalProgressReporter::CheckAbortGenerateData
void CheckAbortGenerateData()
Definition: itkTotalProgressReporter.h:65
itkIntTypes.h
itk::TotalProgressReporter::CompletedPixel
void CompletedPixel()
Definition: itkTotalProgressReporter.h:81
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:139
itk::TotalProgressReporter::m_ProgressWeight
float m_ProgressWeight
Definition: itkTotalProgressReporter.h:132
itk::Math::e
static constexpr double e
Definition: itkMath.h:56
itk::TotalProgressReporter::m_PixelsPerUpdate
SizeValueType m_PixelsPerUpdate
Definition: itkTotalProgressReporter.h:130
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83