From 89a4209793f083233281ccbc932f3d519f71ca8e Mon Sep 17 00:00:00 2001 From: James Noeckel Date: Tue, 1 Sep 2020 00:24:17 -0700 Subject: [PATCH 1/3] fix compilation errors in clang --- CMakeLists.txt | 25 +++++++++++------- .../curve-tracer/curve_constraints.hpp | 2 +- include/polyvec/curve-tracer/spline.hpp | 4 +-- include/polyvec/geometry/raster.hpp | 1 + .../curve-tracer/curve_constraints.cpp | 2 +- source/polyvec/curve-tracer/curve_solver.cpp | 2 +- .../polyvec/polygon-tracer/boundary-graph.cpp | 6 ++--- source/polyvec/regularity/continuations.cpp | 26 +++++++++---------- .../polyvec/regularity/regularity_action.cpp | 2 +- 9 files changed, 39 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f8e395..d039a7b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,11 +103,12 @@ elseif((${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") OR ) find_path( - Cairo_INCLUDE_DIRS - cairo/cairo.h + Cairo_INCLUDE_DIRS + cairo.h HINTS "/usr/include" "/usr/local/include" + "/usr/local/include/cairo" ) target_include_directories(polyvec-lib SYSTEM PUBLIC ${Cairo_INCLUDE_DIRS}) @@ -136,15 +137,21 @@ if (MSVC) target_compile_definitions(polyvec-lib PUBLIC "-D_CRT_SECURE_NO_WARNINGS") endif() +if (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC") # more header-only dependencies -target_include_directories(polyvec-lib SYSTEM PUBLIC - # Used to list files in directory - "${CMAKE_SOURCE_DIR}/dependencies/dirent" - - # Used to read raster images - "${CMAKE_SOURCE_DIR}/dependencies/stb" -) + target_include_directories(polyvec-lib SYSTEM PUBLIC + # Used to list files in directory + "${CMAKE_SOURCE_DIR}/dependencies/dirent" + # Used to read raster images + "${CMAKE_SOURCE_DIR}/dependencies/stb" + ) +else() + target_include_directories(polyvec-lib SYSTEM PUBLIC + # Used to read raster images + "${CMAKE_SOURCE_DIR}/dependencies/stb" + ) +endif() # Building executables depending on it add_subdirectory(apps) diff --git a/include/polyvec/curve-tracer/curve_constraints.hpp b/include/polyvec/curve-tracer/curve_constraints.hpp index 1454e01..3f5ce0f 100644 --- a/include/polyvec/curve-tracer/curve_constraints.hpp +++ b/include/polyvec/curve-tracer/curve_constraints.hpp @@ -9,7 +9,7 @@ NAMESPACE_BEGIN(polyvec) class GlobFitConstraint_LineDirection : public GlobFitConstraint { public: - GlobFitConstraint_LineDirection(GlobFitLineParametrization* line, GlobFitCurveParametrization::ParameterAddress& target); + GlobFitConstraint_LineDirection(GlobFitLineParametrization* line, const GlobFitCurveParametrization::ParameterAddress& target); std::pair f(); diff --git a/include/polyvec/curve-tracer/spline.hpp b/include/polyvec/curve-tracer/spline.hpp index 816e09d..4627031 100644 --- a/include/polyvec/curve-tracer/spline.hpp +++ b/include/polyvec/curve-tracer/spline.hpp @@ -189,9 +189,9 @@ public : }; // Returns if the edge has a tangent we want to preserve (i.e., axis-aligned of 45°) - bool polyvec::CurveSequenceFitter::edge_has_important_tangent(int i_edge) const; + bool edge_has_important_tangent(int i_edge) const; - //Prototypes for fits for each polygon corner. Each corner is represented by a number of individual curves. + //Prototypes for fits for each polygon corner. Each corner is represented by a number curves. std::vector> initial_fits[TANGENT_FIT_SAMPLES_COUNT]; //Initializes the fits for the fitting types up to FIT - 1 for all corners. diff --git a/include/polyvec/geometry/raster.hpp b/include/polyvec/geometry/raster.hpp index 9569a35..39c09cc 100644 --- a/include/polyvec/geometry/raster.hpp +++ b/include/polyvec/geometry/raster.hpp @@ -55,4 +55,5 @@ PV_INLINE bool are_points_axis_aligned(const vec2& p0, const vec2& p1, const dou NAMESPACE_END(GeomRaster) NAMESPACE_END(polyfit) +#include #include "raster.inl" diff --git a/source/polyvec/curve-tracer/curve_constraints.cpp b/source/polyvec/curve-tracer/curve_constraints.cpp index 6402855..25bde84 100644 --- a/source/polyvec/curve-tracer/curve_constraints.cpp +++ b/source/polyvec/curve-tracer/curve_constraints.cpp @@ -2,7 +2,7 @@ using namespace polyvec; -GlobFitConstraint_LineDirection::GlobFitConstraint_LineDirection(GlobFitLineParametrization* line, GlobFitCurveParametrization::ParameterAddress& target) +GlobFitConstraint_LineDirection::GlobFitConstraint_LineDirection(GlobFitLineParametrization* line, const GlobFitCurveParametrization::ParameterAddress& target) : line(line) { this->source_params.push_back(GlobFitCurveParametrization::ParameterAddress(line, 0)); diff --git a/source/polyvec/curve-tracer/curve_solver.cpp b/source/polyvec/curve-tracer/curve_solver.cpp index c5847a3..aefc941 100644 --- a/source/polyvec/curve-tracer/curve_solver.cpp +++ b/source/polyvec/curve-tracer/curve_solver.cpp @@ -600,7 +600,7 @@ void GlobFitter::report_errors(FILE* error_file) { Eigen::MatrixXd jac; obj->compute_objective_and_jacobian(res, jac); auto type = globfitobjectivetype_as_string(obj->get_type()); - fprintf(error_file, "objective: %s\n", type); + fprintf(error_file, "objective: %s\n", type.c_str()); fprintf(error_file, "values: "); for (Eigen::Index k = 0; k < res.size(); ++k) { diff --git a/source/polyvec/polygon-tracer/boundary-graph.cpp b/source/polyvec/polygon-tracer/boundary-graph.cpp index efdb17c..a5663de 100644 --- a/source/polyvec/polygon-tracer/boundary-graph.cpp +++ b/source/polyvec/polygon-tracer/boundary-graph.cpp @@ -1141,7 +1141,7 @@ bool trace_symmetric(const mat2x& R, bool fit_failed = false; if (Vsym.empty()) { - PF_VERBOSE_F("no path found"); + PF_VERBOSE_S("no path found"); fit_failed = true; } else { @@ -1150,7 +1150,7 @@ bool trace_symmetric(const mat2x& R, const int Vsym_inflections = AngleUtils::count_inflections(Psym, circular); if (Vsym_inflections > V_inflections) { - PF_VERBOSE_F("bad symmetric fit, it would introduce an inflection"); + PF_VERBOSE_S("bad symmetric fit, it would introduce an inflection"); fit_failed = true; } @@ -1159,7 +1159,7 @@ bool trace_symmetric(const mat2x& R, // good, applying the changes if (!fit_failed) { - PF_VERBOSE_F("symmetric fit found, applying changes"); + PF_VERBOSE_S("symmetric fit found, applying changes"); E = std::move(Esym); N = std::move(Nsym); V = std::move(Vsym); diff --git a/source/polyvec/regularity/continuations.cpp b/source/polyvec/regularity/continuations.cpp index 279bdc0..cdfc514 100644 --- a/source/polyvec/regularity/continuations.cpp +++ b/source/polyvec/regularity/continuations.cpp @@ -260,25 +260,25 @@ bool is_continuation_valid( // Test separation angle if (std::min(r.angle_separation_0, r.angle_separation_1) < Options::get()->regularity_continuation_angle_separation_max - PF_EPS) { - PF_VERBOSE_F("Fails angle separation"); + PF_VERBOSE_S("Fails angle separation"); return false; } // Testing the continuation angle if (r.angle_continuation_difference_0 < -PF_RAD(5) || r.angle_continuation_difference_1 < -PF_RAD(5)) { - PF_VERBOSE_F("Fails continuation difference"); + PF_VERBOSE_S("Fails continuation difference"); return false; } if ((r.angle_continuation_0 > PF_EPS && r.angle_continuation_0 < Options::get()->regularity_continuation_angle_max) || (r.angle_continuation_1 > PF_EPS && r.angle_continuation_1 < Options::get()->regularity_continuation_angle_max)) { - PF_VERBOSE_F("Fails continuation angle"); + PF_VERBOSE_S("Fails continuation angle"); return false; } #if NEW_ANGLE_CRITERION if (r.angle_polygon_0 < M_PI_4 - PF_EPS && r.angle_polygon_1 < M_PI_4 - PF_EPS) { - PF_VERBOSE_F("Fails polygon angle"); + PF_VERBOSE_S("Fails polygon angle"); return false; } @@ -295,24 +295,24 @@ bool is_continuation_valid( #else if (r.angle_polygon_0 < M_PI_4 + PF_EPS && r.angle_polygon_1 < M_PI_4 + PF_EPS) { - PF_VERBOSE_F("Fails polygon angle"); + PF_VERBOSE_S("Fails polygon angle"); return false; } #endif // Testing the flat polygon angle if (std::min(r.angle_polygon_0, r.angle_polygon_1) < Options::get()->regularity_continuation_angle_polygon_max) { - PF_VERBOSE_F("Fails polygon angle 2"); + PF_VERBOSE_S("Fails polygon angle 2"); return false; } // Testing the intersection angle if (r.intersection_angle < Options::get()->regularity_continuation_angle_intersection_max) { - PF_VERBOSE_F("Fails intersection separation"); + PF_VERBOSE_S("Fails intersection separation"); return false; } - PF_VERBOSE_F("Passes"); + PF_VERBOSE_S("Passes"); return true; } @@ -373,13 +373,13 @@ void Regularity::pick_continuations( if (vertex_movement[r.v0] != INVALID && vertex_movement[r.v0] != r.move_v0) { - PF_VERBOSE_F("Already moved vertex"); + PF_VERBOSE_S("Already moved vertex"); continue; //We already moved v0 differently } if (vertex_movement[r.v1] != INVALID && vertex_movement[r.v1] != r.move_v1) { - PF_VERBOSE_F("Already moved vertex"); + PF_VERBOSE_S("Already moved vertex"); continue; //We already moved v1 differently } @@ -388,13 +388,13 @@ void Regularity::pick_continuations( if (target_v0 == CircularAt(V, r.v0 - 1) || target_v0 == CircularAt(V, r.v0 + 1)) { - PF_VERBOSE_F("Vertex V0 moves onto other vertex."); + PF_VERBOSE_S("Vertex V0 moves onto other vertex."); continue; } if (target_v1 == CircularAt(V, r.v1 - 1) || target_v1 == CircularAt(V, r.v1 + 1)) { - PF_VERBOSE_F("Vertex V1 moves onto other vertex."); + PF_VERBOSE_S("Vertex V1 moves onto other vertex."); continue; } @@ -403,7 +403,7 @@ void Regularity::pick_continuations( if (cont0 || cont1) { - PF_VERBOSE_F("One of the edges already has a continuation."); + PF_VERBOSE_S("One of the edges already has a continuation."); continue; } diff --git a/source/polyvec/regularity/regularity_action.cpp b/source/polyvec/regularity/regularity_action.cpp index 8d56ead..5fc5cc9 100644 --- a/source/polyvec/regularity/regularity_action.cpp +++ b/source/polyvec/regularity/regularity_action.cpp @@ -79,7 +79,7 @@ void PolygonTracer::apply_regularities( // In case of failure, restoring the older connectivty if (fail) { - PF_VERBOSE_F("failed to apply regularity"); + PF_VERBOSE_S("failed to apply regularity"); current = old; E.insert(E.end(), E_rm.begin(), E_rm.end()); PF_VERBOSE_F("restore older path and insert %d edges", E_rm.size()); From e3a7a81032f620fc89ae4b2715359246746010da Mon Sep 17 00:00:00 2001 From: James Noeckel Date: Tue, 1 Sep 2020 16:27:03 -0700 Subject: [PATCH 2/3] fixed bug in bitwise operator precedence, suppress some warnings --- include/polyvec/regularity/regularity_action.hpp | 1 + source/polyvec/curve-tracer/refinement.cpp | 12 ++++++------ source/polyvec/curve-tracer/spline.cpp | 12 ++++++------ source/polyvec/polygon-tracer/boundary-graph.cpp | 2 +- source/polyvec/regularity/test_continuation.cpp | 2 +- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/include/polyvec/regularity/regularity_action.hpp b/include/polyvec/regularity/regularity_action.hpp index bde8c5d..2a76423 100644 --- a/include/polyvec/regularity/regularity_action.hpp +++ b/include/polyvec/regularity/regularity_action.hpp @@ -17,6 +17,7 @@ class RegularityAction virtual bool can_introduce_degenerate_edges() const = 0; virtual bool can_introduce_inflections() const { return false; } virtual bool is_polygon_acceptable(const mat2x& raster, const vecXi& polygon_old, const vecXi& polygon_new, bool circular) const = 0; + virtual ~RegularityAction() = default; }; // Applies regularities by modifying the edge set of a boundary graph. If a regularity diff --git a/source/polyvec/curve-tracer/refinement.cpp b/source/polyvec/curve-tracer/refinement.cpp index 2c3ef89..050dfe1 100644 --- a/source/polyvec/curve-tracer/refinement.cpp +++ b/source/polyvec/curve-tracer/refinement.cpp @@ -64,8 +64,8 @@ int collapse_asymmetric_constant_steps( continue; } - fprintf(stderr, "Collapse %d(%d) %d(%d)\n", i, vi, Circular(P, i + 1), vj); - fprintf(stderr, "dist %f %\n ", (pi - pj)(0), (pi - pj)(1)); + fprintf(stderr, "Collapse %zu(%zu) %zu(%zu)\n", i, vi, Circular(P, i + 1), vj); + fprintf(stderr, "dist %f %f\n ", (pi - pj)(0), (pi - pj)(1)); Index i_opp = -1, j_opp = -1; int i_opp_sym_size = 0, j_opp_sym_size = 0; @@ -110,8 +110,8 @@ int collapse_asymmetric_constant_steps( const int vdist_prev = CircularDist(B, PathUtils::next_transition_vertex(C, vi, -1, circular), vi); const int vdist_next = CircularDist(B, vj, PathUtils::next_transition_vertex(C, vj, +1, circular)); - printf("dist to %d : %d\n", vi, vdist_prev); - printf("dist from %d : %d\n", vj, vdist_next); + printf("dist to %zu : %d\n", vi, vdist_prev); + printf("dist from %zu : %d\n", vj, vdist_next); Index vnew, vnew_opp = -1; if (vdist_prev > vdist_next) { @@ -130,13 +130,13 @@ int collapse_asymmetric_constant_steps( } PF_ASSERT(vnew != -1); - printf("relocating %d: %d -> %d\n", i, P(i), vnew); + printf("relocating %zu: %d -> %zu\n", i, P(i), vnew); P(i) = vnew; tangent_fits[i] = TANGENT_FIT_CONSTANT; if (is_opp_valid) { PF_ASSERT(vnew_opp != -1); - printf("relocating %d: %d -> %d\n", i_opp, P(i_opp), vnew_opp); + printf("relocating %zu: %d -> %zu\n", i_opp, P(i_opp), vnew_opp); P(i_opp) = vnew_opp; tangent_fits[i_opp] = TANGENT_FIT_CONSTANT; } diff --git a/source/polyvec/curve-tracer/spline.cpp b/source/polyvec/curve-tracer/spline.cpp index a9b6ae6..b0ae8fc 100644 --- a/source/polyvec/curve-tracer/spline.cpp +++ b/source/polyvec/curve-tracer/spline.cpp @@ -87,7 +87,7 @@ bool polyvec::CurveSequenceFitter::edge_has_important_tangent(int i_edge) const if (std::abs(d.x()) < PF_EPS || std::abs(d.y()) < PF_EPS) return true; - // 45° + // 45� if (std::abs(std::abs(d.x()) - std::abs(d.y())) < PF_EPS) return true; @@ -566,7 +566,7 @@ void CurveSequenceFitter::solve(CurvePrimitiveSequence& seq, bool circular, int solve(seq, circular, primitiveFrom, primitiveTo, allow_parallel_handling); } -std::vector polyvec::get_important_or_axis_aligned_edges(const Eigen::Matrix2Xd& polygon, const polyfit::Regularity::RegularityInformation& regularity) +std::vector get_important_or_axis_aligned_edges(const Eigen::Matrix2Xd& polygon, const polyfit::Regularity::RegularityInformation& regularity) { std::vector edge_is_important(polygon.cols(), false); for (auto& r : regularity.important_edges()) @@ -583,7 +583,7 @@ std::vector polyvec::get_important_or_axis_aligned_edges(const Eigen::Matr return edge_is_important; } -std::vector polyvec::find_edge_angles_from_parallel(const Eigen::Matrix2Xd& polygon, const polyfit::Regularity::RegularityInformation& regularity) +std::vector find_edge_angles_from_parallel(const Eigen::Matrix2Xd& polygon, const polyfit::Regularity::RegularityInformation& regularity) { struct EntryData { @@ -639,7 +639,7 @@ std::vector polyvec::find_edge_angles_from_parallel(const Eigen::Matrix2 return edge_angles; } -void polyvec::addCurveSequenceToFitter +void addCurveSequenceToFitter (polyvec::CurveFitter& curve_fitter, CurvePrimitiveSequence& seq, bool circular, int primitiveFrom, int primitiveTo, int polygon_corners, const std::vector& is_edge_important_or_axisaligned, const std::vector& edge_angles, bool allow_parallel_handling) { @@ -1045,8 +1045,8 @@ void CurveSequenceFitter::classify_evolutionary_simple( FittingAttempt fits[3]; for (int j = 0; j < 3; ++j) { - bool fixFront = j & 1 == 1; - bool fixEnd = (j >> 1) & 1 == 1; + bool fixFront = (j & 1) == 1; + bool fixEnd = ((j >> 1) & 1) == 1; fits[j].primitive_seq = all_with_type(TangentFitType(type), true, fixFront, fixEnd); fits[j].measure_sequence(polygon); diff --git a/source/polyvec/polygon-tracer/boundary-graph.cpp b/source/polyvec/polygon-tracer/boundary-graph.cpp index a5663de..a6ac028 100644 --- a/source/polyvec/polygon-tracer/boundary-graph.cpp +++ b/source/polyvec/polygon-tracer/boundary-graph.cpp @@ -492,7 +492,7 @@ void connect_valid_edges( edge.flags |= ErrorMetrics::EDGE_LAST_IN_PATH; } - if (circular || i > 0 && i < P.cols() - 2) { + if (circular || (i > 0 && i < P.cols() - 2)) { const vec2 p0 = CircularAt(P, i - 1); const vec2 p1 = CircularAt(P, i); const vec2 p2 = CircularAt(P, i + 1); diff --git a/source/polyvec/regularity/test_continuation.cpp b/source/polyvec/regularity/test_continuation.cpp index 45c2271..8786153 100644 --- a/source/polyvec/regularity/test_continuation.cpp +++ b/source/polyvec/regularity/test_continuation.cpp @@ -198,7 +198,7 @@ void filter_same_side_continuations_greedy( const bool same_side_01 = R[i].v0 == R_unique[j].v1 && R[i].v0_prev == R_unique[j].v1_next; const bool same_side_10 = R[i].v1 == R_unique[j].v0 && R[i].v1_next == R_unique[j].v0_prev; const bool same_side_11 = R[i].v1 == R_unique[j].v1 && R[i].v1_next == R_unique[j].v1_next; - discard = (same_polygon_0 && (same_side_00 || same_side_01) || + discard = ((same_polygon_0 && (same_side_00 || same_side_01)) || (same_polygon_1 && (same_side_10 || same_side_11))); } From 51ddc6365a794db1678459140658211cb78f65b1 Mon Sep 17 00:00:00 2001 From: James Noeckel Date: Tue, 1 Sep 2020 17:36:32 -0700 Subject: [PATCH 3/3] use system Eigen on linux and mac --- CMakeLists.txt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d039a7b..ba993fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,7 +112,7 @@ elseif((${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") OR ) target_include_directories(polyvec-lib SYSTEM PUBLIC ${Cairo_INCLUDE_DIRS}) - target_link_libraries(polyvec-lib PUBLIC ${Cairo_LIBRARIES}) + target_link_libraries(polyvec-lib PUBLIC Eigen3::Eigen ${Cairo_LIBRARIES}) else() message(FATAL_ERROR "Unrecognized compiler ${CMAKE_CXX_COMPILER_ID}") endif() @@ -125,9 +125,14 @@ target_include_directories(polyvec-lib SYSTEM PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/random-forest/include" ) -# Eigen3.3 + -# Todo: provide a FindEigen3.cmake -target_include_directories(polyvec-lib SYSTEM PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/eigen") +if (WIN32) + # Eigen3.3 + + # Todo: provide a FindEigen3.cmake + target_include_directories(polyvec-lib SYSTEM PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/eigen") +else() + find_package( EIGEN3 3.3 REQUIRED NO_MODULE ) + target_include_directories( polyvec-lib SYSTEM PUBLIC ${EIGEN3_INCLUDE_DIRS} ) +endif() if (WIN32) target_compile_definitions(polyvec-lib PUBLIC "-D_ENABLE_EXTENDED_ALIGNED_STORAGE")