FillAdaptive.hpp 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. ///|/ Copyright (c) Prusa Research 2020 - 2021 Lukáš Matěna @lukasmatena, Vojtěch Bubník @bubnikv, Lukáš Hejl @hejllukas, Tomáš Mészáros @tamasmeszaros
  2. ///|/
  3. ///|/ PrusaSlicer is released under the terms of the AGPLv3 or higher
  4. ///|/
  5. // Adaptive cubic infill was inspired by the work of @mboerwinkle
  6. // as implemented for Cura.
  7. // https://github.com/Ultimaker/CuraEngine/issues/381
  8. // https://github.com/Ultimaker/CuraEngine/pull/401
  9. //
  10. // Our implementation is more accurate (discretizes a bit less cubes than Cura's)
  11. // by splitting only such cubes which contain a triangle.
  12. // Our line extraction is time optimal instead of O(n^2) when connecting extracted lines,
  13. // and we also implemented adaptivity for supporting internal overhangs only.
  14. #ifndef slic3r_FillAdaptive_hpp_
  15. #define slic3r_FillAdaptive_hpp_
  16. #include "FillBase.hpp"
  17. struct indexed_triangle_set;
  18. namespace Slic3r {
  19. class PrintObject;
  20. namespace FillAdaptive
  21. {
  22. struct Octree;
  23. // To keep the definition of Octree opaque, we have to define a custom deleter.
  24. struct OctreeDeleter { void operator()(Octree *p); };
  25. using OctreePtr = std::unique_ptr<Octree, OctreeDeleter>;
  26. // Calculate line spacing for
  27. // 1) adaptive cubic infill
  28. // 2) adaptive internal support cubic infill
  29. // Returns zero for a particular infill type if no such infill is to be generated.
  30. std::pair<double, double> adaptive_fill_line_spacing(const PrintObject &print_object);
  31. // Rotation of the octree to stand on one of its corners.
  32. Eigen::Quaterniond transform_to_world();
  33. // Inverse roation of the above.
  34. Eigen::Quaterniond transform_to_octree();
  35. FillAdaptive::OctreePtr build_octree(
  36. // Mesh is rotated to the coordinate system of the octree.
  37. const indexed_triangle_set &triangle_mesh,
  38. // Overhang triangles extracted from fill surfaces with stInternalBridge type,
  39. // rotated to the coordinate system of the octree.
  40. const std::vector<Vec3d> &overhang_triangles,
  41. coordf_t line_spacing,
  42. // If true, octree is densified below internal overhangs only.
  43. bool support_overhangs_only);
  44. //
  45. // Some of the algorithms used by class FillAdaptive were inspired by
  46. // Cura Engine's class SubDivCube
  47. // https://github.com/Ultimaker/CuraEngine/blob/master/src/infill/SubDivCube.h
  48. //
  49. class Filler : public Slic3r::Fill
  50. {
  51. public:
  52. ~Filler() override {}
  53. protected:
  54. Fill* clone() const override { return new Filler(*this); }
  55. void _fill_surface_single(
  56. const FillParams &params,
  57. unsigned int thickness_layers,
  58. const std::pair<float, Point> &direction,
  59. ExPolygon expolygon,
  60. Polylines &polylines_out) const override;
  61. // Let the G-code export reoder the infill lines.
  62. //FIXME letting the G-code exporter to reorder infill lines of Adaptive Cubic Infill
  63. // may not be optimal as the internal infill lines may get extruded before the long infill
  64. // lines to which the short infill lines are supposed to anchor.
  65. bool no_sort() const override { return false; }
  66. };
  67. } // namespace FillAdaptive
  68. } // namespace Slic3r
  69. #endif // slic3r_FillAdaptive_hpp_