Wildmeshing Toolkit
mesh_utils.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <wmtk/Mesh.hpp>
4 
5 #include <string>
6 
7 namespace wmtk::mesh_utils {
8 template <typename Mat>
10  const Mat& data,
11  const std::string& name,
12  const PrimitiveType& type,
13  Mesh& mesh)
14 {
16  mesh.template register_attribute<typename Mat::Scalar>(name, type, data.cols());
17 
18 
19  auto thandle = handle.as<typename Mat::Scalar>();
20 
21  auto accessor = mesh.create_accessor(thandle);
22  const auto tuples = mesh.get_all(type);
23  for (size_t i = 0; i < tuples.size(); ++i) {
24  const auto& t = tuples[i];
25  accessor.vector_attribute(t) = data.row(i).transpose();
26  }
27 
28  return handle;
29 }
30 
36 
41 
46 compute_vertex_normal(const TriMesh& m, const attribute::Accessor<double>& pos, const Tuple& v);
47 
48 } // namespace wmtk::mesh_utils
std::vector< Tuple > get_all(PrimitiveType type) const
Generate a vector of Tuples from global vertex/edge/triangle/tetrahedron index.
Definition: Mesh.cpp:18
attribute::Accessor< T, Mesh, D > create_accessor(const attribute::MeshAttributeHandle &handle)
A CachingAccessor that uses tuples for accessing attributes instead of indices.
Definition: Accessor.hpp:25
auto as() const -> const held_handle_type< held_type_from_primitive< T >()> &
Eigen::Vector3d compute_face_normal(const TriMesh &m, const attribute::Accessor< double > &pos, const Tuple &f)
compute the normalized face normal based on the vertex positions
Definition: mesh_utils.cpp:23
Eigen::Vector3d compute_face_normal_area_weighted(const TriMesh &m, const attribute::Accessor< double > &pos, const Tuple &f)
compute area vector of face
Definition: mesh_utils.cpp:7
Eigen::Vector3d compute_vertex_normal(const TriMesh &m, const attribute::Accessor< double > &pos, const Tuple &v)
compute the normalized vertex normal from the incident area weighted face normals
Definition: mesh_utils.cpp:29
attribute::MeshAttributeHandle set_matrix_attribute(const Mat &data, const std::string &name, const PrimitiveType &type, Mesh &mesh)
Definition: mesh_utils.hpp:9
Vector< double, 3 > Vector3d
Definition: Types.hpp:39