test_printobject.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. #include <catch2/catch.hpp>
  2. #include "libslic3r/libslic3r.h"
  3. #include "libslic3r/Print.hpp"
  4. #include "libslic3r/Layer.hpp"
  5. #include "test_data.hpp"
  6. using namespace Slic3r;
  7. using namespace Slic3r::Test;
  8. SCENARIO("PrintObject: object layer heights", "[PrintObject]") {
  9. GIVEN("20mm cube and default initial config, initial layer height of 2mm") {
  10. WHEN("generate_object_layers() is called for 2mm layer heights and nozzle diameter of 3mm") {
  11. Slic3r::Print print;
  12. Slic3r::Test::init_and_process_print({TestMesh::cube_20x20x20}, print, {
  13. { "first_layer_height", 2 },
  14. { "layer_height", 2 },
  15. { "nozzle_diameter", 3 }
  16. });
  17. ConstLayerPtrsAdaptor layers = print.objects().front()->layers();
  18. THEN("The output vector has 10 entries") {
  19. REQUIRE(layers.size() == 10);
  20. }
  21. AND_THEN("Each layer is approximately 2mm above the previous Z") {
  22. coordf_t last = 0.0;
  23. for (size_t i = 0; i < layers.size(); ++ i) {
  24. REQUIRE((layers[i]->print_z - last) == Approx(2.0));
  25. last = layers[i]->print_z;
  26. }
  27. }
  28. }
  29. WHEN("generate_object_layers() is called for 10mm layer heights and nozzle diameter of 11mm") {
  30. Slic3r::Print print;
  31. Slic3r::Test::init_and_process_print({TestMesh::cube_20x20x20}, print, {
  32. { "first_layer_height", 2 },
  33. { "layer_height", 10 },
  34. { "nozzle_diameter", 11 }
  35. });
  36. ConstLayerPtrsAdaptor layers = print.objects().front()->layers();
  37. THEN("The output vector has 3 entries") {
  38. REQUIRE(layers.size() == 3);
  39. }
  40. AND_THEN("Layer 0 is at 2mm") {
  41. REQUIRE(layers.front()->print_z == Approx(2.0));
  42. }
  43. AND_THEN("Layer 1 is at 12mm") {
  44. REQUIRE(layers[1]->print_z == Approx(12.0));
  45. }
  46. }
  47. WHEN("generate_object_layers() is called for 15mm layer heights and nozzle diameter of 16mm") {
  48. Slic3r::Print print;
  49. Slic3r::Test::init_and_process_print({TestMesh::cube_20x20x20}, print, {
  50. { "first_layer_height", 2 },
  51. { "layer_height", 15 },
  52. { "nozzle_diameter", 16 }
  53. });
  54. ConstLayerPtrsAdaptor layers = print.objects().front()->layers();
  55. THEN("The output vector has 2 entries") {
  56. REQUIRE(layers.size() == 2);
  57. }
  58. AND_THEN("Layer 0 is at 2mm") {
  59. REQUIRE(layers[0]->print_z == Approx(2.0));
  60. }
  61. AND_THEN("Layer 1 is at 17mm") {
  62. REQUIRE(layers[1]->print_z == Approx(17.0));
  63. }
  64. }
  65. #if 0
  66. WHEN("generate_object_layers() is called for 15mm layer heights and nozzle diameter of 5mm") {
  67. Slic3r::Print print;
  68. Slic3r::Test::init_and_process_print({TestMesh::cube_20x20x20}, print, {
  69. { "first_layer_height", 2 },
  70. { "layer_height", 15 },
  71. { "nozzle_diameter", 5 }
  72. });
  73. const std::vector<Slic3r::Layer*> &layers = print.objects().front()->layers();
  74. THEN("The layer height is limited to 5mm.") {
  75. CHECK(layers.size() == 5);
  76. coordf_t last = 2.0;
  77. for (size_t i = 1; i < layers.size(); i++) {
  78. REQUIRE((layers[i]->print_z - last) == Approx(5.0));
  79. last = layers[i]->print_z;
  80. }
  81. }
  82. }
  83. #endif
  84. }
  85. }
  86. SCENARIO("PrintObject: minimum horizontal shells", "[PrintObject]") {
  87. GIVEN("20mm cube and default initial config, initial layer height of 0.1mm") {
  88. auto config {Slic3r::DynamicPrintConfig::full_print_config()};
  89. TestMesh m { TestMesh::cube_20x20x20 };
  90. Slic3r::Model model;
  91. config.set_deserialize({
  92. {"nozzle_diameter", 3},
  93. {"bottom_solid_layers", 0},
  94. {"top_solid_layers", 0},
  95. {"perimeters", 1},
  96. {"first_layer_height", 0.1},
  97. {"layer_height", 0.1},
  98. {"fill_density", 0},
  99. {"top_solid_min_thickness", 0.0},
  100. {"bottom_solid_min_thickness", 0.0}
  101. });
  102. WHEN("bottom_solid_min_thickness is 1.0 with layer height of 0.1") {
  103. Slic3r::Print print;
  104. config.set("bottom_solid_min_thickness", 1.0);
  105. Slic3r::Test::init_print({m}, print, model, config);
  106. print.process();
  107. THEN("Layers 0-9 are solid (Z < 1.0) (all fill_surfaces are solid)") {
  108. for (int i = 0; i < 10; i++) {
  109. CHECK(print.objects().at(0)->layers().at(i)->print_z <= (i+1 * 0.1));
  110. for (auto* r : print.objects().at(0)->layers().at(i)->regions()) {
  111. for (auto s : r->fill_surfaces) {
  112. REQUIRE(s.has_fill_solid());
  113. }
  114. }
  115. }
  116. }
  117. AND_THEN("Layer 10 (Z > 1.0) is not solid.") {
  118. for (auto* r : print.objects().at(0)->layers().at(10)->regions()) {
  119. for (auto s : r->fill_surfaces) {
  120. REQUIRE(!s.has_fill_solid());
  121. }
  122. }
  123. }
  124. AND_THEN("Top layer is not solid.") {
  125. for (auto* r : print.objects().at(0)->layers().back()->regions()) {
  126. for (auto s : r->fill_surfaces) {
  127. REQUIRE(!s.has_fill_solid());
  128. }
  129. }
  130. }
  131. }
  132. WHEN("min shell thickness is 1.22 with layer height of 0.1") {
  133. Slic3r::Print print;
  134. config.set("bottom_solid_min_thickness", 1.22);
  135. config.set("layer_height", 0.1);
  136. Slic3r::Test::init_print({m}, print, model, config);
  137. print.process();
  138. AND_THEN("Layers 0-12 are solid (bottom of layer >= 1.22) (all fill_surfaces are solid)") {
  139. for (int i = 0; i < 13; i++) {
  140. CHECK(print.objects().front()->layers().at(i)->print_z <= (i+1 * 0.1));
  141. for (auto* r : print.objects().at(0)->layers().at(i)->regions()) {
  142. for (auto s : r->fill_surfaces) {
  143. REQUIRE(s.has_fill_solid());
  144. }
  145. }
  146. }
  147. }
  148. AND_THEN("Layer 13 (Z > 1.0) is not solid.") {
  149. for (auto* r : print.objects().at(0)->layers().at(13)->regions()) {
  150. for (auto s : r->fill_surfaces) {
  151. REQUIRE(!s.has_fill_solid());
  152. }
  153. }
  154. }
  155. AND_THEN("Top layer is not solid.") {
  156. for (auto* r : print.objects().at(0)->layers().back()->regions()) {
  157. for (auto s : r->fill_surfaces) {
  158. REQUIRE(!s.has_fill_solid());
  159. }
  160. }
  161. }
  162. }
  163. WHEN("min shell thickness is 1.22 14 bottom layers") {
  164. config.set("bottom_solid_min_thickness", 1.22);
  165. config.set("bottom_solid_layers", 14);
  166. config.set("layer_height", 0.1);
  167. Slic3r::Print print;
  168. Slic3r::Test::init_print({m}, print, model, config);
  169. print.process();
  170. for (int i = 0; i < 20; i++)
  171. print.objects().at(0)->layers().at(i)->make_fills();
  172. AND_THEN("Layers 0-13 are solid (bottom of layer >= 1.22) (all fill_surfaces are solid)") {
  173. for (int i = 0; i < 14; i++) {
  174. CHECK(print.objects().at(0)->layers().at(i)->print_z <= (i+1 * 0.1));
  175. for (auto* r : print.objects().at(0)->layers().at(i)->regions()) {
  176. for (auto s : r->fill_surfaces) {
  177. REQUIRE(s.has_fill_solid());
  178. }
  179. }
  180. }
  181. }
  182. AND_THEN("Layer 14 is not solid.") {
  183. for (auto* r : print.objects().at(0)->layers().at(14)->regions()) {
  184. for (auto s : r->fill_surfaces) {
  185. REQUIRE(!s.has_fill_solid());
  186. }
  187. }
  188. }
  189. AND_THEN("Top layer is not solid.") {
  190. for (auto* r : print.objects().at(0)->layers().back()->regions()) {
  191. for (auto s : r->fill_surfaces) {
  192. REQUIRE(!s.has_fill_solid());
  193. }
  194. }
  195. }
  196. }
  197. WHEN("top_solid_min_thickness is 1.0 with layer height of 0.1") {
  198. Slic3r::Print print;
  199. config.set("top_solid_min_thickness", 1.0);
  200. Slic3r::Test::init_print({m}, print, model, config);
  201. print.process();
  202. THEN("Top 9 Layers are solid (Z < 1.0) (all fill_surfaces are solid)") {
  203. for (int i = 0; i < 10; i++) {
  204. CHECK(print.objects().at(0)->layers().at(i)->print_z <= (i+1 * 0.1));
  205. for (auto* r : print.objects().at(0)->layers().at(i)->regions()) {
  206. for (auto s : r->fill_surfaces) {
  207. REQUIRE(s.has_fill_solid());
  208. }
  209. }
  210. }
  211. }
  212. AND_THEN("Layer 10 (Z > 1.0) is not solid.") {
  213. for (auto* r : print.objects().at(0)->layers().at(10)->regions()) {
  214. for (auto s : r->fill_surfaces) {
  215. REQUIRE(!s.has_fill_solid());
  216. }
  217. }
  218. }
  219. AND_THEN("Top layer is not solid.") {
  220. for (auto* r : print.objects().at(0)->layers().back()->regions()) {
  221. for (auto s : r->fill_surfaces) {
  222. REQUIRE(!s.has_fill_solid());
  223. }
  224. }
  225. }
  226. }
  227. WHEN("min shell thickness is 1.22 with layer height of 0.1") {
  228. Slic3r::Print print;
  229. config.set("bottom_solid_min_thickness", 1.22);
  230. config.set("layer_height", 0.1);
  231. Slic3r::Test::init_print({m}, print, model, config);
  232. print.process();
  233. AND_THEN("Layers 0-12 are solid (bottom of layer >= 1.22) (all fill_surfaces are solid)") {
  234. for (int i = 0; i < 13; i++) {
  235. CHECK(print.objects().front()->layers().at(i)->print_z <= (i+1 * 0.1));
  236. for (auto* r : print.objects().at(0)->layers().at(i)->regions()) {
  237. for (auto s : r->fill_surfaces) {
  238. REQUIRE(s.has_fill_solid());
  239. }
  240. }
  241. }
  242. }
  243. AND_THEN("Layer 13 (Z > 1.0) is not solid.") {
  244. for (auto* r : print.objects().at(0)->layers().at(13)->regions()) {
  245. for (auto s : r->fill_surfaces) {
  246. REQUIRE(!s.has_fill_solid());
  247. }
  248. }
  249. }
  250. AND_THEN("Top layer is not solid.") {
  251. for (auto* r : print.objects().at(0)->layers().back()->regions()) {
  252. for (auto s : r->fill_surfaces) {
  253. REQUIRE(!s.has_fill_solid());
  254. }
  255. }
  256. }
  257. }
  258. WHEN("min shell thickness is 1.22 14 bottom layers") {
  259. config.set("bottom_solid_min_thickness", 1.22);
  260. config.set("bottom_solid_layers", 14);
  261. config.set("layer_height", 0.1);
  262. Slic3r::Print print;
  263. Slic3r::Test::init_print({m}, print, model, config);
  264. print.process();
  265. for (int i = 0; i < 20; i++)
  266. print.objects().at(0)->layers().at(i)->make_fills();
  267. AND_THEN("Layers 0-13 are solid (bottom of layer >= 1.22) (all fill_surfaces are solid)") {
  268. for (int i = 0; i < 14; i++) {
  269. CHECK(print.objects().at(0)->layers().at(i)->print_z <= (i+1 * 0.1));
  270. for (auto* r : print.objects().at(0)->layers().at(i)->regions()) {
  271. for (auto s : r->fill_surfaces) {
  272. REQUIRE(s.has_fill_solid());
  273. }
  274. }
  275. }
  276. }
  277. AND_THEN("Layer 14 is not solid.") {
  278. for (auto* r : print.objects().at(0)->layers().at(14)->regions()) {
  279. for (auto s : r->fill_surfaces) {
  280. REQUIRE(!s.has_fill_solid());
  281. }
  282. }
  283. }
  284. AND_THEN("Top layer is not solid.") {
  285. for (auto* r : print.objects().at(0)->layers().back()->regions()) {
  286. for (auto s : r->fill_surfaces) {
  287. REQUIRE(!s.has_fill_solid());
  288. }
  289. }
  290. }
  291. }
  292. }
  293. }