Wildmeshing Toolkit
Loading...
Searching...
No Matches
VertexTangentialLaplacianSmooth.cpp
Go to the documentation of this file.
2
3#include <wmtk/TriMesh.hpp>
6
7
8namespace wmtk::operations {
11 const double damping_factor)
12 : VertexLaplacianSmooth(handle)
13 , m_damping_factor(damping_factor)
14{}
15
17{
18 auto accessor = mesh.create_accessor<double>(m_attibute_handle);
19 const Eigen::Vector3d p = accessor.vector_attribute(simplex.tuple());
20
21 if (!VertexLaplacianSmooth::operator()(mesh, simplex)) return false;
22
23 const Tuple tup = simplex.tuple();
24
25
26 assert(mesh.is_valid(tup));
27 const Eigen::Vector3d g = accessor.vector_attribute(tup); // center of gravity
28
29 if (mesh.is_boundary(PrimitiveType::Vertex, tup)) {
30 //
31 Tuple t0 = tup;
32 while (!mesh.is_boundary(PrimitiveType::Edge, t0)) {
34 }
35 const Tuple v0 = mesh.switch_tuple(t0, PrimitiveType::Vertex);
36
38 while (!mesh.is_boundary(PrimitiveType::Edge, t1)) {
40 }
41 const Tuple v1 = mesh.switch_tuple(t1, PrimitiveType::Vertex);
42
43 const Eigen::Vector3d p0 = accessor.vector_attribute(v0);
44 const Eigen::Vector3d p1 = accessor.vector_attribute(v1);
45
46 const Eigen::Vector3d tang = (p1 - p0).normalized();
47 if (tang.squaredNorm() < 1e-10) {
48 return false;
49 }
50
51 accessor.vector_attribute(tup) = p + m_damping_factor * tang * tang.transpose() * (g - p);
52
53 } else {
54 const Eigen::Vector3d n =
55 mesh_utils::compute_vertex_normal(static_cast<TriMesh&>(mesh), accessor, tup);
56
57 if (n.squaredNorm() < 1e-10) {
58 return false;
59 }
60
61 // following Botsch&Kobbelt - Remeshing for Multiresolution Modeling
62 accessor.vector_attribute(tup) =
63 p + m_damping_factor * (Eigen::Matrix3d::Identity() - n * n.transpose()) * (g - p);
64 }
65
66 return true;
67}
68
69
70} // namespace wmtk::operations
bool is_boundary(const simplex::Simplex &tuple) const
check if a simplex lies on a boundary or not
Definition Mesh.cpp:107
attribute::Accessor< T, Mesh, D > create_accessor(const attribute::MeshAttributeHandle &handle)
Tuple switch_tuples(const Tuple &tuple, const ContainerType &op_sequence) const
Definition Mesh.hpp:953
virtual bool is_valid(const Tuple &tuple) const
check validity of tuple including its hash
Definition Mesh.cpp:113
virtual Tuple switch_tuple(const Tuple &tuple, PrimitiveType type) const =0
switch the orientation of the Tuple of the given dimension
The Tuple is the basic navigation tool in our mesh data structure.
Definition Tuple.hpp:19
attribute::MeshAttributeHandle m_attibute_handle
VertexTangentialLaplacianSmooth(attribute::MeshAttributeHandle &handle, double damping_factor=DEFAULT_DAMPING_FACTOR)
bool operator()(Mesh &m, const simplex::Simplex &s) override
const Tuple & tuple() const
Definition Simplex.hpp:53
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