mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-11-02 12:41:18 -07:00 
			
		
		
		
	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.
		
	
			
		
			
				
	
	
		
			123 lines
		
	
	
	
		
			4.7 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			123 lines
		
	
	
	
		
			4.7 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
#include <catch2/catch.hpp>
 | 
						|
 | 
						|
#include "libslic3r/Model.hpp"
 | 
						|
#include "libslic3r/Format/3mf.hpp"
 | 
						|
#include "libslic3r/Format/STL.hpp"
 | 
						|
 | 
						|
#include <boost/filesystem/operations.hpp>
 | 
						|
 | 
						|
using namespace Slic3r;
 | 
						|
 | 
						|
SCENARIO("Reading 3mf file", "[3mf]") {
 | 
						|
    GIVEN("umlauts in the path of the file") {
 | 
						|
        Model model;
 | 
						|
        WHEN("3mf model is read") {
 | 
						|
        	std::string path = std::string(TEST_DATA_DIR) + "/test_3mf/Geräte/Büchse.3mf";
 | 
						|
        	DynamicPrintConfig config;
 | 
						|
            ConfigSubstitutionContext ctxt{ ForwardCompatibilitySubstitutionRule::Disable };
 | 
						|
            bool ret = load_3mf(path.c_str(), config, ctxt, &model, false);
 | 
						|
            THEN("load should succeed") {
 | 
						|
                REQUIRE(ret);
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
SCENARIO("Export+Import geometry to/from 3mf file cycle", "[3mf]") {
 | 
						|
    GIVEN("world vertices coordinates before save") {
 | 
						|
        // load a model from stl file
 | 
						|
        Model src_model;
 | 
						|
        std::string src_file = std::string(TEST_DATA_DIR) + "/test_3mf/Prusa.stl";
 | 
						|
        load_stl(src_file.c_str(), &src_model);
 | 
						|
        src_model.add_default_instances();
 | 
						|
 | 
						|
        ModelObject* src_object = src_model.objects.front();
 | 
						|
 | 
						|
        // apply generic transformation to the 1st volume
 | 
						|
        Geometry::Transformation src_volume_transform;
 | 
						|
        src_volume_transform.set_offset({ 10.0, 20.0, 0.0 });
 | 
						|
        src_volume_transform.set_rotation({ Geometry::deg2rad(25.0), Geometry::deg2rad(35.0), Geometry::deg2rad(45.0) });
 | 
						|
        src_volume_transform.set_scaling_factor({ 1.1, 1.2, 1.3 });
 | 
						|
        src_volume_transform.set_mirror({ -1.0, 1.0, -1.0 });
 | 
						|
        src_object->volumes.front()->set_transformation(src_volume_transform);
 | 
						|
 | 
						|
        // apply generic transformation to the 1st instance
 | 
						|
        Geometry::Transformation src_instance_transform;
 | 
						|
        src_instance_transform.set_offset({ 5.0, 10.0, 0.0 });
 | 
						|
        src_instance_transform.set_rotation({ Geometry::deg2rad(12.0), Geometry::deg2rad(13.0), Geometry::deg2rad(14.0) });
 | 
						|
        src_instance_transform.set_scaling_factor({ 0.9, 0.8, 0.7 });
 | 
						|
        src_instance_transform.set_mirror({ 1.0, -1.0, -1.0 });
 | 
						|
        src_object->instances.front()->set_transformation(src_instance_transform);
 | 
						|
 | 
						|
        WHEN("model is saved+loaded to/from 3mf file") {
 | 
						|
            // save the model to 3mf file
 | 
						|
            std::string test_file = std::string(TEST_DATA_DIR) + "/test_3mf/prusa.3mf";
 | 
						|
            store_3mf(test_file.c_str(), &src_model, nullptr, false);
 | 
						|
 | 
						|
            // load back the model from the 3mf file
 | 
						|
            Model dst_model;
 | 
						|
            DynamicPrintConfig dst_config;
 | 
						|
            {
 | 
						|
                ConfigSubstitutionContext ctxt{ ForwardCompatibilitySubstitutionRule::Disable };
 | 
						|
                load_3mf(test_file.c_str(), dst_config, ctxt, &dst_model, false);
 | 
						|
            }
 | 
						|
            boost::filesystem::remove(test_file);
 | 
						|
 | 
						|
            // compare meshes
 | 
						|
            TriangleMesh src_mesh = src_model.mesh();
 | 
						|
            TriangleMesh dst_mesh = dst_model.mesh();
 | 
						|
 | 
						|
            bool res = src_mesh.its.vertices.size() == dst_mesh.its.vertices.size();
 | 
						|
            if (res) {
 | 
						|
                for (size_t i = 0; i < dst_mesh.its.vertices.size(); ++i) {
 | 
						|
                    res &= dst_mesh.its.vertices[i].isApprox(src_mesh.its.vertices[i]);
 | 
						|
                }
 | 
						|
            }
 | 
						|
            THEN("world vertices coordinates after load match") {
 | 
						|
                REQUIRE(res);
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
SCENARIO("2D convex hull of sinking object", "[3mf]") {
 | 
						|
    GIVEN("model") {
 | 
						|
        // load a model
 | 
						|
        Model model;
 | 
						|
        std::string src_file = std::string(TEST_DATA_DIR) + "/test_3mf/Prusa.stl";
 | 
						|
        load_stl(src_file.c_str(), &model);
 | 
						|
        model.add_default_instances();
 | 
						|
 | 
						|
        WHEN("model is rotated, scaled and set as sinking") {
 | 
						|
            ModelObject* object = model.objects.front();
 | 
						|
            object->center_around_origin(false);
 | 
						|
 | 
						|
            // set instance's attitude so that it is rotated, scaled and sinking
 | 
						|
            ModelInstance* instance = object->instances.front();
 | 
						|
            instance->set_rotation(X, -M_PI / 4.0);
 | 
						|
            instance->set_offset(Vec3d::Zero());
 | 
						|
            instance->set_scaling_factor({ 2.0, 2.0, 2.0 });
 | 
						|
 | 
						|
            // calculate 2D convex hull
 | 
						|
            Polygon hull_2d = object->convex_hull_2d(instance->get_transformation().get_matrix());
 | 
						|
 | 
						|
            // verify result
 | 
						|
            Points result = {
 | 
						|
                { -91501496, -15914144 },
 | 
						|
                { 91501496, -15914144 },
 | 
						|
                { 91501496, 4243 },
 | 
						|
                { 78229680, 4246883 },
 | 
						|
                { 56898100, 4246883 },
 | 
						|
                { -85501496, 4242641 },
 | 
						|
                { -91501496, 4243 }
 | 
						|
            };
 | 
						|
 | 
						|
            bool res = hull_2d.points == result;
 | 
						|
 | 
						|
            THEN("2D convex hull should match with reference") {
 | 
						|
                REQUIRE(res);
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 | 
						|
 |