diff --git a/CMakeLists.txt b/CMakeLists.txt index a80ed6a09c..f464343731 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -710,6 +710,7 @@ set(SIMPLNX_SRCS ${SIMPLNX_SOURCE_DIR}/Utilities/Math/MatrixMath.cpp ${SIMPLNX_SOURCE_DIR}/Utilities/SampleSurfaceMesh.cpp ${SIMPLNX_SOURCE_DIR}/Utilities/MontageUtilities.cpp + ${SIMPLNX_SOURCE_DIR}/Utilities/TimeUtilities.cpp ${SIMPLNX_SOURCE_DIR}/Utilities/Parsing/DREAM3D/Dream3dIO.cpp diff --git a/src/Plugins/OrientationAnalysis/src/OrientationAnalysis/Filters/Algorithms/FindKernelAvgMisorientations.cpp b/src/Plugins/OrientationAnalysis/src/OrientationAnalysis/Filters/Algorithms/FindKernelAvgMisorientations.cpp index 3fb8d78f5c..2154df2e89 100644 --- a/src/Plugins/OrientationAnalysis/src/OrientationAnalysis/Filters/Algorithms/FindKernelAvgMisorientations.cpp +++ b/src/Plugins/OrientationAnalysis/src/OrientationAnalysis/Filters/Algorithms/FindKernelAvgMisorientations.cpp @@ -68,7 +68,7 @@ class FindKernelAvgMisorientationsImpl if(counter > increment) { auto now = std::chrono::steady_clock::now(); - if(std::chrono::duration_cast(now - start).count() < 1000) + if(std::chrono::duration_cast(now - start).count() > 1000) { m_Filter->sendThreadSafeProgressMessage(counter); counter = 0; @@ -186,7 +186,7 @@ void FindKernelAvgMisorientations::sendThreadSafeProgressMessage(usize counter) m_ProgressCounter += counter; auto now = std::chrono::steady_clock::now(); - if(std::chrono::duration_cast(now - m_InitialPoint).count() < 1000) + if(std::chrono::duration_cast(now - m_InitialPoint).count() > 1000) { return; } diff --git a/src/Plugins/SimplnxCore/docs/WriteVtkRectilinearGridFilter.md b/src/Plugins/SimplnxCore/docs/WriteVtkRectilinearGridFilter.md index 1fd8b21372..b2e76ce101 100644 --- a/src/Plugins/SimplnxCore/docs/WriteVtkRectilinearGridFilter.md +++ b/src/Plugins/SimplnxCore/docs/WriteVtkRectilinearGridFilter.md @@ -1,4 +1,4 @@ -# Vtk Rectilinear Grid Exporter +# Write Vtk Rectilinear Grid ## Group (Subgroup) @@ -6,7 +6,7 @@ I/O Filters ## Description -This Filter reads the **Feature** and phase ids together with image parameters required by Vtk to an output file named by the user. The file is used to generate the image of the **Features** and phases of the **Features**. +This Filter writes a VTK legacy file with a Dataset type of `RECTILINEAR_GRID`. The user can select which arrays from the Image Geometry will be written to the file. % Auto generated parameter table will be inserted here diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/FeatureFaceCurvature.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/FeatureFaceCurvature.cpp index 211d84be0a..c01c7816eb 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/FeatureFaceCurvature.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/FeatureFaceCurvature.cpp @@ -146,6 +146,7 @@ void FeatureFaceCurvature::sendThreadSafeProgressMessage(usize counter) m_ProgressCounter += counter; auto now = std::chrono::steady_clock::now(); + // We DO NOT Want to print at more than once a second. Hey. Don't copy/paste this line. if(std::chrono::duration_cast(now - m_InitialPoint).count() < 1000) { return; diff --git a/src/simplnx/Utilities/TimeUtilities.cpp b/src/simplnx/Utilities/TimeUtilities.cpp new file mode 100644 index 0000000000..c0e21a8927 --- /dev/null +++ b/src/simplnx/Utilities/TimeUtilities.cpp @@ -0,0 +1,33 @@ +#include "TimeUtilities.hpp" + +#include +#include + +#include + +using namespace nx::core; + +// ----------------------------------------------------------------------------- +void StopWatch::start() +{ + start_time = std::chrono::steady_clock::now(); +} + +// ----------------------------------------------------------------------------- +void StopWatch::stop() +{ + end_time = std::chrono::steady_clock::now(); +} + +// ----------------------------------------------------------------------------- +void StopWatch::print(std::ostream& os) const +{ + os << toString(); +} + +// ----------------------------------------------------------------------------- +std::string StopWatch::toString() const +{ + auto elapsed = end_time - start_time; + return fmt::format("{:%H:%M:%S}.{:03}", elapsed, std::chrono::duration_cast(elapsed).count() % 1000); +} diff --git a/src/simplnx/Utilities/TimeUtilities.hpp b/src/simplnx/Utilities/TimeUtilities.hpp index 73b6bd7f11..e971aed62f 100644 --- a/src/simplnx/Utilities/TimeUtilities.hpp +++ b/src/simplnx/Utilities/TimeUtilities.hpp @@ -1,5 +1,7 @@ #pragma once +#include "simplnx/simplnx_export.hpp" + #include #include @@ -25,4 +27,60 @@ inline std::string ConvertMillisToHrsMinSecs(unsigned long long int millis) return fmt::format("{:0>2}:{:0>2}:{:0>2}", hours, minutes, seconds); } +/** + * @brief A stopwatch class for measuring durations with high precision. + * + * The StopWatch class utilizes the std::chrono library to measure time intervals. + * It can be started and stopped to measure specific durations, and the elapsed time + * can be printed to an output stream in a formatted manner. + */ +class SIMPLNX_EXPORT StopWatch +{ +public: + StopWatch() = default; + ~StopWatch() = default; + + StopWatch(const StopWatch&) = default; // Copy Constructor Not Implemented + StopWatch(StopWatch&&) = default; // Move Constructor Not Implemented + StopWatch& operator=(const StopWatch&) = default; // Copy Assignment Not Implemented + StopWatch& operator=(StopWatch&&) = default; // Move Assignment Not Implemented + + /** + * @brief Start the stopwatch. + * + * Captures the current time as the start point of the duration measurement. + * This function must be called before calling stop(). + */ + void start(); + + /** + * @brief Stop the stopwatch. + * + * Captures the current time as the end point of the duration measurement. + * This function should be called after start(). + */ + void stop(); + + /** + * @brief Print the elapsed time to a given output stream. + * + * Calculates the elapsed time between the start and stop points and formats it as + * "Hours:Minutes:Seconds.Milliseconds". This formatted string is then written to + * the provided std::ostream object. + * + * @param os The output stream to which the elapsed time will be written. + */ + void print(std::ostream& os) const; + + /** + * @brief Returns a generated string of the elapsed time + * @return + */ + std::string toString() const; + +private: + std::chrono::steady_clock::time_point start_time; ///< The start time point of the measurement. + std::chrono::steady_clock::time_point end_time; ///< The end time point of the measurement. +}; + } // namespace nx::core