Skip to content

Commit fd883c0

Browse files
committed
Exposed additional layout code
1 parent b90f67c commit fd883c0

File tree

3 files changed

+156
-130
lines changed

3 files changed

+156
-130
lines changed

src/parameterization/layout.cpp

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,136 @@ get_consistent_layout(
876876
return std::make_tuple(_u_o, _v_o, is_cut_c, is_cut_o);
877877
}
878878

879+
std::
880+
tuple<
881+
OverlayMesh<Scalar>, // m_o
882+
Eigen::MatrixXd, // V_o
883+
Eigen::MatrixXi, // F_o
884+
Eigen::MatrixXd, // uv_o
885+
Eigen::MatrixXi, // FT_o
886+
std::vector<bool>, // is_cut_h
887+
std::vector<bool>, // is_cut_o
888+
std::vector<int>, // Fn_to_F
889+
std::vector<std::pair<int, int>> // endpoints_o
890+
>
891+
consistent_overlay_mesh_to_VL(
892+
const Eigen::MatrixXi& F,
893+
const std::vector<Scalar>& Theta_hat,
894+
OverlayMesh<Scalar>& mo,
895+
std::vector<Scalar>& u,
896+
std::vector<std::vector<Scalar>>& V_overlay,
897+
std::vector<int>& vtx_reindex,
898+
std::vector<std::pair<int, int>>& endpoints,
899+
const std::vector<bool>& is_cut_orig,
900+
const std::vector<bool>& is_cut)
901+
{
902+
// get cones and bd
903+
std::vector<int> cones, bd;
904+
std::vector<bool> is_bd = igl::is_border_vertex(F);
905+
for (size_t i = 0; i < is_bd.size(); i++) {
906+
if (is_bd[i]) {
907+
bd.push_back(i);
908+
}
909+
}
910+
for (size_t i = 0; i < Theta_hat.size(); i++) {
911+
if ((!is_bd[i]) && abs(Theta_hat[i] - 2 * M_PI) > 1e-15) {
912+
cones.push_back(i);
913+
}
914+
}
915+
916+
std::vector<int> f_labels = get_overlay_face_labels(mo);
917+
918+
// reindex cones and bd
919+
std::vector<int> vtx_reindex_rev(vtx_reindex.size());
920+
for (size_t i = 0; i < vtx_reindex.size(); i++) {
921+
vtx_reindex_rev[vtx_reindex[i]] = i;
922+
}
923+
for (size_t i = 0; i < cones.size(); i++) {
924+
cones[i] = vtx_reindex_rev[cones[i]];
925+
}
926+
for (size_t i = 0; i < bd.size(); i++) {
927+
bd[i] = vtx_reindex_rev[bd[i]];
928+
}
929+
930+
spdlog::trace("#bd_vt: {}", bd.size());
931+
spdlog::trace("#cones: {}", cones.size());
932+
spdlog::trace("vtx reindex size: {}", vtx_reindex.size());
933+
spdlog::trace("mc.out size: {}", mo.cmesh().out.size());
934+
935+
// get layout
936+
auto layout_res = get_consistent_layout(mo, u, cones, is_cut_orig, is_cut);
937+
auto u_o = std::get<0>(layout_res);
938+
auto v_o = std::get<1>(layout_res);
939+
auto is_cut_h = std::get<2>(layout_res);
940+
auto is_cut_o = std::get<3>(layout_res);
941+
942+
// get output VF and metric
943+
auto FVFT_res = get_FV_FTVT(mo, endpoints, is_cut_o, V_overlay, u_o, v_o);
944+
auto v3d = std::get<0>(FVFT_res);
945+
auto u_o_out = std::get<1>(FVFT_res);
946+
auto v_o_out = std::get<2>(FVFT_res);
947+
auto F_out = std::get<3>(FVFT_res);
948+
auto FT_out = std::get<4>(FVFT_res);
949+
auto Fn_to_F = std::get<5>(FVFT_res);
950+
auto remapped_endpoints = std::get<6>(FVFT_res);
951+
952+
// v3d_out = v3d^T
953+
std::vector<std::vector<Scalar>> v3d_out(v3d[0].size());
954+
for (size_t i = 0; i < v3d[0].size(); i++) {
955+
v3d_out[i].resize(3);
956+
for (int j = 0; j < 3; j++) {
957+
v3d_out[i][j] = v3d[j][i];
958+
}
959+
}
960+
961+
// reindex back
962+
auto u_o_out_copy = u_o_out;
963+
auto v_o_out_copy = v_o_out;
964+
auto v3d_out_copy = v3d_out;
965+
auto endpoints_out = remapped_endpoints;
966+
int num_vertices = vtx_reindex.size();
967+
for (size_t i = 0; i < F_out.size(); i++) {
968+
for (int j = 0; j < 3; j++) {
969+
if (F_out[i][j] < num_vertices) {
970+
F_out[i][j] = vtx_reindex[F_out[i][j]];
971+
}
972+
if (FT_out[i][j] < num_vertices) {
973+
FT_out[i][j] = vtx_reindex[FT_out[i][j]];
974+
}
975+
}
976+
}
977+
for (size_t i = 0; i < vtx_reindex.size(); i++) {
978+
u_o_out[vtx_reindex[i]] = u_o_out_copy[i];
979+
v_o_out[vtx_reindex[i]] = v_o_out_copy[i];
980+
v3d_out[vtx_reindex[i]] = v3d_out_copy[i];
981+
}
982+
for (size_t i = vtx_reindex.size(); i < endpoints_out.size(); i++) {
983+
int a = vtx_reindex[endpoints_out[i].first];
984+
int b = vtx_reindex[endpoints_out[i].second];
985+
endpoints_out[i] = std::make_pair(a, b);
986+
}
987+
988+
// Convert vector formats to matrices
989+
Eigen::MatrixXd V_o, uv_o;
990+
Eigen::VectorXd u_o_col, v_o_col;
991+
Eigen::MatrixXi F_o, FT_o;
992+
convert_std_to_eigen_matrix(v3d_out, V_o);
993+
convert_std_to_eigen_matrix(F_out, F_o);
994+
convert_std_to_eigen_matrix(FT_out, FT_o);
995+
convert_std_to_eigen_vector(u_o_out, u_o_col);
996+
convert_std_to_eigen_vector(v_o_out, v_o_col);
997+
uv_o.resize(u_o_col.size(), 2);
998+
uv_o.col(0) = u_o_col;
999+
uv_o.col(1) = v_o_col;
1000+
1001+
// Check for validity
1002+
if (!check_uv(V_o, F_o, uv_o, FT_o)) {
1003+
spdlog::error("Inconsistent uvs");
1004+
}
1005+
1006+
return std::make_tuple(mo, V_o, F_o, uv_o, FT_o, is_cut_h, is_cut_o, Fn_to_F, endpoints_out);
1007+
}
1008+
8791009
#ifdef PYBIND
8801010
std::
8811011
tuple<

