Skip to content
Snippets Groups Projects
Commit d1a11a02 authored by Guillaume Pasero's avatar Guillaume Pasero
Browse files

ENH: filter other watcher messages for non-interactive cout

parent bc8c365b
No related branches found
No related tags found
2 merge requests!621Release 7.0 (master),!364No progress to file
......@@ -97,6 +97,10 @@ private:
int m_StarsCount;
int m_CurrentNbStars;
bool m_CoutIsConsole;
std::string m_Buffer;
};
} // end namespace otb
......
......@@ -115,6 +115,10 @@ private:
/** Stars coutning */
unsigned int m_StarsCount;
bool m_CoutIsConsole;
std::string m_Buffer;
};
} // end namespace otb
......
......@@ -20,6 +20,7 @@
*/
#include "otbStandardFilterWatcher.h"
#include "otbSystem.h"
namespace otb
{
......@@ -28,26 +29,30 @@ StandardFilterWatcher
::StandardFilterWatcher(itk::ProcessObject* process,
const char *comment)
: FilterWatcherBase(process, comment)
, m_StarsCount(50)
, m_CurrentNbStars(-1)
, m_CoutIsConsole( System::IsInteractive(1) )
{
m_StarsCount = 50;
m_CurrentNbStars = -1;
}
StandardFilterWatcher
::StandardFilterWatcher(itk::ProcessObject* process,
const std::string& comment)
: FilterWatcherBase(process, comment.c_str())
, m_StarsCount(50)
, m_CurrentNbStars(-1)
, m_CoutIsConsole( System::IsInteractive(1) )
{
m_StarsCount = 50;
m_CurrentNbStars = -1;
}
StandardFilterWatcher
::StandardFilterWatcher(const StandardFilterWatcher& watch) : FilterWatcherBase(watch)
::StandardFilterWatcher(const StandardFilterWatcher& watch)
: FilterWatcherBase(watch)
, m_StarsCount(watch.m_StarsCount)
, m_CurrentNbStars(watch.m_CurrentNbStars)
, m_CoutIsConsole( System::IsInteractive(1) )
{
// Initialize state
m_StarsCount = watch.m_StarsCount;
m_CurrentNbStars = watch.m_CurrentNbStars;
}
void
......@@ -89,7 +94,16 @@ StandardFilterWatcher
{
std::string stars(nbStars, '*');
std::string blanks(nbBlanks, ' ');
std::cout << "\rProcessing progress: " << progressPercent << "% [" << stars << blanks << "]" << std::flush;
std::ostringstream oss;
oss << "Processing progress: " << progressPercent << "% [" << stars << blanks << "]";
if (m_CoutIsConsole)
{
std::cout << "\r" << oss.str() << std::flush;
}
else
{
m_Buffer = oss.str();
}
}
m_CurrentNbStars = nbStars;
......@@ -110,6 +124,11 @@ StandardFilterWatcher
::EndFilter()
{
m_Stopwatch.Stop();
if (m_Process && !m_CoutIsConsole)
{
std::cout << m_Buffer;
m_Buffer = std::string("");
}
std::cout << std::endl << "Filter took ";
m_Stopwatch.GetElapsedHumanReadableTime(std::cout);
std::cout << std::endl;
......
......@@ -86,20 +86,16 @@ StandardOneLineFilterWatcher
{
std::string stars(nbStars, '*');
std::string blanks(nbBlanks, ' ');
std::ostringstream oss;
oss << m_Comment
<< ": "
<< progressPercent << "% [" << stars << blanks << "]";
if (m_CoutIsConsole)
{
std::cout << "\r"
<< m_Comment
<< ": "
<< progressPercent << "% [" << stars << blanks << "]"
<< std::flush;
std::cout << "\r" << oss.str() << std::flush;
}
else
{
std::ostringstream oss;
oss << m_Comment
<< ": "
<< progressPercent << "% [" << stars << blanks << "]";
m_Buffer = oss.str();
}
}
......
......@@ -23,6 +23,7 @@
#include "otbStandardWriterWatcher.h"
#include "otbStopwatch.h"
#include "otbSystem.h"
namespace otb
{
......@@ -31,39 +32,44 @@ StandardWriterWatcher
::StandardWriterWatcher(itk::ProcessObject* process,
const char *comment)
: WriterWatcherBase(process, comment)
, m_StarsCount(50)
, m_CoutIsConsole( System::IsInteractive(1) )
{
m_StarsCount = 50;
}
StandardWriterWatcher
::StandardWriterWatcher(itk::ProcessObject* process, itk::ProcessObject * source,
const char *comment)
: WriterWatcherBase(process, source, comment)
, m_StarsCount(50)
, m_CoutIsConsole( System::IsInteractive(1) )
{
m_StarsCount = 50;
}
StandardWriterWatcher
::StandardWriterWatcher(itk::ProcessObject* process,
const std::string& comment)
: WriterWatcherBase(process, comment.c_str())
, m_StarsCount(50)
, m_CoutIsConsole( System::IsInteractive(1) )
{
m_StarsCount = 50;
}
StandardWriterWatcher
::StandardWriterWatcher(itk::ProcessObject* process, itk::ProcessObject * source,
const std::string& comment)
: WriterWatcherBase(process, source, comment.c_str())
, m_StarsCount(50)
, m_CoutIsConsole( System::IsInteractive(1) )
{
m_StarsCount = 50;
}
StandardWriterWatcher
::StandardWriterWatcher(const StandardWriterWatcher& watch) : WriterWatcherBase(watch)
::StandardWriterWatcher(const StandardWriterWatcher& watch)
: WriterWatcherBase(watch)
, m_StarsCount(watch.m_StarsCount)
, m_CoutIsConsole( System::IsInteractive(1) )
{
// Initialize state
m_StarsCount = watch.m_StarsCount;
}
void
......@@ -141,9 +147,17 @@ StandardWriterWatcher
{
oss << " ";
}
oss << progressPercent << "% [" << stars << blanks << "]" << std::flush;
oss << progressPercent << "% [" << stars << blanks << "]";
}
if (m_CoutIsConsole)
{
std::cout << "\r" << oss.str() << std::flush;
}
else
{
m_Buffer = oss.str();
}
std::cout << oss.str();
}
void
......@@ -162,6 +176,11 @@ StandardWriterWatcher
::EndWriter()
{
m_Stopwatch.Stop();
if (!m_CoutIsConsole)
{
std::cout << m_Buffer;
m_Buffer = std::string("");
}
std::cout << std::endl << "Writing task took ";
m_Stopwatch.GetElapsedHumanReadableTime(std::cout);
std::cout << std::endl;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment