mirror of
https://github.com/QIDITECH/QIDISlicer.git
synced 2026-01-31 07:58:43 +03:00
update test
This commit is contained in:
@@ -1,21 +1,17 @@
|
||||
#include <catch2/catch.hpp>
|
||||
#include <test_utils.hpp>
|
||||
|
||||
#include <libslic3r/Polygon.hpp>
|
||||
#include <libslic3r/Polyline.hpp>
|
||||
#include <libslic3r/EdgeGrid.hpp>
|
||||
#include <libslic3r/Geometry.hpp>
|
||||
#include "libslic3r/Geometry/VoronoiUtilsCgal.hpp"
|
||||
|
||||
#include <libslic3r/Geometry/VoronoiOffset.hpp>
|
||||
#include <libslic3r/Geometry/VoronoiVisualUtils.hpp>
|
||||
|
||||
#include <numeric>
|
||||
|
||||
// #define VORONOI_DEBUG_OUT
|
||||
//#define VORONOI_DEBUG_OUT
|
||||
|
||||
#ifdef VORONOI_DEBUG_OUT
|
||||
#include <libslic3r/VoronoiVisualUtils.hpp>
|
||||
#include <libslic3r/Geometry/VoronoiVisualUtils.hpp>
|
||||
#include <libslic3r/Utils.hpp>
|
||||
#endif
|
||||
|
||||
using boost::polygon::voronoi_builder;
|
||||
@@ -340,7 +336,7 @@ TEST_CASE("Voronoi division by zero 12903", "[Voronoi]")
|
||||
// Funny sample from a dental industry?
|
||||
// Vojtech confirms this test fails and rightly so, because the input data contain self intersections.
|
||||
// This test is suppressed.
|
||||
TEST_CASE("Voronoi NaN coordinates 12139", "[Voronoi][!hide][!mayfail]")
|
||||
TEST_CASE("Voronoi NaN coordinates 12139", "[Voronoi]")
|
||||
{
|
||||
Lines lines = {
|
||||
{ { 260500,1564400 }, { 261040,1562960 } },
|
||||
@@ -1924,23 +1920,6 @@ TEST_CASE("Voronoi skeleton", "[VoronoiSkeleton]")
|
||||
REQUIRE(! skeleton_edges.empty());
|
||||
}
|
||||
|
||||
// Simple detection with complexity N^2 if there is any point in the input polygons that doesn't have Voronoi vertex.
|
||||
[[maybe_unused]] static bool has_missing_voronoi_vertices(const Polygons &polygons, const VD &vd)
|
||||
{
|
||||
auto are_equal = [](const VD::vertex_type v, const Point &p) { return (Vec2d(v.x(), v.y()) - p.cast<double>()).norm() <= SCALED_EPSILON; };
|
||||
|
||||
Points poly_points = to_points(polygons);
|
||||
std::vector<bool> found_vertices(poly_points.size());
|
||||
for (const Point &point : poly_points)
|
||||
for (const auto &vertex : vd.vertices())
|
||||
if (are_equal(vertex, point)) {
|
||||
found_vertices[&point - &poly_points.front()] = true;
|
||||
break;
|
||||
}
|
||||
|
||||
return std::find(found_vertices.begin(), found_vertices.end(), false) != found_vertices.end();
|
||||
}
|
||||
|
||||
// This case is composed of one square polygon, and one of the edges is divided into two parts by a point that lies on this edge.
|
||||
// In some applications, this point is unnecessary and can be removed (merge two parts to one edge). But for the case of
|
||||
// multi-material segmentation, these points are necessary. In this case, Voronoi vertex for the point, which divides the edge
|
||||
@@ -1955,12 +1934,9 @@ TEST_CASE("Voronoi missing vertex 1", "[VoronoiMissingVertex1]")
|
||||
{-25000000, 25000000},
|
||||
{-25000000, -25000000},
|
||||
{-12412500, -25000000},
|
||||
// {- 1650000, -25000000},
|
||||
{ 25000000, -25000000}
|
||||
};
|
||||
|
||||
// poly.rotate(PI / 6);
|
||||
|
||||
REQUIRE(poly.area() > 0.);
|
||||
REQUIRE(intersecting_edges({poly}).empty());
|
||||
|
||||
@@ -1971,7 +1947,7 @@ TEST_CASE("Voronoi missing vertex 1", "[VoronoiMissingVertex1]")
|
||||
dump_voronoi_to_svg(debug_out_path("voronoi-missing-vertex1-out.svg").c_str(), vd, Points(), lines);
|
||||
#endif
|
||||
|
||||
// REQUIRE(!has_missing_voronoi_vertices({poly}, vd));
|
||||
REQUIRE(vd.is_valid());
|
||||
}
|
||||
|
||||
// This case is composed of two square polygons (contour and hole), and again one of the edges is divided into two parts by a
|
||||
@@ -1998,8 +1974,6 @@ TEST_CASE("Voronoi missing vertex 2", "[VoronoiMissingVertex2]")
|
||||
}
|
||||
};
|
||||
|
||||
// polygons_rotate(poly, PI / 6);
|
||||
|
||||
double area = std::accumulate(poly.begin(), poly.end(), 0., [](double a, auto &poly) { return a + poly.area(); });
|
||||
REQUIRE(area > 0.);
|
||||
REQUIRE(intersecting_edges(poly).empty());
|
||||
@@ -2011,7 +1985,7 @@ TEST_CASE("Voronoi missing vertex 2", "[VoronoiMissingVertex2]")
|
||||
dump_voronoi_to_svg(debug_out_path("voronoi-missing-vertex2-out.svg").c_str(), vd, Points(), lines);
|
||||
#endif
|
||||
|
||||
// REQUIRE(!has_missing_voronoi_vertices(poly, vd));
|
||||
REQUIRE(vd.is_valid());
|
||||
}
|
||||
|
||||
// This case is composed of two polygons, and again one of the edges is divided into two parts by a point that lies on this edge,
|
||||
@@ -2042,9 +2016,6 @@ TEST_CASE("Voronoi missing vertex 3", "[VoronoiMissingVertex3]")
|
||||
REQUIRE(area > 0.);
|
||||
REQUIRE(intersecting_edges(poly).empty());
|
||||
|
||||
// polygons_rotate(poly, PI/180);
|
||||
// polygons_rotate(poly, PI/6);
|
||||
|
||||
VD vd;
|
||||
Lines lines = to_lines(poly);
|
||||
vd.construct_voronoi(lines.begin(), lines.end());
|
||||
@@ -2052,7 +2023,7 @@ TEST_CASE("Voronoi missing vertex 3", "[VoronoiMissingVertex3]")
|
||||
dump_voronoi_to_svg(debug_out_path("voronoi-missing-vertex3-out.svg").c_str(), vd, Points(), lines);
|
||||
#endif
|
||||
|
||||
// REQUIRE(!has_missing_voronoi_vertices(poly, vd));
|
||||
REQUIRE(vd.is_valid());
|
||||
}
|
||||
|
||||
TEST_CASE("Voronoi missing vertex 4", "[VoronoiMissingVertex4]")
|
||||
@@ -2097,6 +2068,9 @@ TEST_CASE("Voronoi missing vertex 4", "[VoronoiMissingVertex4]")
|
||||
dump_voronoi_to_svg(debug_out_path("voronoi-missing-vertex4-1-out.svg").c_str(), vd_1, Points(), lines_1);
|
||||
dump_voronoi_to_svg(debug_out_path("voronoi-missing-vertex4-2-out.svg").c_str(), vd_2, Points(), lines_2);
|
||||
#endif
|
||||
|
||||
REQUIRE(vd_1.is_valid());
|
||||
REQUIRE(vd_2.is_valid());
|
||||
}
|
||||
|
||||
// In this case, the Voronoi vertex (146873, -146873) is included twice.
|
||||
@@ -2117,8 +2091,6 @@ TEST_CASE("Duplicate Voronoi vertices", "[Voronoi]")
|
||||
{ 25000000, 10790627},
|
||||
};
|
||||
|
||||
// poly.rotate(PI / 6);
|
||||
|
||||
REQUIRE(poly.area() > 0.);
|
||||
REQUIRE(intersecting_edges({poly}).empty());
|
||||
|
||||
@@ -2129,16 +2101,7 @@ TEST_CASE("Duplicate Voronoi vertices", "[Voronoi]")
|
||||
dump_voronoi_to_svg(debug_out_path("voronoi-duplicate-vertices-out.svg").c_str(), vd, Points(), lines);
|
||||
#endif
|
||||
|
||||
[[maybe_unused]] auto has_duplicate_vertices = [](const VD &vd) -> bool {
|
||||
std::vector<Vec2d> vertices;
|
||||
for (const auto &vertex : vd.vertices())
|
||||
vertices.emplace_back(Vec2d(vertex.x(), vertex.y()));
|
||||
|
||||
std::sort(vertices.begin(), vertices.end(), [](const Vec2d &l, const Vec2d &r) { return l.x() < r.x() || (l.x() == r.x() && l.y() < r.y()); });
|
||||
return std::unique(vertices.begin(), vertices.end()) != vertices.end();
|
||||
};
|
||||
|
||||
// REQUIRE(!has_duplicate_vertices(vd));
|
||||
REQUIRE(vd.is_valid());
|
||||
}
|
||||
|
||||
// In this case, there are three very close Voronoi vertices like in the previous test case after rotation. There is also one
|
||||
@@ -2157,8 +2120,6 @@ TEST_CASE("Intersecting Voronoi edges", "[Voronoi]")
|
||||
{ 25000000, - 146873},
|
||||
};
|
||||
|
||||
// poly.rotate(PI / 6);
|
||||
|
||||
REQUIRE(poly.area() > 0.);
|
||||
REQUIRE(intersecting_edges({poly}).empty());
|
||||
|
||||
@@ -2169,38 +2130,7 @@ TEST_CASE("Intersecting Voronoi edges", "[Voronoi]")
|
||||
dump_voronoi_to_svg(debug_out_path("voronoi-intersecting-edges-out.svg").c_str(), vd, Points(), lines);
|
||||
#endif
|
||||
|
||||
[[maybe_unused]] auto has_intersecting_edges = [](const Polygon &poly, const VD &vd) -> bool {
|
||||
BoundingBox bbox = get_extents(poly);
|
||||
const double bbox_dim_max = double(std::max(bbox.size().x(), bbox.size().y()));
|
||||
|
||||
std::vector<Voronoi::Internal::segment_type> segments;
|
||||
for (const Line &line : to_lines(poly))
|
||||
segments.emplace_back(Voronoi::Internal::point_type(double(line.a.x()), double(line.a.y())),
|
||||
Voronoi::Internal::point_type(double(line.b.x()), double(line.b.y())));
|
||||
|
||||
Lines edges;
|
||||
for (const auto &edge : vd.edges())
|
||||
if (edge.cell()->source_index() < edge.twin()->cell()->source_index()) {
|
||||
if (edge.is_finite()) {
|
||||
edges.emplace_back(Point(coord_t(edge.vertex0()->x()), coord_t(edge.vertex0()->y())),
|
||||
Point(coord_t(edge.vertex1()->x()), coord_t(edge.vertex1()->y())));
|
||||
} else if (edge.is_infinite()) {
|
||||
std::vector<Voronoi::Internal::point_type> samples;
|
||||
Voronoi::Internal::clip_infinite_edge(poly.points, segments, edge, bbox_dim_max, &samples);
|
||||
if (!samples.empty())
|
||||
edges.emplace_back(Point(coord_t(samples[0].x()), coord_t(samples[0].y())), Point(coord_t(samples[1].x()), coord_t(samples[1].y())));
|
||||
}
|
||||
}
|
||||
|
||||
Point intersect_point;
|
||||
for (auto first_it = edges.begin(); first_it != edges.end(); ++first_it)
|
||||
for (auto second_it = first_it + 1; second_it != edges.end(); ++second_it)
|
||||
if (first_it->intersection(*second_it, &intersect_point) && first_it->a != intersect_point && first_it->b != intersect_point)
|
||||
return true;
|
||||
return false;
|
||||
};
|
||||
|
||||
// REQUIRE(!has_intersecting_edges(poly, vd));
|
||||
REQUIRE(vd.is_valid());
|
||||
}
|
||||
|
||||
// In this case resulting Voronoi diagram is not planar. This case was distilled from GH issue #8474.
|
||||
@@ -2219,8 +2149,6 @@ TEST_CASE("Non-planar voronoi diagram", "[VoronoiNonPlanar]")
|
||||
{ 5500000, 40000000},
|
||||
};
|
||||
|
||||
// poly.rotate(PI / 6);
|
||||
|
||||
REQUIRE(poly.area() > 0.);
|
||||
REQUIRE(intersecting_edges({poly}).empty());
|
||||
|
||||
@@ -2231,7 +2159,7 @@ TEST_CASE("Non-planar voronoi diagram", "[VoronoiNonPlanar]")
|
||||
dump_voronoi_to_svg(debug_out_path("voronoi-non-planar-out.svg").c_str(), vd, Points(), lines);
|
||||
#endif
|
||||
|
||||
// REQUIRE(Geometry::VoronoiUtilsCgal::is_voronoi_diagram_planar_intersection(vd));
|
||||
REQUIRE(vd.is_valid());
|
||||
}
|
||||
|
||||
// This case is extracted from SPE-1729, where several ExPolygon with very thin lines
|
||||
@@ -2288,4 +2216,69 @@ TEST_CASE("Invalid Voronoi diagram - Thin lines - SPE-1729", "[InvalidVoronoiDia
|
||||
#endif
|
||||
|
||||
// REQUIRE(vd.is_valid());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Voronoi cell doesn't contain a source point - SPE-2298", "[VoronoiCellSourcePointSPE2298]")
|
||||
{
|
||||
Polygon polygon = {
|
||||
{ 9854534, -39739718}, {- 4154002, -34864557}, {-13073118, -31802214},
|
||||
{-21265508, -29026626}, {-31388055, -25645073}, {-32409943, -25279942},
|
||||
{-33418087, -24864987}, {-34400568, -24404312}, {-35354754, -23899358},
|
||||
{-36278795, -23351325}, {-37170015, -22762146}, {-38025776, -22134628},
|
||||
{-38845825, -21468175}, {-39627905, -20764801}, {-40370549, -20026061},
|
||||
{-41072075, -19253859}, {-41731000, -18450032}, {-42345940, -17616466},
|
||||
{-42915530, -16755283}, {-43438684, -15868338}, {-43914245, -14957822},
|
||||
{-44341235, -14025879}, {-44718686, -13074712}, {-45045890, -12106566},
|
||||
{-45322386, -11123499}, {-45547674, -10127656}, {-45721021, - 9121581},
|
||||
{-45842174, - 8107658}, {-45910990, - 7088089}, {-45927405, - 6065217},
|
||||
{-45891432, - 5041288}, {-45803222, - 4018728}, {-45663042, - 2999801},
|
||||
{-45471245, - 1986784}, {-45230690, - 991761}, {-38655400, 23513180},
|
||||
{-38366034, 24494742}, {-38025334, 25467666}, {-37636844, 26420074},
|
||||
{-37200678, 27349843}, {-36718169, 28254419}, {-36191104, 29131704},
|
||||
{-35620587, 29979748}, {-35007621, 30796895}, {-34353751, 31580950},
|
||||
{-33660293, 32330182}, {-32928806, 33042775}, {-32160862, 33717057},
|
||||
{-31358104, 34351432}, {-30522331, 34944323}, {-29655434, 35494277},
|
||||
{-28759338, 35999922}, {-27835963, 36460011}, {-26921721, 36858494},
|
||||
{-25914008, 37239556}, {-24919466, 37557049}, {-24204878, 37746930},
|
||||
{-22880526, 38041931}, {-21833362, 38209050}, {-21449204, 38252031},
|
||||
{-20775657, 38324377}, {-19711119, 38387480}, {-18638667, 38398812},
|
||||
{-17762260, 38366962}, {-16480321, 38266321}, {-15396213, 38120856},
|
||||
{-14327987, 37925343}, {- 5801522, 36175494}, { 7791637, 33457589},
|
||||
{ 15887399, 31878986}, { 28428609, 29478881}, { 28438392, 29512722},
|
||||
{ 27850323, 29743358}, { 27058729, 29970066}, { 14135560, 32452875},
|
||||
{ 6101685, 34019760}, {- 5352362, 36305237}, {-14423391, 38160442},
|
||||
{-15528705, 38361745}, {-16625379, 38507834}, {-17721787, 38600631},
|
||||
{-18812787, 38641330}, {-19563804, 38633844}, {-20975692, 38563412},
|
||||
{-22036069, 38446419}, {-23087710, 38277136}, {-24123993, 38056689},
|
||||
{-25141240, 37786307}, {-26138324, 37466465}, {-26851801, 37197652},
|
||||
{-28067514, 36680229}, {-28988984, 36219404}, {-29886302, 35711371},
|
||||
{-30754551, 35158840}, {-31124518, 34896643}, {-31589528, 34564743},
|
||||
{-32392776, 33928220}, {-33161225, 33251721}, {-33454722, 32966117},
|
||||
{-33891684, 32538320}, {-34585318, 31787066}, {-35239508, 31000793},
|
||||
{-35527715, 30616853}, {-35851756, 30182731}, {-36422833, 29331982},
|
||||
{-36950377, 28452000}, {-37265788, 27860633}, {-37432874, 27545549},
|
||||
{-37870512, 26612217}, {-38261423, 25655915}, {-38581885, 24744387},
|
||||
{-38902507, 23671594}, {-45523689, - 1006672}, {-45770290, - 2026713},
|
||||
{-45963584, - 3043930}, {-46104330, - 4066310}, {-46192377, - 5092635},
|
||||
{-46228310, - 6120019}, {-46211987, - 7145807}, {-46143426, - 8167812},
|
||||
{-46022719, - 9183674}, {-45850055, -10191399}, {-45625772, -11188531},
|
||||
{-45350245, -12172975}, {-45023965, -13142600}, {-44647538, -14095222},
|
||||
{-44221691, -15028602}, {-43747176, -15940794}, {-43224933, -16829570},
|
||||
{-42655872, -17693052}, {-42041183, -18529065}, {-41381752, -19335983},
|
||||
{-40677899, -20112975}, {-39932077, -20856972}, {-39145730, -21566171},
|
||||
{-38320552, -22238686}, {-37458030, -22872953}, {-36560036, -23467217},
|
||||
{-35627745, -24020614}, {-34662272, -24532977}, {-33667551, -25000722},
|
||||
{-32645434, -25422669}, {-31588226, -25801077}, {-24380013, -28208306},
|
||||
{-24380013, -28208306}, {-13354262, -31942517}, {-13354261, -31942515},
|
||||
{-2032305, -35842454}, { 8025116, -39348505}, { 8820397, -39587703},
|
||||
{ 9636283, -39751794}, { 9847092, -39773278}};
|
||||
|
||||
VD vd;
|
||||
Lines lines = to_lines(polygon);
|
||||
vd.construct_voronoi(lines.begin(), lines.end());
|
||||
#ifdef VORONOI_DEBUG_OUT
|
||||
// dump_voronoi_to_svg(debug_out_path("voronoi-cell-source-point-spe2298.svg").c_str(), vd, Points(), lines);
|
||||
#endif
|
||||
|
||||
REQUIRE(vd.is_valid());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user