src/parameterization/layout.hh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,32 @@ get_consistent_layout(
149149
const std::vector<bool>& is_cut_orig,
150150
const std::vector<bool>& is_cut);
151151

152+
153+
// TODO: Document this technical function
154+
// Exposed for usage in other libraries
155+
std::
156+
tuple<
157+
OverlayMesh<Scalar>, // m_o
158+
Eigen::MatrixXd, // V_o
159+
Eigen::MatrixXi, // F_o
160+
Eigen::MatrixXd, // uv_o
161+
Eigen::MatrixXi, // FT_o
162+
std::vector<bool>, // is_cut_h
163+
std::vector<bool>, // is_cut_o
164+
std::vector<int>, // Fn_to_F
165+
std::vector<std::pair<int, int>> // endpoints_o
166+
>
167+
consistent_overlay_mesh_to_VL(
168+
const Eigen::MatrixXi& F,
169+
const std::vector<Scalar>& Theta_hat,
170+
OverlayMesh<Scalar>& mo,
171+
std::vector<Scalar>& u,
172+
std::vector<std::vector<Scalar>>& V_overlay,
173+
std::vector<int>& vtx_reindex,
174+
std::vector<std::pair<int, int>>& endpoints,
175+
const std::vector<bool>& is_cut_orig,
176+
const std::vector<bool>& is_cut);
177+
152178
#ifdef PYBIND
153179
std::
154180
tuple<

src/penner_optimization_interface.cpp

Lines changed: 0 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -169,136 +169,6 @@ void write_obj_with_uv(
169169
}
170170

171171

