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 itkProgressTransformer_h
19 #define itkProgressTransformer_h
20 
21 #include "itkProcessObject.h"
22 #include "itkCommand.h"
23 
24 namespace itk
25 {
26 /**
27  * \class ProgressTransformer
28  * \brief Transforms progress updates from [0%, 100%] to desired scale.
29  *
30  * This class is designed to be allocated on the stack. Code sample:
31  *
32  *   ProgressTransformer progress2( 0.55f, 0.6f, this );
33  *   multiThreader->ParallelizeArray(0, m_SomeArray.size(),
34  *     [this]( SizeValueType index ) { this->ComputeInParallel( index ); },
35  *     progress2.GetProcessObject() );
36  *
37  *
38  * \sa ProgressReporter, ProcessObject
39  * \ingroup ITKCommon
40  */
41 class ITKCommon_EXPORT ProgressTransformer
42 {
43 public:
44   ITK_DISALLOW_COPY_AND_ASSIGN( ProgressTransformer );
45 
46   ProgressTransformer(float start, float end, ProcessObject* targetFilter);
47 
GetProcessObject()48   ProcessObject* GetProcessObject()
49   {
50     return m_Dummy.GetPointer();
51   }
52 
53   void UpdateProgress();
54 
55   ~ProgressTransformer();
56 
57 private:
58   float m_Start;
59   float m_End;
60 
61   ProcessObject* m_TargetFilter;
62 
63   ProcessObject::Pointer m_Dummy;
64 
65   using CommandType = SimpleMemberCommand< ProgressTransformer >;
66   CommandType::Pointer m_ProgressCommand;
67 
68   unsigned long m_ProgressTag;
69 };
70 } // end namespace itk
71 #endif // itkProgressTransformer_h
72