ITK  5.2.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  * 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:
63  ITK_DISALLOW_COPY_AND_ASSIGN(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  }
93 
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  }
110 
111  this->CheckAbortGenerateData();
112  }
113  }
114 
115 protected:
124 };
125 } // end namespace itk
126 
127 #endif
itk::ProgressReporter::m_InitialProgress
float m_InitialProgress
Definition: itkProgressReporter.h:122
itk::ProgressReporter::CheckAbortGenerateData
void CheckAbortGenerateData()
Definition: itkProgressReporter.h:80
itk::ProgressReporter::m_ProgressWeight
float m_ProgressWeight
Definition: itkProgressReporter.h:123
itk::ProgressReporter::m_CurrentPixel
SizeValueType m_CurrentPixel
Definition: itkProgressReporter.h:119
itk::ProgressReporter::CompletedPixel
void CompletedPixel()
Definition: itkProgressReporter.h:96
itk::ThreadIdType
unsigned int ThreadIdType
Definition: itkIntTypes.h:99
itkProcessObject.h
itkIntTypes.h
itk::ProgressReporter::m_Filter
ProcessObject * m_Filter
Definition: itkProgressReporter.h:116
itk::ProgressReporter::m_PixelsPerUpdate
SizeValueType m_PixelsPerUpdate
Definition: itkProgressReporter.h:120
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:138
itk::ProgressReporter::m_PixelsBeforeUpdate
SizeValueType m_PixelsBeforeUpdate
Definition: itkProgressReporter.h:121
itk::Math::e
static constexpr double e
Definition: itkMath.h:54
itk::ProgressReporter
Implements progress tracking for a filter.
Definition: itkProgressReporter.h:60
itk::ProgressReporter::m_InverseNumberOfPixels
float m_InverseNumberOfPixels
Definition: itkProgressReporter.h:118
itk::ProgressReporter::m_ThreadId
ThreadIdType m_ThreadId
Definition: itkProgressReporter.h:117
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83