From b3686c1641973a82d5cd5a3f8fcab655a01f07ff Mon Sep 17 00:00:00 2001 From: Hartmut Seichter Date: Wed, 21 May 2025 22:30:57 +0200 Subject: [PATCH 1/3] clean up some old leftovers --- src/core/include/pw/core/aabb.hpp | 5 +- src/core/include/pw/core/debug.hpp | 93 +++++++++++++--------------- src/core/include/pw/core/math.hpp | 68 ++++++++++---------- src/core/include/pw/core/matrix.hpp | 1 - src/core/include/pw/core/mesh.hpp | 1 + src/core/tests/pwcore_test_image.cpp | 12 +++- 6 files changed, 94 insertions(+), 86 deletions(-) diff --git a/src/core/include/pw/core/aabb.hpp b/src/core/include/pw/core/aabb.hpp index f1ea3c3..a651acb 100644 --- a/src/core/include/pw/core/aabb.hpp +++ b/src/core/include/pw/core/aabb.hpp @@ -40,8 +40,9 @@ template struct aabb final { constexpr auto dimension() const noexcept { return max - min; } - static constexpr auto make( - const std::vector>& vertices) -> aabb { + static constexpr auto + make(const std::vector>& vertices) + -> aabb { return std::accumulate( std::begin(vertices), std::end(vertices), aabb{.min{vertices.front()}, .max{vertices.front()}}, diff --git a/src/core/include/pw/core/debug.hpp b/src/core/include/pw/core/debug.hpp index 6f0876e..c1ce297 100644 --- a/src/core/include/pw/core/debug.hpp +++ b/src/core/include/pw/core/debug.hpp @@ -8,8 +8,8 @@ * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, @@ -26,72 +26,67 @@ #include -#include #include +#include namespace pw { /** - * @brief multipurpose logger used internally - */ + * @brief multipurpose logger used internally + */ class debug { -public: - + public: enum level { - none, //!< nothing will be logged, even no errors - error, //!< only errors will be logged - warning, //!< log warnings (non-critical errors) - message, //!< log messages (something to note but not an error) - notification, //!< log some more information - info, //!< log verbose information - all = 0xFF //!< log absolutely everything + none, //!< nothing will be logged, even no errors + error, //!< only errors will be logged + warning, //!< log warnings (non-critical errors) + message, //!< log messages (something to note but not an error) + notification, //!< log some more information + info, //!< log verbose information + all = 0xFF //!< log absolutely everything }; /** * @brief the streaming interface for the logger */ class stream { - public: - - + public: stream(debug* log = nullptr); ~stream(); stream(const stream& other); + stream& operator<<(const bool& value); + stream& operator<<(const char* value); + stream& operator<<(const std::string& value); ///! log a string + stream& + operator<<(const std::string_view& value); ///! log a string_view - stream& operator << (const bool &value); - stream& operator << (const char *value); - stream& operator << (const std::string& value); ///! log a string - stream& operator << (const std::string_view& value); ///! log a string_view + stream& operator<<(const float& value); ///! log a float value + stream& operator<<(const double& value); ///! log a double value - stream& operator << (const float &value); ///! log a float value - stream& operator << (const double &value); ///! log a double value + stream& operator<<(const int& value); ///! log a int value + stream& operator<<(const unsigned int& value); ///! log a int value - stream& operator << (const int &value); ///! log a int value - stream& operator << (const unsigned int &value); ///! log a int value + stream& operator<<(const long& value); ///! log a long value + stream& operator<<(const unsigned long& value); ///! log a int value - stream& operator << (const long &value); ///! log a long value - stream& operator << (const unsigned long &value); ///! log a int value - - stream& operator << (const void *value); ///! pointer - - - protected: + stream& operator<<(const void* value); ///! pointer + protected: debug* _log; std::string _line; }; /** sets the logging level */ - void set_level(level level) {_level = level;} + void set_level(level level) { _level = level; } /** gets the logging level */ level level() const { return _level; } /** - * @brief get the stream interface of the logger - * @return return a temporary object that will write and flush the logger - */ + * @brief get the stream interface of the logger + * @return return a temporary object that will write and flush the logger + */ static stream s(enum level level = info); inline static stream d() { return s(debug::info); } @@ -108,15 +103,14 @@ public: * @brief write a message to the log * @param message string */ - void write(const std::string &message); + void write(const std::string& message); typedef std::function Callback; typedef std::vector CallbackList; ~debug(); -protected: - + protected: debug(); CallbackList _callbacks; @@ -126,7 +120,7 @@ protected: ///** // * @brief helper for changing the log level in a scope // */ -//struct ScopeLogLevel +// struct ScopeLogLevel //{ // debug::level levelOutside; // explicit ScopeLogLevel(debug::level level) @@ -140,12 +134,12 @@ protected: // } //}; -//template -//struct tpScopeLog { -// const char* info; -// explicit tpScopeLog(const char* i) : info(i) { -// debug::s(level) << info; -// } +// template +// struct tpScopeLog { +// const char* info; +// explicit tpScopeLog(const char* i) : info(i) { +// debug::s(level) << info; +// } // ~tpScopeLog() { // debug::s(level) << info; @@ -154,9 +148,8 @@ protected: // some macros -//#define LOG_INFO() Log::s() -//#define LOG_FUNC() LOG_INFO() << __FUNCTION__ << " " << __LINE__ << " " -} - +// #define LOG_INFO() Log::s() +// #define LOG_FUNC() LOG_INFO() << __FUNCTION__ << " " << __LINE__ << " " +} // namespace pw #endif diff --git a/src/core/include/pw/core/math.hpp b/src/core/include/pw/core/math.hpp index 4545255..2ba1347 100644 --- a/src/core/include/pw/core/math.hpp +++ b/src/core/include/pw/core/math.hpp @@ -8,8 +8,8 @@ * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, @@ -23,54 +23,60 @@ #ifndef PW_CORE_MATH_HPP #define PW_CORE_MATH_HPP -#include #include +#include +#include #include namespace pw { -constexpr double __PW_PI = 3.1415926535897932384626433832795028841971693993751058209; -constexpr double __PW_PI_DOUBLE = 2.0 * __PW_PI; +static constexpr double __PW_PI{ + 3.1415926535897932384626433832795028841971693993751058209}; +static constexpr double __PW_PI_DOUBLE{2 * __PW_PI}; -template -inline const T pi() { return static_cast(__PW_PI); } - -template -inline const T one_over_pi() { return static_cast(1 / __PW_PI); } - -template -inline T rad_to_deg(const T& angle_in_radian) { - return angle_in_radian * static_cast(180) * one_over_pi(); +template inline static constexpr T pi() { + return static_cast(__PW_PI); } -template -inline T deg_to_rad(const T& angle_in_degree) { - return angle_in_degree * pi() / static_cast(180); +template inline const T one_over_pi() { + return static_cast(1 / __PW_PI); } -template -inline T repeat(const T& t, const T& length) { - return std::clamp(t - std::floor(t / length) * length, T(0), length); +template inline T rad_to_deg(const T& angle_in_radian) { + return angle_in_radian * static_cast(180) * one_over_pi(); } -template -inline T ping_pong(const T& t,const T& length) { - auto tn = repeat(t, length * T(2)); - return length - std::abs(tn - length); +template inline T deg_to_rad(const T& angle_in_degree) { + return angle_in_degree * pi() / static_cast(180); } -template -inline T wrap_angle(const T& angle_in_radian) { - using std::floor; - return angle_in_radian - __PW_PI_DOUBLE * floor( angle_in_radian / __PW_PI_DOUBLE ); +template inline T repeat(const T& t, const T& length) { + return std::clamp(t - std::floor(t / length) * length, T{}, length); } -//void extractRotation(const matrix &A, Quaterniond &q,const unsigned int maxIter) +template inline T ping_pong(const T& t, const T& length) { + auto tn = repeat(t, length * T{2}); + return length - std::abs(tn - length); +} + +template inline T wrap_angle(const T& angle_in_radian) { + using std::floor; + return angle_in_radian - + __PW_PI_DOUBLE * floor(angle_in_radian / __PW_PI_DOUBLE); +} + +// void extractRotation(const matrix &A, Quaterniond &q,const unsigned int +// maxIter) //{ // for (auto iter = 0; iter < maxIter; iter++){ // auto R = q.matrix(); -// Vector3d omega = (R.col(0).cross(A.col(0)) + R.col(1).cross(A.col(1)) + R.col(2).cross(A.col(2)))*(1.0 / fabs(R.col(0).dot(A.col(0)) + R.col(1).dot(A.col(1)) + R.col(2).dot(A.col(2))) +1.0e-9);double w = omega.norm();if (w < 1.0e-9)break;q = Quaterniond(AngleAxisd(w, (1.0 / w)*omega))*q;q.normalize();}} +// Vector3d omega = (R.col(0).cross(A.col(0)) + +// R.col(1).cross(A.col(1)) + R.col(2).cross(A.col(2)))*(1.0 / +// fabs(R.col(0).dot(A.col(0)) + R.col(1).dot(A.col(1)) + +// R.col(2).dot(A.col(2))) +1.0e-9);double w = omega.norm();if (w +//< 1.0e-9)break;q = Quaterniond(AngleAxisd(w, (1.0 / +// w)*omega))*q;q.normalize();}} -} +} // namespace pw #endif diff --git a/src/core/include/pw/core/matrix.hpp b/src/core/include/pw/core/matrix.hpp index e22ff47..40e3b0e 100644 --- a/src/core/include/pw/core/matrix.hpp +++ b/src/core/include/pw/core/matrix.hpp @@ -23,7 +23,6 @@ #ifndef PW_CORE_MATRIX_HPP #define PW_CORE_MATRIX_HPP -#include "vector.hpp" #include #include #include diff --git a/src/core/include/pw/core/mesh.hpp b/src/core/include/pw/core/mesh.hpp index de48299..a85b5c9 100644 --- a/src/core/include/pw/core/mesh.hpp +++ b/src/core/include/pw/core/mesh.hpp @@ -27,6 +27,7 @@ #include #include +#include namespace pw { diff --git a/src/core/tests/pwcore_test_image.cpp b/src/core/tests/pwcore_test_image.cpp index 2c66bb2..79cf378 100644 --- a/src/core/tests/pwcore_test_image.cpp +++ b/src/core/tests/pwcore_test_image.cpp @@ -2,17 +2,22 @@ #include #include #include -#include #include +#include + +#include namespace pw { struct image_layout { + enum pixel_layout { RGB8, RGBA8, LUM8, DEPTH }; static constexpr auto bits_per_channel(pixel_layout layout) { - constexpr auto lut = + constexpr static auto lut = std::array{std::make_tuple(RGB8, sizeof(std::uint8_t) << 3), + std::make_tuple(RGBA8, sizeof(std::uint8_t) << 3), + std::make_tuple(LUM8, sizeof(std::uint8_t) << 3), std::make_tuple(DEPTH, sizeof(float) << 3)}; const auto iter = std::find_if( @@ -34,6 +39,9 @@ auto main() -> int { std::print("DEPTH = {}bits per channel\n", pw::image_layout::bits_per_channel( pw::image_layout::pixel_layout::DEPTH)); + std::print("LUM8 = {}bits per channel\n", + pw::image_layout::bits_per_channel( + pw::image_layout::pixel_layout::LUM8)); // pw::image } From 379bfb0a1431c2710f695182b24ed7c27fe814d1 Mon Sep 17 00:00:00 2001 From: Hartmut Seichter Date: Fri, 2 Aug 2024 23:48:07 +0200 Subject: [PATCH 2/3] remove vscode cruft --- .vscode/launch.json | 7 --- .vscode/settings.json | 110 ------------------------------------------ .vscode/tasks.json | 28 ----------- 3 files changed, 145 deletions(-) delete mode 100644 .vscode/launch.json delete mode 100644 .vscode/settings.json delete mode 100644 .vscode/tasks.json diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 5c7247b..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [] -} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 9763060..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,110 +0,0 @@ -{ - "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools", - "cmake.configureOnOpen": true, - "files.associations": { - "array": "cpp", - "cwchar": "cpp", - "unordered_map": "cpp", - "vector": "cpp", - "exception": "cpp", - "functional": "cpp", - "initializer_list": "cpp", - "iosfwd": "cpp", - "istream": "cpp", - "new": "cpp", - "ostream": "cpp", - "stdexcept": "cpp", - "streambuf": "cpp", - "type_traits": "cpp", - "tuple": "cpp", - "cmath": "cpp", - "span": "cpp", - "*.tcc": "cpp", - "*.inc": "cpp", - "*.ipp": "cpp", - "bit": "cpp", - "bitset": "cpp", - "chrono": "cpp", - "format": "cpp", - "future": "cpp", - "optional": "cpp", - "ranges": "cpp", - "shared_mutex": "cpp", - "stop_token": "cpp", - "regex": "cpp", - "valarray": "cpp", - "*.def": "cpp", - "boundingsphere": "cpp", - "callback": "cpp", - "geometry": "cpp", - "node": "cpp", - "nodevisitor": "cpp", - "object": "cpp", - "plane": "cpp", - "program": "cpp", - "shape": "cpp", - "stateattribute": "cpp", - "observer_ptr": "cpp", - "thread": "cpp", - "concepts": "cpp", - "typeinfo": "cpp", - "drawable": "cpp", - "userdatacontainer": "cpp", - "*.txx": "cpp", - "cctype": "cpp", - "clocale": "cpp", - "csignal": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cstring": "cpp", - "ctime": "cpp", - "cwctype": "cpp", - "any": "cpp", - "atomic": "cpp", - "hash_map": "cpp", - "strstream": "cpp", - "cfenv": "cpp", - "charconv": "cpp", - "cinttypes": "cpp", - "codecvt": "cpp", - "compare": "cpp", - "complex": "cpp", - "condition_variable": "cpp", - "coroutine": "cpp", - "cstdint": "cpp", - "deque": "cpp", - "forward_list": "cpp", - "list": "cpp", - "map": "cpp", - "set": "cpp", - "string": "cpp", - "unordered_set": "cpp", - "algorithm": "cpp", - "iterator": "cpp", - "memory": "cpp", - "memory_resource": "cpp", - "numeric": "cpp", - "random": "cpp", - "ratio": "cpp", - "source_location": "cpp", - "string_view": "cpp", - "system_error": "cpp", - "utility": "cpp", - "hash_set": "cpp", - "fstream": "cpp", - "iomanip": "cpp", - "iostream": "cpp", - "limits": "cpp", - "mutex": "cpp", - "numbers": "cpp", - "semaphore": "cpp", - "sstream": "cpp", - "stdfloat": "cpp", - "text_encoding": "cpp", - "typeindex": "cpp", - "variant": "cpp" - }, - "mesonbuild.configureOnOpen": false -} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index 05054c5..0000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "tasks": [ - { - "type": "cppbuild", - "label": "C/C++: g++ build active file", - "command": "/usr/bin/g++", - "args": [ - "-fdiagnostics-color=always", - "-g", - "${file}", - "-o", - "${fileDirname}/${fileBasenameNoExtension}" - ], - "options": { - "cwd": "${fileDirname}" - }, - "problemMatcher": [ - "$gcc" - ], - "group": { - "kind": "build", - "isDefault": true - }, - "detail": "Task generated by Debugger." - } - ], - "version": "2.0.0" -} \ No newline at end of file From 2cf82d4da95802d6a74fe3e8a1b6da73fbf2332d Mon Sep 17 00:00:00 2001 From: Hartmut Seichter Date: Mon, 2 Jun 2025 21:36:18 +0200 Subject: [PATCH 3/3] new image class --- src/core/include/pw/core/matrix.hpp | 4 +- src/core/tests/pwcore_test_image.cpp | 69 ++++++++++++++++++++++++---- 2 files changed, 61 insertions(+), 12 deletions(-) diff --git a/src/core/include/pw/core/matrix.hpp b/src/core/include/pw/core/matrix.hpp index 40e3b0e..1111708 100644 --- a/src/core/include/pw/core/matrix.hpp +++ b/src/core/include/pw/core/matrix.hpp @@ -70,8 +70,8 @@ struct matrix final { template auto get(this auto&& self) -> decltype(auto) { static_assert(idx < Rows, "Out of bounds access to a member."); // TODO: use forward_like when clang is catching up - // return std::forward_like(self.m_[idx]); - return std::forward(self).m_[idx]; + return std::forward_like(self.m_[idx]); + // return std::forward(self).m_[idx]; } constexpr auto diagonal() const noexcept -> diag_type { diff --git a/src/core/tests/pwcore_test_image.cpp b/src/core/tests/pwcore_test_image.cpp index 79cf378..d905b2f 100644 --- a/src/core/tests/pwcore_test_image.cpp +++ b/src/core/tests/pwcore_test_image.cpp @@ -6,19 +6,20 @@ #include #include +#include namespace pw { struct image_layout { - enum pixel_layout { RGB8, RGBA8, LUM8, DEPTH }; + enum struct pixel_layout { RGB8, RGBA8, LUM8, DEPTH }; static constexpr auto bits_per_channel(pixel_layout layout) { - constexpr static auto lut = - std::array{std::make_tuple(RGB8, sizeof(std::uint8_t) << 3), - std::make_tuple(RGBA8, sizeof(std::uint8_t) << 3), - std::make_tuple(LUM8, sizeof(std::uint8_t) << 3), - std::make_tuple(DEPTH, sizeof(float) << 3)}; + constexpr static auto lut = std::array{ + std::make_tuple(pixel_layout::RGB8, sizeof(std::uint8_t) << 3), + std::make_tuple(pixel_layout::RGBA8, sizeof(std::uint8_t) << 3), + std::make_tuple(pixel_layout::LUM8, sizeof(std::uint8_t) << 3), + std::make_tuple(pixel_layout::DEPTH, sizeof(float) << 3)}; const auto iter = std::find_if( std::begin(lut), std::end(lut), @@ -26,16 +27,53 @@ struct image_layout { return iter != std::end(lut) ? std::get<1>(*iter) : 0u; } + + static constexpr auto channels(pixel_layout layout) { + constexpr static auto lut = + std::array{std::make_tuple(pixel_layout::RGB8, 3), + std::make_tuple(pixel_layout::RGBA8, 4), + std::make_tuple(pixel_layout::LUM8, 1), + std::make_tuple(pixel_layout::DEPTH, 1)}; + + const auto iter = std::find_if( + std::begin(lut), std::end(lut), + [&layout](const auto& v) { return std::get<0>(v) == layout; }); + + return iter != std::end(lut) ? std::get<1>(*iter) : 0u; + } + + size size_{}; + pixel_layout layout_{pixel_layout::RGB8}; +}; + +struct image_new { + + using buffer_type = std::vector; + using size_type = pw::size; + + image_layout layout; + buffer_type buffer{}; + + static constexpr auto make(const image_new::size_type& size_, + image_layout::pixel_layout layout_) + -> image_new { + + return {.layout{.layout_ = layout_}, + .buffer{buffer_type{ + static_cast( + (image_layout::bits_per_channel(layout_) >> 3) * + size_.area() * image_layout::channels(layout_)), + buffer_type::value_type{0}}}}; + } }; } // namespace pw auto main() -> int { - auto val = pw::image_layout::bits_per_channel( - pw::image_layout::pixel_layout::RGB8); - - std::print("RGB8 = {}bits per channel\n", val); + std::print("RGB8 = {}bits per channel\n", + pw::image_layout::bits_per_channel( + pw::image_layout::pixel_layout::RGB8)); std::print("DEPTH = {}bits per channel\n", pw::image_layout::bits_per_channel( pw::image_layout::pixel_layout::DEPTH)); @@ -43,5 +81,16 @@ auto main() -> int { pw::image_layout::bits_per_channel( pw::image_layout::pixel_layout::LUM8)); + std::print( + "RGB8 = {}channels\n", + pw::image_layout::channels(pw::image_layout::pixel_layout::RGB8)); + std::print( + "DEPTH = {}channels\n", + pw::image_layout::channels(pw::image_layout::pixel_layout::DEPTH)); + std::print( + "LUM8 = {}channels\n", + pw::image_layout::channels(pw::image_layout::pixel_layout::LUM8)); // pw::image + + pw::image_new::make(pw::iamge, image_layout::pixel_layout layout_) }