Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,16 @@ 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})
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()
Expand All @@ -124,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")
Expand All @@ -136,15 +142,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)
2 changes: 1 addition & 1 deletion include/polyvec/curve-tracer/curve_constraints.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double, Eigen::VectorXd> f();

Expand Down
4 changes: 2 additions & 2 deletions include/polyvec/curve-tracer/spline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::vector<CornerFitPrototypePrimitive>> initial_fits[TANGENT_FIT_SAMPLES_COUNT];

//Initializes the fits for the fitting types up to FIT - 1 for all corners.
Expand Down
1 change: 1 addition & 0 deletions include/polyvec/geometry/raster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <polyvec/api.hpp>
#include "raster.inl"
1 change: 1 addition & 0 deletions include/polyvec/regularity/regularity_action.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion source/polyvec/curve-tracer/curve_constraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion source/polyvec/curve-tracer/curve_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions source/polyvec/curve-tracer/refinement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down
12 changes: 6 additions & 6 deletions source/polyvec/curve-tracer/spline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -566,7 +566,7 @@ void CurveSequenceFitter::solve(CurvePrimitiveSequence& seq, bool circular, int
solve(seq, circular, primitiveFrom, primitiveTo, allow_parallel_handling);
}

std::vector<bool> polyvec::get_important_or_axis_aligned_edges(const Eigen::Matrix2Xd& polygon, const polyfit::Regularity::RegularityInformation& regularity)
std::vector<bool> get_important_or_axis_aligned_edges(const Eigen::Matrix2Xd& polygon, const polyfit::Regularity::RegularityInformation& regularity)
{
std::vector<bool> edge_is_important(polygon.cols(), false);
for (auto& r : regularity.important_edges())
Expand All @@ -583,7 +583,7 @@ std::vector<bool> polyvec::get_important_or_axis_aligned_edges(const Eigen::Matr
return edge_is_important;
}

std::vector<double> polyvec::find_edge_angles_from_parallel(const Eigen::Matrix2Xd& polygon, const polyfit::Regularity::RegularityInformation& regularity)
std::vector<double> find_edge_angles_from_parallel(const Eigen::Matrix2Xd& polygon, const polyfit::Regularity::RegularityInformation& regularity)
{
struct EntryData
{
Expand Down Expand Up @@ -639,7 +639,7 @@ std::vector<double> 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<bool>& is_edge_important_or_axisaligned, const std::vector<double>& edge_angles, bool allow_parallel_handling)
{
Expand Down Expand Up @@ -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;
Comment on lines -1048 to -1049
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at least according to clang, 1==1 is executed first. I assume this wasn't the intention.

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);
Expand Down
8 changes: 4 additions & 4 deletions source/polyvec/polygon-tracer/boundary-graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
}

Expand All @@ -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);
Expand Down
26 changes: 13 additions & 13 deletions source/polyvec/regularity/continuations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -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
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion source/polyvec/regularity/regularity_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion source/polyvec/regularity/test_continuation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}

Expand Down