Skip to content

Commit df14b87

Browse files
committed
Fixed mpfr support
1 parent 6cf2e82 commit df14b87

File tree

11 files changed

+72
-36
lines changed

11 files changed

+72
-36
lines changed

src/optimization/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ target_link_libraries(MetricOptimizationLib PUBLIC
3131
igl::predicates
3232
spdlog::spdlog
3333
pybind11::module
34-
${Boost_FILESYSTEM_LIBRARY}
35-
${Boost_SYSTEM_LIBRARY}
34+
${MPFR_LIBRARIES}
3635
)
3736
target_compile_definitions(MetricOptimizationLib PUBLIC
3837
SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_DEBUG

src/optimization/common.hh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,34 @@ convert_eigen_to_std_vector(const VectorX& vector_eigen,
501501
}
502502
}
503503

504+
/// Convert vector of scalars to doubles
505+
inline Eigen::Matrix<double, Eigen::Dynamic, 1>
506+
convert_scalar_to_double_vector(const VectorX& vector_scalar)
507+
{
508+
int num_entries = vector_scalar.size();
509+
Eigen::Matrix<double, Eigen::Dynamic, 1> vector_double(num_entries);
510+
for (int i = 0; i < num_entries; ++i)
511+
{
512+
vector_double[i] = (double) (vector_scalar[i]);
513+
}
514+
515+
return vector_double;
516+
}
517+
518+
/// Convert vector of scalars to doubles
519+
inline std::vector<Eigen::Matrix<double, Eigen::Dynamic, 1>>
520+
convert_scalar_to_double_vector(const std::vector<VectorX>& vector_scalar)
521+
{
522+
int num_entries = vector_scalar.size();
523+
std::vector<Eigen::Matrix<double, Eigen::Dynamic, 1>> vector_double(num_entries);
524+
for (int i = 0; i < num_entries; ++i)
525+
{
526+
vector_double[i] = convert_scalar_to_double_vector(vector_scalar[i]);
527+
}
528+
529+
return vector_double;
530+
}
531+
504532
/// *****************
505533
/// Vector Generation
506534
/// *****************

src/optimization/energies.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ root_mean_square_error(const VectorX &x, const VectorX &x0)
577577
error += diff * diff;
578578
}
579579

580-
return std::sqrt(error / num_var);
580+
return sqrt(error / num_var);
581581
}
582582

583583
Scalar
@@ -596,7 +596,7 @@ relative_root_mean_square_error(const VectorX &x, const VectorX &x0)
596596
denom += (x0[i] * x0[i]);
597597
}
598598

599-
return std::sqrt(error / (num_var * denom));
599+
return sqrt(error / (num_var * denom));
600600
}
601601

602602
Scalar
@@ -613,7 +613,7 @@ root_mean_square_relative_error(const VectorX &x, const VectorX &x0)
613613
error += (rel_err * rel_err);
614614
}
615615

616-
return std::sqrt(error / num_var);
616+
return sqrt(error / num_var);
617617

618618
}
619619

src/optimization/explicit_optimization.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include "nonlinear_optimization.hh"
99
#include "projection.hh"
1010
#include "shear.hh"
11+
#include <Eigen/SparseLU>
12+
#include <Eigen/SparseQR>
1113

1214
/// FIXME Do cleaning pass
1315

