ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkProgressAccumulator.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkProgressAccumulator_h
00019 #define __itkProgressAccumulator_h
00020 
00021 #include "itkCommand.h"
00022 #include "itkProcessObject.h"
00023 #include <vector>
00024 
00025 namespace itk
00026 {
00040 class ITKCommon_EXPORT ProgressAccumulator:public Object
00041 {
00042 public:
00043 
00045   typedef ProgressAccumulator        Self;
00046   typedef Object                     Superclass;
00047   typedef SmartPointer< Self >       Pointer;
00048   typedef SmartPointer< const Self > ConstPointer;
00049 
00051   typedef ProcessObject              GenericFilterType;
00052   typedef GenericFilterType::Pointer GenericFilterPointer;
00053 
00055   itkNewMacro(Self);
00056 
00058   itkTypeMacro(ProgressAccumulator, Object);
00059 
00061   itkGetConstMacro(AccumulatedProgress, float);
00062 
00064   itkSetObjectMacro(MiniPipelineFilter, ProcessObject);
00065 
00067   itkGetConstObjectMacro(MiniPipelineFilter, ProcessObject);
00068 
00073   void RegisterInternalFilter(GenericFilterType *filter, float weight);
00074 
00078   void UnregisterAllFilters();
00079 
00085   void ResetProgress();
00086 
00087   void ResetFilterProgressAndKeepAccumulatedProgress();
00088 
00089 protected:
00090   ProgressAccumulator();
00091   virtual ~ProgressAccumulator();
00092   void PrintSelf(std::ostream & s, Indent indent) const;
00093 
00094 private:
00096   typedef MemberCommand< Self > CommandType;
00097   typedef CommandType::Pointer  CommandPointer;
00098 
00100   struct FilterRecord {
00101     // Pointer to the filter
00102     GenericFilterPointer Filter;
00103 
00104     // The weight of the filter in total progress of the mini-pipeline
00105     float Weight;
00106 
00107     // The tags for adding/removing observers to mini-pipeline filter
00108     unsigned long ProgressObserverTag;
00109     unsigned long IterationObserverTag;
00110 
00111     // The progress accumulated by the filter since last Reset()
00112     float Progress;
00113   };
00114 
00116   void ReportProgress(Object *object, const EventObject & event);
00117 
00119   GenericFilterPointer m_MiniPipelineFilter;
00120 
00122   typedef std::vector< struct FilterRecord > FilterRecordVector;
00123 
00125   float m_AccumulatedProgress;
00126 
00128   float m_BaseAccumulatedProgress;
00129 
00134   FilterRecordVector m_FilterRecord;
00135 
00137   CommandPointer m_CallbackCommand;
00138 };
00139 } // End namespace itk
00140 
00141 #endif // __itkProgressAccumulator_h_
00142