test_support_material.cpp 8.6 KB

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