22 const Eigen::MatrixXi &f,
23 const Eigen::MatrixXd &v,
24 Eigen::SparseMatrix<double> &vertex_to_face_indices)
26 using t = Eigen::Triplet<double>;
27 std::vector<t> coefficients;
29 for (
int i = 0; i < f.rows(); i++) {
31 int vertex_index1 = f(i, 0);
32 int vertex_index2 = f(i, 1);
33 int vertex_index3 = f(i, 2);
35 double angle1 =
compute_angle(v.row(vertex_index2) - v.row(vertex_index1),
36 v.row(vertex_index3) - v.row(vertex_index1));
37 double angle2 =
compute_angle(v.row(vertex_index3) - v.row(vertex_index2),
38 v.row(vertex_index1) - v.row(vertex_index2));
39 double angle3 =
compute_angle(v.row(vertex_index1) - v.row(vertex_index3),
40 v.row(vertex_index2) - v.row(vertex_index3));
42 coefficients.emplace_back(vertex_index1, 2 * vertex_index2, angle3);
43 coefficients.emplace_back(vertex_index1, 2 * vertex_index3 + 1, angle2);
45 coefficients.emplace_back(vertex_index2, 2 * vertex_index1 + 1, angle3);
46 coefficients.emplace_back(vertex_index2, 2 * vertex_index3, angle1);
48 coefficients.emplace_back(vertex_index3, 2 * vertex_index1, angle2);
49 coefficients.emplace_back(vertex_index3, 2 * vertex_index2 + 1, angle1);
52 vertex_to_face_indices.setFromTriplets(coefficients.begin(), coefficients.end());
56 const Eigen::MatrixXi &f,
57 const Eigen::MatrixXd &v,
58 Eigen::SparseMatrix<double> &vertex_to_face_indices)
61 using t = Eigen::Triplet<double>;
62 std::vector<t> coefficients;
64 for (
int i = 0; i < f.rows(); i++) {
66 int vertex_index1 = f(i, 0);
67 int vertex_index2 = f(i, 1);
68 int vertex_index3 = f(i, 2);
70 double angle1 =
compute_angle(v.row(vertex_index2) - v.row(vertex_index1),
71 v.row(vertex_index3) - v.row(vertex_index1));
72 double angle2 =
compute_angle(v.row(vertex_index3) - v.row(vertex_index2),
73 v.row(vertex_index1) - v.row(vertex_index2));
74 double angle3 =
compute_angle(v.row(vertex_index1) - v.row(vertex_index3),
75 v.row(vertex_index2) - v.row(vertex_index3));
77 coefficients.emplace_back(vertex_index1, 2 * vertex_index2, angle1);
78 coefficients.emplace_back(vertex_index1, 2 * vertex_index3 + 1, angle1);
80 coefficients.emplace_back(vertex_index2, 2 * vertex_index1 + 1, angle2);
81 coefficients.emplace_back(vertex_index2, 2 * vertex_index3, angle2);
83 coefficients.emplace_back(vertex_index3, 2 * vertex_index1, angle3);
84 coefficients.emplace_back(vertex_index3, 2 * vertex_index2 + 1, angle3);
87 vertex_to_face_indices.setFromTriplets(coefficients.begin(), coefficients.end());
93 const Eigen::MatrixXd &v,
94 const Eigen::MatrixXi &e,
95 const Eigen::VectorXd &el,
96 const Eigen::VectorXi &bnd,
97 const Eigen::MatrixXd &bnd_uv,
101 int verts_num = uv.rows();
102 int edges_num = e.rows();
104 Eigen::SparseMatrix<double> vertex_to_angles(verts_num, verts_num * 2);
117 int n_unknowns = verts_num - bnd.size();
118 int n_knowns = bnd.size();
120 Eigen::SparseMatrix<double> aint(n_unknowns, n_unknowns);
121 Eigen::SparseMatrix<double> abnd(n_unknowns, n_knowns);
122 Eigen::VectorXd
z(n_knowns);
124 std::vector<Eigen::Triplet<double>> int_triplet_vector;
125 std::vector<Eigen::Triplet<double>> bnd_triplet_vector;
129 double edge_weight, edge_length;
130 Eigen::RowVector2i edge;
132 int first_vertex, second_vertex;
134 for (
int e_idx = 0; e_idx < edges_num; e_idx++) {
136 edge_length = el(e_idx);
137 first_vertex = edge(0);
138 second_vertex = edge(1);
140 if (first_vertex >= n_knowns) {
142 rowindex = first_vertex - n_knowns;
144 double angle1 = vertex_to_angles.coeff(first_vertex, 2 * second_vertex);
145 double angle2 = vertex_to_angles.coeff(first_vertex, 2 * second_vertex + 1);
149 edge_weight = 1 /
tan(angle1) + 1 /
tan(angle2);
152 edge_weight =
tan(angle1 / 2) +
tan(angle2 / 2);
153 edge_weight /= edge_length;
160 int_triplet_vector.emplace_back(rowindex, rowindex, edge_weight);
162 if (second_vertex >= n_knowns) {
164 columnindex = second_vertex - n_knowns;
166 int_triplet_vector.emplace_back(rowindex, columnindex, -edge_weight);
170 columnindex = second_vertex;
171 bnd_triplet_vector.emplace_back(rowindex, columnindex, edge_weight);
176 aint.setFromTriplets(int_triplet_vector.begin(), int_triplet_vector.end());
177 aint.makeCompressed();
179 abnd.setFromTriplets(bnd_triplet_vector.begin(), bnd_triplet_vector.end());
180 abnd.makeCompressed();
182 for (
int i = 0; i < n_unknowns; i++) {
183 double factor = aint.coeff(i, i);
184 aint.row(i) /= factor;
185 abnd.row(i) /= factor;
188 Eigen::SparseLU<Eigen::SparseMatrix<double>> solver;
189 solver.compute(aint);
191 for (
int i = 0; i < 2; i++) {
193 for (
int zindex = 0; zindex < n_knowns; zindex++) {
194 z(zindex) = bnd_uv(bnd(zindex), i);
197 Eigen::VectorXd
b = abnd *
z;
200 uvs = solver.solve(
b);
202 Eigen::VectorXd boundary = bnd_uv.col(i);
203 Eigen::VectorXd interior = uvs;
205 uv.col(i) << boundary, interior;
247 double pi =
atan(1) * 4;
248 int boundary_vertices_num = vertex_positions.rows();
250 double angle = 2 * pi / boundary_vertices_num;
252 for (
int i = 0; i < boundary_vertices_num; i++) {
255 vertex_positions(i, 0) = (
x * 0.5) + 0.5;
256 vertex_positions(i, 1) = (
y * 0.5) + 0.5;
261 const Eigen::MatrixXd &uv,
262 std::vector<int> &flip_idx)
265 for (
int i = 0; i < f.rows(); i++) {
267 Eigen::Vector2d v1_n = uv.row(f(i, 0));
268 Eigen::Vector2d v2_n = uv.row(f(i, 1));
269 Eigen::Vector2d v3_n = uv.row(f(i, 2));
271 Eigen::MatrixXd t2_homo(3, 3);
272 t2_homo.col(0) << v1_n(0), v1_n(1), 1;
273 t2_homo.col(1) << v2_n(0), v2_n(1), 1;
274 t2_homo.col(2) << v3_n(0), v3_n(1), 1;
275 double det = t2_homo.determinant();
278 flip_idx.push_back(i);
void tutte(const Eigen::MatrixXi &f, const Eigen::MatrixXd &v, const Eigen::MatrixXi &e, const Eigen::VectorXd &el, const Eigen::VectorXi &bnd, const Eigen::MatrixXd &bnd_uv, Eigen::MatrixXd &uv)
void mvc(const Eigen::MatrixXi &f, const Eigen::MatrixXd &v, const Eigen::MatrixXi &e, const Eigen::VectorXd &el, const Eigen::VectorXi &bnd, const Eigen::MatrixXd &bnd_uv, Eigen::MatrixXd &uv)
void convex_border_parameterization(const Eigen::MatrixXi &f, const Eigen::MatrixXd &v, const Eigen::MatrixXi &e, const Eigen::VectorXd &el, const Eigen::VectorXi &bnd, const Eigen::MatrixXd &bnd_uv, Eigen::MatrixXd &uv, Method method)
void harmonic(const Eigen::MatrixXi &f, const Eigen::MatrixXd &v, const Eigen::MatrixXi &e, const Eigen::VectorXd &el, const Eigen::VectorXi &bnd, const Eigen::MatrixXd &bnd_uv, Eigen::MatrixXd &uv)