diff --git a/Modules/Core/Common/src/otbLogger.cxx b/Modules/Core/Common/src/otbLogger.cxx index 84aa243ced516bd9cd9206bbd36141919886a5a4..95e107e9090c02e3633df05fbadec43c301e83dc 100644 --- a/Modules/Core/Common/src/otbLogger.cxx +++ b/Modules/Core/Common/src/otbLogger.cxx @@ -47,8 +47,7 @@ Logger * Logger::CreateInstance() Logger * logger = new Logger; // By default redirect logs to std::cout - itk::StdStreamLogOutput::Pointer defaultOutput = - itk::StdStreamLogOutput::New(); + itk::StdStreamLogOutput::Pointer defaultOutput = itk::StdStreamLogOutput::New(); defaultOutput->SetStream(std::cout); logger->AddLogOutput(defaultOutput); diff --git a/Modules/Wrappers/SWIG/src/otbWrapperSWIGIncludes.h b/Modules/Wrappers/SWIG/src/otbWrapperSWIGIncludes.h index ffbbbd640975ce9a388ac7eab22804d3f4066737..bd694359e6afadf9f9bd02e2bfc71cd8ae980352 100644 --- a/Modules/Wrappers/SWIG/src/otbWrapperSWIGIncludes.h +++ b/Modules/Wrappers/SWIG/src/otbWrapperSWIGIncludes.h @@ -43,12 +43,12 @@ typedef otb::Wrapper::ComplexInputImageParameter ComplexInputImageParame typedef otb::Wrapper::ImageBaseType ImageBaseType; -typedef otb::Logger Logger; -typedef otb::Logger::Pointer Logger_Pointer; -typedef otb::LogOutputCallback LogOutputCallback; -typedef otb::PythonLogOutput PythonLogOutput; -typedef otb::PythonLogOutput::Pointer PythonLogOutput_Pointer; -typedef otb::ProgressReporterManager ProgressReporterManager; -typedef otb::ProgressReporterManager::Pointer ProgressReporterManager_Pointer; +typedef otb::Logger Logger; +typedef otb::Logger::Pointer Logger_Pointer; +typedef otb::LogOutputCallback LogOutputCallback; +typedef otb::PythonLogOutput PythonLogOutput; +typedef otb::PythonLogOutput::Pointer PythonLogOutput_Pointer; +typedef otb::ProgressReporterManager ProgressReporterManager; +typedef otb::ProgressReporterManager::Pointer ProgressReporterManager_Pointer; #endif diff --git a/Modules/Wrappers/SWIG/src/python/otbCallbackProgressReporter.cxx b/Modules/Wrappers/SWIG/src/python/otbCallbackProgressReporter.cxx index 02f3ec61d97dd2d3bd6ef93c1efeaa79fbe08c08..438bc2ce90ea750f0e6671fa172bceb71c8bd018 100644 --- a/Modules/Wrappers/SWIG/src/python/otbCallbackProgressReporter.cxx +++ b/Modules/Wrappers/SWIG/src/python/otbCallbackProgressReporter.cxx @@ -24,104 +24,78 @@ namespace otb { -CallbackProgressReporter -::CallbackProgressReporter() +CallbackProgressReporter::CallbackProgressReporter() { } -CallbackProgressReporter -::CallbackProgressReporter(itk::ProcessObject* process, - const char *comment) - : FilterWatcherBase(process, comment), - m_StarsCount(50), - m_CurrentNbStars(-1) +CallbackProgressReporter::CallbackProgressReporter(itk::ProcessObject* process, const char* comment) + : FilterWatcherBase(process, comment), m_StarsCount(50), m_CurrentNbStars(-1) { } -CallbackProgressReporter -::CallbackProgressReporter(itk::ProcessObject* process, - const std::string& comment) - : FilterWatcherBase(process, comment.c_str()), - m_StarsCount(50), - m_CurrentNbStars(-1) +CallbackProgressReporter::CallbackProgressReporter(itk::ProcessObject* process, const std::string& comment) + : FilterWatcherBase(process, comment.c_str()), m_StarsCount(50), m_CurrentNbStars(-1) { } -void -CallbackProgressReporter -::ShowProgress() +void CallbackProgressReporter::ShowProgress() { if (m_Process) - { + { int progressPercent = static_cast<int>(m_Process->GetProgress() * 100); - int nbStars = static_cast<int>(m_Process->GetProgress() * m_StarsCount); - int nbBlanks = m_StarsCount - nbStars; + int nbStars = static_cast<int>(m_Process->GetProgress() * m_StarsCount); + int nbBlanks = m_StarsCount - nbStars; if (nbBlanks < 0) - { + { nbBlanks = 0; - } - + } + if (nbStars > m_StarsCount) - { + { nbStars = m_StarsCount; - } + } if (progressPercent > 100) - { + { progressPercent = 100; - } - + } + if (nbStars > m_CurrentNbStars) - { + { std::string stars(nbStars, '*'); std::string blanks(nbBlanks, ' '); - + if (m_Callback->Isatty()) - { - m_Callback->Call("\r" - +m_Comment - +": " - +std::to_string(progressPercent) - +"% [" - +stars - +blanks - +"]"); + { + m_Callback->Call("\r" + m_Comment + ": " + std::to_string(progressPercent) + "% [" + stars + blanks + "]"); m_Callback->Flush(); - } + } else - { - m_Buffer= "\r"+m_Comment+": "+std::to_string(progressPercent) - +"% ["+stars+blanks+"]"; - } + { + m_Buffer = "\r" + m_Comment + ": " + std::to_string(progressPercent) + "% [" + stars + blanks + "]"; } + } m_CurrentNbStars = nbStars; - } + } } -void -CallbackProgressReporter -::StartFilter() +void CallbackProgressReporter::StartFilter() { m_Stopwatch.Start(); } -void -CallbackProgressReporter -::EndFilter() +void CallbackProgressReporter::EndFilter() { m_Stopwatch.Stop(); - + if (m_Process && !(m_Callback->Isatty())) - { + { m_Callback->Call(m_Buffer); m_Buffer = std::string(""); - } + } - m_Callback->Call(" (" - +m_Stopwatch.GetElapsedHumanReadableTime() - +")\n"); + m_Callback->Call(" (" + m_Stopwatch.GetElapsedHumanReadableTime() + ")\n"); } - } diff --git a/Modules/Wrappers/SWIG/src/python/otbCallbackProgressReporter.h b/Modules/Wrappers/SWIG/src/python/otbCallbackProgressReporter.h index d94f7e1a87ef2caf26695094b82bc3ddb34bdab4..8bc629b32a5e2acce3266bf40d77c276ca4b1126 100644 --- a/Modules/Wrappers/SWIG/src/python/otbCallbackProgressReporter.h +++ b/Modules/Wrappers/SWIG/src/python/otbCallbackProgressReporter.h @@ -34,17 +34,15 @@ namespace otb * the LogOutputCallback. The LogOutputCallback is also used to determine * if the output is interactive. */ - + class CallbackProgressReporter : public FilterWatcherBase { public: /** Constructor. Takes a ProcessObject to monitor and an optional * comment string that is prepended to each event message. */ - CallbackProgressReporter(itk::ProcessObject* process, - const char *comment = ""); + CallbackProgressReporter(itk::ProcessObject* process, const char* comment = ""); - CallbackProgressReporter(itk::ProcessObject* process, - const std::string& comment = ""); + CallbackProgressReporter(itk::ProcessObject* process, const std::string& comment = ""); /** Default constructor */ CallbackProgressReporter(); @@ -53,13 +51,13 @@ public: virtual ~CallbackProgressReporter() = default; typedef LogOutputCallback CallbackType; - + /** Set the callback method */ - void SetCallback(CallbackType * callback) - { + void SetCallback(CallbackType* callback) + { m_Callback = callback; - } - + } + protected: /** Callback method to show the ProgressEvent */ virtual void ShowProgress() override; @@ -71,19 +69,18 @@ protected: virtual void EndFilter() override; private: - /** Total number of stars in the progress bar */ int m_StarsCount; /** Current number of stars in the progress bar */ int m_CurrentNbStars; - + /** The Callback used for printing */ - CallbackType * m_Callback; - + CallbackType* m_Callback; + /** buffer used when sys.stdout.isatty() == false */ std::string m_Buffer; }; } -#endif //otbCallbackProgressReporter_h +#endif // otbCallbackProgressReporter_h diff --git a/Modules/Wrappers/SWIG/src/python/otbLogOutputCallback.h b/Modules/Wrappers/SWIG/src/python/otbLogOutputCallback.h index 5548c67f0c5018047ec8a9694b90ec3a468e74d0..41b98e061175bffc81190a2b5da8f45109114d95 100644 --- a/Modules/Wrappers/SWIG/src/python/otbLogOutputCallback.h +++ b/Modules/Wrappers/SWIG/src/python/otbLogOutputCallback.h @@ -33,27 +33,29 @@ namespace otb * class PythonLogOutputCallback, that uses Swig directors to override these * methods. */ - + class LogOutputCallback { public: /** Constructor */ LogOutputCallback() = default; - + /** Destructor */ virtual ~LogOutputCallback() = default; /** Write a string to a buffer */ - virtual void Call(std::string const &) {}; - + virtual void Call(std::string const&){}; + /** Flush the buffer */ - virtual void Flush() {}; - + virtual void Flush(){}; + /** Determine if the bufer is interactive */ - virtual bool Isatty() {return false;}; + virtual bool Isatty() + { + return false; + }; }; } // namespace otb #endif // otbPythonLogOutputCallback_h - diff --git a/Modules/Wrappers/SWIG/src/python/otbProgressReporterManager.cxx b/Modules/Wrappers/SWIG/src/python/otbProgressReporterManager.cxx index afbeb3ca04a710dc7f6a505153c1db7d27550703..89ea154a4387642a86e318c21506a5105e6db651 100644 --- a/Modules/Wrappers/SWIG/src/python/otbProgressReporterManager.cxx +++ b/Modules/Wrappers/SWIG/src/python/otbProgressReporterManager.cxx @@ -23,27 +23,23 @@ namespace otb { - -ProgressReporterManager -::ProgressReporterManager() + +ProgressReporterManager::ProgressReporterManager() { // Add the callback to be added when a AddProcessToWatch event is invoked m_AddProcessCommand = AddProcessCommandType::New(); m_AddProcessCommand->SetCallbackFunction(this, &ProgressReporterManager::LinkWatchers); } -void ProgressReporterManager::LinkWatchers(itk::Object * itkNotUsed(caller), const itk::EventObject & event) +void ProgressReporterManager::LinkWatchers(itk::Object* itkNotUsed(caller), const itk::EventObject& event) { - if (typeid(otb::Wrapper::AddProcessToWatchEvent) == typeid( event )) - { - const Wrapper::AddProcessToWatchEvent* eventToWatch = dynamic_cast<const Wrapper::AddProcessToWatchEvent*> (&event); + if (typeid(otb::Wrapper::AddProcessToWatchEvent) == typeid(event)) + { + const Wrapper::AddProcessToWatchEvent* eventToWatch = dynamic_cast<const Wrapper::AddProcessToWatchEvent*>(&event); - CallbackProgressReporter * watch = new CallbackProgressReporter(eventToWatch->GetProcess(), - eventToWatch->GetProcessDescription()); + CallbackProgressReporter* watch = new CallbackProgressReporter(eventToWatch->GetProcess(), eventToWatch->GetProcessDescription()); watch->SetCallback(m_Callback); m_WatcherList.push_back(watch); - } + } } - - } diff --git a/Modules/Wrappers/SWIG/src/python/otbProgressReporterManager.h b/Modules/Wrappers/SWIG/src/python/otbProgressReporterManager.h index 588846c8a463ee799bed3c2988d4cd973ed09c02..e1aaf0d1f86398b94b1440d3fbc4ae1055a8bdfe 100644 --- a/Modules/Wrappers/SWIG/src/python/otbProgressReporterManager.h +++ b/Modules/Wrappers/SWIG/src/python/otbProgressReporterManager.h @@ -41,37 +41,36 @@ class ProgressReporterManager : public itk::Object { public: /** Standard class typedefs. */ - typedef ProgressReporterManager Self; - typedef itk::Object Superclass; - typedef itk::SmartPointer<Self> Pointer; + typedef ProgressReporterManager Self; + typedef itk::Object Superclass; + typedef itk::SmartPointer<Self> Pointer; typedef itk::SmartPointer<const Self> ConstPointer; - + itkTypeMacro(ProgressReporterManager, itk::Object); itkNewMacro(ProgressReporterManager); typedef LogOutputCallback CallbackType; /** Command Member */ - typedef itk::MemberCommand< Self > AddProcessCommandType; + typedef itk::MemberCommand<Self> AddProcessCommandType; /** Filter watcher list type */ - typedef std::vector<CallbackProgressReporter *> WatcherListType; - + typedef std::vector<CallbackProgressReporter*> WatcherListType; + /** Set the logger callback function */ - void SetLogOutputCallback(CallbackType * callback) + void SetLogOutputCallback(CallbackType* callback) { m_Callback = callback; this->Modified(); } - + /** Getter to AddProcessCommand */ AddProcessCommandType* GetAddProcessCommand() { return m_AddProcessCommand.GetPointer(); } - -protected: +protected: /** Default constructor */ ProgressReporterManager(); @@ -79,19 +78,18 @@ protected: virtual ~ProgressReporterManager() = default; /** Load the watchers for internal progress and writing progress report. */ - void LinkWatchers(itk::Object * caller, const itk::EventObject & event); + void LinkWatchers(itk::Object* caller, const itk::EventObject& event); private: /** The LogOutputCallback used for printing */ - CallbackType * m_Callback; - + CallbackType* m_Callback; + /** Command associated to the LinkWatchers command */ - AddProcessCommandType::Pointer m_AddProcessCommand; - + AddProcessCommandType::Pointer m_AddProcessCommand; + /** container storing all the watchers (CallbackProgressReporter) */ - WatcherListType m_WatcherList; + WatcherListType m_WatcherList; }; - } -#endif //otbProgressReporterManager_h +#endif // otbProgressReporterManager_h diff --git a/Modules/Wrappers/SWIG/src/python/otbPythonLogOutput.cxx b/Modules/Wrappers/SWIG/src/python/otbPythonLogOutput.cxx index 1cd99e63fccd010c26598ab7c531d47e0aa5529c..d8f703c4b8d1eb4b2f6a932d7e02c0a648b6fc15 100644 --- a/Modules/Wrappers/SWIG/src/python/otbPythonLogOutput.cxx +++ b/Modules/Wrappers/SWIG/src/python/otbPythonLogOutput.cxx @@ -32,17 +32,17 @@ void PythonLogOutput::Write(double timestamp) m_Callback->Call(std::to_string(timestamp)); } -void PythonLogOutput::Write(std::string const & content) +void PythonLogOutput::Write(std::string const& content) { m_Callback->Call(content); } -void PythonLogOutput::Write(std::string const & content, double timestamp) +void PythonLogOutput::Write(std::string const& content, double timestamp) { m_Callback->Call(std::to_string(timestamp) + " : " + content); } -void PythonLogOutput::PrintSelf(std::ostream & os, itk::Indent indent) const +void PythonLogOutput::PrintSelf(std::ostream& os, itk::Indent indent) const { Superclass::PrintSelf(os, indent); } diff --git a/Modules/Wrappers/SWIG/src/python/otbPythonLogOutput.h b/Modules/Wrappers/SWIG/src/python/otbPythonLogOutput.h index 57cc5ce3adf2f192e1dc009bece15922c8d059fe..17b2f3eee7d5ae0fd2c092c6f1e86d5341e50cf0 100644 --- a/Modules/Wrappers/SWIG/src/python/otbPythonLogOutput.h +++ b/Modules/Wrappers/SWIG/src/python/otbPythonLogOutput.h @@ -35,10 +35,10 @@ namespace otb class PythonLogOutput : public itk::LogOutput { public: - typedef PythonLogOutput Self; - typedef itk::LogOutput Superclass; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; + typedef PythonLogOutput Self; + typedef itk::LogOutput Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; typedef LogOutputCallback CallbackType; itkTypeMacro(PythonLogOutput, itk::LogOutput); @@ -46,12 +46,12 @@ public: itkNewMacro(PythonLogOutput); /** Set the callback method */ - void SetCallback(CallbackType * callback) - { + void SetCallback(CallbackType* callback) + { m_Callback = callback; this->Modified(); - } - + } + /** flush a buffer */ virtual void Flush() override; @@ -59,10 +59,10 @@ public: virtual void Write(double timestamp) override; /** Write to a buffer */ - virtual void Write(std::string const & content) override; + virtual void Write(std::string const& content) override; /** Write to a buffer */ - virtual void Write(std::string const & content, double timestamp) override; + virtual void Write(std::string const& content, double timestamp) override; protected: /** Constructor */ @@ -71,10 +71,10 @@ protected: /** Destructor */ virtual ~PythonLogOutput() override = default; - virtual void PrintSelf(std::ostream & os, itk::Indent indent) const override; + virtual void PrintSelf(std::ostream& os, itk::Indent indent) const override; private: - CallbackType * m_Callback; + CallbackType* m_Callback; }; } // namespace otb