From 824c332a6a5f4b7e3c9da58712bc2abef46e1140 Mon Sep 17 00:00:00 2001 From: Otto Link Date: Sun, 18 Aug 2024 19:29:46 +0200 Subject: [PATCH] Move Timer class to a specific header, add dbg folder and header branch, make Timer class based on a singleton pattern for ease of use --- HighMap/include/highmap.hpp | 2 +- HighMap/include/highmap/dbg.hpp | 108 ----------- HighMap/include/highmap/dbg/timer.hpp | 182 ++++++++++++++++++ HighMap/src/dbg/timer.cpp | 98 ++++++++++ HighMap/src/erosion/erosion_maps.cpp | 6 +- HighMap/src/erosion/hydraulic_particle.cpp | 6 +- .../erosion/hydraulic_particle_multiscale.cpp | 3 - HighMap/src/erosion/hydraulic_vpipes.cpp | 6 +- HighMap/src/gpu/filters_gpu.cpp | 37 ---- HighMap/src/heightmap/heightmap_rgba.cpp | 2 +- HighMap/src/io/export_asset.cpp | 2 +- HighMap/src/io/export_normal_map.cpp | 2 +- HighMap/src/io/export_vector_glyph.cpp | 2 +- HighMap/src/morphology/distance_transform.cpp | 3 +- .../pyramid_decomposition.cpp | 4 +- examples/ex_export_asset/ex_export_asset.cpp | 5 +- .../ex_find_flow_sinks/ex_find_flow_sinks.cpp | 5 +- .../ex_gpu_hydraulic_particle.cpp | 3 +- .../ex_gpu_maximum_local_weighted.cpp | 5 +- .../ex_gpu_median_3x3/ex_gpu_median_3x3.cpp | 5 +- .../ex_gpu_ridgelines/ex_gpu_ridgelines.cpp | 5 +- examples/ex_gpu_simplex/ex_gpu_simplex.cpp | 5 +- .../ex_gpu_voronoise/ex_gpu_voronoise.cpp | 5 +- examples/ex_graph/ex_graph.cpp | 2 +- .../ex_graph_dijkstra/ex_graph_dijkstra.cpp | 2 +- .../ex_graph_minimum_spanning_tree_prim.cpp | 2 +- .../ex_noise_function/ex_noise_function.cpp | 1 - .../ex_pyramid_transform.cpp | 9 +- examples/ex_ridgelines/ex_ridgelines.cpp | 1 - .../ex_ridgelines_bezier.cpp | 1 - examples/ex_to_cv_mat/ex_to_cv_mat.cpp | 5 - tests/parameter_influence/main.cpp | 3 - tests/sandbox/main.cpp | 20 +- 33 files changed, 333 insertions(+), 214 deletions(-) delete mode 100644 HighMap/include/highmap/dbg.hpp create mode 100644 HighMap/include/highmap/dbg/timer.hpp create mode 100644 HighMap/src/dbg/timer.cpp diff --git a/HighMap/include/highmap.hpp b/HighMap/include/highmap.hpp index 2570e3b1..94dd316d 100644 --- a/HighMap/include/highmap.hpp +++ b/HighMap/include/highmap.hpp @@ -23,6 +23,7 @@ #include "highmap/colormaps.hpp" #include "highmap/convolve.hpp" #include "highmap/erosion.hpp" +#include "highmap/export.hpp" #include "highmap/features.hpp" #include "highmap/filters.hpp" #include "highmap/functions.hpp" @@ -31,7 +32,6 @@ #include "highmap/gradient.hpp" #include "highmap/heightmap.hpp" #include "highmap/hydrology.hpp" -#include "highmap/export.hpp" #include "highmap/kernels.hpp" #include "highmap/math.hpp" #include "highmap/morphology.hpp" diff --git a/HighMap/include/highmap/dbg.hpp b/HighMap/include/highmap/dbg.hpp deleted file mode 100644 index 79620566..00000000 --- a/HighMap/include/highmap/dbg.hpp +++ /dev/null @@ -1,108 +0,0 @@ -/* Copyright (c) 2023 Otto Link. Distributed under the terms of the GNU General - * Public License. The full license is in the file LICENSE, distributed with - * this software. */ - -/** - * @file dbg.hpp - * @author Otto Link (otto.link.bv@gmail.com) - * @brief - * @version 0.1 - * @date 2023-04-30 - * - * @copyright Copyright (c) 2023 - * - */ -#pragma once - -#include -#include -#include -#include -#include - -#include "macrologger.h" - -namespace hmap -{ - -class Recorder -{ -public: - Recorder(std::string name) : name(name) - { - } - - void dump() - { - std::cout << std::setw(20) << this->name; - std::cout << std::setw(10) << this->nb_calls; - std::cout << std::setw(20) << this->total / (float)this->nb_calls << " ms"; - std::cout << std::endl; - } - - void start() - { - this->t0 = std::chrono::high_resolution_clock::now(); - this->nb_calls++; - } - - void stop() - { - std::chrono::high_resolution_clock::time_point t1 = - std::chrono::high_resolution_clock::now(); - this->total += (float)std::chrono::duration_cast( - t1 - t0) - .count() * - 1e-6f; - } - -private: - std::string name; - int nb_calls = 0; - std::chrono::high_resolution_clock::time_point t0; - float total = 0.f; -}; - -class Timer -{ -public: - Timer(std::string sid = "") : sid(sid){}; - ~Timer() - { - this->dump(); - }; - - void dump() - { - std::cout << "Timer dump: " << this->sid << std::endl; - for (auto &n : records) - n.second->dump(); - } - - void start(std::string name) - { - if (records.find(name) == records.end()) - { - Recorder new_recorder = Recorder(name); - data.push_back(new_recorder); - records[name] = &data.back(); - } - records[name]->start(); - } - - void stop(std::string name) - { - if (records.find(name) != records.end()) - records[name]->stop(); - else - std::cout << "Warning! Trying to stop an unknown timer: " << name - << std::endl; - } - -private: - std::string sid; - std::map records; - std::list data; -}; - -} // namespace hmap diff --git a/HighMap/include/highmap/dbg/timer.hpp b/HighMap/include/highmap/dbg/timer.hpp new file mode 100644 index 00000000..0632fbca --- /dev/null +++ b/HighMap/include/highmap/dbg/timer.hpp @@ -0,0 +1,182 @@ +/* Copyright (c) 2023 Otto Link. Distributed under the terms of the GNU General + * Public License. The full license is in the file LICENSE, distributed with + * this software. */ + +/** + * @file dbg.hpp + * @author Otto Link (otto.link.bv@gmail.com) + * @brief Header file containing the implementation of the Recorder and Timer + * classes for high-resolution timing. + * @version 0.1 + * @date 2023-04-30 + * + * @copyright Copyright (c) 2023 + * + */ +#pragma once + +#include +#include +#include +#include +#include + +#include "macrologger.h" + +namespace hmap +{ + +/** + * @brief The Recorder class is responsible for recording timing information for + * individual events. + */ +class Recorder +{ +public: + /** + * @brief Constructs a new Recorder object. + * + * @param name The name of the event to be recorded. + */ + Recorder(std::string name); + + /** + * @brief Outputs the timing data to the console. + */ + void dump(); + + /** + * @brief Starts the timer for this Recorder instance. + */ + void start(); + + /** + * @brief Stops the timer for this Recorder instance and updates the total + * elapsed time. + */ + void stop(); + +private: + std::string name; ///< The name of the event. + int nb_calls = 0; ///< The number of times the event has been recorded. + std::chrono::high_resolution_clock::time_point + t0; ///< The start time of the event. + float total = 0.f; ///< The total time recorded for the event. +}; + +/** + * @brief The Timer class is a singleton that manages multiple Recorders and + * provides an interface for timing events. + * + * The Timer class allows you to measure the duration of multiple events by + * using start and stop commands. Each event is identified by a unique name. The + * Timer class maintains a collection of these events and their corresponding + * durations. The class is designed as a singleton, meaning only one instance of + * Timer will exist throughout the lifetime of the program. + * + * ### Usage Example: + * + * @code + * #include "timer.hpp" + * + * int main() { + * // Start timing an event named "step 1" + * Timer::Start("step 1"); + * + * // Perform some work here... + * + * // Stop timing the event named "step 1" + * Timer::Stop("step 1"); + * + * // Start and stop another event + * Timer::Start("step 2"); + * + * // Perform more work here... + * + * Timer::Stop("step 2"); + * + * // Dump the timing results for all recorded events + * Timer::Dump(); + * + * return 0; + * } + * @endcode + */ +class Timer +{ +public: + /** + * @brief Gets the singleton instance of the Timer class. + * + * @return Timer& Reference to the singleton instance. + */ + static Timer &get_instance(); + + /** + * @brief Starts a timer for the specified event name. + * + * @param name The name of the event to start timing. + */ + static void Start(const std::string &name); + + /** + * @brief Stops the timer for the specified event name. + * + * @param name The name of the event to stop timing. + */ + static void Stop(const std::string &name); + + /** + * @brief Dumps the timing information for all recorded events to the console. + */ + static void Dump(); + +private: + /** + * @brief Constructs a new Timer object. This constructor is private to + * enforce the singleton pattern. + * + * @param sid An optional identifier for the Timer instance. + */ + Timer(std::string sid = ""); + + /** + * @brief Destroys the Timer object and dumps all timing data. + */ + ~Timer(); + + /** + * @brief Starts a timer for the specified event name. + * + * @param name The name of the event to start timing. + */ + void start(const std::string &name); + + /** + * @brief Stops the timer for the specified event name. + * + * @param name The name of the event to stop timing. + */ + void stop(const std::string &name); + + /** + * @brief Dumps the timing information for all recorded events to the console. + */ + void dump(); + + // Deleting the copy constructor and assignment operator to enforce singleton + // pattern. + Timer(const Timer &) = delete; + Timer &operator=(const Timer &) = delete; + +private: + std::string sid; ///< An optional identifier for the Timer instance. + std::map + records; ///< A map of event names to their corresponding Recorder + ///< objects. + std::list + data; ///< A list of Recorder objects that store timing information. + int current_level = 0; ///< Current nesting level (if applicable). +}; + +} // namespace hmap diff --git a/HighMap/src/dbg/timer.cpp b/HighMap/src/dbg/timer.cpp new file mode 100644 index 00000000..8c158900 --- /dev/null +++ b/HighMap/src/dbg/timer.cpp @@ -0,0 +1,98 @@ +/* Copyright (c) 2023 Otto Link. Distributed under the terms of the GNU General + * Public License. The full license is in the file LICENSE, distributed with + * this software. */ + +#include "highmap/dbg/timer.hpp" + +namespace hmap +{ + +Recorder::Recorder(std::string name) : name(name) +{ +} + +void Recorder::dump() +{ + std::cout << std::setw(20) << this->name; + std::cout << std::setw(10) << this->nb_calls; + std::cout << std::setw(20) << this->total / (float)this->nb_calls << " ms"; + std::cout << std::endl; +} + +void Recorder::start() +{ + this->t0 = std::chrono::high_resolution_clock::now(); + this->nb_calls++; +} + +void Recorder::stop() +{ + std::chrono::high_resolution_clock::time_point t1 = + std::chrono::high_resolution_clock::now(); + this->total += (float)std::chrono::duration_cast( + t1 - t0) + .count() * + 1e-6f; +} + +// Static method to get the singleton instance +Timer &Timer::get_instance() +{ + static Timer instance; // This is the singleton instance + return instance; +} + +// Static methods to start and stop timers +void Timer::Start(const std::string &name) +{ + get_instance().start(name); +} + +void Timer::Stop(const std::string &name) +{ + get_instance().stop(name); +} + +void Timer::Dump() +{ + get_instance().dump(); +} + +// Private constructor to prevent instantiation +Timer::Timer(std::string sid) : sid(sid) +{ +} +Timer::~Timer() +{ + this->dump(); +} + +// The actual methods for starting and stopping +void Timer::start(const std::string &name) +{ + if (records.find(name) == records.end()) + { + Recorder new_recorder(name); + data.push_back(new_recorder); + records[name] = &data.back(); + } + records[name]->start(); +} + +void Timer::stop(const std::string &name) +{ + if (records.find(name) != records.end()) + records[name]->stop(); + else + std::cout << "Warning! Trying to stop an unknown timer: " << name + << std::endl; +} + +void Timer::dump() +{ + std::cout << "Timer dump: " << this->sid << std::endl; + for (auto &n : records) + n.second->dump(); +} + +} // namespace hmap diff --git a/HighMap/src/erosion/erosion_maps.cpp b/HighMap/src/erosion/erosion_maps.cpp index f0a03308..7cd176a0 100644 --- a/HighMap/src/erosion/erosion_maps.cpp +++ b/HighMap/src/erosion/erosion_maps.cpp @@ -1,17 +1,15 @@ /* Copyright (c) 2023 Otto Link. Distributed under the terms of the GNU General * Public License. The full license is in the file LICENSE, distributed with * this software. */ - #include +#include "macrologger.h" + #include "highmap/array.hpp" #include "highmap/erosion.hpp" #include "highmap/primitives.hpp" #include "highmap/range.hpp" -#include "highmap/dbg.hpp" -#include "macrologger.h" - namespace hmap { diff --git a/HighMap/src/erosion/hydraulic_particle.cpp b/HighMap/src/erosion/hydraulic_particle.cpp index b014e780..a445085d 100644 --- a/HighMap/src/erosion/hydraulic_particle.cpp +++ b/HighMap/src/erosion/hydraulic_particle.cpp @@ -1,9 +1,10 @@ /* Copyright (c) 2023 Otto Link. Distributed under the terms of the GNU General * Public License. The full license is in the file LICENSE, distributed with * this software. */ - #include +#include "macrologger.h" + #include "highmap/array.hpp" #include "highmap/boundary.hpp" #include "highmap/erosion.hpp" @@ -12,9 +13,6 @@ #include "highmap/primitives.hpp" #include "highmap/range.hpp" -#include "highmap/dbg.hpp" -#include "macrologger.h" - #define DT 1.f #define VOLUME_INIT 1.f #define VOLUME_MIN 0.01f diff --git a/HighMap/src/erosion/hydraulic_particle_multiscale.cpp b/HighMap/src/erosion/hydraulic_particle_multiscale.cpp index 3f6ce0e9..436e4809 100644 --- a/HighMap/src/erosion/hydraulic_particle_multiscale.cpp +++ b/HighMap/src/erosion/hydraulic_particle_multiscale.cpp @@ -1,7 +1,6 @@ /* Copyright (c) 2023 Otto Link. Distributed under the terms of the GNU General * Public License. The full license is in the file LICENSE, distributed with * this software. */ - #include #include "macrologger.h" @@ -12,8 +11,6 @@ #include "highmap/pyramid.hpp" #include "highmap/range.hpp" -#include "highmap/dbg.hpp" - namespace hmap { diff --git a/HighMap/src/erosion/hydraulic_vpipes.cpp b/HighMap/src/erosion/hydraulic_vpipes.cpp index 6f9494c7..4dc1adfd 100644 --- a/HighMap/src/erosion/hydraulic_vpipes.cpp +++ b/HighMap/src/erosion/hydraulic_vpipes.cpp @@ -1,9 +1,10 @@ /* Copyright (c) 2023 Otto Link. Distributed under the terms of the GNU General * Public License. The full license is in the file LICENSE, distributed with * this software. */ - #include +#include "macrologger.h" + #include "highmap/array.hpp" #include "highmap/boundary.hpp" #include "highmap/filters.hpp" @@ -12,9 +13,6 @@ #include "highmap/primitives.hpp" #include "highmap/range.hpp" -#include "highmap/dbg.hpp" -#include "macrologger.h" - #define EPS 1e-6f namespace hmap diff --git a/HighMap/src/gpu/filters_gpu.cpp b/HighMap/src/gpu/filters_gpu.cpp index 3f28fa14..b4a7168e 100644 --- a/HighMap/src/gpu/filters_gpu.cpp +++ b/HighMap/src/gpu/filters_gpu.cpp @@ -10,8 +10,6 @@ #include "highmap/geometry.hpp" #include "highmap/gpu.hpp" -#include "highmap/dbg.hpp" - namespace hmap::gpu { @@ -29,8 +27,6 @@ void hydraulic_particle(OpenCLConfig &config, { int err = 0; - Timer timer = Timer("hydraulic_particle"); - int nparticles_resized = closest_smaller_multiple(nparticles, config.block_size); @@ -81,12 +77,9 @@ void hydraulic_particle(OpenCLConfig &config, OPENCL_ERROR_MESSAGE(err, "enqueueNDRangeKernel"); - timer.start("core"); - err = queue.finish(); OPENCL_ERROR_MESSAGE(err, "finish"); - timer.stop("core"); cl::array origin = {0, 0, 0}; cl::array region = {(size_t)array.shape.y, @@ -130,8 +123,6 @@ void maximum_local_weighted(OpenCLConfig &config, Array &array, Array &weights) else p_weights = &weights; - Timer timer = Timer("maximum_local_weighted"); - cl::CommandQueue queue(config.context, config.device); cl::Buffer buffer_out(config.context, @@ -180,12 +171,9 @@ void maximum_local_weighted(OpenCLConfig &config, Array &array, Array &weights) OPENCL_ERROR_MESSAGE(err, "enqueueNDRangeKernel"); - timer.start("core"); - err = queue.finish(); OPENCL_ERROR_MESSAGE(err, "finish"); - timer.stop("core"); err = queue.enqueueReadBuffer(buffer_out, CL_TRUE, @@ -202,8 +190,6 @@ void median_3x3(OpenCLConfig &config, { int err = 0; - Timer timer = Timer("median_3x3"); - // --- wrapper to GPU host cl::CommandQueue queue(config.context, config.device); @@ -243,12 +229,9 @@ void median_3x3(OpenCLConfig &config, OPENCL_ERROR_MESSAGE(err, "enqueueNDRangeKernel"); - timer.start("core"); - err = queue.finish(); OPENCL_ERROR_MESSAGE(err, "finish"); - timer.stop("core"); err = queue.enqueueReadBuffer(buffer_out, CL_TRUE, @@ -265,8 +248,6 @@ void median_3x3_img(OpenCLConfig &config, { int err = 0; - Timer timer = Timer("median_3x3_img"); - // --- wrapper to GPU host cl::Image2D img_in(config.context, @@ -314,12 +295,9 @@ void median_3x3_img(OpenCLConfig &config, OPENCL_ERROR_MESSAGE(err, "enqueueNDRangeKernel"); - timer.start("core"); - err = queue.finish(); OPENCL_ERROR_MESSAGE(err, "finish"); - timer.stop("core"); cl::array origin = {0, 0, 0}; cl::array region = {(size_t)array.shape.y, @@ -358,8 +336,6 @@ Array ridgelines(OpenCLConfig &config, rescale_grid_to_unit_square(xr_scaled, yr_scaled, bbox); - Timer timer = Timer("ridgelines"); - cl::CommandQueue queue(config.context, config.device); cl::Buffer buffer_out(config.context, @@ -414,12 +390,9 @@ Array ridgelines(OpenCLConfig &config, OPENCL_ERROR_MESSAGE(err, "enqueueNDRangeKernel"); - timer.start("core"); - err = queue.finish(); OPENCL_ERROR_MESSAGE(err, "finish"); - timer.stop("core"); err = queue.enqueueReadBuffer(buffer_out, CL_TRUE, @@ -441,8 +414,6 @@ Array simplex(OpenCLConfig &config, int err = 0; Array array = Array(shape); // output - Timer timer = Timer("simplex"); - cl::CommandQueue queue(config.context, config.device); cl::Buffer buffer_out(config.context, @@ -477,12 +448,9 @@ Array simplex(OpenCLConfig &config, OPENCL_ERROR_MESSAGE(err, "enqueueNDRangeKernel"); - timer.start("core"); - err = queue.finish(); OPENCL_ERROR_MESSAGE(err, "finish"); - timer.stop("core"); err = queue.enqueueReadBuffer(buffer_out, CL_TRUE, @@ -506,8 +474,6 @@ Array voronoise(OpenCLConfig &config, int err = 0; Array array = Array(shape); // output - Timer timer = Timer("voronoise"); - cl::CommandQueue queue(config.context, config.device); cl::Buffer buffer_out(config.context, @@ -544,12 +510,9 @@ Array voronoise(OpenCLConfig &config, OPENCL_ERROR_MESSAGE(err, "enqueueNDRangeKernel"); - timer.start("core"); - err = queue.finish(); OPENCL_ERROR_MESSAGE(err, "finish"); - timer.stop("core"); err = queue.enqueueReadBuffer(buffer_out, CL_TRUE, diff --git a/HighMap/src/heightmap/heightmap_rgba.cpp b/HighMap/src/heightmap/heightmap_rgba.cpp index e8329a7d..28f9d974 100644 --- a/HighMap/src/heightmap/heightmap_rgba.cpp +++ b/HighMap/src/heightmap/heightmap_rgba.cpp @@ -9,8 +9,8 @@ #include "macrologger.h" #include "highmap/colormaps.hpp" -#include "highmap/heightmap.hpp" #include "highmap/export.hpp" +#include "highmap/heightmap.hpp" #include "highmap/math.hpp" #include "highmap/operator.hpp" #include "highmap/primitives.hpp" diff --git a/HighMap/src/io/export_asset.cpp b/HighMap/src/io/export_asset.cpp index 2f86b163..d4b27367 100644 --- a/HighMap/src/io/export_asset.cpp +++ b/HighMap/src/io/export_asset.cpp @@ -11,9 +11,9 @@ #include #include "highmap/array.hpp" +#include "highmap/export.hpp" #include "highmap/geometry.hpp" #include "highmap/interpolate.hpp" -#include "highmap/export.hpp" #include "highmap/operator.hpp" namespace hmap diff --git a/HighMap/src/io/export_normal_map.cpp b/HighMap/src/io/export_normal_map.cpp index 20fefe29..6521ee6f 100644 --- a/HighMap/src/io/export_normal_map.cpp +++ b/HighMap/src/io/export_normal_map.cpp @@ -4,8 +4,8 @@ #include "macrologger.h" #include "highmap/array.hpp" -#include "highmap/gradient.hpp" #include "highmap/export.hpp" +#include "highmap/gradient.hpp" #include "highmap/operator.hpp" namespace hmap diff --git a/HighMap/src/io/export_vector_glyph.cpp b/HighMap/src/io/export_vector_glyph.cpp index 76e435fe..834d362b 100644 --- a/HighMap/src/io/export_vector_glyph.cpp +++ b/HighMap/src/io/export_vector_glyph.cpp @@ -4,8 +4,8 @@ #include "macrologger.h" #include "highmap/array.hpp" -#include "highmap/geometry.hpp" #include "highmap/export.hpp" +#include "highmap/geometry.hpp" #include "highmap/math.hpp" #include "highmap/operator.hpp" diff --git a/HighMap/src/morphology/distance_transform.cpp b/HighMap/src/morphology/distance_transform.cpp index 7334f910..65b88234 100644 --- a/HighMap/src/morphology/distance_transform.cpp +++ b/HighMap/src/morphology/distance_transform.cpp @@ -1,8 +1,9 @@ /* Copyright (c) 2023 Otto Link. Distributed under the terms of the GNU General * Public License. The full license is in the file LICENSE, distributed with * this software. */ +#include "macrologger.h" + #include "highmap/array.hpp" -#include "highmap/dbg.hpp" #include "highmap/math.hpp" #include "highmap/operator.hpp" diff --git a/HighMap/src/pyramid_decomposition/pyramid_decomposition.cpp b/HighMap/src/pyramid_decomposition/pyramid_decomposition.cpp index 9c639cae..8d0ddf99 100644 --- a/HighMap/src/pyramid_decomposition/pyramid_decomposition.cpp +++ b/HighMap/src/pyramid_decomposition/pyramid_decomposition.cpp @@ -1,11 +1,11 @@ /* Copyright (c) 2023 Otto Link. Distributed under the terms of the GNU General * Public License. The full license is in the file LICENSE, distributed with * this software. */ +#include "macrologger.h" #include "highmap/array.hpp" -#include "highmap/dbg.hpp" -#include "highmap/filters.hpp" #include "highmap/export.hpp" +#include "highmap/filters.hpp" #include "highmap/math.hpp" #include "highmap/operator.hpp" #include "highmap/pyramid.hpp" diff --git a/examples/ex_export_asset/ex_export_asset.cpp b/examples/ex_export_asset/ex_export_asset.cpp index dcb3226c..98bd5a61 100644 --- a/examples/ex_export_asset/ex_export_asset.cpp +++ b/examples/ex_export_asset/ex_export_asset.cpp @@ -1,5 +1,6 @@ +#include + #include "highmap.hpp" -#include "highmap/dbg.hpp" int main(void) { @@ -18,7 +19,7 @@ int main(void) for (auto &[export_id, export_infos] : hmap::asset_export_format_as_string) { - LOG_INFO("exporting format: %s", export_infos[0].c_str()); + std::cout << "exporting format: " << export_infos[0] << "\n"; float error_tolerance = 1e-2f; // for tri_optimized only diff --git a/examples/ex_find_flow_sinks/ex_find_flow_sinks.cpp b/examples/ex_find_flow_sinks/ex_find_flow_sinks.cpp index e1386fc5..b656535f 100644 --- a/examples/ex_find_flow_sinks/ex_find_flow_sinks.cpp +++ b/examples/ex_find_flow_sinks/ex_find_flow_sinks.cpp @@ -1,5 +1,6 @@ +#include + #include "highmap.hpp" -#include "highmap/dbg.hpp" int main(void) { @@ -13,5 +14,5 @@ int main(void) hmap::find_flow_sinks(z, is, js); for (size_t k = 0; k < is.size(); k++) - LOG_INFO("%d %d", is[k], js[k]); + std::cout << is[k] << " " << js[k] << "\n"; } diff --git a/examples/ex_gpu_hydraulic_particle/ex_gpu_hydraulic_particle.cpp b/examples/ex_gpu_hydraulic_particle/ex_gpu_hydraulic_particle.cpp index c255886a..d1ceeddc 100644 --- a/examples/ex_gpu_hydraulic_particle/ex_gpu_hydraulic_particle.cpp +++ b/examples/ex_gpu_hydraulic_particle/ex_gpu_hydraulic_particle.cpp @@ -1,5 +1,6 @@ +#include + #include "highmap.hpp" -#include "highmap/dbg.hpp" int main(void) { diff --git a/examples/ex_gpu_maximum_local_weighted/ex_gpu_maximum_local_weighted.cpp b/examples/ex_gpu_maximum_local_weighted/ex_gpu_maximum_local_weighted.cpp index cebe9a2d..822e5d4e 100644 --- a/examples/ex_gpu_maximum_local_weighted/ex_gpu_maximum_local_weighted.cpp +++ b/examples/ex_gpu_maximum_local_weighted/ex_gpu_maximum_local_weighted.cpp @@ -1,5 +1,6 @@ +#include + #include "highmap.hpp" -#include "highmap/dbg.hpp" int main(void) { @@ -39,6 +40,6 @@ int main(void) {z, z1, z2}, hmap::cmap::inferno); #else - LOG_ERROR("OpenCL not activated"); + std::cout << "OpenCL not activated\n"; #endif } diff --git a/examples/ex_gpu_median_3x3/ex_gpu_median_3x3.cpp b/examples/ex_gpu_median_3x3/ex_gpu_median_3x3.cpp index 8bbce068..8e96bda9 100644 --- a/examples/ex_gpu_median_3x3/ex_gpu_median_3x3.cpp +++ b/examples/ex_gpu_median_3x3/ex_gpu_median_3x3.cpp @@ -1,5 +1,6 @@ +#include + #include "highmap.hpp" -#include "highmap/dbg.hpp" int main(void) { @@ -46,6 +47,6 @@ int main(void) {z, z1, z2}, hmap::cmap::inferno); #else - LOG_ERROR("OpenCL not activated"); + std::cout << "OpenCL not activated\n"; #endif } diff --git a/examples/ex_gpu_ridgelines/ex_gpu_ridgelines.cpp b/examples/ex_gpu_ridgelines/ex_gpu_ridgelines.cpp index 415a037b..ee479850 100644 --- a/examples/ex_gpu_ridgelines/ex_gpu_ridgelines.cpp +++ b/examples/ex_gpu_ridgelines/ex_gpu_ridgelines.cpp @@ -1,5 +1,6 @@ +#include + #include "highmap.hpp" -#include "highmap/dbg.hpp" int main(void) { @@ -32,6 +33,6 @@ int main(void) {z1, z2, z3}, hmap::cmap::inferno); #else - LOG_ERROR("OpenCL not activated"); + std::cout << "OpenCL not activated\n"; #endif } diff --git a/examples/ex_gpu_simplex/ex_gpu_simplex.cpp b/examples/ex_gpu_simplex/ex_gpu_simplex.cpp index 81a6e6ae..d40a54f8 100644 --- a/examples/ex_gpu_simplex/ex_gpu_simplex.cpp +++ b/examples/ex_gpu_simplex/ex_gpu_simplex.cpp @@ -1,5 +1,6 @@ +#include + #include "highmap.hpp" -#include "highmap/dbg.hpp" int main(void) { @@ -27,6 +28,6 @@ int main(void) hmap::export_banner_png("ex_gpu_simplex.png", {z1, z2}, hmap::cmap::viridis); #else - LOG_ERROR("OpenCL not activated"); + std::cout << "OpenCL not activated\n"; #endif } diff --git a/examples/ex_gpu_voronoise/ex_gpu_voronoise.cpp b/examples/ex_gpu_voronoise/ex_gpu_voronoise.cpp index b383ca3b..04d7310e 100644 --- a/examples/ex_gpu_voronoise/ex_gpu_voronoise.cpp +++ b/examples/ex_gpu_voronoise/ex_gpu_voronoise.cpp @@ -1,5 +1,6 @@ +#include + #include "highmap.hpp" -#include "highmap/dbg.hpp" int main(void) { @@ -26,6 +27,6 @@ int main(void) {z1, z2, z3, z4}, hmap::cmap::viridis); #else - LOG_ERROR("OpenCL not activated"); + std::cout << "OpenCL not activated\n"; #endif } diff --git a/examples/ex_graph/ex_graph.cpp b/examples/ex_graph/ex_graph.cpp index 9e0072bf..6e7954c4 100644 --- a/examples/ex_graph/ex_graph.cpp +++ b/examples/ex_graph/ex_graph.cpp @@ -1,6 +1,6 @@ #include "highmap/array.hpp" -#include "highmap/geometry.hpp" #include "highmap/export.hpp" +#include "highmap/geometry.hpp" int main(void) { diff --git a/examples/ex_graph_dijkstra/ex_graph_dijkstra.cpp b/examples/ex_graph_dijkstra/ex_graph_dijkstra.cpp index 0c52dfeb..d018c3f1 100644 --- a/examples/ex_graph_dijkstra/ex_graph_dijkstra.cpp +++ b/examples/ex_graph_dijkstra/ex_graph_dijkstra.cpp @@ -1,6 +1,6 @@ #include "highmap/array.hpp" -#include "highmap/geometry.hpp" #include "highmap/export.hpp" +#include "highmap/geometry.hpp" int main(void) { diff --git a/examples/ex_graph_minimum_spanning_tree_prim/ex_graph_minimum_spanning_tree_prim.cpp b/examples/ex_graph_minimum_spanning_tree_prim/ex_graph_minimum_spanning_tree_prim.cpp index 0741cfb2..86b4d583 100644 --- a/examples/ex_graph_minimum_spanning_tree_prim/ex_graph_minimum_spanning_tree_prim.cpp +++ b/examples/ex_graph_minimum_spanning_tree_prim/ex_graph_minimum_spanning_tree_prim.cpp @@ -1,6 +1,6 @@ #include "highmap/array.hpp" -#include "highmap/geometry.hpp" #include "highmap/export.hpp" +#include "highmap/geometry.hpp" int main(void) { diff --git a/examples/ex_noise_function/ex_noise_function.cpp b/examples/ex_noise_function/ex_noise_function.cpp index 98bb5aeb..41cacbff 100644 --- a/examples/ex_noise_function/ex_noise_function.cpp +++ b/examples/ex_noise_function/ex_noise_function.cpp @@ -1,5 +1,4 @@ #include "highmap.hpp" -#include "highmap/dbg.hpp" int main(void) { diff --git a/examples/ex_pyramid_transform/ex_pyramid_transform.cpp b/examples/ex_pyramid_transform/ex_pyramid_transform.cpp index 22e0d28e..b205d5e3 100644 --- a/examples/ex_pyramid_transform/ex_pyramid_transform.cpp +++ b/examples/ex_pyramid_transform/ex_pyramid_transform.cpp @@ -1,5 +1,6 @@ +#include + #include "highmap.hpp" -#include "highmap/dbg.hpp" int main(void) { @@ -19,10 +20,8 @@ int main(void) // 'transform' function auto fct = [&seed](const hmap::Array &input, const int current_level) { - LOG_INFO("applying erosion to level: %d, shape: {%d, %d}", - current_level, - input.shape.x, - input.shape.y); + std::cout << "applying erosion to level and shape: " << current_level << " " + << input.shape.x << " " << input.shape.y << "\n"; // apply hydraulic erosion to each component hmap::Array output = input; diff --git a/examples/ex_ridgelines/ex_ridgelines.cpp b/examples/ex_ridgelines/ex_ridgelines.cpp index 99b0ed89..86065e9a 100644 --- a/examples/ex_ridgelines/ex_ridgelines.cpp +++ b/examples/ex_ridgelines/ex_ridgelines.cpp @@ -1,5 +1,4 @@ #include "highmap.hpp" -#include "highmap/dbg.hpp" int main(void) { diff --git a/examples/ex_ridgelines_bezier/ex_ridgelines_bezier.cpp b/examples/ex_ridgelines_bezier/ex_ridgelines_bezier.cpp index 784a8388..6b3d00c0 100644 --- a/examples/ex_ridgelines_bezier/ex_ridgelines_bezier.cpp +++ b/examples/ex_ridgelines_bezier/ex_ridgelines_bezier.cpp @@ -1,5 +1,4 @@ #include "highmap.hpp" -#include "highmap/dbg.hpp" int main(void) { diff --git a/examples/ex_to_cv_mat/ex_to_cv_mat.cpp b/examples/ex_to_cv_mat/ex_to_cv_mat.cpp index ad599b89..64f80c84 100644 --- a/examples/ex_to_cv_mat/ex_to_cv_mat.cpp +++ b/examples/ex_to_cv_mat/ex_to_cv_mat.cpp @@ -2,12 +2,10 @@ #include #include "highmap.hpp" -#include "highmap/dbg.hpp" int main(void) { #ifdef ENABLE_OPENCV - LOG_DEBUG("opencv enabled"); hmap::Vec2 shape = {512, 256}; hmap::Vec2 res = {4.f, 2.f}; @@ -43,8 +41,5 @@ int main(void) cv::imshow("example", img); cv::waitKey(0); -#else - LOG_DEBUG("opencv not available"); - #endif } diff --git a/tests/parameter_influence/main.cpp b/tests/parameter_influence/main.cpp index b1a83b09..be93b37b 100644 --- a/tests/parameter_influence/main.cpp +++ b/tests/parameter_influence/main.cpp @@ -3,7 +3,6 @@ #include #include "highmap.hpp" -#include "highmap/dbg.hpp" template void show_influence(std::string label, @@ -25,8 +24,6 @@ void show_influence(std::string label, int main(void) { - hmap::Timer timer = hmap::Timer(); - const hmap::Vec2 shape = {512, 512}; const hmap::Vec2 res = {4.f, 4.f}; int seed = 1; diff --git a/tests/sandbox/main.cpp b/tests/sandbox/main.cpp index 74679ccc..3dc333db 100644 --- a/tests/sandbox/main.cpp +++ b/tests/sandbox/main.cpp @@ -1,19 +1,15 @@ #include "highmap.hpp" -#include "highmap/dbg.hpp" +#include "highmap/dbg/timer.hpp" int main(void) { - hmap::Timer timer = hmap::Timer(); + const hmap::Vec2 shape = {512, 512}; + const hmap::Vec2 res = {4.f, 4.f}; + int seed = 2; - { - const hmap::Vec2 shape = {512, 512}; - const hmap::Vec2 res = {4.f, 4.f}; - int seed = 2; + hmap::Timer::Start("fbm_perlin"); + hmap::Array z = hmap::noise(hmap::NoiseType::PERLIN, shape, res, seed); + hmap::Timer::Stop("fbm_perlin"); - timer.start("fbm_perlin"); - hmap::Array z = hmap::noise(hmap::NoiseType::PERLIN, shape, res, seed); - timer.stop("fbm_perlin"); - - z.to_png("out.png", hmap::Cmap::INFERNO); - } + z.to_png("out.png", hmap::Cmap::INFERNO); }