clean up some old leftovers

This commit is contained in:
Hartmut Seichter 2025-05-21 22:30:57 +02:00
parent dcfdc8a81a
commit 9bc7491266
6 changed files with 94 additions and 86 deletions

View file

@ -40,8 +40,9 @@ template <typename Scalar, std::size_t N> struct aabb final {
constexpr auto dimension() const noexcept { return max - min; }
static constexpr auto make(
const std::vector<pw::vector<Scalar, N>>& vertices) -> aabb<Scalar, N> {
static constexpr auto
make(const std::vector<pw::vector<Scalar, N>>& vertices)
-> aabb<Scalar, N> {
return std::accumulate(
std::begin(vertices), std::end(vertices),
aabb{.min{vertices.front()}, .max{vertices.front()}},

View file

@ -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 <pw/core/globals.hpp>
#include <vector>
#include <functional>
#include <vector>
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<void(const char*)> Callback;
typedef std::vector<Callback> 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 <debug::level level>
//struct tpScopeLog {
// const char* info;
// explicit tpScopeLog(const char* i) : info(i) {
// debug::s(level) << info;
// }
// template <debug::level level>
// 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

View file

@ -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 <cmath>
#include <algorithm>
#include <cmath>
#include <concepts>
#include <numbers>
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 <typename T>
inline const T pi() { return static_cast<T>(__PW_PI); }
template <typename T>
inline const T one_over_pi() { return static_cast<T>(1 / __PW_PI); }
template <typename T>
inline T rad_to_deg(const T& angle_in_radian) {
return angle_in_radian * static_cast<T>(180) * one_over_pi<T>();
template <std::floating_point T> inline static constexpr T pi() {
return static_cast<T>(__PW_PI);
}
template <typename T>
inline T deg_to_rad(const T& angle_in_degree) {
return angle_in_degree * pi<T>() / static_cast<T>(180);
template <std::floating_point T> inline const T one_over_pi() {
return static_cast<T>(1 / __PW_PI);
}
template <typename T>
inline T repeat(const T& t, const T& length) {
return std::clamp(t - std::floor(t / length) * length, T(0), length);
template <std::floating_point T> inline T rad_to_deg(const T& angle_in_radian) {
return angle_in_radian * static_cast<T>(180) * one_over_pi<T>();
}
template <typename T>
inline T ping_pong(const T& t,const T& length) {
auto tn = repeat(t, length * T(2));
return length - std::abs(tn - length);
template <std::floating_point T> inline T deg_to_rad(const T& angle_in_degree) {
return angle_in_degree * pi<T>() / static_cast<T>(180);
}
template <typename T>
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 <typename T> 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 <typename T> inline T ping_pong(const T& t, const T& length) {
auto tn = repeat(t, length * T{2});
return length - std::abs(tn - length);
}
template <std::floating_point T> 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

View file

@ -23,7 +23,6 @@
#ifndef PW_CORE_MATRIX_HPP
#define PW_CORE_MATRIX_HPP
#include "vector.hpp"
#include <pw/core/globals.hpp>
#include <pw/core/math.hpp>
#include <pw/core/vector.hpp>

View file

@ -27,6 +27,7 @@
#include <pw/core/primitives.hpp>
#include <atomic>
#include <variant>
namespace pw {

View file

@ -2,17 +2,22 @@
#include <cstdint>
#include <map>
#include <print>
#include <pw/core/image.hpp>
#include <tuple>
#include <vector>
#include <pw/core/image.hpp>
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
}