37 F.resize((n - 1) * (n - 1) * 2, 3);
38 const double delta = 1. / (n - 1.);
39 std::vector<int> map(n * n, -1);
42 for (
int i = 0; i < n; ++i)
44 for (
int j = 0; j < n; ++j)
46 if (tri && i + j >= n)
48 map[i + j * n] = index;
49 V.row(index) << i * delta, j * delta;
54 V.conservativeResize(index, 2);
56 std::array<int, 3> tmp;
59 for (
int i = 0; i < n - 1; ++i)
61 for (
int j = 0; j < n - 1; ++j)
63 tmp = {{map[i + j * n], map[i + 1 + j * n], map[i + (j + 1) * n]}};
64 if (tmp[0] >= 0 && tmp[1] >= 0 && tmp[2] >= 0)
66 F.row(index) << tmp[0], tmp[1], tmp[2];
70 tmp = {{map[i + 1 + j * n], map[i + 1 + (j + 1) * n], map[i + (j + 1) * n]}};
71 if (tmp[0] >= 0 && tmp[1] >= 0 && tmp[2] >= 0)
73 F.row(index) << tmp[0], tmp[1], tmp[2];
79 F.conservativeResize(index, 3);
127 const double delta = 1. / (n - 1.);
128 T.resize((n - 1) * (n - 1) * (n - 1) * 6, 4);
129 V.resize(n * n * n, 3);
130 std::vector<int> map(n * n * n, -1);
133 for (
int i = 0; i < n; ++i)
135 for (
int j = 0; j < n; ++j)
137 for (
int k = 0; k < n; ++k)
139 if (tet && i + j + k >= n)
141 if (prism && i + j >= n)
143 map[(i + j * n) * n + k] = index;
144 V.row(index) << i * delta, j * delta, k * delta;
149 V.conservativeResize(index, 3);
151 std::array<int, 8> indices;
152 std::array<int, 4> tmp;
154 for (
int i = 0; i < n - 1; ++i)
156 for (
int j = 0; j < n - 1; ++j)
158 for (
int k = 0; k < n - 1; ++k)
160 indices = {{(i + j * n) * n + k,
161 (i + 1 + j * n) * n + k,
162 (i + 1 + (j + 1) * n) * n + k,
163 (i + (j + 1) * n) * n + k,
165 (i + j * n) * n + k + 1,
166 (i + 1 + j * n) * n + k + 1,
167 (i + 1 + (j + 1) * n) * n + k + 1,
168 (i + (j + 1) * n) * n + k + 1}};
170 tmp = {{map[indices[1 - 1]], map[indices[2 - 1]], map[indices[4 - 1]], map[indices[5 - 1]]}};
171 add_tet(tmp,
V, index, T);
173 tmp = {{map[indices[6 - 1]], map[indices[3 - 1]], map[indices[7 - 1]], map[indices[8 - 1]]}};
174 add_tet(tmp,
V, index, T);
176 tmp = {{map[indices[5 - 1]], map[indices[2 - 1]], map[indices[6 - 1]], map[indices[4 - 1]]}};
177 add_tet(tmp,
V, index, T);
179 tmp = {{map[indices[5 - 1]], map[indices[4 - 1]], map[indices[8 - 1]], map[indices[6 - 1]]}};
180 add_tet(tmp,
V, index, T);
182 tmp = {{map[indices[4 - 1]], map[indices[2 - 1]], map[indices[6 - 1]], map[indices[3 - 1]]}};
183 add_tet(tmp,
V, index, T);
185 tmp = {{map[indices[3 - 1]], map[indices[4 - 1]], map[indices[8 - 1]], map[indices[6 - 1]]}};
186 add_tet(tmp,
V, index, T);
191 T.conservativeResize(index, 4);
193 F.resize(4 * index, 3);
195 F.block(0, 0, index, 1) = T.col(1);
196 F.block(0, 1, index, 1) = T.col(0);
197 F.block(0, 2, index, 1) = T.col(2);
199 F.block(index, 0, index, 1) = T.col(0);
200 F.block(index, 1, index, 1) = T.col(1);
201 F.block(index, 2, index, 1) = T.col(3);
203 F.block(2 * index, 0, index, 1) = T.col(1);
204 F.block(2 * index, 1, index, 1) = T.col(2);
205 F.block(2 * index, 2, index, 1) = T.col(3);
207 F.block(3 * index, 0, index, 1) = T.col(2);
208 F.block(3 * index, 1, index, 1) = T.col(0);
209 F.block(3 * index, 2, index, 1) = T.col(3);
424#ifdef POLYFEM_WITH_TRIANGLE
425 Eigen::MatrixXi E(poly.rows(), 2);
426 const Eigen::MatrixXd H(0, 2);
427 const std::string flags =
"Qzqa" + std::to_string(
area_param_ / 10.0);
429 for (
int i = 0; i < poly.rows(); ++i)
430 E.row(i) << i, (i + 1) % poly.rows();
432 igl::triangle::triangulate(poly, E, H, flags, pts,
faces);
435 const Eigen::MatrixXi rt = Eigen::MatrixXi::Zero(poly.rows(), 1);
438 Eigen::MatrixXd area;
439 igl::predicates::ear_clipping(poly, rt,
faces, I);
441 igl::doublearea(poly,
faces, area);
443 const double area_avg = area.array().sum() / poly.rows() / 2;
447 Eigen::MatrixXi new_faces;
449 igl::upsample(poly,
faces, pts, new_faces, n_refs);
453 std::vector<int> loop;
454 igl::default_num_threads(1);
455 igl::boundary_loop(
faces, loop);
456 igl::default_num_threads(0);
457 edges.resize(loop.size(), 2);
458 for (
int i = 0; i < loop.size(); ++i)
459 edges.row(i) << loop[i], loop[(i + 1) % loop.size()];