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 "cmtkProgress.h"
00034 #include <System/cmtkConsole.h>
00035
00036 namespace
00037 cmtk
00038 {
00039
00042
00043 Progress* Progress::ProgressInstance = 0;
00044
00045 void
00046 Progress::Begin
00047 ( const double start, const double end, const double increment, const std::string& taskName ){
00048 if ( ProgressInstance )
00049 {
00050 ProgressInstance->BeginVirtual( start, end, increment, taskName );
00051 }
00052 }
00053
00054 void
00055 Progress::BeginVirtual
00056 ( const double start, const double end, const double increment, const std::string& taskName )
00057 {
00058 this->m_RangeStack.push_front( Self::Range( start, end, increment, taskName ) );
00059 }
00060
00061 void
00062 Progress::SetProgressCurrent( const double progress )
00063 {
00064 RangeStackType::iterator current = this->m_RangeStack.begin();
00065
00066 if ( current != this->m_RangeStack.end() )
00067 {
00068 current->m_Current = progress;
00069 }
00070 }
00071
00072 Progress::ResultEnum
00073 Progress::SetProgress( const double progress )
00074 {
00075 if ( ProgressInstance )
00076 {
00077 ProgressInstance->SetProgressCurrent( progress );
00078 return ProgressInstance->UpdateProgress();
00079 }
00080 else
00081 return Self::OK;
00082 }
00083
00084 void
00085 Progress::Done()
00086 {
00087 if ( ProgressInstance )
00088 ProgressInstance->DoneVirtual();
00089 }
00090
00091 void
00092 Progress::DoneVirtual()
00093 {
00094 if ( this->m_RangeStack.begin() != this->m_RangeStack.end() )
00095 this->m_RangeStack.pop_front();
00096 }
00097
00098 double
00099 Progress::Range::GetFractionComplete( const double nestedFraction ) const
00100 {
00101 return ( ( this->m_Current + nestedFraction * this->m_Increment ) - this->m_Start) / (this->m_End - this->m_Start);
00102 }
00103
00104 double
00105 Progress::GetFractionComplete() const
00106 {
00107 double fraction = 0;
00108 for ( RangeStackType::const_iterator it = this->m_RangeStack.begin(); it != this->m_RangeStack.end(); ++it )
00109 {
00110 fraction = it->GetFractionComplete( fraction );
00111 }
00112
00113 return fraction;
00114 }
00115
00116 const std::string
00117 Progress::GetCurrentTaskName() const
00118 {
00119 RangeStackType::const_reverse_iterator it = this->m_RangeStack.rbegin();
00120 if ( it != this->m_RangeStack.rend() )
00121 return it->m_TaskName;
00122 return std::string("");
00123 }
00124
00125 }