CortidQCT  1.2.2.52
WeightedARAPFitter.h
Go to the documentation of this file.
1 
13 #pragma once
14 
15 #include "MeshHelpers.h"
16 
17 #include <Eigen/Core>
18 #include <Eigen/Sparse>
19 
20 namespace CortidQCT {
21 namespace Internal {
22 
23 #pragma clang diagnostic push
24 #pragma clang diagnostic ignored "-Wpadded"
25 
31 template <class T> class WeightedARAPFitter {
32 
33 public:
34  using Scalar = T;
35 
41  WeightedARAPFitter(Mesh<T> const &referenceMesh, T sigma);
42 
49  template <class DerivedV, class DerivedF>
50  inline WeightedARAPFitter(Eigen::MatrixBase<DerivedV> const &V,
51  Eigen::MatrixBase<DerivedF> const &F, T sigma)
52  : V0_(V), F_(F), sigmaSqInv_(static_cast<T>(1) / (sigma * sigma)) {
53  computeLaplacian();
54  }
55 
66  VertexMatrix<Scalar> fit(VertexMatrix<Scalar> const &Y,
67  VertexMatrix<Scalar> const &N,
68  Eigen::Matrix<Scalar, Eigen::Dynamic, 1> const &gamma);
69 
70 private:
71  using RotationMatrix = Eigen::Matrix<Scalar, 3, Eigen::Dynamic>;
72 
74  void computeLaplacian();
75 
78  void initRotationMatrix();
79 
82  void optimizePositions(
83  Eigen::Matrix<Scalar, Eigen::Dynamic, 1> const &d,
84  Eigen::ConjugateGradient<Eigen::SparseMatrix<Scalar>,
85  Eigen::Lower | Eigen::Upper> &solver,
86  Eigen::Matrix<Scalar, Eigen::Dynamic, 1> &cOut,
87  VertexMatrix<Scalar> &Vout) const;
88 
90  void optimizeRotations(VertexMatrix<Scalar> const &V);
91 
93  Scalar rigidityEnergy(VertexMatrix<Scalar> const &V) const;
94 
96  VertexMatrix<Scalar> V0_;
98  FacetMatrix F_;
100  Scalar sigmaSqInv_;
102  LaplacianMatrix<Scalar> L_;
104  RotationMatrix R_;
105 };
106 #pragma clang diagnostic pop
107 
108 extern template class WeightedARAPFitter<float>;
109 extern template class WeightedARAPFitter<double>;
110 
111 } // namespace Internal
112 } // namespace CortidQCT
Name namespace for CortidQCT library.
Definition: CortidQCT.h:23
A triangle mesh class.
Definition: BarycentricPoint.h:20
This class implements a weighted as-rigid-as-possible mesh fitting algorithm that uses a point-to-pla...
Definition: WeightedARAPFitter.h:31
WeightedARAPFitter(Eigen::MatrixBase< DerivedV > const &V, Eigen::MatrixBase< DerivedF > const &F, T sigma)
Constructs an object that can be used to fit the given reference mesh.
Definition: WeightedARAPFitter.h:50
WeightedARAPFitter(Mesh< T > const &referenceMesh, T sigma)
Constructs an object that can be used to fit the given reference mesh.
Definition: WeightedARAPFitter.cpp:82
VertexMatrix< Scalar > fit(VertexMatrix< Scalar > const &Y, VertexMatrix< Scalar > const &N, Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > const &gamma)
Fits the reference mesh to the given target vertices by minimizing the wiehgted point-to-plane distan...
Definition: WeightedARAPFitter.cpp:199
This header contains mesh related helper functions.