test_support_material.cpp 8.5 KB

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