cmtkProgressConsole.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 "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 } // namespace cmtk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines