|
16 | 16 |
|
17 | 17 | #pragma once |
18 | 18 | #include <ostream> |
19 | | -#include <glog/logging.h> |
20 | 19 | #include <Eigen/Dense> |
21 | 20 | #include <tf2/LinearMath/Quaternion.h> |
22 | 21 | #include <rclcpp/rclcpp.hpp> |
|
28 | 27 | #include "magic_enum/magic_enum.hpp" |
29 | 28 | #include <sensor_msgs/msg/point_cloud2.hpp> |
30 | 29 |
|
| 30 | + |
| 31 | +namespace orbbec_camera { |
| 32 | +inline void LogFatal(const char *file, int line, const std::string &message) { |
| 33 | + std::cerr << "Check failed at " << file << ":" << line << ": " << message << std::endl; |
| 34 | + std::abort(); |
| 35 | +} |
| 36 | +} // namespace orbbec_camera |
| 37 | + |
| 38 | +// Macros for checking conditions and comparing values |
| 39 | +#define CHECK(condition) \ |
| 40 | + (!(condition) ? LogFatal(__FILE__, __LINE__, "Check failed: " #condition) : (void)0) |
| 41 | + |
| 42 | +template <typename T1, typename T2> |
| 43 | +void CheckOp(const char *expr, const char *file, int line, T1 val1, T2 val2, bool result) { |
| 44 | + if (!result) { |
| 45 | + std::ostringstream os; |
| 46 | + os << "Check failed: " << expr << " (" << val1 << " vs. " << val2 << ")"; |
| 47 | + orbbec_camera::LogFatal(file, line, os.str()); |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +#define CHECK_OP(opname, op, val1, val2) \ |
| 52 | + CheckOp(#val1 " " #op " " #val2, __FILE__, __LINE__, val1, val2, (val1)op(val2)) |
| 53 | + |
| 54 | +#define CHECK_EQ(val1, val2) CHECK_OP(_EQ, ==, val1, val2) |
| 55 | +#define CHECK_NE(val1, val2) CHECK_OP(_NE, !=, val1, val2) |
| 56 | +#define CHECK_LE(val1, val2) CHECK_OP(_LE, <=, val1, val2) |
| 57 | +#define CHECK_LT(val1, val2) CHECK_OP(_LT, <, val1, val2) |
| 58 | +#define CHECK_GE(val1, val2) CHECK_OP(_GE, >=, val1, val2) |
| 59 | +#define CHECK_GT(val1, val2) CHECK_OP(_GT, >, val1, val2) |
| 60 | + |
| 61 | +// Overload for raw pointers |
| 62 | +template <typename T> |
| 63 | +T *CheckNotNull(T *ptr, const char *file, int line) { |
| 64 | + if (ptr == nullptr) { |
| 65 | + std::ostringstream os; |
| 66 | + os << "Null pointer passed to CheckNotNull at " << file << ":" << line; |
| 67 | + orbbec_camera::LogFatal(file, line, os.str()); |
| 68 | + } |
| 69 | + return ptr; |
| 70 | +} |
| 71 | + |
| 72 | +// Template for smart pointers like std::shared_ptr, std::unique_ptr |
| 73 | +template <typename T> |
| 74 | +T &CheckNotNull(T &ptr, const char *file, int line) { |
| 75 | + if (ptr == nullptr) { |
| 76 | + std::ostringstream os; |
| 77 | + os << "Null pointer passed to CheckNotNull at " << file << ":" << line; |
| 78 | + orbbec_camera::LogFatal(file, line, os.str()); |
| 79 | + } |
| 80 | + return ptr; |
| 81 | +} |
| 82 | + |
| 83 | +#if defined(CHECK_NOTNULL) |
| 84 | +#undef CHECK_NOTNULL |
| 85 | +#endif |
| 86 | +#define CHECK_NOTNULL(val) CheckNotNull(val, __FILE__, __LINE__) |
| 87 | + |
31 | 88 | namespace orbbec_camera { |
32 | 89 | sensor_msgs::msg::CameraInfo convertToCameraInfo(OBCameraIntrinsic intrinsic, |
33 | 90 | OBCameraDistortion distortion, int width); |
|
0 commit comments