14 #ifndef __itkCommandProgressUpdate_h 15 #define __itkCommandProgressUpdate_h 17 #include "itkCommand.h" 18 #include "itkObject.h" 19 #include "itkProcessObject.h" 20 #include "itkTimeProbe.h" 21 #include "itkRealTimeClock.h" 44 itkSetMacro(UseColor,
bool);
45 itkGetConstMacro(UseColor,
bool);
46 itkBooleanMacro(UseColor);
51 itkSetMacro(Style, StyleType);
52 itkGetConstMacro(Style, StyleType);
77 Execute( (
const Object *)caller, event );
82 const ProcessObject * filter =
83 dynamic_cast< const ProcessObject *
>(object);
84 if (!ProgressEvent().CheckEvent( &event ))
91 m_SuppressOutput =
false;
94 float progress = filter->GetProgress();
95 unsigned int progressInRoundedPercent =
96 static_cast<unsigned int>( 100 * progress );
98 std::string redPrefix =
"";
99 std::string greenPrefix =
"";
100 std::string yellowPrefix =
"";
101 std::string bluePrefix =
"";
102 std::string magentaPrefix =
"";
103 std::string cyanPrefix =
"";
104 std::string suffix =
"";
108 redPrefix =
"\033[1;31m";
109 greenPrefix =
"\033[32m";
110 yellowPrefix =
"\033[33m";
111 bluePrefix =
"\033[1;34m";
112 magentaPrefix =
"\033[35m";
113 cyanPrefix =
"\033[36m";
121 std::cout <<
" >>>> " 126 << std::setiosflags(std::ios::right)
127 << progressInRoundedPercent <<
"%" 128 << suffix <<
" completed" << std::flush;
132 m_SuppressOutput =
false;
133 std::cout << std::endl;
142 << std::setiosflags(std::ios::fixed)
143 << std::setprecision(3)
146 << clock.GetMean() <<
"s" << suffix <<
" elapsed" << std::endl;
147 std::cout.precision(6);
150 if (progress == 1) m_SuppressOutput =
true;
156 m_LastProgress = progress;
157 m_SuppressOutput =
false;
158 m_StartTimeStamp = m_Clock->GetTimeInSeconds();
169 << std::setiosflags(std::ios::right)
170 << progressInRoundedPercent <<
"%" << suffix << std::flush;
172 std::cout <<
" [" << std::flush;
173 for (
unsigned int k=0; k<NumberOfBarSegments+1; k++)
175 if ( k == (
unsigned int)(progress * NumberOfBarSegments) )
177 std::cout << greenPrefix <<
">" << suffix << std::flush;
179 else if ( k < (
unsigned int)(progress * NumberOfBarSegments) )
181 std::cout << greenPrefix <<
"=" << suffix << std::flush;
185 std::cout <<
" " << std::flush;
191 unsigned int secondsLeft = (
unsigned int)
192 (clock.GetMean() * (1 - progress) * 100 + 0.5);
193 unsigned int hoursLeft = secondsLeft/3600;
194 secondsLeft = secondsLeft % 3600;
195 unsigned int minutesLeft = secondsLeft/60;
196 secondsLeft = secondsLeft % 60;
198 unsigned int secondsElapsed = (
unsigned int)
199 (m_Clock->GetTimeInSeconds() - m_StartTimeStamp + 0.5);
200 unsigned int hoursElapsed = secondsElapsed/3600;
201 secondsElapsed = secondsElapsed % 3600;
202 unsigned int minutesElapsed = secondsElapsed/60;
203 secondsElapsed = secondsElapsed % 60;
205 float secondsPerPercent;
207 if ( progress > 0.01 )
209 secondsPerPercent = clock.GetMean()/(progress -
m_LastProgress)/100;
213 secondsPerPercent = 0;
216 m_LastProgress = progress;
218 std::cout <<
"] " << std::flush;
221 << std::setiosflags(std::ios::fixed)
222 << std::setprecision(3)
223 << secondsPerPercent <<
" s" <<
"/%" 251 <<
" " << std::flush;
252 std::cout.precision(6);
260 m_SuppressOutput =
true;
ClockType::Pointer m_Clock
SmartPointer< Self > Pointer
void Execute(Object *caller, const EventObject &event) ITK_OVERRIDE
Observer for progress notification.
virtual void UseColorOn()
ClockType::TimeStampType TimeStampType
void Execute(const Object *object, const EventObject &event) ITK_OVERRIDE
TimeStampType m_StartTimeStamp
static const unsigned int NumberOfBarSegments
CommandProgressUpdate Self