mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-02 04:31:16 +08:00
Porting test 1.
This commit is contained in:
parent
02e489a11f
commit
93b0cd436a
@ -84,7 +84,7 @@ include_directories(${LIBDIR}/poly2tri/common)
|
||||
add_library(ZipArchive STATIC
|
||||
${LIBDIR}/Zip/ZipArchive.cpp
|
||||
)
|
||||
|
||||
target_compile_features(ZipArchive PUBLIC cxx_std_11)
|
||||
|
||||
add_library(libslic3r STATIC
|
||||
${LIBDIR}/libslic3r/BoundingBox.cpp
|
||||
@ -165,6 +165,8 @@ add_library(expat STATIC
|
||||
${LIBDIR}/expat/xmlrole.c
|
||||
${LIBDIR}/expat/xmltok.c
|
||||
)
|
||||
target_compile_features(clipper PUBLIC cxx_std_11)
|
||||
|
||||
add_library(polypartition STATIC ${LIBDIR}/polypartition.cpp)
|
||||
add_library(poly2tri STATIC
|
||||
${LIBDIR}/poly2tri/common/shapes.cc
|
||||
@ -191,7 +193,7 @@ set(UI_TEST_SOURCES
|
||||
set(SLIC3R_TEST_SOURCES
|
||||
${TESTDIR}/test_harness.cpp
|
||||
${TESTDIR}/libslic3r/test_trianglemesh.cpp
|
||||
)
|
||||
test/libslic3r/test_support_material.cpp)
|
||||
add_executable(slic3r slic3r.cpp)
|
||||
#set_target_properties(slic3r PROPERTIES LINK_SEARCH_START_STATIC 1)
|
||||
#set_target_properties(slic3r PROPERTIES LINK_SEARCH_END_STATIC 1)
|
||||
|
98
src/test/libslic3r/test_support_material.cpp
Normal file
98
src/test/libslic3r/test_support_material.cpp
Normal file
@ -0,0 +1,98 @@
|
||||
#include <catch.hpp>
|
||||
//#include "/home/ahmedsamir/Work/SamirSlic3r/Slic3r/build/external/Catch/include/catch.hpp"
|
||||
|
||||
#include "libslic3r.h"
|
||||
#include "TriangleMesh.hpp"
|
||||
#include "Model.hpp"
|
||||
#include "SupportMaterial.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace Slic3r;
|
||||
|
||||
SCENARIO("SupportMaterial: support_layers_z and contact_distance")
|
||||
{
|
||||
GIVEN("A print object having one modelObject") {
|
||||
// Create a mesh & modelObject.
|
||||
TriangleMesh mesh = TriangleMesh::make_cube(20, 20, 20);
|
||||
|
||||
// Create modelObject.
|
||||
Model model = Model();
|
||||
ModelObject *object = model.add_object();
|
||||
object->add_volume(mesh);
|
||||
model.add_default_instances();
|
||||
|
||||
// Align to origin.
|
||||
model.align_instances_to_origin();
|
||||
|
||||
// Create Print.
|
||||
Print print = Print();
|
||||
print.default_object_config.set_deserialize("support_material", "1");
|
||||
|
||||
vector<coordf_t> contact_z = {1.9};
|
||||
vector<coordf_t> top_z = {1.1};
|
||||
|
||||
WHEN("Layer height = 0.2 and, first layer height = 0.3") {
|
||||
|
||||
print.default_object_config.set_deserialize("layer_height", "0.2");
|
||||
print.default_object_config.set_deserialize("first_layer_height", "0.3");
|
||||
|
||||
print.add_model_object(model.objects[0]);
|
||||
print.objects.front()->_slice();
|
||||
|
||||
SupportMaterial support = SupportMaterial(&print.config, &print.objects.front()->config);
|
||||
|
||||
vector<coordf_t>
|
||||
support_z = support.support_layers_z(contact_z, top_z, print.default_object_config.layer_height.value);
|
||||
|
||||
THEN("First layer height is honored") {
|
||||
REQUIRE((support_z[0] == print.default_object_config.first_layer_height.value));
|
||||
}
|
||||
|
||||
THEN("No null or negative support layers") {
|
||||
bool check = true;
|
||||
for (size_t i = 1; i < support_z.size(); ++i)
|
||||
if (support_z[i] - support_z[i - 1] <= 0) check = false;
|
||||
REQUIRE(check);
|
||||
}
|
||||
|
||||
THEN("No layers thicker than nozzle diameter") {
|
||||
bool check = true;
|
||||
for (size_t i = 1; i < support_z.size(); ++i)
|
||||
if (support_z[i] - support_z[i - 1] > print.config.nozzle_diameter.get_at(0) + EPSILON)
|
||||
check = false;
|
||||
REQUIRE(check);
|
||||
}
|
||||
|
||||
THEN("Layers above top surfaces are spaced correctly") {
|
||||
coordf_t expected_top_spacing = support
|
||||
.contact_distance(print.default_object_config.layer_height, print.config.nozzle_diameter.get_at(0));
|
||||
|
||||
bool wrong_top_spacing = 0;
|
||||
for (coordf_t top_z_el : top_z) {
|
||||
// find layer index of this top surface.
|
||||
int layer_id = -1;
|
||||
for (int i = 0; i < support_z.size(); i++) {
|
||||
if (abs(support_z[i] - top_z_el) < EPSILON) {
|
||||
layer_id = i;
|
||||
i = static_cast<int>(support_z.size());
|
||||
}
|
||||
}
|
||||
|
||||
// check that first support layer above this top surface (or the next one) is spaced with nozzle diameter
|
||||
if (abs(support_z[layer_id + 1] - support_z[layer_id] - expected_top_spacing) > EPSILON
|
||||
&& abs(support_z[layer_id + 2] - support_z[layer_id] - expected_top_spacing) > EPSILON) {
|
||||
wrong_top_spacing = 1;
|
||||
}
|
||||
REQUIRE(!wrong_top_spacing);
|
||||
}
|
||||
}
|
||||
}
|
||||
// /* Test Also with this
|
||||
// $config->set('first_layer_height', 0.4);
|
||||
// $test->();
|
||||
//
|
||||
// $config->set('layer_height', $config->nozzle_diameter->[0]);
|
||||
// $test->();
|
||||
// */
|
||||
}
|
||||
}
|
@ -162,12 +162,11 @@ SupportMaterial::support_layers_z(vector<coordf_t> contact_z,
|
||||
}
|
||||
|
||||
// Create other layers (skip raft layers as they're already done and use thicker layers).
|
||||
for (size_t i = z.size(); i >= object_config->raft_layers; i--) {
|
||||
for (int i = static_cast<int>(z.size()); i >= object_config->raft_layers.value; i--) {
|
||||
coordf_t target_height = support_material_height;
|
||||
if (i > 0 && is_top[z[i - 1]]) {
|
||||
target_height = nozzle_diameter;
|
||||
}
|
||||
|
||||
// Enforce first layer height.
|
||||
if ((i == 0 && z[i] > target_height + first_layer_height)
|
||||
|| (z[i] - z[i - 1] > target_height + EPSILON)) {
|
||||
@ -179,10 +178,10 @@ SupportMaterial::support_layers_z(vector<coordf_t> contact_z,
|
||||
// Remove duplicates and make sure all 0.x values have the leading 0.
|
||||
{
|
||||
set<coordf_t> s;
|
||||
for (auto el : z)
|
||||
s.insert(roundf(static_cast<float>((el * 100)) / 100)); // round it to 2 decimal places.
|
||||
for (coordf_t el : z)
|
||||
s.insert(int(el * 100) / 100.0); // round it to 2 decimal places.
|
||||
z = vector<coordf_t>();
|
||||
for (auto el : s)
|
||||
for (coordf_t el : s)
|
||||
z.push_back(el);
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,7 @@ constexpr coordf_t PILLAR_SIZE = 2.5;
|
||||
|
||||
constexpr coordf_t PILLAR_SPACING = 10;
|
||||
|
||||
/// Struct for carrying the toolpaths parameters needed for each thread.
|
||||
struct toolpaths_params
|
||||
{
|
||||
int contact_loops;
|
||||
@ -36,11 +37,11 @@ struct toolpaths_params
|
||||
Polygon circle;
|
||||
SupportMaterialPattern pattern;
|
||||
vector<int> angles;
|
||||
double interface_angle;
|
||||
double interface_spacing;
|
||||
float interface_density;
|
||||
double support_spacing;
|
||||
double support_density;
|
||||
double interface_angle{};
|
||||
double interface_spacing{};
|
||||
float interface_density{};
|
||||
double support_spacing{};
|
||||
double support_density{};
|
||||
|
||||
toolpaths_params(int contact_loops = 0,
|
||||
coordf_t circle_radius = 0,
|
||||
@ -60,11 +61,11 @@ struct toolpaths_params
|
||||
class SupportMaterial
|
||||
{
|
||||
public:
|
||||
PrintConfig *config; ///<
|
||||
PrintObjectConfig *object_config; ///<
|
||||
Flow *flow; ///<
|
||||
Flow *first_layer_flow; ///<
|
||||
Flow *interface_flow; ///<
|
||||
PrintConfig *config; ///< The print config
|
||||
PrintObjectConfig *object_config; ///< The object print config.
|
||||
Flow *flow; ///< The intermediate layers print flow.
|
||||
Flow *first_layer_flow; ///< The first (base) layers print flow.
|
||||
Flow *interface_flow; ///< The interface layers print flow.
|
||||
|
||||
SupportMaterial(PrintConfig *print_config,
|
||||
PrintObjectConfig *print_object_config,
|
||||
@ -79,14 +80,17 @@ public:
|
||||
object(nullptr)
|
||||
{}
|
||||
|
||||
/// Generate the extrusions paths for the support matterial generated for the given print object.
|
||||
void generate_toolpaths(PrintObject *object,
|
||||
map<coordf_t, Polygons> overhang,
|
||||
map<coordf_t, Polygons> contact,
|
||||
map<int, Polygons> interface,
|
||||
map<int, Polygons> base);
|
||||
|
||||
/// Generate support material for the given print object.
|
||||
void generate(PrintObject *object);
|
||||
|
||||
/// Generate the support layers z coordinates. (TODO Dicuss more).
|
||||
vector<coordf_t> support_layers_z(vector<coordf_t> contact_z,
|
||||
vector<coordf_t> top_z,
|
||||
coordf_t max_object_layer_height);
|
||||
@ -129,10 +133,13 @@ public:
|
||||
void process_layer(int layer_id, toolpaths_params params);
|
||||
|
||||
private:
|
||||
// Get the maximum layer height given a print object.
|
||||
coordf_t get_max_layer_height(PrintObject *object);
|
||||
|
||||
// (Deprecated) use append_to instead TODO @Samir55.
|
||||
void append_polygons(Polygons &dst, Polygons &src);
|
||||
|
||||
// Return polygon vector given a vector of surfaces.
|
||||
Polygons p(SurfacesPtr &surfaces);
|
||||
|
||||
vector<coordf_t> get_keys_sorted(map<coordf_t, Polygons> _map);
|
||||
@ -148,96 +155,6 @@ private:
|
||||
|
||||
};
|
||||
|
||||
// To Be converted to catch.
|
||||
// Supports Material tests.
|
||||
class SupportMaterialTests
|
||||
{
|
||||
public:
|
||||
bool test_1()
|
||||
{
|
||||
// Create a mesh & modelObject.
|
||||
TriangleMesh mesh = TriangleMesh::make_cube(20, 20, 20);
|
||||
|
||||
// Create modelObject.
|
||||
Model model = Model();
|
||||
ModelObject *object = model.add_object();
|
||||
object->add_volume(mesh);
|
||||
model.add_default_instances();
|
||||
|
||||
// Align to origin.
|
||||
model.align_instances_to_origin();
|
||||
|
||||
// Create Print.
|
||||
Print print = Print();
|
||||
|
||||
// Configure the printObjectConfig.
|
||||
print.default_object_config.set_deserialize("support_material", "1");
|
||||
print.default_object_config.set_deserialize("layer_height", "0.2");
|
||||
print.config.set_deserialize("first_layer_height", "0.3");
|
||||
|
||||
vector<coordf_t> contact_z;
|
||||
vector<coordf_t> top_z;
|
||||
contact_z.push_back(1.9);
|
||||
top_z.push_back(1.9);
|
||||
|
||||
// Add the modelObject.
|
||||
print.add_model_object(model.objects[0]);
|
||||
|
||||
// Create new supports.
|
||||
SupportMaterial support = SupportMaterial(&print.config, &print.objects.front()->config);
|
||||
|
||||
vector<coordf_t>
|
||||
support_z = support.support_layers_z(contact_z, top_z, print.default_object_config.layer_height);
|
||||
|
||||
// bool
|
||||
// is_1 = (support_z[0] == print.default_object_config.first_layer_height); // 'first layer height is honored'.
|
||||
//
|
||||
// bool is_2 = false; // 'no null or negative support layers'.
|
||||
// for (int i = 1; i < support_z.size(); ++i) {
|
||||
// if (support_z[i] - support_z[i - 1] <= 0) is_2 = true;
|
||||
// }
|
||||
//
|
||||
// bool is_3 = false; // 'no layers thicker than nozzle diameter'.
|
||||
// for (int i = 1; i < support_z.size(); ++i) {
|
||||
// if (support_z[i] - support_z[i - 1] > print.config.nozzle_diameter.get_at(0) + EPSILON) is_2 = true;
|
||||
// }
|
||||
//
|
||||
// coordf_t expected_top_spacing =
|
||||
// support.contact_distance(print.default_object_config.layer_height, print.config.nozzle_diameter.get_at(0));
|
||||
// coordf_t wrong_top_spacing = 0;
|
||||
// for (auto top_z_el : top_z) {
|
||||
// // find layer index of this top surface.
|
||||
// int layer_id = -1;
|
||||
// for (int i = 0; i < support_z.size(); i++) {
|
||||
// if (abs(support_z[i] - top_z_el) < EPSILON) {
|
||||
// layer_id = i;
|
||||
// i = static_cast<int>(support_z.size());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // check that first support layer above this top surface (or the next one) is spaced with nozzle diameter
|
||||
// if ((support_z[layer_id + 1] - support_z[layer_id]) != expected_top_spacing
|
||||
// && (support_z[layer_id + 2] - support_z[layer_id]) != expected_top_spacing)
|
||||
// wrong_top_spacing = 1;
|
||||
// }
|
||||
// bool is_4 = !wrong_top_spacing; // 'layers above top surfaces are spaced correctly'
|
||||
|
||||
/* Test Also with this
|
||||
$config->set('first_layer_height', 0.4);
|
||||
$test->();
|
||||
|
||||
$config->set('layer_height', $config->nozzle_diameter->[0]);
|
||||
$test->();
|
||||
*/
|
||||
}
|
||||
|
||||
bool test_2()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user