otbStandardWriterWatcher.cxx 3.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/*=========================================================================

  Program:   ORFEO Toolbox
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
  See OTBCopyright.txt for details.

  Some parts of this code are derived from ITK. See ITKCopyright.txt
  for details.


     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#include "otbStandardWriterWatcher.h"

namespace otb
{

StandardWriterWatcher
::StandardWriterWatcher(itk::ProcessObject* process,
			const char *comment)
  : WriterWatcherBase(process, comment)
{
  m_StarsCount = 50;
}

34 35 36 37 38 39 40 41
StandardWriterWatcher
::StandardWriterWatcher(itk::ProcessObject* process,itk::ProcessObject * source,
			const char *comment)
  : WriterWatcherBase(process,source,comment)
{
  m_StarsCount = 50;
}

42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
StandardWriterWatcher
::StandardWriterWatcher( const StandardWriterWatcher& watch)
{ 
  // Initialize state
  m_StarsCount = watch.m_StarsCount;
}

void
StandardWriterWatcher
::operator=(const StandardWriterWatcher &watch)
{
  // Initialize state
  m_StarsCount = watch.m_StarsCount;
}

void
StandardWriterWatcher
::ShowWriterProgress()
{
  this->ShowProgress();
}

void
StandardWriterWatcher
::ShowFilterProgress()
{
  this->ShowProgress();
}

void
StandardWriterWatcher
::ShowProgress()
{
  itk::OStringStream oss;
  oss.str("");
  oss<<"\r";

  if (m_SourceProcess)
    {
      double progress = m_SourceProcess->GetProgress();
      int progressPercent = static_cast<int>(progress*100);
      std::string stars(static_cast<int>(progress*m_StarsCount),'*');
      std::string blanks(m_StarsCount - stars.length(),' ');
      oss << "Current Tile: ";
      if(progressPercent<10)
	{
	  oss<<" ";
	}
      if(progressPercent<100)
	{
	  oss<<" ";
	}
      oss<<progressPercent << "% [" << stars << blanks << "]  ";
    }

  if (m_Process)
    {
      double progress = m_Process->GetProgress();
      int progressPercent = static_cast<int>(progress*100);
      std::string stars(static_cast<int>(progress*m_StarsCount),'*');
      std::string blanks(m_StarsCount - stars.length(),' ');
      oss << "Writing: ";
      if(progressPercent<10)
	{
	  oss<<" ";
	}
      if(progressPercent<100)
	{
	  oss<<" ";
	}
      oss<< progressPercent << "% [" << stars << blanks << "]" << std::flush;
    }
  std::cout<<oss.str();
}



void
StandardWriterWatcher
::StartWriter()
{
  m_TimeProbe.Start();
  std::cout<<"Writing task: "<< " \"" << m_Comment << "\" " << std::endl;
  std::cout << "Writer type: "<<(m_Process.GetPointer() ? m_Process->GetNameOfClass() : "None")<< std::endl;
  std::cout << "Filter type: "<<(m_SourceProcess.GetPointer() ? m_SourceProcess->GetNameOfClass() : "None")<< std::endl;
}

void
StandardWriterWatcher
::EndWriter()
{
  m_TimeProbe.Stop();
  std::cout << std::endl << "Writing task took "
	    << m_TimeProbe.GetMeanTime()
	    << " seconds." << std::endl;
}

} // end namespace otb