Slicer  4.11
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
itkPluginFilterWatcher.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Copyright (c) Insight Software Consortium. All rights reserved.
4  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
5 
6  This software is distributed WITHOUT ANY WARRANTY; without even
7  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8  PURPOSE. See the above copyright notices for more information.
9 
10 =========================================================================*/
11 #ifndef itkPluginFilterWatcher_h
12 #define itkPluginFilterWatcher_h
13 
14 // ModuleDescriptionParser includes
15 #include <ModuleProcessInformation.h>
16 
17 // ITK includes
18 #include <itkSimpleFilterWatcher.h>
19 
20 namespace itk
21 {
22 
28 class PluginFilterWatcher: public SimpleFilterWatcher
29 {
30 public:
31  PluginFilterWatcher(itk::ProcessObject* o,
32  const char *comment="",
33  ModuleProcessInformation *inf=nullptr,
34  double fraction = 1.0,
35  double start = 0.0)
36  : SimpleFilterWatcher(o, comment)
37  {
39  m_Fraction = fraction;
40  m_Start = start;
41  }
42 
43 protected:
44 
45 //-----------------------------------------------------------------------------
47 void ShowProgress() override
48 {
49  if (this->GetProcess())
50  {
51  this->SetSteps( this->GetSteps()+1 );
52  if (!this->GetQuiet())
53  {
55  {
56  strncpy(m_ProcessInformation->ProgressMessage,
57  this->GetComment().c_str(), 1023);
58  m_ProcessInformation->Progress =
59  (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
69  = this->GetTimeProbe().GetMean()
70  * this->GetTimeProbe().GetNumberOfStops();
71  }
72  catch(...)
73  {
74  // ignore time probe exceptions
75  }
76  this->GetTimeProbe().Start();
77 
78  if (m_ProcessInformation->Abort)
79  {
80  this->GetProcess()->AbortGenerateDataOn();
81  m_ProcessInformation->Progress = 0;
82  m_ProcessInformation->StageProgress = 0;
83  }
84 
85  if (m_ProcessInformation->ProgressCallbackFunction
86  && m_ProcessInformation->ProgressCallbackClientData)
87  {
88  (*(m_ProcessInformation->ProgressCallbackFunction))(m_ProcessInformation->ProgressCallbackClientData);
89  }
90  }
91  else
92  {
93  std::cout << "<filter-progress>"
94  << (this->GetProcess()->GetProgress() * m_Fraction) + m_Start
95  << "</filter-progress>"
96  << std::endl;
97  if (m_Fraction != 1.0)
98  {
99  std::cout << "<filter-stage-progress>"
100  << this->GetProcess()->GetProgress()
101  << "</filter-stage-progress>"
102  << std::endl;
103  }
104  std::cout << std::flush;
105  }
106  }
107  }
108 }
109 
110 //-----------------------------------------------------------------------------
112 void StartFilter() override
113 {
114  this->SetSteps(0);
115  this->SetIterations(0);
116  this->GetTimeProbe().Start();
117  if (!this->GetQuiet())
118  {
120  {
121  m_ProcessInformation->Progress = 0;
122  m_ProcessInformation->StageProgress = 0;
123  strncpy(m_ProcessInformation->ProgressMessage,
124  this->GetComment().c_str(), 1023);
125 
126  if (m_ProcessInformation->ProgressCallbackFunction
127  && m_ProcessInformation->ProgressCallbackClientData)
128  {
129  (*(m_ProcessInformation->ProgressCallbackFunction))(m_ProcessInformation->ProgressCallbackClientData);
130  }
131  }
132  else
133  {
134  std::cout << "<filter-start>"
135  << std::endl;
136  std::cout << "<filter-name>"
137  << (this->GetProcess()
138  ? this->GetProcess()->GetNameOfClass() : "None")
139  << "</filter-name>"
140  << std::endl;
141  std::cout << "<filter-comment>"
142  << " \"" << this->GetComment() << "\" "
143  << "</filter-comment>"
144  << std::endl;
145  std::cout << "</filter-start>"
146  << std::endl;
147  std::cout << std::flush;
148  }
149  }
150 }
151 
152 //-----------------------------------------------------------------------------
154 void EndFilter() override
155 {
156  this->GetTimeProbe().Stop();
157  if (!this->GetQuiet())
158  {
160  {
161  m_ProcessInformation->Progress = 0;
162  m_ProcessInformation->StageProgress = 0;
163 
164  m_ProcessInformation->ElapsedTime
165  = this->GetTimeProbe().GetMean()
166  * this->GetTimeProbe().GetNumberOfStops();
167 
168  if (m_ProcessInformation->ProgressCallbackFunction
169  && m_ProcessInformation->ProgressCallbackClientData)
170  {
171  (*(m_ProcessInformation->ProgressCallbackFunction))(m_ProcessInformation->ProgressCallbackClientData);
172  }
173  }
174  else
175  {
176  std::cout << "<filter-end>"
177  << std::endl;
178  std::cout << "<filter-name>"
179  << (this->GetProcess()
180  ? this->GetProcess()->GetNameOfClass() : "None")
181  << "</filter-name>"
182  << std::endl;
183  std::cout << "<filter-time>"
184  << this->GetTimeProbe().GetMean()
185  << "</filter-time>"
186  << std::endl;
187  std::cout << "</filter-end>";
188  std::cout << std::flush;
189  }
190  }
191 }
192 
193 
194  ModuleProcessInformation *m_ProcessInformation;
195 
196  double m_Fraction;
197  double m_Start;
198 };
199 
200 } // end namespace itk
201 
202 #endif
Simplified inverse ITK transforms.
PluginFilterWatcher(itk::ProcessObject *o, const char *comment="", ModuleProcessInformation *inf=nullptr, double fraction=1.0, double start=0.0)
ModuleProcessInformation * m_ProcessInformation
Simple mechanism for monitoring the pipeline events of a filter and reporting these events to std::co...