test_denserinfill.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. //#define CATCH_CONFIG_DISABLE
  2. #include <catch_main.hpp>
  3. #include "test_data.hpp"
  4. #include <libslic3r/libslic3r.h>
  5. #include <libslic3r/Print.hpp>
  6. #include <libslic3r/Layer.hpp>
  7. using namespace Slic3r;
  8. using namespace Slic3r::Geometry;
  9. SCENARIO("denser infills: ")
  10. {
  11. GIVEN("center hole")
  12. {
  13. WHEN("dense infill to enlarged") {
  14. Model model{};
  15. Print print{};
  16. DynamicPrintConfig &config = Slic3r::DynamicPrintConfig::full_print_config();
  17. config.set_key_value("layer_height", new ConfigOptionFloat(0.2));
  18. config.set_key_value("first_layer_height", new ConfigOptionFloatOrPercent(0.2, false));
  19. config.set_key_value("infill_dense", new ConfigOptionBool(true));
  20. config.set_key_value("infill_dense_algo", new ConfigOptionEnum<DenseInfillAlgo>(dfaEnlarged));
  21. config.save("C:\\Users\\Admin\\Desktop\\config_def.ini");
  22. Slic3r::Test::init_print(print, { Slic3r::Test::TestMesh::di_5mm_center_notch }, model, &config, false);
  23. print.process();
  24. const PrintObject& object = *(print.objects().at(0));
  25. //for (int lidx = 0; lidx < object.layers().size(); lidx++) {
  26. // std::cout << "layer " << lidx << " : \n";
  27. // std::cout << " - region_count= " << object.layers()[lidx]->region_count() << "\n";
  28. // for (int ridx = 0; ridx < object.layers()[lidx]->regions().size(); ridx++) {
  29. // std::cout << " region " << ridx << " : \n";
  30. // std::cout << " - fills= " << object.layers()[lidx]->regions()[ridx]->fills.entities().size() << "\n";
  31. // std::cout << " - surfaces= " << object.layers()[lidx]->regions()[ridx]->fill_surfaces.surfaces.size() << "\n";
  32. // for (int sidx = 0; sidx < object.layers()[lidx]->regions()[ridx]->fill_surfaces.surfaces.size(); sidx++) {
  33. // std::cout << " - type= " << object.layers()[lidx]->regions()[ridx]->fill_surfaces.surfaces[sidx].surface_type << "\n";
  34. // }
  35. // }
  36. //}
  37. /*THEN("67 layers exist in the model") {
  38. REQUIRE(object.layers().size() == 25);
  39. }
  40. THEN("at layer 16 , there are 1 region") {
  41. REQUIRE(object.layers()[16]->region_count() == 1);
  42. }
  43. THEN("at layer 17 , there are 2 region") {
  44. REQUIRE(object.layers()[17]->region_count() == 2);
  45. }
  46. THEN("at layer 18 , there are 2 region") {
  47. REQUIRE(object.layers()[18]->region_count() == 2);
  48. }*/
  49. THEN("correct number of fills") {
  50. REQUIRE(object.layers()[20]->regions()[0]->fills.entities().size() == 1); //sparse
  51. REQUIRE(object.layers()[21]->regions()[0]->fills.entities().size() == 2); //sparse + dense
  52. REQUIRE(object.layers()[21]->regions()[0]->fill_surfaces.surfaces.size() == 2);
  53. REQUIRE(object.layers()[21]->regions()[0]->fill_surfaces.surfaces[0].surface_type == (SurfaceType::stDensSparse | SurfaceType::stPosInternal));
  54. REQUIRE(object.layers()[21]->regions()[0]->fill_surfaces.surfaces[1].surface_type == (SurfaceType::stDensSparse | SurfaceType::stPosInternal));
  55. REQUIRE(std::min(object.layers()[21]->regions()[0]->fill_surfaces.surfaces[0].maxNbSolidLayersOnTop, object.layers()[21]->regions()[0]->fill_surfaces.surfaces[1].maxNbSolidLayersOnTop) == 1);
  56. Surface* srfSparse = &object.layers()[21]->regions()[0]->fill_surfaces.surfaces[0];
  57. Surface* srfDense = &object.layers()[21]->regions()[0]->fill_surfaces.surfaces[1];
  58. if (srfSparse->maxNbSolidLayersOnTop == 1) {
  59. srfSparse = srfDense;
  60. srfDense = &object.layers()[21]->regions()[0]->fill_surfaces.surfaces[0];
  61. }
  62. //std::cout << "sparse area = " << unscaled(unscaled(srfSparse->area())) << " , dense area = " << unscaled(unscaled(srfDense->area())) << "\n";
  63. REQUIRE(unscaled(unscaled(srfSparse->area())) > unscaled(unscaled(srfDense->area())));
  64. REQUIRE(object.layers()[22]->regions()[0]->fills.entities().size() == 2); //sparse + solid-bridge
  65. REQUIRE(object.layers()[22]->regions()[0]->fill_surfaces.surfaces.size() == 2);
  66. if (object.layers()[22]->regions()[0]->fill_surfaces.surfaces[0].surface_type == (SurfaceType::stDensSparse | SurfaceType::stPosInternal)) {
  67. REQUIRE(object.layers()[22]->regions()[0]->fill_surfaces.surfaces[1].surface_type == (SurfaceType::stDensSolid | SurfaceType::stPosInternal | SurfaceType::stModBridge));
  68. } else {
  69. REQUIRE(object.layers()[22]->regions()[0]->fill_surfaces.surfaces[0].surface_type == (SurfaceType::stDensSolid | SurfaceType::stPosInternal | SurfaceType::stModBridge));
  70. REQUIRE(object.layers()[22]->regions()[0]->fill_surfaces.surfaces[1].surface_type == (SurfaceType::stDensSparse | SurfaceType::stPosInternal));
  71. }
  72. REQUIRE(object.layers()[23]->regions()[0]->fills.entities().size() == 2); //sparse + solid
  73. REQUIRE(object.layers()[24]->regions()[0]->fills.entities().size() == 3); //sparse + solid-top + solid-top (over perimeters)
  74. REQUIRE(object.layers()[25]->regions()[0]->fills.entities().size() == 1); //sparse
  75. }
  76. }
  77. }
  78. GIVEN("side hole")
  79. {
  80. WHEN("dense infill to auto") {
  81. Model model{};
  82. Print print{};
  83. DynamicPrintConfig &config = Slic3r::DynamicPrintConfig::full_print_config();
  84. config.set_key_value("layer_height", new ConfigOptionFloat(0.2));
  85. config.set_key_value("first_layer_height", new ConfigOptionFloatOrPercent(0.2, false));
  86. config.set_key_value("infill_dense", new ConfigOptionBool(true));
  87. config.set_key_value("infill_dense_algo", new ConfigOptionEnum<DenseInfillAlgo>(dfaAutomatic));
  88. config.save("C:\\Users\\Admin\\Desktop\\config_def.ini");
  89. Slic3r::Test::init_print(print, { Slic3r::Test::TestMesh::di_10mm_notch }, model, &config, false);
  90. print.process();
  91. const PrintObject& object = *(print.objects().at(0));
  92. THEN("correct number of fills") {
  93. REQUIRE(object.layers().size() == 50);
  94. REQUIRE(object.layers()[20]->regions()[0]->fills.entities().size() == 1); //sparse
  95. REQUIRE(object.layers()[21]->regions()[0]->fills.entities().size() == 2); //sparse + dense
  96. REQUIRE(object.layers()[21]->regions()[0]->fill_surfaces.surfaces.size() == 2);
  97. REQUIRE(object.layers()[21]->regions()[0]->fill_surfaces.surfaces[0].surface_type == (SurfaceType::stDensSparse | SurfaceType::stPosInternal));
  98. REQUIRE(object.layers()[21]->regions()[0]->fill_surfaces.surfaces[1].surface_type == (SurfaceType::stDensSparse | SurfaceType::stPosInternal));
  99. REQUIRE(std::min(object.layers()[21]->regions()[0]->fill_surfaces.surfaces[0].maxNbSolidLayersOnTop, object.layers()[21]->regions()[0]->fill_surfaces.surfaces[1].maxNbSolidLayersOnTop) == 1);
  100. Surface* srfSparse = &object.layers()[21]->regions()[0]->fill_surfaces.surfaces[0];
  101. Surface* srfDense = &object.layers()[21]->regions()[0]->fill_surfaces.surfaces[1];
  102. if (srfSparse->maxNbSolidLayersOnTop == 1) {
  103. srfSparse = srfDense;
  104. srfDense = &object.layers()[21]->regions()[0]->fill_surfaces.surfaces[0];
  105. }
  106. REQUIRE(unscaled(unscaled(srfSparse->area())) > unscaled(unscaled(srfDense->area())));
  107. REQUIRE(object.layers()[22]->regions()[0]->fills.entities().size() == 2); //sparse + solid-bridge
  108. REQUIRE(object.layers()[22]->regions()[0]->fill_surfaces.surfaces.size() == 2);
  109. if (object.layers()[22]->regions()[0]->fill_surfaces.surfaces[0].surface_type == (SurfaceType::stDensSparse | SurfaceType::stPosInternal)) {
  110. REQUIRE(object.layers()[22]->regions()[0]->fill_surfaces.surfaces[1].surface_type == (SurfaceType::stDensSolid | SurfaceType::stPosInternal | SurfaceType::stModBridge));
  111. } else {
  112. REQUIRE(object.layers()[22]->regions()[0]->fill_surfaces.surfaces[0].surface_type == (SurfaceType::stDensSolid | SurfaceType::stPosInternal | SurfaceType::stModBridge));
  113. REQUIRE(object.layers()[22]->regions()[0]->fill_surfaces.surfaces[1].surface_type == (SurfaceType::stDensSparse | SurfaceType::stPosInternal));
  114. }
  115. REQUIRE(object.layers()[23]->regions()[0]->fills.entities().size() == 2); //sparse + solid
  116. REQUIRE(object.layers()[24]->regions()[0]->fills.entities().size() == 3); //sparse + solid-top + solid-top (over perimeters)
  117. REQUIRE(object.layers()[25]->regions()[0]->fills.entities().size() == 1); //sparse
  118. REQUIRE(object.layers()[45]->regions()[0]->fills.entities().size() == 1); //sparse
  119. REQUIRE(object.layers()[45]->regions()[0]->fill_surfaces.surfaces.size() == 1);
  120. REQUIRE(object.layers()[45]->regions()[0]->fill_surfaces.surfaces[0].surface_type == (SurfaceType::stDensSparse | SurfaceType::stPosInternal));
  121. REQUIRE(object.layers()[45]->regions()[0]->fill_surfaces.surfaces[0].maxNbSolidLayersOnTop > 1);
  122. REQUIRE(object.layers()[46]->regions()[0]->fills.entities().size() == 1); //dense
  123. REQUIRE(object.layers()[46]->regions()[0]->fills.entities().size() == 1);
  124. REQUIRE(object.layers()[46]->regions()[0]->fill_surfaces.surfaces.size() == 1);
  125. REQUIRE(object.layers()[46]->regions()[0]->fill_surfaces.surfaces[0].surface_type == (SurfaceType::stDensSparse | SurfaceType::stPosInternal));
  126. REQUIRE(object.layers()[46]->regions()[0]->fill_surfaces.surfaces[0].maxNbSolidLayersOnTop == 1);
  127. REQUIRE(object.layers()[47]->regions()[0]->fills.entities().size() == 1); //solid-bridge
  128. REQUIRE(object.layers()[47]->regions()[0]->fill_surfaces.surfaces.size() == 1);
  129. REQUIRE(object.layers()[47]->regions()[0]->fill_surfaces.surfaces[0].surface_type == (SurfaceType::stDensSolid | SurfaceType::stPosInternal | SurfaceType::stModBridge));
  130. REQUIRE(object.layers()[47]->regions()[0]->fill_surfaces.surfaces[0].maxNbSolidLayersOnTop > 1);
  131. REQUIRE(object.layers()[48]->regions()[0]->fills.entities().size() == 1); //solid
  132. REQUIRE(object.layers()[48]->regions()[0]->fill_surfaces.surfaces.size() == 1);
  133. REQUIRE(object.layers()[48]->regions()[0]->fill_surfaces.surfaces[0].surface_type == (SurfaceType::stDensSolid | SurfaceType::stPosInternal));
  134. REQUIRE(object.layers()[48]->regions()[0]->fill_surfaces.surfaces[0].maxNbSolidLayersOnTop > 1);
  135. REQUIRE(object.layers()[49]->regions()[0]->fills.entities().size() == 1); //top
  136. REQUIRE(object.layers()[49]->regions()[0]->fill_surfaces.surfaces.size() == 1);
  137. REQUIRE(object.layers()[49]->regions()[0]->fill_surfaces.surfaces[0].surface_type == (SurfaceType::stDensSolid | SurfaceType::stPosTop));
  138. REQUIRE(object.layers()[49]->regions()[0]->fill_surfaces.surfaces[0].maxNbSolidLayersOnTop > 1);
  139. }
  140. }
  141. WHEN("dense infill to auto-not-full") {
  142. Model model{};
  143. Print print{};
  144. DynamicPrintConfig &config = Slic3r::DynamicPrintConfig::full_print_config();
  145. config.set_key_value("layer_height", new ConfigOptionFloat(0.2));
  146. config.set_key_value("first_layer_height", new ConfigOptionFloatOrPercent(0.2, false));
  147. config.set_key_value("infill_dense", new ConfigOptionBool(true));
  148. config.set_key_value("infill_dense_algo", new ConfigOptionEnum<DenseInfillAlgo>(dfaAutoNotFull));
  149. config.save("C:\\Users\\Admin\\Desktop\\config_def.ini");
  150. Slic3r::Test::init_print(print, { Slic3r::Test::TestMesh::di_10mm_notch }, model, &config, false);
  151. print.process();
  152. const PrintObject& object = *(print.objects().at(0));
  153. THEN("correct number of fills") {
  154. REQUIRE(object.layers().size() == 50);
  155. REQUIRE(object.layers()[20]->regions()[0]->fills.entities().size() == 1); //sparse
  156. REQUIRE(object.layers()[21]->regions()[0]->fills.entities().size() == 2); //sparse + dense
  157. REQUIRE(object.layers()[21]->regions()[0]->fill_surfaces.surfaces.size() == 2);
  158. REQUIRE(object.layers()[21]->regions()[0]->fill_surfaces.surfaces[0].surface_type == (SurfaceType::stDensSparse | SurfaceType::stPosInternal));
  159. REQUIRE(object.layers()[21]->regions()[0]->fill_surfaces.surfaces[1].surface_type == (SurfaceType::stDensSparse | SurfaceType::stPosInternal));
  160. REQUIRE(std::min(object.layers()[21]->regions()[0]->fill_surfaces.surfaces[0].maxNbSolidLayersOnTop, object.layers()[21]->regions()[0]->fill_surfaces.surfaces[1].maxNbSolidLayersOnTop) == 1);
  161. Surface* srfSparse = &object.layers()[21]->regions()[0]->fill_surfaces.surfaces[0];
  162. Surface* srfDense = &object.layers()[21]->regions()[0]->fill_surfaces.surfaces[1];
  163. if (srfSparse->maxNbSolidLayersOnTop == 1) {
  164. srfSparse = srfDense;
  165. srfDense = &object.layers()[21]->regions()[0]->fill_surfaces.surfaces[0];
  166. }
  167. REQUIRE(unscaled(unscaled(srfSparse->area())) > unscaled(unscaled(srfDense->area())));
  168. REQUIRE(object.layers()[22]->regions()[0]->fills.entities().size() == 2); //sparse + solid-bridge
  169. REQUIRE(object.layers()[22]->regions()[0]->fill_surfaces.surfaces.size() == 2);
  170. if (object.layers()[22]->regions()[0]->fill_surfaces.surfaces[0].surface_type == (SurfaceType::stDensSparse | SurfaceType::stPosInternal)) {
  171. REQUIRE(object.layers()[22]->regions()[0]->fill_surfaces.surfaces[1].surface_type == (SurfaceType::stDensSolid | SurfaceType::stPosInternal | SurfaceType::stModBridge));
  172. } else {
  173. REQUIRE(object.layers()[22]->regions()[0]->fill_surfaces.surfaces[0].surface_type == (SurfaceType::stDensSolid | SurfaceType::stPosInternal | SurfaceType::stModBridge));
  174. REQUIRE(object.layers()[22]->regions()[0]->fill_surfaces.surfaces[1].surface_type == (SurfaceType::stDensSparse | SurfaceType::stPosInternal));
  175. }
  176. REQUIRE(object.layers()[23]->regions()[0]->fills.entities().size() == 2); //sparse + solid
  177. REQUIRE(object.layers()[24]->regions()[0]->fills.entities().size() == 3); //sparse + solid-top + solid-top (over perimeters)
  178. REQUIRE(object.layers()[25]->regions()[0]->fills.entities().size() == 1); //sparse
  179. REQUIRE(object.layers()[45]->regions()[0]->fills.entities().size() == 1); //sparse
  180. REQUIRE(object.layers()[45]->regions()[0]->fill_surfaces.surfaces.size() == 1);
  181. REQUIRE(object.layers()[45]->regions()[0]->fill_surfaces.surfaces[0].surface_type == (SurfaceType::stDensSparse | SurfaceType::stPosInternal));
  182. REQUIRE(object.layers()[45]->regions()[0]->fill_surfaces.surfaces[0].maxNbSolidLayersOnTop > 1);
  183. REQUIRE(object.layers()[46]->regions()[0]->fills.entities().size() == 1); //dense
  184. REQUIRE(object.layers()[46]->regions()[0]->fill_surfaces.surfaces.size() == 1);
  185. REQUIRE(object.layers()[46]->regions()[0]->fill_surfaces.surfaces[0].surface_type == (SurfaceType::stDensSparse | SurfaceType::stPosInternal));
  186. REQUIRE(object.layers()[46]->regions()[0]->fill_surfaces.surfaces[0].maxNbSolidLayersOnTop > 1);
  187. REQUIRE(object.layers()[47]->regions()[0]->fills.entities().size() == 1); //solid-bridge
  188. REQUIRE(object.layers()[47]->regions()[0]->fill_surfaces.surfaces.size() == 1);
  189. REQUIRE(object.layers()[47]->regions()[0]->fill_surfaces.surfaces[0].surface_type == (SurfaceType::stDensSolid | SurfaceType::stPosInternal | SurfaceType::stModBridge));
  190. REQUIRE(object.layers()[47]->regions()[0]->fill_surfaces.surfaces[0].maxNbSolidLayersOnTop > 1);
  191. REQUIRE(object.layers()[48]->regions()[0]->fills.entities().size() == 1); //solid
  192. REQUIRE(object.layers()[48]->regions()[0]->fill_surfaces.surfaces.size() == 1);
  193. REQUIRE(object.layers()[48]->regions()[0]->fill_surfaces.surfaces[0].surface_type == (SurfaceType::stDensSolid | SurfaceType::stPosInternal));
  194. REQUIRE(object.layers()[48]->regions()[0]->fill_surfaces.surfaces[0].maxNbSolidLayersOnTop > 1);
  195. REQUIRE(object.layers()[49]->regions()[0]->fills.entities().size() == 1); //top
  196. REQUIRE(object.layers()[49]->regions()[0]->fill_surfaces.surfaces.size() == 1);
  197. REQUIRE(object.layers()[49]->regions()[0]->fill_surfaces.surfaces[0].surface_type == (SurfaceType::stDensSolid | SurfaceType::stPosTop));
  198. REQUIRE(object.layers()[49]->regions()[0]->fill_surfaces.surfaces[0].maxNbSolidLayersOnTop > 1);
  199. }
  200. }
  201. }
  202. }