172-
std::
173-
tuple<
174-
OverlayMesh<Scalar>, // m_o
175-
Eigen::MatrixXd, // V_o
176-
Eigen::MatrixXi, // F_o
177-
Eigen::MatrixXd, // uv_o
178-
Eigen::MatrixXi, // FT_o
179-
std::vector<bool>, // is_cut_h
180-
std::vector<bool>, // is_cut_o
181-
std::vector<int>, // Fn_to_F
182-
std::vector<std::pair<int, int>> // endpoints_o
183-
>
184-
consistent_overlay_mesh_to_VL(
185-
const Eigen::MatrixXi& F,
186-
const std::vector<Scalar>& Theta_hat,
187-
OverlayMesh<Scalar>& mo,
188-
std::vector<Scalar>& u,
189-
std::vector<std::vector<Scalar>>& V_overlay,
190-
std::vector<int>& vtx_reindex,
191-
std::vector<std::pair<int, int>>& endpoints,
192-
const std::vector<bool>& is_cut_orig,
193-
const std::vector<bool>& is_cut)
194-
{
195-
// get cones and bd
196-
std::vector<int> cones, bd;
197-
std::vector<bool> is_bd = igl::is_border_vertex(F);
198-
for (size_t i = 0; i < is_bd.size(); i++) {
199-
if (is_bd[i]) {
200-
bd.push_back(i);
201-
}
202-
}
203-
for (size_t i = 0; i < Theta_hat.size(); i++) {
204-
if ((!is_bd[i]) && abs(Theta_hat[i] - 2 * M_PI) > 1e-15) {
205-
cones.push_back(i);
206-
}
207-
}
208-
209-
std::vector<int> f_labels = get_overlay_face_labels(mo);
210-
211-
// reindex cones and bd
212-
std::vector<int> vtx_reindex_rev(vtx_reindex.size());
213-
for (size_t i = 0; i < vtx_reindex.size(); i++) {
214-
vtx_reindex_rev[vtx_reindex[i]] = i;
215-
}
216-
for (size_t i = 0; i < cones.size(); i++) {
217-
cones[i] = vtx_reindex_rev[cones[i]];
218-
}
219-
for (size_t i = 0; i < bd.size(); i++) {
220-
bd[i] = vtx_reindex_rev[bd[i]];
221-
}
222-
223-
spdlog::trace("#bd_vt: {}", bd.size());
224-
spdlog::trace("#cones: {}", cones.size());
225-
spdlog::trace("vtx reindex size: {}", vtx_reindex.size());
226-
spdlog::trace("mc.out size: {}", mo.cmesh().out.size());
227-
228-
// get layout
229-
auto layout_res = get_consistent_layout(mo, u, cones, is_cut_orig, is_cut);
230-
auto u_o = std::get<0>(layout_res);
231-
auto v_o = std::get<1>(layout_res);
232-
auto is_cut_h = std::get<2>(layout_res);
233-
auto is_cut_o = std::get<3>(layout_res);
234-
235-
// get output VF and metric
236-
auto FVFT_res = get_FV_FTVT(mo, endpoints, is_cut_o, V_overlay, u_o, v_o);
237-
auto v3d = std::get<0>(FVFT_res);
238-
auto u_o_out = std::get<1>(FVFT_res);
239-
auto v_o_out = std::get<2>(FVFT_res);
240-
auto F_out = std::get<3>(FVFT_res);
241-
auto FT_out = std::get<4>(FVFT_res);
242-
auto Fn_to_F = std::get<5>(FVFT_res);
243-
auto remapped_endpoints = std::get<6>(FVFT_res);
244-
245-
// v3d_out = v3d^T
246-
std::vector<std::vector<Scalar>> v3d_out(v3d[0].size());
247-
for (size_t i = 0; i < v3d[0].size(); i++) {
248-
v3d_out[i].resize(3);
249-
for (int j = 0; j < 3; j++) {
250-
v3d_out[i][j] = v3d[j][i];
251-
}
252-
}
253-
254-
// reindex back
255-
auto u_o_out_copy = u_o_out;
256-
auto v_o_out_copy = v_o_out;
257-
auto v3d_out_copy = v3d_out;
258-
auto endpoints_out = remapped_endpoints;
259-
int num_vertices = vtx_reindex.size();
260-
for (size_t i = 0; i < F_out.size(); i++) {
261-
for (int j = 0; j < 3; j++) {
262-
if (F_out[i][j] < num_vertices) {
263-
F_out[i][j] = vtx_reindex[F_out[i][j]];
264-
}
265-
if (FT_out[i][j] < num_vertices) {
266-
FT_out[i][j] = vtx_reindex[FT_out[i][j]];
267-
}
268-
}
269-
}
270-
for (size_t i = 0; i < vtx_reindex.size(); i++) {
271-
u_o_out[vtx_reindex[i]] = u_o_out_copy[i];
272-
v_o_out[vtx_reindex[i]] = v_o_out_copy[i];
273-
v3d_out[vtx_reindex[i]] = v3d_out_copy[i];
274-
}
275-
for (size_t i = vtx_reindex.size(); i < endpoints_out.size(); i++) {
276-
int a = vtx_reindex[endpoints_out[i].first];
277-
int b = vtx_reindex[endpoints_out[i].second];
278-
endpoints_out[i] = std::make_pair(a, b);
279-
}
280-
281-
// Convert vector formats to matrices
282-
Eigen::MatrixXd V_o, uv_o;
283-
Eigen::VectorXd u_o_col, v_o_col;
284-
Eigen::MatrixXi F_o, FT_o;
285-
convert_std_to_eigen_matrix(v3d_out, V_o);
286-
convert_std_to_eigen_matrix(F_out, F_o);
287-
convert_std_to_eigen_matrix(FT_out, FT_o);
288-
convert_std_to_eigen_vector(u_o_out, u_o_col);
289-
convert_std_to_eigen_vector(v_o_out, v_o_col);
290-
uv_o.resize(u_o_col.size(), 2);
291-
uv_o.col(0) = u_o_col;
292-
uv_o.col(1) = v_o_col;
293-
294-
// Check for validity
295-
if (!check_uv(V_o, F_o, uv_o, FT_o)) {
296-
spdlog::error("Inconsistent uvs");
297-
}
298-
299-
return std::make_tuple(mo, V_o, F_o, uv_o, FT_o, is_cut_h, is_cut_o, Fn_to_F, endpoints_out);
300-
}
301-
302172
std::
303173
tuple<
304174
OverlayMesh<Scalar>, // m_o

0 commit comments

Comments
 (0)