mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-31 12:41:20 -06:00 
			
		
		
		
	 8a2a9dba2f
			
		
	
	
		8a2a9dba2f
		
	
	
	
	
		
			
			TriangleMesh newly only holds indexed_triangle_set and
TriangleMeshStats. TriangleMeshStats contains an excerpt of stl_stats.
TriangleMeshStats are updated when initializing with indexed_triangle_set.
Admesh triangle mesh fixing is newly only used when loading an STL.
AMF / 3MF / OBJ file formats are already indexed triangle sets, thus
they are no more converted to admesh stl_file format, nor fixed
through admesh repair machinery. When importing AMF / 3MF / OBJ files,
volume is calculated and if negative, all faces are flipped. Also
a bounding box and number of open edges is calculated.
Implemented its_number_of_patches(), its_num_open_edges()
Optimized its_split(), its_is_splittable() using a visitor pattern.
Reworked QHull integration into TriangleMesh:
    1) Face normals were not right.
    2) Indexed triangle set is newly emitted instead of duplicating
       vertices for each face.
Fixed cut_mesh(): Orient the triangulated faces correctly.
		
	
			
		
			
				
	
	
		
			60 lines
		
	
	
	
		
			1.8 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			60 lines
		
	
	
	
		
			1.8 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| #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.);
 | |
| 
 | |
|     auto tree = AABBTreeIndirect::build_aabb_tree_over_indexed_triangle_set(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_to_indexed_triangle_set(
 | |
| 		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_to_indexed_triangle_set(
 | |
| 		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.));
 | |
| }
 |