Computer Assisted Medical Intervention Tool Kit  version 5.1
ItkProgressObserver.h
Go to the documentation of this file.
1/*****************************************************************************
2 * $CAMITK_LICENCE_BEGIN$
3 *
4 * CamiTK - Computer Assisted Medical Intervention ToolKit
5 * (c) 2001-2023 Univ. Grenoble Alpes, CNRS, Grenoble INP, TIMC, 38000 Grenoble, France
6 *
7 * Visit http://camitk.imag.fr for more information
8 *
9 * This file is part of CamiTK.
10 *
11 * CamiTK is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
14 *
15 * CamiTK is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
22 *
23 * $CAMITK_LICENCE_END$
24 ****************************************************************************/
25
26#ifndef ITK_PROGRESS_OBSERVER
27#define ITK_PROGRESS_OBSERVER
28
29// -- Core image component stuff
30#include "Application.h"
31
32// -- itk stuff
33#include <itkCommand.h>
34#include <itkProcessObject.h>
35
36namespace camitk {
37
46class ItkProgressObserver : public itk::Command {
47public:
49 typedef itk::Command Superclass;
50 typedef itk::SmartPointer<Self> Pointer;
52
53protected:
55
56public:
57 void Execute(itk::Object* caller, const itk::EventObject& event);
58 void Execute(const itk::Object* object, const itk::EventObject& event);
59 void Reset();
60 void SetCoef(double coef);
61 void SetStartValue(double startValue);
62
63private :
64 double compteur;
65 double coef;
66 double startValue;
67};
68
69
71 coef = 1.0;
72 compteur = 0.0;
73 startValue = 0.0;
74 // update the progress bar if there is one!
76}
77
78inline void ItkProgressObserver::Execute(itk::Object* caller, const itk::EventObject& event) {
79 Execute((const itk::Object*)caller, event);
80}
81
82inline void ItkProgressObserver::Execute(const itk::Object* object, const itk::EventObject& event) {
83 const itk::ProcessObject* filter =
84 dynamic_cast< const itk::ProcessObject* >(object);
85 if (! itk::ProgressEvent().CheckEvent(&event)) {
86 return;
87 }
88 compteur = filter->GetProgress();
89 // update the progress bar if there is one!
90 Application::setProgressBarValue(startValue + compteur * coef);
91}
92
94 compteur = 0.0;
95 startValue = 0.0;
96 // update the progress bar if there is one!
98}
99
100inline void ItkProgressObserver::SetCoef(double coef) {
101 this->coef = coef;
102}
103
104inline void ItkProgressObserver::SetStartValue(double startValue) {
105 this->startValue = startValue;
106}
107
108}
109
110#endif //ITK_PROGRESS_OBSERVER
static void setProgressBarValue(int)
set the progress bar value, value should be in [0..100].
Definition: Application.cpp:374
Allows showing a progress bar when using ITK methods.
Definition: ItkProgressObserver.h:46
itk::SmartPointer< Self > Pointer
Definition: ItkProgressObserver.h:50
ItkProgressObserver()
Definition: ItkProgressObserver.h:70
void Reset()
Definition: ItkProgressObserver.h:93
void Execute(itk::Object *caller, const itk::EventObject &event)
Definition: ItkProgressObserver.h:78
void SetCoef(double coef)
Definition: ItkProgressObserver.h:100
void SetStartValue(double startValue)
Definition: ItkProgressObserver.h:104
itk::Command Superclass
Definition: ItkProgressObserver.h:49
ItkProgressObserver Self
Definition: ItkProgressObserver.h:48
Definition: Action.cpp:35