Wildmeshing Toolkit
PositionMapAMIPS2D.cpp
Go to the documentation of this file.
1 #include "PositionMapAMIPS2D.hpp"
2 #include <wmtk/Types.hpp>
5 
6 namespace wmtk::function {
8  const TriMesh& mesh,
9  const MeshAttributeHandle<double>& vertex_uv_handle,
10  const image::Image& image)
11  : TriangleAMIPS(mesh, vertex_uv_handle)
12  , m_pos_evaluator(image)
13 {}
14 
16  const TriMesh& mesh,
17  const MeshAttributeHandle<double>& vertex_uv_handle,
18  const wmtk::image::SamplingAnalyticFunction::FunctionType type,
19  const double a,
20  const double b,
21  const double c)
22  : TriangleAMIPS(mesh, vertex_uv_handle)
23  , m_pos_evaluator(type, a, b, c)
24 {}
25 
26 
28 {
29  // get_autodiff_value sets the autodiff size if necessary
30  // get the uv coordinates of the triangle
31  ConstAccessor<double> pos = mesh().create_const_accessor(get_coordinate_attribute_handle());
32 
33  const Tuple& tuple = simplex;
34  auto tuple_value = pos.const_vector_attribute(tuple);
35 
36  Vector2<DScalar> uv0;
37  uv0 = utils::as_DScalar<DScalar>(tuple_value);
38 
39  constexpr static PrimitiveType PV = PrimitiveType::Vertex;
40  constexpr static PrimitiveType PE = PrimitiveType::Edge;
41 
42  Eigen::Vector2d uv2 = pos.const_vector_attribute(mesh().switch_tuples(tuple, {PE, PV}));
43  Eigen::Vector2d uv1 = pos.const_vector_attribute(mesh().switch_tuples(tuple, {PV, PE}));
44 
45  Vector3<DScalar> pos0 = m_pos_evaluator.uv_to_pos(uv0);
46  Eigen::Vector3d pos1 = m_pos_evaluator.uv_to_pos(uv1);
47  Eigen::Vector3d pos2 = m_pos_evaluator.uv_to_pos(uv2);
48 
49  return utils::amips(pos0, pos1, pos2);
50 }
51 
52 } // namespace wmtk::function
DScalar get_value_autodiff(const Tuple &simplex) const override
PositionMapAMIPS2D(const TriMesh &mesh, const MeshAttributeHandle< double > &vertex_uv_handle, const image::Image &image)
This is the implementation of the AMIPS energy function of a triangle mesh that can be embedded in 2d...
auto amips(const Eigen::MatrixBase< Derived > &B)
Definition: amips.hpp:20
Vector< T, 3 > Vector3
Definition: Types.hpp:24
constexpr PrimitiveType PV
Vector< double, 3 > Vector3d
Definition: Types.hpp:39
constexpr PrimitiveType PE
Vector< T, 2 > Vector2
Definition: Types.hpp:22
Automatic differentiation scalar with first- and second-order derivatives.
Definition: autodiff.h:501