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);
116 void regular_3d_grid(
const int nn,
bool tet, Eigen::MatrixXd &
V, Eigen::MatrixXi &
F, Eigen::MatrixXi &T)
119 const double delta = 1. / (n - 1.);
120 T.resize((n - 1) * (n - 1) * (n - 1) * 6, 4);
121 V.resize(n * n * n, 3);
122 std::vector<int> map(n * n * n, -1);
125 for (
int i = 0; i < n; ++i)
127 for (
int j = 0; j < n; ++j)
129 for (
int k = 0; k < n; ++k)
131 if (tet && i + j + k >= n)
133 map[(i + j * n) * n + k] = index;
134 V.row(index) << i * delta, j * delta, k * delta;
139 V.conservativeResize(index, 3);
141 std::array<int, 8> indices;
142 std::array<int, 4> tmp;
144 for (
int i = 0; i < n - 1; ++i)
146 for (
int j = 0; j < n - 1; ++j)
148 for (
int k = 0; k < n - 1; ++k)
150 indices = {{(i + j * n) * n + k,
151 (i + 1 + j * n) * n + k,
152 (i + 1 + (j + 1) * n) * n + k,
153 (i + (j + 1) * n) * n + k,
155 (i + j * n) * n + k + 1,
156 (i + 1 + j * n) * n + k + 1,
157 (i + 1 + (j + 1) * n) * n + k + 1,
158 (i + (j + 1) * n) * n + k + 1}};
160 tmp = {{map[indices[1 - 1]], map[indices[2 - 1]], map[indices[4 - 1]], map[indices[5 - 1]]}};
161 add_tet(tmp,
V, index, T);
163 tmp = {{map[indices[6 - 1]], map[indices[3 - 1]], map[indices[7 - 1]], map[indices[8 - 1]]}};
164 add_tet(tmp,
V, index, T);
166 tmp = {{map[indices[5 - 1]], map[indices[2 - 1]], map[indices[6 - 1]], map[indices[4 - 1]]}};
167 add_tet(tmp,
V, index, T);
169 tmp = {{map[indices[5 - 1]], map[indices[4 - 1]], map[indices[8 - 1]], map[indices[6 - 1]]}};
170 add_tet(tmp,
V, index, T);
172 tmp = {{map[indices[4 - 1]], map[indices[2 - 1]], map[indices[6 - 1]], map[indices[3 - 1]]}};
173 add_tet(tmp,
V, index, T);
175 tmp = {{map[indices[3 - 1]], map[indices[4 - 1]], map[indices[8 - 1]], map[indices[6 - 1]]}};
176 add_tet(tmp,
V, index, T);
181 T.conservativeResize(index, 4);
183 F.resize(4 * index, 3);
185 F.block(0, 0, index, 1) = T.col(1);
186 F.block(0, 1, index, 1) = T.col(0);
187 F.block(0, 2, index, 1) = T.col(2);
189 F.block(index, 0, index, 1) = T.col(0);
190 F.block(index, 1, index, 1) = T.col(1);
191 F.block(index, 2, index, 1) = T.col(3);
193 F.block(2 * index, 0, index, 1) = T.col(1);
194 F.block(2 * index, 1, index, 1) = T.col(2);
195 F.block(2 * index, 2, index, 1) = T.col(3);
197 F.block(3 * index, 0, index, 1) = T.col(2);
198 F.block(3 * index, 1, index, 1) = T.col(0);
199 F.block(3 * index, 2, index, 1) = T.col(3);
371#ifdef POLYFEM_WITH_TRIANGLE
372 Eigen::MatrixXi E(poly.rows(), 2);
373 const Eigen::MatrixXd H(0, 2);
374 const std::string flags =
"Qzqa" + std::to_string(
area_param_ / 10.0);
376 for (
int i = 0; i < poly.rows(); ++i)
377 E.row(i) << i, (i + 1) % poly.rows();
379 igl::triangle::triangulate(poly, E, H, flags, pts,
faces);
382 const Eigen::MatrixXi rt = Eigen::MatrixXi::Zero(poly.rows(), 1);
385 Eigen::MatrixXd area;
386 igl::predicates::ear_clipping(poly, rt,
faces, I);
388 igl::doublearea(poly,
faces, area);
390 const double area_avg = area.array().sum() / poly.rows() / 2;
394 Eigen::MatrixXi new_faces;
396 igl::upsample(poly,
faces, pts, new_faces, n_refs);
400 std::vector<int> loop;
401 igl::default_num_threads(1);
402 igl::boundary_loop(
faces, loop);
403 igl::default_num_threads(0);
404 edges.resize(loop.size(), 2);
405 for (
int i = 0; i < loop.size(); ++i)
406 edges.row(i) << loop[i], loop[(i + 1) % loop.size()];