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 }