Browse Source

fix some bugs

V2-integral
Zhicheng Wang 1 week ago
parent
commit
0af4c4e8a2
  1. 14
      primitive_process/interface/data/data_type.hpp
  2. 12
      primitive_process/interface/subface/simple/cylinder_face.hpp
  3. 10
      primitive_process/interface/subface/simple/plane.hpp
  4. 10
      primitive_process/interface/subface/simple/sphere_face.hpp
  5. 7
      primitive_process/src/data/data_center.cpp
  6. 2
      primitive_process/src/primitive/simple/sphere.cpp
  7. 2
      shared_module/utils/hash_ext.hpp
  8. 5
      shared_module/utils/marked_ptr.hpp
  9. 2
      shared_module/utils/pointer_wrapper.hpp

14
primitive_process/interface/data/data_type.hpp

@ -100,6 +100,20 @@ struct default_elem_ctor<internal::paired_model_matrix, internal::paired_model_m
internal::paired_model_matrix operator()(const internal::paired_model_matrix& k) const { return k; }
};
struct subface;
template <typename T>
struct default_elem_ctor<internal::paired_model_matrix_ptr_t, T> {
T operator()(const internal::paired_model_matrix& k) const
{
// TODO: this will cause error, try to handle it
// static_assert(std::is_base_of<subface, T>{});
T res{};
res.model_matrices = make_pointer_wrapper(k);
return res;
}
};
// template <>
// struct default_elem_ctor<internal::transform_block*, internal::inverted_transform_block> {
// internal::inverted_transform_block operator()(const internal::transform_block* k) const

12
primitive_process/interface/subface/simple/cylinder_face.hpp

@ -36,21 +36,11 @@ struct tagged_hasher<internal::paired_model_matrix_ptr_t, cylinder_surface_tag>
auto R = block.world_to_local.linear().topLeftCorner<2, 3>(); // 2x3
auto b = block.local_to_world.translation(); // 3x1
Eigen::Matrix<double, 3, 4> hash_mat = Eigen::Matrix3d::Zero();
Eigen::Matrix<double, 3, 4> hash_mat = Eigen::Matrix<double, 3, 4>::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::paired_model_matrix_ptr_t, internal::cylinder_face_t> {
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

10
primitive_process/interface/subface/simple/plane.hpp

@ -43,14 +43,4 @@ struct tagged_hasher<internal::paired_model_matrix_ptr_t, plane_surface_tag> {
return hash_funcs(normal);
}
};
template <>
struct default_elem_ctor<internal::paired_model_matrix_ptr_t, internal::plane_t> {
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

10
primitive_process/interface/subface/simple/sphere_face.hpp

@ -30,14 +30,4 @@ namespace detail
struct sphere_surface_tag
{
};
template <>
struct default_elem_ctor<internal::paired_model_matrix_ptr_t, internal::sphere_face_t> {
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

7
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>& 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<plane_container_t>(this->surfaces[static_cast<uint8_t>(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<sphere_container_t>(this->surfaces[static_cast<uint8_t>(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<cylinder_container_t>(this->surfaces[static_cast<uint8_t>(type)]).release(model_matrices);
release_transform_block(model_matrices);
break;

2
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<subface>(sphere_face));
}

2
shared_module/utils/hash_ext.hpp

@ -44,7 +44,7 @@ struct hash_funcs_fn
else if constexpr (std::is_floating_point_v<T>)
{
using integral_type = typename detail::float_to_int_type<T>::type;
Eigen::Matrix<integral_type, N, N + 1> int_mat = (trans.matrix().array() / static_cast<T>(detail::float_hash_epsilon)).template cast<integral_type>();
Eigen::Matrix<integral_type, N, N + 1> int_mat = (trans.affine().array() / static_cast<T>(detail::float_hash_epsilon)).template cast<integral_type>();
return XXH3_64bits(int_mat.data(), sizeof(integral_type) * N * (N + 1));
}
else

5
shared_module/utils/marked_ptr.hpp

@ -5,6 +5,7 @@
template <typename T, size_t bits_to_store>
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(); }

2
shared_module/utils/pointer_wrapper.hpp

@ -38,5 +38,5 @@ auto make_pointer_wrapper(T* p) noexcept -> pointer_wrapper<T>
template <typename T>
auto make_pointer_wrapper(T& x) noexcept -> pointer_wrapper<T>
{
return pointer_wrapper<T>(x);
return pointer_wrapper<T>(&x);
}
Loading…
Cancel
Save