6 #include <SimpleBVH/BVH.hpp>
11 std::shared_ptr<Operation> main_op,
14 :
ProjectOperation(main_op, {std::make_pair(project_to_mesh, child_mesh_coordinates)})
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) {
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;
59 pair.first.
mesh().create_const_accessor(pair.first.as<
Rational>());
62 for (
const auto& f : facest) {
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;
80 auto bvh = std::make_shared<SimpleBVH::BVH>();
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) {
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;
std::vector< Tuple > get_all(PrimitiveType type) const
Generate a vector of Tuples from global vertex/edge/triangle/tetrahedron index.
std::vector< Tuple > map_tuples(const Mesh &other_mesh, const simplex::Simplex &my_simplex) const
maps a simplex from this mesh to any other mesh
A CachingAccessor that uses tuples for accessing attributes instead of indices.
MapResult< D > vector_attribute(const ArgType &t)
ConstMapResult< D > const_vector_attribute(const ArgType &t) const
const Mesh & mesh() const
ProjectOperation(std::shared_ptr< Operation > main_op, const attribute::MeshAttributeHandle &project_to_mesh, attribute::MeshAttributeHandle &child_mesh_coordinates)
std::vector< BVHConstrainPair > m_bvh
PrimitiveType primitive_type() const override
const std::shared_ptr< wmtk::operations::Operation > m_main_op
std::vector< simplex::Simplex > execute(const simplex::Simplex &simplex) override
returns an empty vector in case of failure
std::vector< Tuple > vertices(const Mesh &m, const Simplex &simplex)
std::vector< Tuple > faces_single_dimension_tuples(const Mesh &mesh, const Simplex &simplex, const PrimitiveType face_type)
SimplexCollection faces(const Mesh &mesh, const Simplex &simplex, const bool sort_and_clean)
Returns all faces of a simplex.
Vector< double, 3 > Vector3d