ITK  6.0.0
Insight Toolkit
itkProgressReporter.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 itkProgressReporter_h
19#define itkProgressReporter_h
20
21#include "itkIntTypes.h"
22#include "itkProcessObject.h"
23
24namespace itk
25{
60class ITKCommon_EXPORT ProgressReporter
61{
62public:
63 ITK_DISALLOW_COPY_AND_MOVE(ProgressReporter);
64
67 ThreadIdType threadId,
68 SizeValueType numberOfPixels,
69 SizeValueType numberOfUpdates = 100,
70 float initialProgress = 0.0f,
71 float progressWeight = 1.0f);
72
75
79 void
81 {
82 // all threads needs to check the abort flag
83 if (m_Filter && m_Filter->GetAbortGenerateData())
84 {
85 std::string msg;
86 ProcessAborted e(__FILE__, __LINE__);
87 msg += "Object " + std::string(m_Filter->GetNameOfClass()) + ": AbortGenerateDataOn";
88 e.SetDescription(msg);
89 throw e;
90 }
91 }
95 void
97 {
98 // Inline implementation for efficiency.
99 if (--m_PixelsBeforeUpdate == 0)
100 {
101 m_PixelsBeforeUpdate = m_PixelsPerUpdate;
102 m_CurrentPixel += m_PixelsPerUpdate;
103 // only thread 0 should update the progress of the filter
104 if (m_ThreadId == 0 && m_Filter)
105 {
106 m_Filter->UpdateProgress(static_cast<float>(m_CurrentPixel) * m_InverseNumberOfPixels * m_ProgressWeight +
107 m_InitialProgress);
108 }
111 this->CheckAbortGenerateData();
112 }
113 }
114
115protected:
124};
125} // end namespace itk
126
127#endif
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Implements progress tracking for a filter.
SizeValueType m_PixelsBeforeUpdate
ProgressReporter(ProcessObject *filter, ThreadIdType threadId, SizeValueType numberOfPixels, SizeValueType numberOfUpdates=100, float initialProgress=0.0f, float progressWeight=1.0f)
static constexpr double e
Definition: itkMath.h:56
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned int ThreadIdType
Definition: itkIntTypes.h:102
unsigned long SizeValueType
Definition: itkIntTypes.h:86