KWStyle - itkIterationReporter.h
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkIterationReporter.h.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:40 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12      This software is distributed WITHOUT ANY WARRANTY; without even 
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14      PURPOSE.  See the above copyright notices for more information.
15
16 =========================================================================*/
17 DEF #ifndef _itkIterationReporter_h
18 DEF #define _itkIterationReporter_h
19
20 #include "itkProcessObject.h"
21
22 namespace itk
23 {
24
25 /** \class IterationReporter
26  * \brief Implements iterations tracking for a filter.
27  *
28  * This is a utility class for use by filter implementations in
29  * GenerateData() and ThreadedGenerateData().
30  *
31  * This class is intended to be used in iterative filter for which
32  * a progress cannot be stablished. These filters run until an stopping
33  * criterion is reached and it is not possible to anticipate how long
34  * it will take to get to the stopping point.
35  *
36  * This class is constructed before entering the iteration loop in the 
37  * filter. The CompletedStep() method should be called at every iteration.
38  * The reporter will count the number of calls and will invoke an
39  * IterationEvent every certain number of calls. The default period
40  * is 100.
41  *
42  * Example usage:
43  *
44  *   IterationReporter iteration(this, threadId, 100);
45  *
46  *   for( each pixel )
47  *     {
48 IND **     ...
49 IND **     iteration.CompletedStep();
50 IND **     }
51  *
52  * When used in a non-threaded filter, the threadId argument should be 0.
53  */
54 class ITKCommon_EXPORT IterationReporter
55 {
56 public:
57   /** Constructor sets progress to 0 because the filter is starting.  */
58   IterationReporter(ProcessObject* filter, int threadId,
59                    unsigned long stepsPerUpdate = 100);
60   
61   /** Destructor */
62   ~IterationReporter() {};
63   
64   /** Called by a filter once per iteration.  */
65   void CompletedStep()
66     {
67     // Inline implementation for efficiency.
68     // We don't need to test for thread id 0 here because the
69     // constructor sets m_StepsBeforeUpdate to a value larger than
70     // the number of pixels for threads other than 0.
71     if(--m_StepsBeforeUpdate == 0)
72       {
73       m_StepsBeforeUpdate = m_StepsPerUpdate;
74       m_Filter->InvokeEvent( IterationEvent() );
75       }
76     }
77 protected:
78   ProcessObject* m_Filter;
79   int m_ThreadId;
80   unsigned long m_StepsPerUpdate;
81   unsigned long m_StepsBeforeUpdate;
82 };
83
84 // end namespace itk
85
86 #endif
87

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:17PM
© Kitware Inc.