ITK  5.1.0
Insight Toolkit
itkProgressReporter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 
77  void
79  {
80  // Inline implementation for efficiency.
81  if (--m_PixelsBeforeUpdate == 0)
82  {
83  m_PixelsBeforeUpdate = m_PixelsPerUpdate;
84  m_CurrentPixel += m_PixelsPerUpdate;
85  // only thread 0 should update the progress of the filter
86  if (m_ThreadId == 0)
87  {
88  m_Filter->UpdateProgress(static_cast<float>(m_CurrentPixel) * m_InverseNumberOfPixels * m_ProgressWeight +
89  m_InitialProgress);
90  }
91  // all threads needs to check the abort flag
92  if (m_Filter->GetAbortGenerateData())
93  {
94  std::string msg;
95  ProcessAborted e(__FILE__, __LINE__);
96  msg += "Object " + std::string(m_Filter->GetNameOfClass()) + ": AbortGenerateDataOn";
97  e.SetDescription(msg);
98  throw e;
99  }
100  }
101  }
103 
104 protected:
113 };
114 } // end namespace itk
115 
116 #endif
itk::ProgressReporter::m_InitialProgress
float m_InitialProgress
Definition: itkProgressReporter.h:111
itk::ProgressReporter::m_ProgressWeight
float m_ProgressWeight
Definition: itkProgressReporter.h:112
itk::ProgressReporter::m_CurrentPixel
SizeValueType m_CurrentPixel
Definition: itkProgressReporter.h:108
itk::ProgressReporter::CompletedPixel
void CompletedPixel()
Definition: itkProgressReporter.h:78
itk::ThreadIdType
unsigned int ThreadIdType
Definition: itkIntTypes.h:99
itkProcessObject.h
itkIntTypes.h
itk::ProgressReporter::m_Filter
ProcessObject * m_Filter
Definition: itkProgressReporter.h:105
itk::ProgressReporter::m_PixelsPerUpdate
SizeValueType m_PixelsPerUpdate
Definition: itkProgressReporter.h:109
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkArray.h:26
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:135
itk::ProgressReporter::m_PixelsBeforeUpdate
SizeValueType m_PixelsBeforeUpdate
Definition: itkProgressReporter.h:110
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:107
itk::ProgressReporter::m_ThreadId
ThreadIdType m_ThreadId
Definition: itkProgressReporter.h:106
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83