KWStyle - itkProgressAccumulator.cxx
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkProgressAccumulator.cxx.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 DEF =========================================================================*/
17 #include "itkProgressAccumulator.h"
18
19 namespace itk {
20
21 ProgressAccumulator
22 ::ProgressAccumulator()
23 {
24   m_MiniPipelineFilter = 0;
25
26   // Initialize the progress values
27   this->ResetProgress();
28
29   // Create a member command
30   m_CallbackCommand = CommandType::New();
31   m_CallbackCommand->SetCallbackFunction( this, & Self::ReportProgress );
32 }
33
34 ProgressAccumulator
35 ::~ProgressAccumulator()
36 {
37   UnregisterAllFilters();
38 }
39
40 void
41 ProgressAccumulator
42 ::RegisterInternalFilter(GenericFilterType *filter,float weight)
43 {
44   // Observe the filter
45   unsigned long progressTag = 
46 IND ****filter->AddObserver(ProgressEvent(), m_CallbackCommand);
47   unsigned long iterationTag = 
48 IND ****filter->AddObserver(IterationEvent(), m_CallbackCommand);
49   
50   // Create a record for the filter
51   struct FilterRecord record;
52   record.Filter = filter;
53   record.Weight = weight;
54   record.ProgressObserverTag = progressTag;
55   record.IterationObserverTag = iterationTag;
56   record.Progress = 0.0f;
57
58   // Add the record to the list
59   m_FilterRecord.push_back(record);
60 }
61
62 void 
63 ProgressAccumulator
64 ::UnregisterAllFilters()
65 {
66   // The filters should no longer be observing us
67   FilterRecordVector::iterator it;
68   for(it = m_FilterRecord.begin();it!=m_FilterRecord.end();++it)
69     {
70     it->Filter->RemoveObserver(it->ProgressObserverTag);
71     it->Filter->RemoveObserver(it->IterationObserverTag);
72     }
73
74   // Clear the filter array
75   m_FilterRecord.clear();
76
77   // Reset the progress meter
78   ResetProgress();
79 }
80
81 void 
82 ProgressAccumulator
83 ::ResetProgress()
84 {
85   // Reset the accumulated progress
86   m_AccumulatedProgress     = 0.0f;
87   m_BaseAccumulatedProgress = 0.0f;
88   
89   // Reset each of the individial progress meters 
90   FilterRecordVector::iterator it;
91   for(it = m_FilterRecord.begin();it!=m_FilterRecord.end();++it)
92     {
93     it->Progress = 0.0f;
94     it->Filter->SetProgress( 0.0f );
95     }
96 }
97
98 void 
99 ProgressAccumulator
100 ::ResetFilterProgressAndKeepAccumulatedProgress()
101 {
102   m_BaseAccumulatedProgress = m_AccumulatedProgress;
103   // Reset each of the individial progress meters 
104   FilterRecordVector::iterator it;
105   for(it = m_FilterRecord.begin();it!=m_FilterRecord.end();++it)
106     {
107     it->Progress = 0.0f;
108     it->Filter->SetProgress( 0.0f );
109     }
110 }
111
112
113 void 
114 ProgressAccumulator
115 ::ReportProgress(Object *, const EventObject &event)
116 {
117   ProgressEvent  pe;
118   IterationEvent ie;
119   if( typeid( event ) == typeid( pe ) )
120     {
121     // Add up the progress from different filters
122     m_AccumulatedProgress = m_BaseAccumulatedProgress;
123
124     FilterRecordVector::iterator it;
125     for(it = m_FilterRecord.begin();it!=m_FilterRecord.end();++it)
126       {
127       m_AccumulatedProgress += it->Filter->GetProgress() * it->Weight;
128       }
129
130     // Update the progress of the client mini-pipeline filter
131     m_MiniPipelineFilter->UpdateProgress(m_AccumulatedProgress);
132     }
133   else if (typeid( event ) == typeid ( ie ) )
134     {
135     }
136 }
137
138 void ProgressAccumulator
139 ::PrintSelf(std::ostream &os, Indent indent) const
140 {
141   Superclass::PrintSelf(os,indent);
142
143   if (m_MiniPipelineFilter)
144     {
145     os << indent << m_MiniPipelineFilter << std::endl;
146     }
147   os << indent << m_AccumulatedProgress     << std::endl;
148   os << indent << m_BaseAccumulatedProgress << std::endl;
149 }
150
151 // End namespace itk
152
153 EOF
154 EOF,EML

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