19 std::shared_ptr<Operation> main_op,
20 const std::vector<MeshConstrainPair>& mesh_constaint_pairs)
24 for (
auto& pair : mesh_constaint_pairs) {
28 const std::vector<Tuple>& facest =
29 pair.first.
mesh().
get_all(pair.first.mesh().top_simplex_type());
31 const int64_t dim = int64_t(pair.first.mesh().top_simplex_type()) + 1;
33 Eigen::MatrixXd vertices(dim * facest.size(), pair.first.dimension());
34 Eigen::MatrixXi faces(facest.size(), dim);
37 if (pair.first.holds<
double>()) {
39 pair.first.
mesh().create_const_accessor(pair.first.as<
double>());
41 for (
const auto& f : facest) {
42 auto tmp = faces_single_dimension_tuples(
44 simplex::Simplex(pair.first.mesh(), pair.first.mesh().top_simplex_type(), f),
47 assert(tmp.size() == dim);
48 for (int64_t j = 0; j < tmp.size(); ++j) {
50 faces(index, j) = count;
51 vertices.row(dim * index + j) = p;
59 pair.first.
mesh().create_const_accessor(pair.first.as<
Rational>());
62 for (
const auto& f : facest) {
63 auto tmp = faces_single_dimension_tuples(
65 simplex::Simplex(pair.first.mesh(), pair.first.mesh().top_simplex_type(), f),
68 assert(tmp.size() == dim);
69 for (int64_t j = 0; j < tmp.size(); ++j) {
71 faces(index, j) = count;
72 vertices.row(dim * index + j) = p;
80 auto bvh = std::make_shared<SimpleBVH::BVH>();
81 bvh->init(vertices, faces, 1e-10);
83 m_bvh.emplace_back(pair.second, bvh);
91 const auto main_simplices = (*m_main_op)(simplex);
92 if (main_simplices.empty())
return {};
93 assert(main_simplices.size() == 1);
94 const auto main_tup = main_simplices.front().tuple();
97 for (
auto& pair :
m_bvh) {
98 const std::vector<Tuple> mapped_tuples_after =
101 if (mapped_tuples_after.empty())
continue;
103 if (pair.first.holds<
double>()) {
105 pair.first.
mesh().create_accessor(pair.first.as<
double>());
107 for (
const auto& t : mapped_tuples_after) {
109 SimpleBVH::VectorMax3d nearest_point;
111 pair.second->nearest_facet(p, nearest_point, sq_dist);
115 assert((pair.first.holds<
Rational>()));
117 pair.first.
mesh().create_accessor(pair.first.as<
Rational>());
119 for (
const auto& t : mapped_tuples_after) {
122 if (p_map.rows() == 3) {
123 const Eigen::Vector3d p = p_map.cast<
double>();
124 SimpleBVH::VectorMax3d nearest_point;
126 pair.second->nearest_facet(p, nearest_point, sq_dist);
127 for (int64_t d = 0; d < pair.first.dimension(); ++d) {
128 p_map(d) =
Rational(nearest_point[d],
true);
130 }
else if (p_map.rows() == 2) {
131 const Eigen::Vector2d p = p_map.cast<
double>();
132 SimpleBVH::VectorMax3d nearest_point;
134 pair.second->nearest_facet(p, nearest_point, sq_dist);
135 for (int64_t d = 0; d < pair.first.dimension(); ++d) {
136 p_map(d) =
Rational(nearest_point[d],
true);
139 throw std::runtime_error(
"wrong vector dimension");
145 return main_simplices;