Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorVojtech Bubnik <bubnikv@gmail.com>2020-05-20 17:30:30 +0300
committerVojtech Bubnik <bubnikv@gmail.com>2020-05-22 10:29:21 +0300
commiteeb9590d2865bca9099441ca5d76eba904360ea5 (patch)
tree221db842aabd76661da5a86e8ebfe67843d32a7d /tests
parentabf279fc44f877f79085c707a6c93228aeea7a0d (diff)
WIP: own AABBTreeIndirect, builds up the tree 4x quicker than libigl.
Diffstat (limited to 'tests')
-rw-r--r--tests/libslic3r/CMakeLists.txt1
-rw-r--r--tests/libslic3r/test_aabbindirect.cpp61
2 files changed, 62 insertions, 0 deletions
diff --git a/tests/libslic3r/CMakeLists.txt b/tests/libslic3r/CMakeLists.txt
index b41dbf8ba..7f86144cd 100644
--- a/tests/libslic3r/CMakeLists.txt
+++ b/tests/libslic3r/CMakeLists.txt
@@ -3,6 +3,7 @@ get_filename_component(_TEST_NAME ${CMAKE_CURRENT_LIST_DIR} NAME)
add_executable(${_TEST_NAME}_tests
${_TEST_NAME}_tests.cpp
test_3mf.cpp
+ test_aabbindirect.cpp
test_clipper_offset.cpp
test_clipper_utils.cpp
test_config.cpp
diff --git a/tests/libslic3r/test_aabbindirect.cpp b/tests/libslic3r/test_aabbindirect.cpp
new file mode 100644
index 000000000..017df9307
--- /dev/null
+++ b/tests/libslic3r/test_aabbindirect.cpp
@@ -0,0 +1,61 @@
+#include <catch2/catch.hpp>
+#include <test_utils.hpp>
+
+#include <libslic3r/TriangleMesh.hpp>
+#include <libslic3r/AABBTreeIndirect.hpp>
+
+using namespace Slic3r;
+
+TEST_CASE("Building a tree over a box, ray caster and closest query", "[AABBIndirect]")
+{
+ TriangleMesh tmesh = make_cube(1., 1., 1.);
+ tmesh.repair();
+
+ auto tree = AABBTreeIndirect::build_aabb_tree(tmesh.its.vertices, tmesh.its.indices);
+ REQUIRE(! tree.empty());
+
+ igl::Hit hit;
+ bool intersected = AABBTreeIndirect::intersect_ray_first_hit(
+ tmesh.its.vertices, tmesh.its.indices,
+ tree,
+ Vec3d(0.5, 0.5, -5.),
+ Vec3d(0., 0., 1.),
+ hit);
+
+ REQUIRE(intersected);
+ REQUIRE(hit.t == Approx(5.));
+
+ std::vector<igl::Hit> hits;
+ bool intersected2 = AABBTreeIndirect::intersect_ray_all_hits(
+ tmesh.its.vertices, tmesh.its.indices,
+ tree,
+ Vec3d(0.3, 0.5, -5.),
+ Vec3d(0., 0., 1.),
+ hits);
+ REQUIRE(intersected2);
+ REQUIRE(hits.size() == 2);
+ REQUIRE(hits.front().t == Approx(5.));
+ REQUIRE(hits.back().t == Approx(6.));
+
+ size_t hit_idx;
+ Vec3d closest_point;
+ double squared_distance = AABBTreeIndirect::squared_distance(
+ tmesh.its.vertices, tmesh.its.indices,
+ tree,
+ Vec3d(0.3, 0.5, -5.),
+ hit_idx, closest_point);
+ REQUIRE(squared_distance == Approx(5. * 5.));
+ REQUIRE(closest_point.x() == Approx(0.3));
+ REQUIRE(closest_point.y() == Approx(0.5));
+ REQUIRE(closest_point.z() == Approx(0.));
+
+ squared_distance = AABBTreeIndirect::squared_distance(
+ tmesh.its.vertices, tmesh.its.indices,
+ tree,
+ Vec3d(0.3, 0.5, 5.),
+ hit_idx, closest_point);
+ REQUIRE(squared_distance == Approx(4. * 4.));
+ REQUIRE(closest_point.x() == Approx(0.3));
+ REQUIRE(closest_point.y() == Approx(0.5));
+ REQUIRE(closest_point.z() == Approx(1.));
+}