ITK  5.1.0
Insight Segmentation and Registration 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  SizeValueType numberOfPixels,
68  SizeValueType numberOfUpdates = 100,
69  float initialProgress = 0.0f,
70  float progressWeight = 1.0f);
71 
74 
77  {
78  // Inline implementation for efficiency.
79  if ( --m_PixelsBeforeUpdate == 0 )
80  {
81  m_PixelsBeforeUpdate = m_PixelsPerUpdate;
82  m_CurrentPixel += m_PixelsPerUpdate;
83  // only thread 0 should update the progress of the filter
84  if ( m_ThreadId == 0 )
85  {
86  m_Filter->UpdateProgress(
87  static_cast<float>(m_CurrentPixel) * m_InverseNumberOfPixels * m_ProgressWeight + m_InitialProgress);
88  }
89  // all threads needs to check the abort flag
90  if ( m_Filter->GetAbortGenerateData() )
91  {
92  std::string msg;
93  ProcessAborted e(__FILE__, __LINE__);
94  msg += "Object " + std::string( m_Filter->GetNameOfClass() ) + ": AbortGenerateDataOn";
95  e.SetDescription(msg);
96  throw e;
97  }
98  }
99  }
101 
102 protected:
111 };
112 } // end namespace itk
113 
114 #endif
unsigned long SizeValueType
Definition: itkIntTypes.h:83
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkArray.h:26
SizeValueType m_PixelsBeforeUpdate
Implements progress tracking for a filter.
static constexpr double e
The base of the natural logarithm or Euler's number
Definition: itkMath.h:53
unsigned int ThreadIdType
Definition: itkIntTypes.h:99