Slicer 5.11
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
27// STD includes
28#include <iostream>
29
30namespace itk
31{
32
38class PluginFilterWatcher : public SimpleFilterWatcher
39{
40public:
41 PluginFilterWatcher(itk::ProcessObject* o, const char* comment = "", ModuleProcessInformation* inf = nullptr, double fraction = 1.0, double start = 0.0)
42 : SimpleFilterWatcher(o, comment)
43 {
45 m_Fraction = fraction;
46 m_Start = start;
47 }
48
49protected:
50 //-----------------------------------------------------------------------------
52 void ShowProgress() override
53 {
54 if (this->GetProcess())
55 {
56 this->SetSteps(this->GetSteps() + 1);
57 if (!this->GetQuiet())
58 {
60 {
61 strncpy(m_ProcessInformation->ProgressMessage, this->GetComment().c_str(), 1023);
62 m_ProcessInformation->Progress = (this->GetProcess()->GetProgress() * m_Fraction + m_Start);
63 if (m_Fraction != 1.0)
64 {
65 m_ProcessInformation->StageProgress = this->GetProcess()->GetProgress();
66 }
67
68 try
69 {
70 this->GetTimeProbe().Stop();
71 m_ProcessInformation->ElapsedTime = this->GetTimeProbe().GetMean() * this->GetTimeProbe().GetNumberOfStops();
72 }
73 catch (...)
74 {
75 // ignore time probe exceptions
76 }
77 this->GetTimeProbe().Start();
78
79 if (m_ProcessInformation->Abort)
80 {
81 this->GetProcess()->AbortGenerateDataOn();
82 m_ProcessInformation->Progress = 0;
83 m_ProcessInformation->StageProgress = 0;
84 }
85
86 if (m_ProcessInformation->ProgressCallbackFunction //
87 && m_ProcessInformation->ProgressCallbackClientData)
88 {
89 (*(m_ProcessInformation->ProgressCallbackFunction))(m_ProcessInformation->ProgressCallbackClientData);
90 }
91 }
92 else
93 {
94 std::cout << "<filter-progress>" << (this->GetProcess()->GetProgress() * m_Fraction) + m_Start << "</filter-progress>" << std::endl;
95 if (m_Fraction != 1.0)
96 {
97 std::cout << "<filter-stage-progress>" << this->GetProcess()->GetProgress() << "</filter-stage-progress>" << std::endl;
98 }
99 std::cout << std::flush;
100 }
101 }
102 }
103 }
104
105 //-----------------------------------------------------------------------------
107 void StartFilter() override
108 {
109 this->SetSteps(0);
110 this->SetIterations(0);
111 this->GetTimeProbe().Start();
112 if (!this->GetQuiet())
113 {
115 {
116 m_ProcessInformation->Progress = 0;
117 m_ProcessInformation->StageProgress = 0;
118 strncpy(m_ProcessInformation->ProgressMessage, this->GetComment().c_str(), 1023);
119
120 if (m_ProcessInformation->ProgressCallbackFunction //
121 && m_ProcessInformation->ProgressCallbackClientData)
122 {
123 (*(m_ProcessInformation->ProgressCallbackFunction))(m_ProcessInformation->ProgressCallbackClientData);
124 }
125 }
126 else
127 {
128 std::cout << "<filter-start>" << std::endl;
129 std::cout << "<filter-name>" << (this->GetProcess() ? this->GetProcess()->GetNameOfClass() : "None") << "</filter-name>" << std::endl;
130 std::cout << "<filter-comment>"
131 << " \"" << this->GetComment() << "\" "
132 << "</filter-comment>" << std::endl;
133 std::cout << "</filter-start>" << std::endl;
134 std::cout << std::flush;
135 }
136 }
137 }
138
139 //-----------------------------------------------------------------------------
141 void EndFilter() override
142 {
143 this->GetTimeProbe().Stop();
144 if (!this->GetQuiet())
145 {
147 {
148 m_ProcessInformation->Progress = 0;
149 m_ProcessInformation->StageProgress = 0;
150
151 m_ProcessInformation->ElapsedTime = this->GetTimeProbe().GetMean() * this->GetTimeProbe().GetNumberOfStops();
152
153 if (m_ProcessInformation->ProgressCallbackFunction //
154 && m_ProcessInformation->ProgressCallbackClientData)
155 {
156 (*(m_ProcessInformation->ProgressCallbackFunction))(m_ProcessInformation->ProgressCallbackClientData);
157 }
158 }
159 else
160 {
161 std::cout << "<filter-end>" << std::endl;
162 std::cout << "<filter-name>" << (this->GetProcess() ? this->GetProcess()->GetNameOfClass() : "None") << "</filter-name>" << std::endl;
163 std::cout << "<filter-time>" << this->GetTimeProbe().GetMean() << "</filter-time>" << std::endl;
164 std::cout << "</filter-end>";
165 std::cout << std::flush;
166 }
167 }
168 }
169
170 ModuleProcessInformation* m_ProcessInformation;
171
173 double m_Start;
174};
175
176} // end namespace itk
177
178#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.