cmtkProgress.cxx

Go to the documentation of this file.
00001 /*
00002 //
00003 //  Copyright 1997-2009 Torsten Rohlfing
00004 //
00005 //  Copyright 2004-2010 SRI International
00006 //
00007 //  This file is part of the Computational Morphometry Toolkit.
00008 //
00009 //  http://www.nitrc.org/projects/cmtk/
00010 //
00011 //  The Computational Morphometry Toolkit is free software: you can
00012 //  redistribute it and/or modify it under the terms of the GNU General Public
00013 //  License as published by the Free Software Foundation, either version 3 of
00014 //  the License, or (at your option) any later version.
00015 //
00016 //  The Computational Morphometry Toolkit is distributed in the hope that it
00017 //  will be useful, but WITHOUT ANY WARRANTY; without even the implied
00018 //  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 //  GNU General Public License for more details.
00020 //
00021 //  You should have received a copy of the GNU General Public License along
00022 //  with the Computational Morphometry Toolkit.  If not, see
00023 //  <http://www.gnu.org/licenses/>.
00024 //
00025 //  $Revision: 2398 $
00026 //
00027 //  $LastChangedDate: 2010-10-05 14:54:37 -0700 (Tue, 05 Oct 2010) $
00028 //
00029 //  $LastChangedBy: torstenrohlfing $
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 } // namespace cmtk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines