Skip to content

Commit 77f00de

Browse files
committed
Fixed explicit optimization
1 parent a41a5a3 commit 77f00de

File tree

4 files changed

+44
-45
lines changed

4 files changed

+44
-45
lines changed

src/app/CMakeLists.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ target_link_libraries(optimize_metric PRIVATE
1212
MetricOptimizationLib
1313
)
1414

15-
#add_executable(optimize_shear
16-
# optimize_shear.cpp
17-
#)
18-
#target_link_libraries(optimize_shear PRIVATE
19-
# MetricOptimizationLib
20-
#)
21-
#
15+
add_executable(optimize_shear
16+
optimize_shear.cpp
17+
)
18+
target_link_libraries(optimize_shear PRIVATE
19+
MetricOptimizationLib
20+
)
21+
2222
#add_executable(plot_shear_energy
2323
# plot_shear_energy.cpp
2424
#)

src/app/optimize_shear.cpp

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "common.hh"
22
#include "explicit_optimization.hh"
33
#include "optimization_interface.hh"
4-
#include "targets.hh"
54
#include "optimization_interface.hh"
65
#include "shear.hh"
76
#include "logging.hh"
@@ -32,61 +31,49 @@ int main(int argc, char *argv[])
3231
igl::readOBJ(input_filename, V, uv, N, F, FT, FN);
3332

3433
// Get input angles
35-
std::vector<Scalar> Th_hat_init, Th_hat;
34+
std::vector<Scalar> Th_hat_init;
3635
spdlog::info("Using cone angles at {}", Th_hat_filename);
3736
read_vector_from_file(Th_hat_filename, Th_hat_init);
38-
correct_cone_angles(Th_hat_init, Th_hat);
37+
std::vector<Scalar> Th_hat = correct_cone_angles(Th_hat_init);
3938

4039
// Get initial mesh for optimization
41-
Mesh<Scalar> m;
4240
std::vector<int> vtx_reindex;
43-
VectorX reduced_metric_target;
44-
generate_initial_mesh(V, F, V, F, Th_hat, m, vtx_reindex, reduced_metric_target);
41+
std::vector<int> free_cones = {};
42+
bool fix_boundary = false;
43+
std::unique_ptr<DifferentiableConeMetric> cone_metric = generate_initial_mesh(V, F, V, F, Th_hat, vtx_reindex, free_cones, fix_boundary, false);
4544

46-
// Get initial metric from file or target
47-
VectorX reduced_metric_init;
48-
if (argc > 4)
49-
{
50-
std::string metric_filename = argv[4];
51-
std::vector<Scalar> reduced_metric_init_vec;
52-
read_vector_from_file(metric_filename, reduced_metric_init_vec);
53-
convert_std_to_eigen_vector(reduced_metric_init_vec, reduced_metric_init);
54-
} else {
55-
reduced_metric_init = reduced_metric_target;
56-
}
45+
// Get energy
46+
LogLengthEnergy opt_energy(*cone_metric);
5747

5848
// Make default parameters
5949
auto proj_params = std::make_shared<ProjectionParameters>();
6050
auto opt_params = std::make_shared<OptimizationParameters>();
61-
opt_params->output_dir = output_dir;
62-
opt_params->num_iter = 500;
51+
//opt_params->output_dir = output_dir;
52+
opt_params->num_iter = 100;
6353
opt_params->min_ratio = 0;
6454
opt_params->max_grad_range = 10;
6555
opt_params->direction_choice = "lbfgs";
6656

6757
// Compute shear dual basis and the corresponding inner product matrix
6858
MatrixX shear_basis_matrix;
6959
std::vector<int> independent_edges;
70-
compute_shear_dual_basis(m, shear_basis_matrix, independent_edges);
60+
compute_shear_dual_basis(*cone_metric, shear_basis_matrix, independent_edges);
7161
//compute_shear_coordinate_basis(m, shear_basis_matrix, independent_edges);
7262

