Commit bb7c8276 authored by Guillaume Pasero's avatar Guillaume Pasero

Merge branch 'no_progress_to_file' into 'develop'

No progress to file

See merge request !364
parents a52635d8 6e13622c
......@@ -97,6 +97,10 @@ private:
int m_StarsCount;
int m_CurrentNbStars;
bool m_CoutIsConsole;
std::string m_Buffer;
};
} // end namespace otb
......
......@@ -93,6 +93,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
......
......@@ -61,6 +61,9 @@ public:
/** Parse a filename with additional information */
static bool ParseFileNameForAdditionalInfo(const std::string& id, std::string& file, unsigned int& addNum);
/** Returns true if the file descriptor fd is interactive (i.e. like isatty on unix) */
static bool IsInteractive(int fd);
};
} // 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;
......
......@@ -24,6 +24,7 @@
#include "otbStandardOneLineFilterWatcher.h"
#include "otbStopwatch.h"
#include "otbSystem.h"
namespace otb
{
......@@ -31,7 +32,8 @@ namespace otb
StandardOneLineFilterWatcher
::StandardOneLineFilterWatcher()
: m_StarsCount(50),
m_CurrentNbStars(-1)
m_CurrentNbStars(-1),
m_CoutIsConsole( System::IsInteractive(1) )
{
}
......@@ -40,7 +42,8 @@ StandardOneLineFilterWatcher
const char *comment)
: FilterWatcherBase(process, comment),
m_StarsCount(50),
m_CurrentNbStars(-1)
m_CurrentNbStars(-1),
m_CoutIsConsole( System::IsInteractive(1) )
{
}
......@@ -49,7 +52,8 @@ StandardOneLineFilterWatcher
const std::string& comment)
: FilterWatcherBase(process, comment.c_str()),
m_StarsCount(50),
m_CurrentNbStars(-1)
m_CurrentNbStars(-1),
m_CoutIsConsole( System::IsInteractive(1) )
{
}
......@@ -82,12 +86,18 @@ StandardOneLineFilterWatcher
{
std::string stars(nbStars, '*');
std::string blanks(nbBlanks, ' ');
std::cout << "\r"
<< m_Comment
<< ": "
<< progressPercent << "% [" << stars << blanks << "]"
<< std::flush;
std::ostringstream oss;
oss << m_Comment
<< ": "
<< progressPercent << "% [" << stars << blanks << "]";
if (m_CoutIsConsole)
{
std::cout << "\r" << oss.str() << std::flush;
}
else
{
m_Buffer = oss.str();
}
}
m_CurrentNbStars = nbStars;
......@@ -107,6 +117,12 @@ StandardOneLineFilterWatcher
{
m_Stopwatch.Stop();
if (m_Process && !m_CoutIsConsole)
{
std::cout << m_Buffer;
m_Buffer = std::string("");
}
std::cout << " (";
m_Stopwatch.GetElapsedHumanReadableTime(std::cout);
std::cout << ")"
......
......@@ -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
......@@ -95,7 +101,6 @@ StandardWriterWatcher
{
std::ostringstream oss;
oss.str("");
oss << "\r";
if (m_SourceProcess)
{
......@@ -141,9 +146,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 +175,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;
......
......@@ -28,6 +28,7 @@
/*=====================================================================
WIN32 / MSVC++ implementation
*====================================================================*/
#include <Windows.h>
#ifndef WIN32CE
# include <io.h>
#else
......@@ -37,6 +38,7 @@
/*=====================================================================
POSIX (Unix) implementation
*====================================================================*/
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#endif
......@@ -202,4 +204,37 @@ bool System::ParseFileNameForAdditionalInfo(const std::string& id, std::string&
return true;
}
bool System::IsInteractive(int fd)
{
#if (defined(WIN32) || defined(WIN32CE)) && !defined(__CYGWIN__) && !defined(__MINGW32__)
// Windows implementation
HANDLE hcon;
/* get OS handle of the file descriptor */
hcon = (HANDLE) _get_osfhandle(fd);
if (hcon == INVALID_HANDLE_VALUE)
return false;
/* check if its a device (i.e. console, printer, serial port) */
if (GetFileType(hcon) != FILE_TYPE_CHAR)
return false;
/* check if its a handle to a console output screen buffer */
CONSOLE_SCREEN_BUFFER_INFO screenBufferInfo;
DWORD mode;
if (!fd)
{
if (!GetConsoleMode(hcon, &mode))
return false;
}
else if (!GetConsoleScreenBufferInfo(hcon, &screenBufferInfo))
return false;
return true;
#else
// Unix implementation
return isatty(fd);
#endif
}
}
......@@ -47,7 +47,7 @@ int otbStreamingMinMaxImageFilter(int itkNotUsed(argc), char * argv[])
filter->GetStreamer()->SetNumberOfLinesStrippedStreaming( 10 );
filter->SetInput(reader->GetOutput());
otb::StandardFilterWatcher watcher(filter, "Min Max Computation");
otb::StandardFilterWatcher watcher(filter->GetStreamer(), "Min Max Computation");
filter->Update();
std::ofstream file;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment