Orfeo Toolbox  3.16
itkProgressAccumulator.cxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkProgressAccumulator.cxx,v $
5  Language: C++
6  Date: $Date: 2007-12-21 18:30:08 $
7  Version: $Revision: 1.10 $
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 #include "itkProgressAccumulator.h"
18 
19 namespace itk {
20 
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 
36 {
37  UnregisterAllFilters();
38 }
39 
40 void
43 {
44  // Observe the filter
45  unsigned long progressTag =
46  filter->AddObserver(ProgressEvent(), m_CallbackCommand);
47  unsigned long iterationTag =
48  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
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
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
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
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  // check for abort
134  if ( m_MiniPipelineFilter->GetAbortGenerateData() )
135  {
136  // Abort the filter that is reporting progress
137  FilterRecordVector::iterator fit;
138  for(fit = m_FilterRecord.begin();fit != m_FilterRecord.end();++fit)
139  {
140  if (who == fit->Filter)
141  {
142  fit->Filter->AbortGenerateDataOn();
143  }
144  }
145  }
146  }
147  else if (typeid( event ) == typeid ( ie ) )
148  {
149  }
150 }
151 
153 ::PrintSelf(std::ostream &os, Indent indent) const
154 {
155  Superclass::PrintSelf(os,indent);
156 
157  if (m_MiniPipelineFilter)
158  {
159  os << indent << m_MiniPipelineFilter << std::endl;
160  }
161  os << indent << m_AccumulatedProgress << std::endl;
162  os << indent << m_BaseAccumulatedProgress << std::endl;
163 }
164 
165 } // End namespace itk

Generated at Sun Feb 3 2013 00:00:03 for Orfeo Toolbox with doxygen 1.8.1.1