Slicer 5.9
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
itkPluginFilterWatcher.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef itkPluginFilterWatcher_h
19#define itkPluginFilterWatcher_h
20
21// ModuleDescriptionParser includes
22#include <ModuleProcessInformation.h>
23
24// ITK includes
25#include <itkSimpleFilterWatcher.h>
26
27namespace itk
28{
29
35class PluginFilterWatcher : public SimpleFilterWatcher
36{
37public:
38 PluginFilterWatcher(itk::ProcessObject* o, const char* comment = "", ModuleProcessInformation* inf = nullptr, double fraction = 1.0, double start = 0.0)
39 : SimpleFilterWatcher(o, comment)
40 {
42 m_Fraction = fraction;
43 m_Start = start;
44 }
45
46protected:
47 //-----------------------------------------------------------------------------
49 void ShowProgress() override
50 {
51 if (this->GetProcess())
52 {
53 this->SetSteps(this->GetSteps() + 1);
54 if (!this->GetQuiet())
55 {
57 {
58 strncpy(m_ProcessInformation->ProgressMessage, this->GetComment().c_str(), 1023);
59 m_ProcessInformation->Progress = (this->GetProcess()->GetProgress() * m_Fraction + m_Start);
60 if (m_Fraction != 1.0)
61 {
62 m_ProcessInformation->StageProgress = this->GetProcess()->GetProgress();
63 }
64
65 try
66 {
67 this->GetTimeProbe().Stop();
68 m_ProcessInformation->ElapsedTime = this->GetTimeProbe().GetMean() * this->GetTimeProbe().GetNumberOfStops();
69 }
70 catch (...)
71 {
72 // ignore time probe exceptions
73 }
74 this->GetTimeProbe().Start();
75
76 if (m_ProcessInformation->Abort)
77 {
78 this->GetProcess()->AbortGenerateDataOn();
79 m_ProcessInformation->Progress = 0;
80 m_ProcessInformation->StageProgress = 0;
81 }
82
83 if (m_ProcessInformation->ProgressCallbackFunction //
84 && m_ProcessInformation->ProgressCallbackClientData)
85 {
86 (*(m_ProcessInformation->ProgressCallbackFunction))(m_ProcessInformation->ProgressCallbackClientData);
87 }
88 }
89 else
90 {
91 std::cout << "<filter-progress>" << (this->GetProcess()->GetProgress() * m_Fraction) + m_Start << "</filter-progress>" << std::endl;
92 if (m_Fraction != 1.0)
93 {
94 std::cout << "<filter-stage-progress>" << this->GetProcess()->GetProgress() << "</filter-stage-progress>" << std::endl;
95 }
96 std::cout << std::flush;
97 }
98 }
99 }
100 }
101
102 //-----------------------------------------------------------------------------
104 void StartFilter() override
105 {
106 this->SetSteps(0);
107 this->SetIterations(0);
108 this->GetTimeProbe().Start();
109 if (!this->GetQuiet())
110 {
112 {
113 m_ProcessInformation->Progress = 0;
114 m_ProcessInformation->StageProgress = 0;
115 strncpy(m_ProcessInformation->ProgressMessage, this->GetComment().c_str(), 1023);
116
117 if (m_ProcessInformation->ProgressCallbackFunction //
118 && m_ProcessInformation->ProgressCallbackClientData)
119 {
120 (*(m_ProcessInformation->ProgressCallbackFunction))(m_ProcessInformation->ProgressCallbackClientData);
121 }
122 }
123 else
124 {
125 std::cout << "<filter-start>" << std::endl;
126 std::cout << "<filter-name>" << (this->GetProcess() ? this->GetProcess()->GetNameOfClass() : "None") << "</filter-name>" << std::endl;
127 std::cout << "<filter-comment>"
128 << " \"" << this->GetComment() << "\" "
129 << "</filter-comment>" << std::endl;
130 std::cout << "</filter-start>" << std::endl;
131 std::cout << std::flush;
132 }
133 }
134 }
135
136 //-----------------------------------------------------------------------------
138 void EndFilter() override
139 {
140 this->GetTimeProbe().Stop();
141 if (!this->GetQuiet())
142 {
144 {
145 m_ProcessInformation->Progress = 0;
146 m_ProcessInformation->StageProgress = 0;
147
148 m_ProcessInformation->ElapsedTime = this->GetTimeProbe().GetMean() * this->GetTimeProbe().GetNumberOfStops();
149
150 if (m_ProcessInformation->ProgressCallbackFunction //
151 && m_ProcessInformation->ProgressCallbackClientData)
152 {
153 (*(m_ProcessInformation->ProgressCallbackFunction))(m_ProcessInformation->ProgressCallbackClientData);
154 }
155 }
156 else
157 {
158 std::cout << "<filter-end>" << std::endl;
159 std::cout << "<filter-name>" << (this->GetProcess() ? this->GetProcess()->GetNameOfClass() : "None") << "</filter-name>" << std::endl;
160 std::cout << "<filter-time>" << this->GetTimeProbe().GetMean() << "</filter-time>" << std::endl;
161 std::cout << "</filter-end>";
162 std::cout << std::flush;
163 }
164 }
165 }
166
167 ModuleProcessInformation* m_ProcessInformation;
168
170 double m_Start;
171};
172
173} // end namespace itk
174
175#endif
PluginFilterWatcher(itk::ProcessObject *o, const char *comment="", ModuleProcessInformation *inf=nullptr, double fraction=1.0, double start=0.0)
ModuleProcessInformation * m_ProcessInformation
Simplified inverse ITK transforms.