Blender V4.3
slim.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2016 Michael Rabinovich
2 * 2023 Blender Authors
3 *
4 * SPDX-License-Identifier: MPL-2.0 */
5
10#pragma once
11
12#include <Eigen/Dense>
13#include <Eigen/Sparse>
14
15#include <stdexcept>
16
17namespace slim {
18
19class SlimFailedException : public std::runtime_error {
20 public:
21 SlimFailedException() : std::runtime_error("Slim operation failed") {}
22};
23
24/* Compute a SLIM map as derived in "Scalable Locally Injective Maps" [Rabinovich et al. 2016].. */
25struct SLIMData {
26 bool valid = true;
27
28 /* Input. */
29 Eigen::MatrixXd V; /* #V by 3 list of mesh vertex positions. */
30 Eigen::MatrixXi F; /* #F by 3/3 list of mesh faces (triangles). */
40
41 /* Optional Input. */
42 /* Soft constraints. */
43 Eigen::VectorXi b;
44 Eigen::MatrixXd bc;
46
47 double exp_factor; /* Used for exponential energies, ignored otherwise. */
48 bool mesh_improvement_3d; /* Only supported for 3d. */
49
51 bool skipInitialization = false;
54
55 /* Output. */
56 Eigen::MatrixXd V_o; /* #V by dim list of mesh vertex positions (dim = 2 for parametrization, 3
57 otherwise). */
58 Eigen::MatrixXd
59 oldUVs; /* #V by dim list of mesh vertex positions (dim = 2 for parametrization,. */
60 /* 3 otherwise). */
61
62 /* Weight-map for weighted parameterization. */
64 Eigen::VectorXf weightmap;
65 Eigen::VectorXf weightPerFaceMap;
68
69 double energy; /* Objective value. */
70
71 /* Internal. */
72 Eigen::VectorXd M;
73 double mesh_area;
75 int v_num;
76 int f_num;
77 double proximal_p;
78
79 Eigen::VectorXd WGL_M;
80 Eigen::VectorXd rhs;
81 Eigen::MatrixXd Ri, Ji;
82 Eigen::VectorXd W_11;
83 Eigen::VectorXd W_12;
84 Eigen::VectorXd W_13;
85 Eigen::VectorXd W_21;
86 Eigen::VectorXd W_22;
87 Eigen::VectorXd W_23;
88 Eigen::VectorXd W_31;
89 Eigen::VectorXd W_32;
90 Eigen::VectorXd W_33;
91 Eigen::SparseMatrix<double> Dx, Dy, Dz;
92 int f_n, v_n;
94 bool has_pre_calc = false;
95 int dim;
96};
97
98/* Compute necessary information to start using SLIM
99 * Inputs:
100 * V #V by 3 list of mesh vertex positions
101 * F #F by 3/3 list of mesh faces (triangles)
102 * b list of boundary indices into V
103 * bc #b by dim list of boundary conditions
104 * soft_p Soft penalty factor (can be zero)
105 * slim_energy Energy to minimize
106 */
107void slim_precompute(Eigen::MatrixXd &V,
108 Eigen::MatrixXi &F,
109 Eigen::MatrixXd &V_init,
110 SLIMData &data,
111 SLIMData::SLIM_ENERGY slim_energy,
112 Eigen::VectorXi &b,
113 Eigen::MatrixXd &bc,
114 double soft_p);
115
116/* Run iter_num iterations of SLIM
117 * Outputs:
118 * V_o (in SLIMData): #V by dim list of mesh vertex positions
119 */
120Eigen::MatrixXd slim_solve(SLIMData &data, int iter_num);
121
122} // namespace slim
local_group_size(16, 16) .push_constant(Type b
void slim_precompute(Eigen::MatrixXd &V, Eigen::MatrixXi &F, Eigen::MatrixXd &V_init, SLIMData &data, SLIMData::SLIM_ENERGY slim_energy, Eigen::VectorXi &b, Eigen::MatrixXd &bc, double soft_p)
Definition slim.cpp:649
Eigen::MatrixXd slim_solve(SLIMData &data, int iter_num)
Definition slim.cpp:764
double avg_edge_length
Definition slim.h:74
bool withWeightedParameterization
Definition slim.h:63
Eigen::MatrixXi F
Definition slim.h:30
Eigen::MatrixXd bc
Definition slim.h:44
int f_num
Definition slim.h:76
double mesh_area
Definition slim.h:73
Eigen::VectorXf weightPerFaceMap
Definition slim.h:65
Eigen::MatrixXd Ri
Definition slim.h:81
Eigen::VectorXd M
Definition slim.h:72
bool skipInitialization
Definition slim.h:51
Eigen::VectorXi b
Definition slim.h:43
SLIM_ENERGY slim_energy
Definition slim.h:39
Eigen::VectorXd W_33
Definition slim.h:90
bool first_solve
Definition slim.h:93
bool has_pre_calc
Definition slim.h:94
double globalScaleInvarianceFactor
Definition slim.h:67
Eigen::SparseMatrix< double > Dy
Definition slim.h:91
bool validPreInitialization
Definition slim.h:52
bool mesh_improvement_3d
Definition slim.h:48
Eigen::VectorXd W_13
Definition slim.h:84
double proximal_p
Definition slim.h:77
Eigen::VectorXf weightmap
Definition slim.h:64
Eigen::MatrixXd V
Definition slim.h:29
int v_num
Definition slim.h:75
Eigen::MatrixXd oldUVs
Definition slim.h:59
Eigen::VectorXd W_23
Definition slim.h:87
@ SYMMETRIC_DIRICHLET
Definition slim.h:34
@ EXP_CONFORMAL
Definition slim.h:36
@ EXP_SYMMETRIC_DIRICHLET
Definition slim.h:37
Eigen::VectorXd WGL_M
Definition slim.h:79
double exp_factor
Definition slim.h:47
Eigen::VectorXd W_11
Definition slim.h:82
double expectedSurfaceAreaOfResultingMap
Definition slim.h:53
Eigen::SparseMatrix< double > Dx
Definition slim.h:91
Eigen::VectorXd W_22
Definition slim.h:86
Eigen::SparseMatrix< double > Dz
Definition slim.h:91
bool valid
Definition slim.h:26
Eigen::VectorXd W_21
Definition slim.h:85
Eigen::VectorXd W_31
Definition slim.h:88
double weightInfluence
Definition slim.h:66
Eigen::MatrixXd Ji
Definition slim.h:81
int reflection_mode
Definition slim.h:50
Eigen::MatrixXd V_o
Definition slim.h:56
double energy
Definition slim.h:69
Eigen::VectorXd rhs
Definition slim.h:80
Eigen::VectorXd W_32
Definition slim.h:89
Eigen::VectorXd W_12
Definition slim.h:83
double soft_const_p
Definition slim.h:45
CCL_NAMESPACE_BEGIN struct Window V