@@ -279,7 +281,9 @@ bool compute_domain_coordinate_energy_with_gradient(
279281
constraint_codomain_matrix.transpose() * constraint_penner_jacobian.transpose();
280282

281283
// Solve for the component of the gradient corresponding to the implicit metric coordinates
282-
Eigen::SparseLU<Eigen::SparseMatrix<Scalar>> solver;
284+
//Eigen::SparseLU<MatrixX> solver;
285+
//Eigen::SparseLU<Eigen::SparseMatrix<Scalar>, Eigen::COLAMDOrdering<int>> solver;
286+
Eigen::SparseQR<Eigen::SparseMatrix<Scalar>, Eigen::COLAMDOrdering<int>> solver;
283287
solver.compute(constraint_codomain_jacobian);
284288
VectorX energy_implicit_gradient =
285289
-constraint_domain_jacobian * solver.solve(energy_codomain_gradient);

src/optimization/implicit_optimization.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "logging.hh"
1010
#include "nonlinear_optimization.hh"
1111
#include "projection.hh"
12+
#include <Eigen/SparseQR>
1213

1314
/// FIXME Do cleaning pass
1415

@@ -347,7 +348,9 @@ void compute_projected_newton_descent_direction(
347348
// Solve for the optimal descent direction
348349
igl::Timer timer;
349350
timer.start();
350-
Eigen::SparseLU<Eigen::SparseMatrix<Scalar>> solver;
351+
// TODO Make solver a global variable or function so easy to replace
352+
//Eigen::SparseLU<Eigen::SparseMatrix<Scalar>> solver;
353+
Eigen::SparseQR<Eigen::SparseMatrix<Scalar>, Eigen::COLAMDOrdering<int>> solver;
351354
solver.compute(hessian_lagrangian);
352355
VectorX solution = solver.solve(rhs);
353356
double time = timer.getElapsedTime();

src/optimization/layout.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ bool check_uv(
140140
}
141141

142142
// Check length consistency
143-
double uv_length_error = compute_uv_length_error(F, uv, F_uv);
143+
Scalar uv_length_error = compute_uv_length_error(F, uv, F_uv);
144144
if (!float_equal(uv_length_error, 0.0)) {
145145
spdlog::warn("Inconsistent uv length error {} across edges", uv_length_error);
146146
}

src/optimization/refinement.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,24 +191,24 @@ RefinementMesh::get_face_iterator(Index face_index) const
191191
return FaceIterator(*this, face_index);
192192
}
193193

194-
VectorX
194+
Eigen::VectorXd
195195
RefinementMesh::get_vertex(
196196
RefinementMesh::Index vertex_index
197197
) const {
198-
return m_V.row(vertex_index);
198+
return m_V.row(vertex_index).transpose();
199199
}
200200

201-
VectorX
201+
Eigen::VectorXd
202202
RefinementMesh::get_uv_vertex(
203203
RefinementMesh::Index vertex_index
204204
) const {
205-
return m_uv.row(vertex_index);
205+
return m_uv.row(vertex_index).transpose();
206206
}
207207

208208
void
209209
RefinementMesh::get_face_vertices(
210210
RefinementMesh::Index face_index,
211-
std::vector<VectorX>& vertices
211+
std::vector<Eigen::VectorXd>& vertices
212212
) const {
213213
vertices.clear();
214214
for (auto iter = get_face_iterator(face_index); !iter.done(); ++iter)
@@ -222,7 +222,7 @@ RefinementMesh::get_face_vertices(
222222
void
223223
RefinementMesh::get_face_uv_vertices(
224224
RefinementMesh::Index face_index,
225-
std::vector<VectorX>& uv_vertices
225+
std::vector<Eigen::VectorXd>& uv_vertices
226226
) const {
227227
uv_vertices.clear();
228228
for (auto iter = get_face_iterator(face_index); !iter.done(); ++iter)
@@ -744,7 +744,7 @@ RefinementMesh::refine_mesh()
744744
// Skip boundary loops
745745
if (is_bnd_loop[fijk]) continue;
746746

747-
std::array<VectorX, 3> triangle;
747+
std::array<Eigen::VectorXd, 3> triangle;
748748
Index hij = h[fijk];
749749
for (int l = 0; l < 3; ++l)
750750
{
@@ -1115,7 +1115,7 @@ RefinementMesh::is_self_overlapping_face(
11151115
if (is_bnd_loop[face_index]) return true;
11161116

11171117
// Get vertices of the face
1118-
std::vector<VectorX> uv_vertices, vertices;
1118+
std::vector<Eigen::VectorXd> uv_vertices, vertices;
11191119
get_face_uv_vertices(face_index, uv_vertices);
11201120
get_face_vertices(face_index, vertices);
11211121

@@ -1151,8 +1151,8 @@ RefinementMesh::triangulate_face(
11511151
// Get uv vertices of the face
11521152
std::vector<int> vertex_indices;
11531153
std::vector<int> uv_vertex_indices;
1154-
std::vector<VectorX> vertices;
1155-
std::vector<VectorX> uv_vertices;
1154+
std::vector<Eigen::VectorXd> vertices;
1155+
std::vector<Eigen::VectorXd> uv_vertices;
11561156
for (auto iter = get_face_iterator(face_index); !iter.done(); ++iter)
11571157
{
11581158
Index hij = *iter;

src/optimization/refinement.hh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public:
172172
///
173173
/// @param[in] vertex_index: index of the vertex in the mesh
174174
/// @return vertex position
175-
VectorX
175+
Eigen::VectorXd
176176
get_vertex(
177177
Index vertex_index
178178
) const;
@@ -181,7 +181,7 @@ public:
181181
///
182182
/// @param[in] vertex_index: index of the vertex in the mesh
183183
/// @return parametric domain coordinates of the vertex
184-
VectorX
184+
Eigen::VectorXd
185185
get_uv_vertex(
186186
Index vertex_index
187187
) const;
@@ -193,7 +193,7 @@ public:
193193
void
194194
get_face_vertices(
195195
Index face_index,
196-
std::vector<VectorX>& vertices
196+
std::vector<Eigen::VectorXd>& vertices
197197
) const;
198198

199199
/// Get the parametric domain coordinates of the vertices of a face
@@ -203,7 +203,7 @@ public:
203203
void
204204
get_face_uv_vertices(
205205
Index face_index,
206-
std::vector<VectorX>& uv_vertices
206+
std::vector<Eigen::VectorXd>& uv_vertices
207207
) const;
208208

209209
/// Clear the data of the mesh

src/optimization/translation.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "reparametrization.hh"
66
#include "shear.hh"
77
#include <Eigen/SparseLU>
8+
#include <Eigen/SparseQR>
89

910
/// FIXME Do cleaning pass
1011

@@ -132,7 +133,8 @@ compute_as_symmetric_as_possible_translations(
132133
lagrangian_matrix.cols(),
133134
right_hand_side.size()
134135
);
135-
Eigen::SparseLU<Eigen::SparseMatrix<Scalar>> solver;
136+
//Eigen::SparseLU<Eigen::SparseMatrix<Scalar>, Eigen::COLAMDOrdering<int>> solver;
137+
Eigen::SparseQR<Eigen::SparseMatrix<Scalar>, Eigen::COLAMDOrdering<int>> solver;
136138
solver.compute(lagrangian_matrix);
137139
VectorX lagrangian_solution = solver.solve(-right_hand_side);
138140

src/optimization/triangulation.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace CurvatureMetric {
2323

2424
Scalar
2525
compute_face_area(
26-
const std::array<VectorX, 3>& vertices
26+
const std::array<Eigen::VectorXd, 3>& vertices
2727
) {
2828
// Get edge lengths for triangle
2929
Scalar li = (vertices[1] - vertices[0]).norm();
@@ -36,7 +36,7 @@ compute_face_area(
3636

3737
bool
3838
is_inverted_triangle(
39-
const std::array<VectorX, 3>& vertices
39+
const std::array<Eigen::VectorXd, 3>& vertices
4040
) {
4141
// Build matrix of triangle homogenous coordinates
4242
Eigen::Matrix<Scalar, 3, 3> tri_homogenous_coords;
@@ -45,15 +45,15 @@ is_inverted_triangle(
4545
tri_homogenous_coords.col(2) << vertices[2][0], vertices[2][1], 1.0;
4646

4747
// Triangle is flipped iff the determinant is negative
48-
double det = tri_homogenous_coords.determinant();
48+
Scalar det = tri_homogenous_coords.determinant();
4949
return (det < 0.0);
5050
}
5151

5252

5353
bool
5454
is_self_overlapping_polygon(
55-
const std::vector<VectorX>& uv_vertices,
56-
const std::vector<VectorX>& vertices,
55+
const std::vector<Eigen::VectorXd>& uv_vertices,
56+
const std::vector<Eigen::VectorXd>& vertices,
5757
std::vector<std::vector<bool>>& is_self_overlapping_subpolygon,
5858
std::vector<std::vector<int>>& splitting_vertices,
5959
std::vector<std::vector<Scalar>>& min_face_areas
@@ -108,8 +108,8 @@ is_self_overlapping_polygon(
108108
for (int k = (i + 1) % face_size; k != j; k = (k + 1) % face_size)
109109
{
110110
// Check if triangle T_ikj is positively oriented
111-
std::array<VectorX, 3> uv_triangle = { uv_vertices[i], uv_vertices[k], uv_vertices[j] };
112-
std::array<VectorX, 3> triangle = { vertices[i], vertices[k], vertices[j] };
111+
std::array<Eigen::VectorXd, 3> uv_triangle = { uv_vertices[i], uv_vertices[k], uv_vertices[j] };
112+
std::array<Eigen::VectorXd, 3> triangle = { vertices[i], vertices[k], vertices[j] };
113113
if (is_inverted_triangle(uv_triangle)) continue;
114114

115115
// Check if the two subpolygons (i, k) and (k, j) are self overlapping
@@ -266,8 +266,8 @@ triangulate_self_overlapping_polygon(
266266
// Helper function to view the triangulated face
267267
void
268268
view_triangulation(
269-
const std::vector<VectorX>& uv_vertices,
270-
const std::vector<VectorX>& vertices,
269+
const std::vector<Eigen::VectorXd>& uv_vertices,
270+
const std::vector<Eigen::VectorXd>& vertices,
271271
const std::vector<std::vector<bool>>& is_self_overlapping_subpolygon,
272272
const std::vector<std::vector<int>>& splitting_vertices,
273273
const std::vector<std::vector<Scalar>>& min_face_areas,

0 commit comments

Comments
 (0)