FillAdaptive.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #ifndef slic3r_FillAdaptive_hpp_
  2. #define slic3r_FillAdaptive_hpp_
  3. #include "../AABBTreeIndirect.hpp"
  4. #include "FillBase.hpp"
  5. namespace Slic3r {
  6. class PrintObject;
  7. namespace FillAdaptive_Internal
  8. {
  9. struct CubeProperties
  10. {
  11. double edge_length; // Lenght of edge of a cube
  12. double height; // Height of rotated cube (standing on the corner)
  13. double diagonal_length; // Length of diagonal of a cube a face
  14. double line_z_distance; // Defines maximal distance from a center of a cube on Z axis on which lines will be created
  15. double line_xy_distance;// Defines maximal distance from a center of a cube on X and Y axis on which lines will be created
  16. };
  17. struct Cube
  18. {
  19. Vec3d center;
  20. std::unique_ptr<Cube> children[8] = {};
  21. Cube(const Vec3d &center) : center(center) {}
  22. };
  23. struct Octree
  24. {
  25. std::unique_ptr<Cube> root_cube;
  26. Vec3d origin;
  27. std::vector<CubeProperties> cubes_properties;
  28. Octree(std::unique_ptr<Cube> rootCube, const Vec3d &origin, const std::vector<CubeProperties> &cubes_properties)
  29. : root_cube(std::move(rootCube)), origin(origin), cubes_properties(cubes_properties) {}
  30. inline static int find_octant(const Vec3d &i_cube, const Vec3d &current)
  31. {
  32. return (i_cube.z() > current.z()) * 4 + (i_cube.y() > current.y()) * 2 + (i_cube.x() > current.x());
  33. }
  34. static void propagate_point(
  35. Vec3d point,
  36. FillAdaptive_Internal::Cube *current_cube,
  37. int depth,
  38. const std::vector<FillAdaptive_Internal::CubeProperties> &cubes_properties);
  39. };
  40. }; // namespace FillAdaptive_Internal
  41. //
  42. // Some of the algorithms used by class FillAdaptive were inspired by
  43. // Cura Engine's class SubDivCube
  44. // https://github.com/Ultimaker/CuraEngine/blob/master/src/infill/SubDivCube.h
  45. //
  46. class FillAdaptive : public Fill
  47. {
  48. public:
  49. virtual ~FillAdaptive() {}
  50. protected:
  51. virtual Fill* clone() const { return new FillAdaptive(*this); };
  52. virtual void _fill_surface_single(
  53. const FillParams &params,
  54. unsigned int thickness_layers,
  55. const std::pair<float, Point> &direction,
  56. ExPolygon &expolygon,
  57. Polylines &polylines_out);
  58. virtual bool no_sort() const { return true; }
  59. void generate_infill_lines(
  60. FillAdaptive_Internal::Cube *cube,
  61. double z_position,
  62. const Vec3d & origin,
  63. const Transform3d & rotation_matrix,
  64. std::vector<Lines> & dir_lines_out,
  65. const std::vector<FillAdaptive_Internal::CubeProperties> &cubes_properties,
  66. int depth);
  67. static void connect_lines(Lines &lines, Line new_line);
  68. void generate_infill(const FillParams & params,
  69. unsigned int thickness_layers,
  70. const std::pair<float, Point> &direction,
  71. ExPolygon & expolygon,
  72. Polylines & polylines_out,
  73. FillAdaptive_Internal::Octree *octree);
  74. public:
  75. static std::unique_ptr<FillAdaptive_Internal::Octree> build_octree(
  76. TriangleMesh &triangle_mesh,
  77. coordf_t line_spacing,
  78. const Vec3d & cube_center);
  79. static void expand_cube(
  80. FillAdaptive_Internal::Cube *cube,
  81. const std::vector<FillAdaptive_Internal::CubeProperties> &cubes_properties,
  82. const AABBTreeIndirect::Tree3f &distance_tree,
  83. const TriangleMesh & triangle_mesh,
  84. int depth);
  85. };
  86. class FillSupportCubic : public FillAdaptive
  87. {
  88. public:
  89. virtual ~FillSupportCubic() = default;
  90. protected:
  91. virtual Fill* clone() const { return new FillSupportCubic(*this); };
  92. virtual bool no_sort() const { return true; }
  93. virtual void _fill_surface_single(
  94. const FillParams &params,
  95. unsigned int thickness_layers,
  96. const std::pair<float, Point> &direction,
  97. ExPolygon &expolygon,
  98. Polylines &polylines_out);
  99. public:
  100. static std::unique_ptr<FillAdaptive_Internal::Octree> build_octree(
  101. TriangleMesh & triangle_mesh,
  102. coordf_t line_spacing,
  103. const Vec3d & cube_center,
  104. const Transform3d &rotation_matrix);
  105. };
  106. // Calculate line spacing for
  107. // 1) adaptive cubic infill
  108. // 2) adaptive internal support cubic infill
  109. // Returns zero for a particular infill type if no such infill is to be generated.
  110. std::pair<double, double> adaptive_fill_line_spacing(const PrintObject &print_object);
  111. } // namespace Slic3r
  112. #endif // slic3r_FillAdaptive_hpp_