From 0af4c4e8a27b02a9a98daca4ea84bb1b96364a0f Mon Sep 17 00:00:00 2001 From: Zhicheng Wang <1627343141@qq.com> Date: Tue, 7 Oct 2025 00:13:04 +0800 Subject: [PATCH] fix some bugs --- primitive_process/interface/data/data_type.hpp | 14 ++++++++++++++ .../interface/subface/simple/cylinder_face.hpp | 12 +----------- .../interface/subface/simple/plane.hpp | 10 ---------- .../interface/subface/simple/sphere_face.hpp | 10 ---------- primitive_process/src/data/data_center.cpp | 7 ++++--- primitive_process/src/primitive/simple/sphere.cpp | 2 +- shared_module/utils/hash_ext.hpp | 2 +- shared_module/utils/marked_ptr.hpp | 5 +++-- shared_module/utils/pointer_wrapper.hpp | 2 +- 9 files changed, 25 insertions(+), 39 deletions(-) diff --git a/primitive_process/interface/data/data_type.hpp b/primitive_process/interface/data/data_type.hpp index c30099e..d379d76 100644 --- a/primitive_process/interface/data/data_type.hpp +++ b/primitive_process/interface/data/data_type.hpp @@ -100,6 +100,20 @@ struct default_elem_ctor +struct default_elem_ctor { + T operator()(const internal::paired_model_matrix& k) const + { + // TODO: this will cause error, try to handle it + // static_assert(std::is_base_of{}); + T res{}; + res.model_matrices = make_pointer_wrapper(k); + return res; + } +}; + // template <> // struct default_elem_ctor { // internal::inverted_transform_block operator()(const internal::transform_block* k) const diff --git a/primitive_process/interface/subface/simple/cylinder_face.hpp b/primitive_process/interface/subface/simple/cylinder_face.hpp index 675572d..b5969a5 100644 --- a/primitive_process/interface/subface/simple/cylinder_face.hpp +++ b/primitive_process/interface/subface/simple/cylinder_face.hpp @@ -36,21 +36,11 @@ struct tagged_hasher auto R = block.world_to_local.linear().topLeftCorner<2, 3>(); // 2x3 auto b = block.local_to_world.translation(); // 3x1 - Eigen::Matrix hash_mat = Eigen::Matrix3d::Zero(); + Eigen::Matrix hash_mat = Eigen::Matrix::Zero(); hash_mat.topLeftCorner<3, 3>() = R.transpose() * R; hash_mat.topRightCorner<2, 1>() = R * b; return hash_funcs(hash_mat); } }; - -template <> -struct default_elem_ctor { - internal::cylinder_face_t operator()(internal::paired_model_matrix& k) const - { - internal::cylinder_face_t res{}; - res.model_matrices = make_pointer_wrapper(k); - return res; - } -}; } // namespace detail \ No newline at end of file diff --git a/primitive_process/interface/subface/simple/plane.hpp b/primitive_process/interface/subface/simple/plane.hpp index 84e0d36..ef839c5 100644 --- a/primitive_process/interface/subface/simple/plane.hpp +++ b/primitive_process/interface/subface/simple/plane.hpp @@ -43,14 +43,4 @@ struct tagged_hasher { return hash_funcs(normal); } }; - -template <> -struct default_elem_ctor { - internal::plane_t operator()(internal::paired_model_matrix_ptr_t &k) const - { - internal::plane_t res{}; - res.model_matrices = make_pointer_wrapper(k); - return res; - } -}; } // namespace detail \ No newline at end of file diff --git a/primitive_process/interface/subface/simple/sphere_face.hpp b/primitive_process/interface/subface/simple/sphere_face.hpp index 410a80f..23680e0 100644 --- a/primitive_process/interface/subface/simple/sphere_face.hpp +++ b/primitive_process/interface/subface/simple/sphere_face.hpp @@ -30,14 +30,4 @@ namespace detail struct sphere_surface_tag { }; - -template <> -struct default_elem_ctor { - internal::sphere_face_t operator()(internal::paired_model_matrix& k) const - { - internal::sphere_face_t res{}; - res.model_matrices = make_pointer_wrapper(k); - return res; - } -}; } // namespace detail \ No newline at end of file diff --git a/primitive_process/src/data/data_center.cpp b/primitive_process/src/data/data_center.cpp index a125d26..cfc2ff7 100644 --- a/primitive_process/src/data/data_center.cpp +++ b/primitive_process/src/data/data_center.cpp @@ -67,24 +67,25 @@ void primitive_data_center_t::release_transform_block(const internal::paired_mod void primitive_data_center_t::release_surface(surface_type type, const marked_subface_ptr_t& subface) { + auto subface_ptr = subface.get_ptr(); switch (type) { case surface_type::plane: { - auto model_matrices = subface->model_matrices; + auto model_matrices = subface_ptr->model_matrices; std::get(this->surfaces[static_cast(type)]).release(model_matrices); release_transform_block(model_matrices); break; } case surface_type::sphere: { - auto model_matrices = subface->model_matrices; + auto model_matrices = subface_ptr->model_matrices; std::get(this->surfaces[static_cast(type)]).release(model_matrices); release_transform_block(model_matrices); break; } case surface_type::cylinder: { - auto model_matrices = subface->model_matrices; + auto model_matrices = subface_ptr->model_matrices; std::get(this->surfaces[static_cast(type)]).release(model_matrices); release_transform_block(model_matrices); break; diff --git a/primitive_process/src/primitive/simple/sphere.cpp b/primitive_process/src/primitive/simple/sphere.cpp index 0c5f4a5..9e5ea0e 100644 --- a/primitive_process/src/primitive/simple/sphere.cpp +++ b/primitive_process/src/primitive/simple/sphere.cpp @@ -9,7 +9,7 @@ void sphere_t::initialize(primitive_data_center_t &data_center) void sphere_t::destroy() { - primitive_data_center_t& data_center = sphere_face->data_center; + primitive_data_center_t& data_center = sphere_face.get_ptr()->data_center; data_center.release_surface(surface_type::sphere, static_pointer_cast(sphere_face)); } diff --git a/shared_module/utils/hash_ext.hpp b/shared_module/utils/hash_ext.hpp index 2f12b65..b5a07ff 100644 --- a/shared_module/utils/hash_ext.hpp +++ b/shared_module/utils/hash_ext.hpp @@ -44,7 +44,7 @@ struct hash_funcs_fn else if constexpr (std::is_floating_point_v) { using integral_type = typename detail::float_to_int_type::type; - Eigen::Matrix int_mat = (trans.matrix().array() / static_cast(detail::float_hash_epsilon)).template cast(); + Eigen::Matrix int_mat = (trans.affine().array() / static_cast(detail::float_hash_epsilon)).template cast(); return XXH3_64bits(int_mat.data(), sizeof(integral_type) * N * (N + 1)); } else diff --git a/shared_module/utils/marked_ptr.hpp b/shared_module/utils/marked_ptr.hpp index 9cce99a..9981a17 100644 --- a/shared_module/utils/marked_ptr.hpp +++ b/shared_module/utils/marked_ptr.hpp @@ -5,6 +5,7 @@ template struct marked_ptr { static constexpr size_t mask = (1 << bits_to_store) - 1; + // static_assert(alignof(T) >= (1 << bits_to_store)); marked_ptr(T* ptr = nullptr) : ptr(ptr) {} @@ -15,9 +16,9 @@ struct marked_ptr { size_t get_mark() const { return (size_t)ptr & mask; } - void set_ptr(T* ptr) { this->ptr = (T*)((size_t)ptr | is_marked()); } + void set_ptr(T* ptr) { this->ptr = (T*)((size_t)ptr | get_mark()); } - void set_mark(size_t mark) { ptr = (T*)((size_t)ptr | (mark & mask)); } + void set_mark(size_t mark) { ptr = (T*)(((size_t)ptr & ~mask) | (mark & mask)); } operator T*() const { return get_ptr(); } diff --git a/shared_module/utils/pointer_wrapper.hpp b/shared_module/utils/pointer_wrapper.hpp index c82035c..e92c46e 100644 --- a/shared_module/utils/pointer_wrapper.hpp +++ b/shared_module/utils/pointer_wrapper.hpp @@ -38,5 +38,5 @@ auto make_pointer_wrapper(T* p) noexcept -> pointer_wrapper template auto make_pointer_wrapper(T& x) noexcept -> pointer_wrapper { - return pointer_wrapper(x); + return pointer_wrapper(&x); } \ No newline at end of file