test_support_material.cpp 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. #include <catch2/catch.hpp>
  2. #include "libslic3r/GCodeReader.hpp"
  3. #include "libslic3r/Layer.hpp"
  4. #include "test_data.hpp" // get access to init_print, etc
  5. using namespace Slic3r::Test;
  6. using namespace Slic3r;
  7. TEST_CASE("SupportMaterial: Three raft layers created", "[SupportMaterial]")
  8. {
  9. Slic3r::Print print;
  10. Slic3r::Test::init_and_process_print({ TestMesh::cube_20x20x20 }, print, {
  11. { "support_material", 1 },
  12. { "raft_layers", 3 }
  13. });
  14. REQUIRE(print.objects().front()->support_layers().size() == 3);
  15. }
  16. SCENARIO("SupportMaterial: support_layers_z and contact_distance", "[SupportMaterial]")
  17. {
  18. // Box h = 20mm, hole bottom at 5mm, hole height 10mm (top edge at 15mm).
  19. TriangleMesh mesh = Slic3r::Test::mesh(Slic3r::Test::TestMesh::cube_with_hole);
  20. mesh.rotate_x(float(M_PI / 2));
  21. // mesh.write_binary("d:\\temp\\cube_with_hole.stl");
  22. auto check = [](Slic3r::Print &print, bool &first_support_layer_height_ok, bool &layer_height_minimum_ok, bool &layer_height_maximum_ok, bool &top_spacing_ok)
  23. {
  24. ConstSupportLayerPtrsAdaptor support_layers = print.objects().front()->support_layers();
  25. first_support_layer_height_ok = support_layers.front()->print_z == print.config().first_layer_height.value;
  26. layer_height_minimum_ok = true;
  27. layer_height_maximum_ok = true;
  28. double min_layer_height = print.config().min_layer_height.values.front();
  29. double max_layer_height = print.config().nozzle_diameter.values.front();
  30. if (print.config().max_layer_height.values.front() > EPSILON)
  31. max_layer_height = std::min(max_layer_height, print.config().max_layer_height.values.front());
  32. for (size_t i = 1; i < support_layers.size(); ++ i) {
  33. if (support_layers[i]->print_z - support_layers[i - 1]->print_z < min_layer_height - EPSILON)
  34. layer_height_minimum_ok = false;
  35. if (support_layers[i]->print_z - support_layers[i - 1]->print_z > max_layer_height + EPSILON)
  36. layer_height_maximum_ok = false;
  37. }
  38. #if 0
  39. double expected_top_spacing = print.default_object_config().layer_height + print.config().nozzle_diameter.get_at(0);
  40. bool wrong_top_spacing = 0;
  41. std::vector<coordf_t> top_z { 1.1 };
  42. for (coordf_t top_z_el : top_z) {
  43. // find layer index of this top surface.
  44. size_t layer_id = -1;
  45. for (size_t i = 0; i < support_z.size(); ++ i) {
  46. if (abs(support_z[i] - top_z_el) < EPSILON) {
  47. layer_id = i;
  48. i = static_cast<int>(support_z.size());
  49. }
  50. }
  51. // check that first support layer above this top surface (or the next one) is spaced with nozzle diameter
  52. if (abs(support_z[layer_id + 1] - support_z[layer_id] - expected_top_spacing) > EPSILON &&
  53. abs(support_z[layer_id + 2] - support_z[layer_id] - expected_top_spacing) > EPSILON) {
  54. wrong_top_spacing = 1;
  55. }
  56. }
  57. d = ! wrong_top_spacing;
  58. #else
  59. top_spacing_ok = true;
  60. #endif
  61. };
  62. GIVEN("A print object having one modelObject") {
  63. WHEN("First layer height = 0.4") {
  64. Slic3r::Print print;
  65. Slic3r::Test::init_and_process_print({ mesh }, print, {
  66. { "support_material", 1 },
  67. { "layer_height", 0.2 },
  68. { "first_layer_height", 0.4 },
  69. { "dont_support_bridges", false },
  70. });
  71. bool a, b, c, d;
  72. check(print, a, b, c, d);
  73. THEN("First layer height is honored") { REQUIRE(a == true); }
  74. THEN("No null or negative support layers") { REQUIRE(b == true); }
  75. THEN("No layers thicker than nozzle diameter") { REQUIRE(c == true); }
  76. // THEN("Layers above top surfaces are spaced correctly") { REQUIRE(d == true); }
  77. }
  78. WHEN("Layer height = 0.2 and, first layer height = 0.3") {
  79. Slic3r::Print print;
  80. Slic3r::Test::init_and_process_print({ mesh }, print, {
  81. { "support_material", 1 },
  82. { "layer_height", 0.2 },
  83. { "first_layer_height", 0.3 },
  84. { "dont_support_bridges", false },
  85. });
  86. bool a, b, c, d;
  87. check(print, a, b, c, d);
  88. THEN("First layer height is honored") { REQUIRE(a == true); }
  89. THEN("No null or negative support layers") { REQUIRE(b == true); }
  90. THEN("No layers thicker than nozzle diameter") { REQUIRE(c == true); }
  91. // THEN("Layers above top surfaces are spaced correctly") { REQUIRE(d == true); }
  92. }
  93. WHEN("Layer height = nozzle_diameter[0]") {
  94. Slic3r::Print print;
  95. Slic3r::Test::init_and_process_print({ mesh }, print, {
  96. { "support_material", 1 },
  97. { "layer_height", 0.2 },
  98. { "first_layer_height", 0.3 },
  99. { "dont_support_bridges", false },
  100. });
  101. bool a, b, c, d;
  102. check(print, a, b, c, d);
  103. THEN("First layer height is honored") { REQUIRE(a == true); }
  104. THEN("No null or negative support layers") { REQUIRE(b == true); }
  105. THEN("No layers thicker than nozzle diameter") { REQUIRE(c == true); }
  106. // THEN("Layers above top surfaces are spaced correctly") { REQUIRE(d == true); }
  107. }
  108. }
  109. }
  110. #if 0
  111. // Test 8.
  112. TEST_CASE("SupportMaterial: forced support is generated", "[SupportMaterial]")
  113. {
  114. // Create a mesh & modelObject.
  115. TriangleMesh mesh = TriangleMesh::make_cube(20, 20, 20);
  116. Model model = Model();
  117. ModelObject *object = model.add_object();
  118. object->add_volume(mesh);
  119. model.add_default_instances();
  120. model.align_instances_to_origin();
  121. Print print = Print();
  122. std::vector<coordf_t> contact_z = {1.9};
  123. std::vector<coordf_t> top_z = {1.1};
  124. print.default_object_config.support_material_enforce_layers = 100;
  125. print.default_object_config.support_material = 0;
  126. print.default_object_config.layer_height = 0.2;
  127. print.default_object_config.set_deserialize("first_layer_height", "0.3");
  128. print.add_model_object(model.objects[0]);
  129. print.objects.front()->_slice();
  130. SupportMaterial *support = print.objects.front()->_support_material();
  131. auto support_z = support->support_layers_z(contact_z, top_z, print.default_object_config.layer_height);
  132. bool check = true;
  133. for (size_t i = 1; i < support_z.size(); i++) {
  134. if (support_z[i] - support_z[i - 1] <= 0)
  135. check = false;
  136. }
  137. REQUIRE(check == true);
  138. }
  139. // TODO
  140. bool test_6_checks(Print& print)
  141. {
  142. bool has_bridge_speed = true;
  143. // Pre-Processing.
  144. PrintObject* print_object = print.objects.front();
  145. print_object->infill();
  146. SupportMaterial* support_material = print.objects.front()->_support_material();
  147. support_material->generate(print_object);
  148. // TODO but not needed in test 6 (make brims and make skirts).
  149. // Exporting gcode.
  150. // TODO validation found in Simple.pm
  151. return has_bridge_speed;
  152. }
  153. // Test 6.
  154. SCENARIO("SupportMaterial: Checking bridge speed", "[SupportMaterial]")
  155. {
  156. GIVEN("Print object") {
  157. // Create a mesh & modelObject.
  158. TriangleMesh mesh = TriangleMesh::make_cube(20, 20, 20);
  159. Model model = Model();
  160. ModelObject *object = model.add_object();
  161. object->add_volume(mesh);
  162. model.add_default_instances();
  163. model.align_instances_to_origin();
  164. Print print = Print();
  165. print.config.brim_width = 0;
  166. print.config.skirts = 0;
  167. print.config.skirts = 0;
  168. print.default_object_config.support_material = 1;
  169. print.default_region_config.top_solid_layers = 0; // so that we don't have the internal bridge over infill.
  170. print.default_region_config.bridge_speed = 99;
  171. print.config.cooling = 0;
  172. print.config.set_deserialize("first_layer_speed", "100%");
  173. WHEN("support_material_contact_distance = 0.2") {
  174. print.default_object_config.support_material_contact_distance = 0.2;
  175. print.add_model_object(model.objects[0]);
  176. bool check = test_6_checks(print);
  177. REQUIRE(check == true); // bridge speed is used.
  178. }
  179. WHEN("support_material_contact_distance = 0") {
  180. print.default_object_config.support_material_contact_distance = 0;
  181. print.add_model_object(model.objects[0]);
  182. bool check = test_6_checks(print);
  183. REQUIRE(check == true); // bridge speed is not used.
  184. }
  185. WHEN("support_material_contact_distance = 0.2 & raft_layers = 5") {
  186. print.default_object_config.support_material_contact_distance = 0.2;
  187. print.default_object_config.raft_layers = 5;
  188. print.add_model_object(model.objects[0]);
  189. bool check = test_6_checks(print);
  190. REQUIRE(check == true); // bridge speed is used.
  191. }
  192. WHEN("support_material_contact_distance = 0 & raft_layers = 5") {
  193. print.default_object_config.support_material_contact_distance = 0;
  194. print.default_object_config.raft_layers = 5;
  195. print.add_model_object(model.objects[0]);
  196. bool check = test_6_checks(print);
  197. REQUIRE(check == true); // bridge speed is not used.
  198. }
  199. }
  200. }
  201. #endif