extract explicit mesh with topology information from implicit surfaces with boolean operations, and do surface/volume integrating on them.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
3.5 KiB

#pragma once
#include "data_type.hpp"
namespace internal
{
namespace model_matrix
{
enum class axis { x, y, z };
template <axis to_axis, bool flip, int dx, int dy, int dz>
struct helper {
static paired_model_matrix get()
{
paired_model_matrix res{};
Eigen::Vector3d src{1, 0, 0}, to{};
if constexpr (to_axis == axis::x)
to = {1, 0, 0};
else if constexpr (to_axis == axis::y)
to = {0, 1, 0};
else
to = {0, 0, 1};
if constexpr (flip) to = -to;
Eigen::Isometry3d local_to_world{};
auto rot = Eigen::Quaterniond::FromTwoVectors(src, to);
local_to_world.linear() = rot.toRotationMatrix();
local_to_world.translation() = Eigen::Vector3d{dx, dy, dz};
res.local_to_world = local_to_world;
res.world_to_local = local_to_world.inverse();
for (auto i = 0; i < res.local_to_world.matrix().size(); ++i) {
if (std::abs(res.local_to_world.data()[i]) < epsilon) res.local_to_world.data()[i] = 0;
if (std::abs(res.world_to_local.data()[i]) < epsilon) res.world_to_local.data()[i] = 0;
}
return res;
}
static paired_model_matrix matrices;
};
template <axis to_axis, bool flip, int dx, int dy, int dz>
paired_model_matrix helper<to_axis, flip, dx, dy, dz>::matrices = helper<to_axis, flip, dx, dy, dz>::get();
} // namespace model_matrix
template <model_matrix::axis to_axis = model_matrix::axis::x, bool flip = false, int dx = 0, int dy = 0, int dz = 0>
static const paired_model_matrix_ptr_t matrices_ptr =
make_pointer_wrapper(model_matrix::helper<to_axis, flip, dx, dy, dz>::matrices);
template <model_matrix::axis to_axis = model_matrix::axis::x, bool flip = false, uint32_t translation = 0>
static const paired_model_matrix_ptr_t trans_by_target_axis_matrices_ptr;
template <bool flip = false, uint32_t translation = 0>
static const paired_model_matrix_ptr_t
trans_by_target_axis_matrices_ptr<model_matrix::axis::x, flip, translation> = matrices_ptr < model_matrix::axis::x,
flip,
flip ? -static_cast<int>(translation)
: static_cast<int>(translation),
0, 0 > ;
template <bool flip = false, uint32_t translation = 0>
static const paired_model_matrix_ptr_t
trans_by_target_axis_matrices_ptr<model_matrix::axis::y, flip, translation> = matrices_ptr < model_matrix::axis::y,
flip, 0,
flip ? -static_cast<int>(translation)
: static_cast<int>(translation),
0 > ;
template <bool flip = false, uint32_t translation = 0>
static const paired_model_matrix_ptr_t
trans_by_target_axis_matrices_ptr<model_matrix::axis::z, flip, translation> = matrices_ptr < model_matrix::axis::z,
flip, 0, 0,
flip ? -static_cast<int>(translation)
: static_cast<int>(translation) > ;
static const auto identity_model_matrix_ptr = matrices_ptr<>;
} // namespace internal