| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkProgressAccumulator.h.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:46 $ |
| 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 __itkProgressAccumulator_h_ |
| 18 |
DEF |
#define __itkProgressAccumulator_h_ |
| 19 |
|
|
| 20 |
|
#include "itkCommand.h" |
| 21 |
|
#include "itkObject.h" |
| 22 |
|
#include "itkProcessObject.h" |
| 23 |
|
#include <vector> |
| 24 |
|
|
| 25 |
|
namespace itk { |
| 26 |
|
|
| 27 |
|
/** |
| 28 |
|
* \class ProgressAccumulator |
| 29 |
|
* \brief Facilitates progress reporting for filters that wrap around |
| 30 |
|
* multiple other filters. |
| 31 |
|
* |
| 32 |
|
* This object allows a mini-pipeline filters to easily keep track of the |
| 33 |
|
* progress performed by the internal filters. |
| 34 |
|
* See DiscreteGaussianImageFilter.txx for an implementation example. |
| 35 |
|
* |
| 36 |
|
* \sa DiscreteGaussianImageFilter |
| 37 |
|
* |
| 38 |
|
*/ |
| 39 |
|
class ITKCommon_EXPORT ProgressAccumulator : public Object |
| 40 |
|
{ |
| 41 |
|
public: |
| 42 |
|
/** Standard class typedefs. */ |
| 43 |
|
typedef ProgressAccumulator Self; |
| 44 |
|
typedef Object Superclass; |
| 45 |
|
typedef SmartPointer<Self> Pointer; |
| 46 |
|
typedef SmartPointer<const Self> ConstPointer; |
| 47 |
|
|
| 48 |
|
/** Typedef for inputting filters */ |
| 49 |
|
typedef ProcessObject GenericFilterType; |
| 50 |
|
typedef GenericFilterType::Pointer GenericFilterPointer; |
| 51 |
|
|
| 52 |
|
/** Standard New method. */ |
| 53 |
|
itkNewMacro(Self); |
| 54 |
|
|
| 55 |
|
/** Runtime information support. */ |
| 56 |
|
itkTypeMacro(ProgressAccumulator,Object); |
| 57 |
|
|
| 58 |
|
/** Get the total progress accumulated by this object */ |
| 59 |
|
itkGetMacro(AccumulatedProgress,float); |
| 60 |
|
|
| 61 |
|
/** Set the mini-pipeline filter */ |
| 62 |
|
itkSetObjectMacro(MiniPipelineFilter,ProcessObject); |
| 63 |
|
|
| 64 |
|
/** Set the mini-pipeline filter */ |
| 65 |
|
itkGetConstObjectMacro(MiniPipelineFilter,ProcessObject); |
| 66 |
|
|
| 67 |
|
/** |
| 68 |
|
* Register a filter with the progress accumulator and specify the |
| 69 |
|
* fraction of the overall progress associated with this filter |
| 70 |
|
*/ |
| 71 |
|
void RegisterInternalFilter(GenericFilterType *filter, float weight); |
| 72 |
|
|
| 73 |
|
/** |
| 74 |
|
* Unregister all filters that have been registered with this object |
| 75 |
|
*/ |
| 76 |
|
void UnregisterAllFilters(); |
| 77 |
|
|
| 78 |
|
/** |
| 79 |
|
* Reset the progress accumulator. This method should be called in |
| 80 |
|
* the beginning of the GenerateData() method in the mini-pipeline |
| 81 |
|
* filter. |
| 82 |
|
*/ |
| 83 |
|
void ResetProgress(); |
| 84 |
|
void ResetFilterProgressAndKeepAccumulatedProgress(); |
| 85 |
|
|
| 86 |
|
protected: |
| 87 |
|
ProgressAccumulator(); |
| 88 |
|
virtual ~ProgressAccumulator(); |
| 89 |
|
void PrintSelf(std::ostream &s, Indent indent) const; |
| 90 |
|
|
| 91 |
|
private: |
| 92 |
|
/** Command for observing progress of pipeline filters */ |
| 93 |
|
typedef MemberCommand< Self > CommandType; |
| 94 |
|
typedef CommandType::Pointer CommandPointer; |
| 95 |
|
|
| 96 |
|
/** Structure associated with each filter in the pipeline */ |
| 97 |
|
struct FilterRecord |
| 98 |
|
{ |
| 99 |
|
// Pointer to the filter |
| 100 |
|
GenericFilterPointer Filter; |
| 101 |
|
|
| 102 |
|
// The weight of the filter in total progress of the mini-pipeline |
| 103 |
|
float Weight; |
| 104 |
|
|
| 105 |
|
// The tags for adding/removing observers to mini-pipeline filter |
| 106 |
|
unsigned long ProgressObserverTag; |
| 107 |
|
unsigned long IterationObserverTag; |
| 108 |
|
|
| 109 |
|
// The progress accumulated by the filter since last Reset() |
| 110 |
|
float Progress; |
| 111 |
|
}; |
| 112 |
|
|
| 113 |
|
/** A callback function that is called by the progressing filters */ |
| 114 |
|
void ReportProgress(Object * object, const EventObject & event); |
| 115 |
|
|
| 116 |
|
/** The client mini-pipeline filter */ |
| 117 |
|
GenericFilterPointer m_MiniPipelineFilter; |
| 118 |
|
|
| 119 |
|
/** An array of record structures */ |
| 120 |
|
typedef std::vector<struct FilterRecord> FilterRecordVector; |
| 121 |
|
|
| 122 |
|
/** The total accumulated progress */ |
| 123 |
|
float m_AccumulatedProgress; |
| 124 |
|
|
| 125 |
|
/** The total accumulated progress for multiple runs of the mini-pipeline */ |
| 126 |
|
float m_BaseAccumulatedProgress; |
| 127 |
|
|
| 128 |
|
/** |
| 129 |
|
* A list of progress proportions of the different filters in the |
| 130 |
|
* pipeline |
| 131 |
|
*/ |
| 132 |
|
FilterRecordVector m_FilterRecord; |
| 133 |
|
|
| 134 |
|
/** The callback command */ |
| 135 |
|
CommandPointer m_CallbackCommand; |
| 136 |
|
}; |
| 137 |
|
|
| 138 |
|
} // End namespace itk |
| 139 |
|
|
| 140 |
|
#endif // __itkProgressAccumulator_h_ |
| 141 |
|
|
| 142 |
EOF |
|