clean up some old leftovers
This commit is contained in:
parent
dcfdc8a81a
commit
9bc7491266
6 changed files with 94 additions and 86 deletions
|
@ -40,8 +40,9 @@ template <typename Scalar, std::size_t N> struct aabb final {
|
||||||
|
|
||||||
constexpr auto dimension() const noexcept { return max - min; }
|
constexpr auto dimension() const noexcept { return max - min; }
|
||||||
|
|
||||||
static constexpr auto make(
|
static constexpr auto
|
||||||
const std::vector<pw::vector<Scalar, N>>& vertices) -> aabb<Scalar, N> {
|
make(const std::vector<pw::vector<Scalar, N>>& vertices)
|
||||||
|
-> aabb<Scalar, N> {
|
||||||
return std::accumulate(
|
return std::accumulate(
|
||||||
std::begin(vertices), std::end(vertices),
|
std::begin(vertices), std::end(vertices),
|
||||||
aabb{.min{vertices.front()}, .max{vertices.front()}},
|
aabb{.min{vertices.front()}, .max{vertices.front()}},
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
@ -26,72 +26,67 @@
|
||||||
|
|
||||||
#include <pw/core/globals.hpp>
|
#include <pw/core/globals.hpp>
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief multipurpose logger used internally
|
* @brief multipurpose logger used internally
|
||||||
*/
|
*/
|
||||||
class debug {
|
class debug {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
enum level {
|
enum level {
|
||||||
none, //!< nothing will be logged, even no errors
|
none, //!< nothing will be logged, even no errors
|
||||||
error, //!< only errors will be logged
|
error, //!< only errors will be logged
|
||||||
warning, //!< log warnings (non-critical errors)
|
warning, //!< log warnings (non-critical errors)
|
||||||
message, //!< log messages (something to note but not an error)
|
message, //!< log messages (something to note but not an error)
|
||||||
notification, //!< log some more information
|
notification, //!< log some more information
|
||||||
info, //!< log verbose information
|
info, //!< log verbose information
|
||||||
all = 0xFF //!< log absolutely everything
|
all = 0xFF //!< log absolutely everything
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief the streaming interface for the logger
|
* @brief the streaming interface for the logger
|
||||||
*/
|
*/
|
||||||
class stream {
|
class stream {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
stream(debug* log = nullptr);
|
stream(debug* log = nullptr);
|
||||||
~stream();
|
~stream();
|
||||||
stream(const stream& other);
|
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 float& value); ///! log a float value
|
||||||
stream& operator << (const char *value);
|
stream& operator<<(const double& value); ///! log a double 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 int& value); ///! log a int value
|
||||||
stream& operator << (const double &value); ///! log a double value
|
stream& operator<<(const unsigned int& value); ///! log a int value
|
||||||
|
|
||||||
stream& operator << (const int &value); ///! log a int value
|
stream& operator<<(const long& value); ///! log a long value
|
||||||
stream& operator << (const unsigned int &value); ///! log a int value
|
stream& operator<<(const unsigned long& value); ///! log a int value
|
||||||
|
|
||||||
stream& operator << (const long &value); ///! log a long value
|
stream& operator<<(const void* value); ///! pointer
|
||||||
stream& operator << (const unsigned long &value); ///! log a int value
|
|
||||||
|
|
||||||
stream& operator << (const void *value); ///! pointer
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
|
protected:
|
||||||
debug* _log;
|
debug* _log;
|
||||||
std::string _line;
|
std::string _line;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** sets the logging level */
|
/** sets the logging level */
|
||||||
void set_level(level level) {_level = level;}
|
void set_level(level level) { _level = level; }
|
||||||
|
|
||||||
/** gets the logging level */
|
/** gets the logging level */
|
||||||
level level() const { return _level; }
|
level level() const { return _level; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief get the stream interface of the logger
|
* @brief get the stream interface of the logger
|
||||||
* @return return a temporary object that will write and flush the logger
|
* @return return a temporary object that will write and flush the logger
|
||||||
*/
|
*/
|
||||||
static stream s(enum level level = info);
|
static stream s(enum level level = info);
|
||||||
|
|
||||||
inline static stream d() { return s(debug::info); }
|
inline static stream d() { return s(debug::info); }
|
||||||
|
@ -108,15 +103,14 @@ public:
|
||||||
* @brief write a message to the log
|
* @brief write a message to the log
|
||||||
* @param message string
|
* @param message string
|
||||||
*/
|
*/
|
||||||
void write(const std::string &message);
|
void write(const std::string& message);
|
||||||
|
|
||||||
typedef std::function<void(const char*)> Callback;
|
typedef std::function<void(const char*)> Callback;
|
||||||
typedef std::vector<Callback> CallbackList;
|
typedef std::vector<Callback> CallbackList;
|
||||||
|
|
||||||
~debug();
|
~debug();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
debug();
|
debug();
|
||||||
|
|
||||||
CallbackList _callbacks;
|
CallbackList _callbacks;
|
||||||
|
@ -126,7 +120,7 @@ protected:
|
||||||
///**
|
///**
|
||||||
// * @brief helper for changing the log level in a scope
|
// * @brief helper for changing the log level in a scope
|
||||||
// */
|
// */
|
||||||
//struct ScopeLogLevel
|
// struct ScopeLogLevel
|
||||||
//{
|
//{
|
||||||
// debug::level levelOutside;
|
// debug::level levelOutside;
|
||||||
// explicit ScopeLogLevel(debug::level level)
|
// explicit ScopeLogLevel(debug::level level)
|
||||||
|
@ -140,12 +134,12 @@ protected:
|
||||||
// }
|
// }
|
||||||
//};
|
//};
|
||||||
|
|
||||||
//template <debug::level level>
|
// template <debug::level level>
|
||||||
//struct tpScopeLog {
|
// struct tpScopeLog {
|
||||||
// const char* info;
|
// const char* info;
|
||||||
// explicit tpScopeLog(const char* i) : info(i) {
|
// explicit tpScopeLog(const char* i) : info(i) {
|
||||||
// debug::s(level) << info;
|
// debug::s(level) << info;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// ~tpScopeLog() {
|
// ~tpScopeLog() {
|
||||||
// debug::s(level) << info;
|
// debug::s(level) << info;
|
||||||
|
@ -154,9 +148,8 @@ protected:
|
||||||
|
|
||||||
// some macros
|
// some macros
|
||||||
|
|
||||||
//#define LOG_INFO() Log::s()
|
// #define LOG_INFO() Log::s()
|
||||||
//#define LOG_FUNC() LOG_INFO() << __FUNCTION__ << " " << __LINE__ << " "
|
// #define LOG_FUNC() LOG_INFO() << __FUNCTION__ << " " << __LINE__ << " "
|
||||||
}
|
} // namespace pw
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
@ -23,54 +23,60 @@
|
||||||
#ifndef PW_CORE_MATH_HPP
|
#ifndef PW_CORE_MATH_HPP
|
||||||
#define PW_CORE_MATH_HPP
|
#define PW_CORE_MATH_HPP
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cmath>
|
||||||
|
#include <concepts>
|
||||||
#include <numbers>
|
#include <numbers>
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
constexpr double __PW_PI = 3.1415926535897932384626433832795028841971693993751058209;
|
static constexpr double __PW_PI{
|
||||||
constexpr double __PW_PI_DOUBLE = 2.0 * __PW_PI;
|
3.1415926535897932384626433832795028841971693993751058209};
|
||||||
|
static constexpr double __PW_PI_DOUBLE{2 * __PW_PI};
|
||||||
|
|
||||||
template <typename T>
|
template <std::floating_point T> inline static constexpr T pi() {
|
||||||
inline const T pi() { return static_cast<T>(__PW_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 <typename T>
|
template <std::floating_point T> inline const T one_over_pi() {
|
||||||
inline T deg_to_rad(const T& angle_in_degree) {
|
return static_cast<T>(1 / __PW_PI);
|
||||||
return angle_in_degree * pi<T>() / static_cast<T>(180);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <std::floating_point T> inline T rad_to_deg(const T& angle_in_radian) {
|
||||||
inline T repeat(const T& t, const T& length) {
|
return angle_in_radian * static_cast<T>(180) * one_over_pi<T>();
|
||||||
return std::clamp(t - std::floor(t / length) * length, T(0), length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <std::floating_point T> inline T deg_to_rad(const T& angle_in_degree) {
|
||||||
inline T ping_pong(const T& t,const T& length) {
|
return angle_in_degree * pi<T>() / static_cast<T>(180);
|
||||||
auto tn = repeat(t, length * T(2));
|
|
||||||
return length - std::abs(tn - length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T> inline T repeat(const T& t, const T& length) {
|
||||||
inline T wrap_angle(const T& angle_in_radian) {
|
return std::clamp(t - std::floor(t / length) * length, T{}, length);
|
||||||
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)
|
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++){
|
// for (auto iter = 0; iter < maxIter; iter++){
|
||||||
// auto R = q.matrix();
|
// 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
|
#endif
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
#ifndef PW_CORE_MATRIX_HPP
|
#ifndef PW_CORE_MATRIX_HPP
|
||||||
#define PW_CORE_MATRIX_HPP
|
#define PW_CORE_MATRIX_HPP
|
||||||
|
|
||||||
#include "vector.hpp"
|
|
||||||
#include <pw/core/globals.hpp>
|
#include <pw/core/globals.hpp>
|
||||||
#include <pw/core/math.hpp>
|
#include <pw/core/math.hpp>
|
||||||
#include <pw/core/vector.hpp>
|
#include <pw/core/vector.hpp>
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include <pw/core/primitives.hpp>
|
#include <pw/core/primitives.hpp>
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <variant>
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
|
|
|
@ -2,17 +2,22 @@
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <print>
|
#include <print>
|
||||||
#include <pw/core/image.hpp>
|
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <pw/core/image.hpp>
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
struct image_layout {
|
struct image_layout {
|
||||||
|
|
||||||
enum pixel_layout { RGB8, RGBA8, LUM8, DEPTH };
|
enum pixel_layout { RGB8, RGBA8, LUM8, DEPTH };
|
||||||
|
|
||||||
static constexpr auto bits_per_channel(pixel_layout layout) {
|
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::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)};
|
std::make_tuple(DEPTH, sizeof(float) << 3)};
|
||||||
|
|
||||||
const auto iter = std::find_if(
|
const auto iter = std::find_if(
|
||||||
|
@ -34,6 +39,9 @@ auto main() -> int {
|
||||||
std::print("DEPTH = {}bits per channel\n",
|
std::print("DEPTH = {}bits per channel\n",
|
||||||
pw::image_layout::bits_per_channel(
|
pw::image_layout::bits_per_channel(
|
||||||
pw::image_layout::pixel_layout::DEPTH));
|
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
|
// pw::image
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue