35 F.resize((n - 1) * (n - 1) * 2, 3);
36 const double delta = 1. / (n - 1.);
37 std::vector<int> map(n * n, -1);
40 for (
int i = 0; i < n; ++i)
42 for (
int j = 0; j < n; ++j)
44 if (tri && i + j >= n)
46 map[i + j * n] = index;
47 V.row(index) << i * delta, j * delta;
52 V.conservativeResize(index, 2);
54 std::array<int, 3> tmp;
57 for (
int i = 0; i < n - 1; ++i)
59 for (
int j = 0; j < n - 1; ++j)
61 tmp = {{map[i + j * n], map[i + 1 + j * n], map[i + (j + 1) * n]}};
62 if (tmp[0] >= 0 && tmp[1] >= 0 && tmp[2] >= 0)
64 F.row(index) << tmp[0], tmp[1], tmp[2];
68 tmp = {{map[i + 1 + j * n], map[i + 1 + (j + 1) * n], map[i + (j + 1) * n]}};
69 if (tmp[0] >= 0 && tmp[1] >= 0 && tmp[2] >= 0)
71 F.row(index) << tmp[0], tmp[1], tmp[2];
77 F.conservativeResize(index, 3);
125 const double delta = 1. / (n - 1.);
126 T.resize((n - 1) * (n - 1) * (n - 1) * 6, 4);
127 V.resize(n * n * n, 3);
128 std::vector<int> map(n * n * n, -1);
131 for (
int i = 0; i < n; ++i)
133 for (
int j = 0; j < n; ++j)
135 for (
int k = 0; k < n; ++k)
137 if (tet && i + j + k >= n)
139 if (prism && i + j >= n)
141 map[(i + j * n) * n + k] = index;
142 V.row(index) << i * delta, j * delta, k * delta;
147 V.conservativeResize(index, 3);
149 std::array<int, 8> indices;
150 std::array<int, 4> tmp;
152 for (
int i = 0; i < n - 1; ++i)
154 for (
int j = 0; j < n - 1; ++j)
156 for (
int k = 0; k < n - 1; ++k)
158 indices = {{(i + j * n) * n + k,
159 (i + 1 + j * n) * n + k,
160 (i + 1 + (j + 1) * n) * n + k,
161 (i + (j + 1) * n) * n + k,
163 (i + j * n) * n + k + 1,
164 (i + 1 + j * n) * n + k + 1,
165 (i + 1 + (j + 1) * n) * n + k + 1,
166 (i + (j + 1) * n) * n + k + 1}};
168 tmp = {{map[indices[1 - 1]], map[indices[2 - 1]], map[indices[4 - 1]], map[indices[5 - 1]]}};
169 add_tet(tmp,
V, index, T);
171 tmp = {{map[indices[6 - 1]], map[indices[3 - 1]], map[indices[7 - 1]], map[indices[8 - 1]]}};
172 add_tet(tmp,
V, index, T);
174 tmp = {{map[indices[5 - 1]], map[indices[2 - 1]], map[indices[6 - 1]], map[indices[4 - 1]]}};
175 add_tet(tmp,
V, index, T);
177 tmp = {{map[indices[5 - 1]], map[indices[4 - 1]], map[indices[8 - 1]], map[indices[6 - 1]]}};
178 add_tet(tmp,
V, index, T);
180 tmp = {{map[indices[4 - 1]], map[indices[2 - 1]], map[indices[6 - 1]], map[indices[3 - 1]]}};
181 add_tet(tmp,
V, index, T);
183 tmp = {{map[indices[3 - 1]], map[indices[4 - 1]], map[indices[8 - 1]], map[indices[6 - 1]]}};
184 add_tet(tmp,
V, index, T);
189 T.conservativeResize(index, 4);
191 F.resize(4 * index, 3);
193 F.block(0, 0, index, 1) = T.col(1);
194 F.block(0, 1, index, 1) = T.col(0);
195 F.block(0, 2, index, 1) = T.col(2);
197 F.block(index, 0, index, 1) = T.col(0);
198 F.block(index, 1, index, 1) = T.col(1);
199 F.block(index, 2, index, 1) = T.col(3);
201 F.block(2 * index, 0, index, 1) = T.col(1);
202 F.block(2 * index, 1, index, 1) = T.col(2);
203 F.block(2 * index, 2, index, 1) = T.col(3);
205 F.block(3 * index, 0, index, 1) = T.col(2);
206 F.block(3 * index, 1, index, 1) = T.col(0);
207 F.block(3 * index, 2, index, 1) = T.col(3);
422#ifdef POLYFEM_WITH_TRIANGLE
423 Eigen::MatrixXi E(poly.rows(), 2);
424 const Eigen::MatrixXd H(0, 2);
425 const std::string flags =
"Qzqa" + std::to_string(
area_param_ / 10.0);
427 for (
int i = 0; i < poly.rows(); ++i)
428 E.row(i) << i, (i + 1) % poly.rows();
430 igl::triangle::triangulate(poly, E, H, flags, pts,
faces);
433 const Eigen::MatrixXi rt = Eigen::MatrixXi::Zero(poly.rows(), 1);
436 Eigen::MatrixXd area;
437 igl::predicates::ear_clipping(poly, rt,
faces, I);
439 igl::doublearea(poly,
faces, area);
441 const double area_avg = area.array().sum() / poly.rows() / 2;
445 Eigen::MatrixXi new_faces;
447 igl::upsample(poly,
faces, pts, new_faces, n_refs);
451 std::vector<int> loop;
452 igl::default_num_threads(1);
453 igl::boundary_loop(
faces, loop);
454 igl::default_num_threads(0);
455 edges.resize(loop.size(), 2);
456 for (
int i = 0; i < loop.size(); ++i)
457 edges.row(i) << loop[i], loop[(i + 1) % loop.size()];