Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "cmtkProgressConsole.h"
00034
00035 #include <System/cmtkConsole.h>
00036 #include <System/cmtkTimers.h>
00037
00038 #include <stdlib.h>
00039
00040 namespace
00041 cmtk
00042 {
00043
00046
00047 ProgressConsole::ProgressConsole( const std::string& programName )
00048 : m_ProgramName( programName )
00049 {
00050 this->m_InsideSlicer3 = ( getenv( "Slicer3_HOME" ) != NULL );
00051
00052 if ( this->m_InsideSlicer3 )
00053 {
00054 std::cout << "<filter-start>\n"
00055 << "<filter-name>" << this->m_ProgramName << "</filter-name>\n"
00056 << "<filter-comment> \"" << this->m_ProgramName << "\" </filter-comment>\n"
00057 << "</filter-start>\n";
00058 std::cout.flush();
00059 }
00060 }
00061
00062 ProgressConsole::~ProgressConsole()
00063 {
00064 if ( this->m_InsideSlicer3 )
00065 {
00066 std::cout << "<filter-end>\n"
00067 << "<filter-name>" << this->m_ProgramName << "</filter-name>\n"
00068 << "<filter-time>" << Timers::GetTimeProcess() - this->m_TimeAtStart << "</filter-time>\n"
00069 << "</filter-end>\n";
00070 std::cout.flush();
00071 }
00072 }
00073
00074 Progress::ResultEnum
00075 ProgressConsole::UpdateProgress()
00076 {
00077 const double fraction = this->GetFractionComplete();
00078
00079 if ( this->m_InsideSlicer3 )
00080 {
00081 std::cout << "<filter-progress>" << fraction << "</filter-progress>\n";
00082 std::cout.flush();
00083 }
00084 else
00085 {
00086 const std::string& currentTaskName = this->GetCurrentTaskName();
00087 if ( currentTaskName.length() )
00088 {
00089 StdErr.printf( "%s: %d %%\r", currentTaskName.c_str(), static_cast<int>( 100.0 * fraction ) );
00090 }
00091 else
00092 {
00093 StdErr.printf( "%d %%\r", static_cast<int>( 100.0 * fraction ) );
00094 }
00095 }
00096
00097 return Self::OK;
00098 }
00099
00100 void
00101 ProgressConsole:: BeginVirtual
00102 ( const double start, const double end, const double increment, const std::string& taskName )
00103 {
00104 this->Superclass::BeginVirtual( start, end, increment, taskName );
00105
00106 if ( this->IsTopLevel() )
00107 {
00108 this->m_TimeAtStart = Timers::GetTimeProcess();
00109 }
00110 }
00111
00112 }