test_denserinfill.cpp 17 KB

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