7363
// Compute the shear dual coordinates for this basis
7464
VectorX shear_basis_coords_init;
7565
VectorX scale_factors_init;
76-
compute_shear_basis_coordinates(m, reduced_metric_init, shear_basis_matrix, shear_basis_coords_init, scale_factors_init);
66+
compute_shear_basis_coordinates(*cone_metric, shear_basis_matrix, shear_basis_coords_init, scale_factors_init);
7767
spdlog::info("Initial coordinates are {}", shear_basis_coords_init);
7868

7969
// Optimize the metric
80-
PennerConeMetric cone_metric(m, reduced_metric_init);
8170
VectorX reduced_metric_coords;
82-
optimize_shear_basis_coordinates(cone_metric,
83-
reduced_metric_target,
84-
shear_basis_coords_init,
85-
scale_factors_init,
86-
shear_basis_matrix,
87-
reduced_metric_coords,
88-
proj_params,
89-
opt_params);
71+
optimize_shear_basis_coordinates(
72+
*cone_metric,
73+
opt_energy,
74+
shear_basis_matrix,
75+
proj_params,
76+
opt_params);
9077

9178
// Write the output
9279
std::string output_filename = join_path(output_dir, "reduced_metric_coords");

src/optimization/explicit_optimization.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ void compute_optimization_domain(
147147
constraint_domain_matrix.setFromTriplets(
148148
domain_triplet_list.begin(),
149149
domain_triplet_list.end());
150+
constraint_domain_matrix = m.change_metric_to_reduced_coordinates(constraint_domain_matrix.transpose()).transpose();
150151
SPDLOG_TRACE("Domain matrix is {}", constraint_domain_matrix);
151152

152153
// Build the codomain matrix
@@ -155,6 +156,7 @@ void compute_optimization_domain(
155156
constraint_codomain_matrix.setFromTriplets(
156157
codomain_triplet_list.begin(),
157158
codomain_triplet_list.end());
159+
constraint_codomain_matrix = m.change_metric_to_reduced_coordinates(constraint_codomain_matrix.transpose()).transpose();
158160
SPDLOG_TRACE("Codomain matrix is {}", constraint_codomain_matrix);
159161
}
160162

src/optimization/shear.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -240,21 +240,31 @@ compute_independent_to_full_edge_shear_matrix(
240240
int hki = m.n[hjk];
241241
int hil = m.n[hji];
242242
int hlj = m.n[hil];
243+
std::vector<int> positive_halfedges = {hjk, hil, m.opp[hjk], m.opp[hil]};
244+
std::vector<int> negative_halfedges = {hki, hlj, m.opp[hki], m.opp[hlj]};
243245

244246
// Add shear vector for the embedded edge
245-
tripletList.push_back(T(hjk, index, 1.0));
246-
tripletList.push_back(T(hki, index, -1.0));
247-
tripletList.push_back(T(hil, index, 1.0));
248-
tripletList.push_back(T(hlj, index, -1.0));
247+
for (int h : positive_halfedges)
248+
{
249+
tripletList.push_back(T(h, index, 1.0));
250+
}
251+
for (int h : negative_halfedges)
252+
{
253+
tripletList.push_back(T(h, index, -1.0));
254+
}
249255

250256
// Add shear vector for the reflected embedded edge
251257
// Note that the signs are inverted due to the inversion of the next relation
252258
if (m.R[hij] > 0)
253259
{
254-
tripletList.push_back(T(m.R[hjk], index, -1.0));
255-
tripletList.push_back(T(m.R[hki], index, 1.0));
256-
tripletList.push_back(T(m.R[hil], index, -1.0));
257-
tripletList.push_back(T(m.R[hlj], index, 1.0));
260+
for (int h : positive_halfedges)
261+
{
262+
tripletList.push_back(T(m.R[h], index, 1.0));
263+
}
264+
for (int h : negative_halfedges)
265+
{
266+
tripletList.push_back(T(m.R[h], index, -1.0));
267+
}
258268
}
259269
}
260270

0 commit comments

Comments
 (0)