PrusaSlicer-NonPlainar/src/libslic3r/Fill/FillAdaptive.hpp

113 lines
3.9 KiB
C++
Raw Normal View History

2020-08-26 14:51:34 +00:00
#ifndef slic3r_FillAdaptive_hpp_
#define slic3r_FillAdaptive_hpp_
#include "../AABBTreeIndirect.hpp"
2020-08-26 14:51:34 +00:00
#include "FillBase.hpp"
namespace Slic3r {
class PrintObject;
2020-08-26 14:51:34 +00:00
namespace FillAdaptive_Internal
{
struct CubeProperties
{
double edge_length; // Lenght of edge of a cube
double height; // Height of rotated cube (standing on the corner)
double diagonal_length; // Length of diagonal of a cube a face
double line_z_distance; // Defines maximal distance from a center of a cube on Z axis on which lines will be created
double line_xy_distance;// Defines maximal distance from a center of a cube on X and Y axis on which lines will be created
};
struct Cube
{
Vec3d center;
2020-09-03 17:21:55 +00:00
std::unique_ptr<Cube> children[8] = {};
Cube(const Vec3d &center) : center(center) {}
2020-08-26 14:51:34 +00:00
};
struct Octree
{
2020-08-27 05:28:43 +00:00
std::unique_ptr<Cube> root_cube;
2020-08-26 14:51:34 +00:00
Vec3d origin;
2020-09-03 17:21:55 +00:00
std::vector<CubeProperties> cubes_properties;
2020-09-03 09:56:41 +00:00
2020-09-03 17:21:55 +00:00
Octree(std::unique_ptr<Cube> rootCube, const Vec3d &origin, const std::vector<CubeProperties> &cubes_properties)
: root_cube(std::move(rootCube)), origin(origin), cubes_properties(cubes_properties) {}
inline static int find_octant(const Vec3d &i_cube, const Vec3d &current)
{
return (i_cube.z() > current.z()) * 4 + (i_cube.y() > current.y()) * 2 + (i_cube.x() > current.x());
}
static void propagate_point(
Vec3d point,
FillAdaptive_Internal::Cube *current_cube,
int depth,
const std::vector<FillAdaptive_Internal::CubeProperties> &cubes_properties);
2020-08-26 14:51:34 +00:00
};
}; // namespace FillAdaptive_Internal
2020-08-26 20:18:51 +00:00
//
// Some of the algorithms used by class FillAdaptive were inspired by
// Cura Engine's class SubDivCube
// https://github.com/Ultimaker/CuraEngine/blob/master/src/infill/SubDivCube.h
//
2020-08-26 14:51:34 +00:00
class FillAdaptive : public Fill
{
public:
virtual ~FillAdaptive() {}
protected:
virtual Fill* clone() const { return new FillAdaptive(*this); };
virtual void _fill_surface_single(
2020-09-03 17:21:55 +00:00
const FillParams &params,
2020-08-26 14:51:34 +00:00
unsigned int thickness_layers,
2020-09-03 17:21:55 +00:00
const std::pair<float, Point> &direction,
ExPolygon &expolygon,
2020-08-26 14:51:34 +00:00
Polylines &polylines_out);
virtual bool no_sort() const { return true; }
2020-09-03 17:21:55 +00:00
void generate_infill_lines(
FillAdaptive_Internal::Cube *cube,
double z_position,
const Vec3d & origin,
const Transform3d & rotation_matrix,
2020-09-03 17:21:55 +00:00
std::vector<Lines> & dir_lines_out,
const std::vector<FillAdaptive_Internal::CubeProperties> &cubes_properties,
int depth);
2020-08-26 23:59:35 +00:00
2020-09-03 12:28:25 +00:00
static void connect_lines(Lines &lines, Line new_line);
2020-08-26 20:18:51 +00:00
public:
2020-08-27 05:28:43 +00:00
static std::unique_ptr<FillAdaptive_Internal::Octree> build_octree(
2020-09-03 17:21:55 +00:00
TriangleMesh &triangle_mesh,
coordf_t line_spacing,
const Vec3d & cube_center);
static void expand_cube(
2020-09-03 17:21:55 +00:00
FillAdaptive_Internal::Cube *cube,
const std::vector<FillAdaptive_Internal::CubeProperties> &cubes_properties,
const AABBTreeIndirect::Tree3f &distance_tree,
const TriangleMesh & triangle_mesh,
int depth);
2020-09-09 07:29:50 +00:00
static std::unique_ptr<FillAdaptive_Internal::Octree> build_octree_for_adaptive_support(
TriangleMesh & triangle_mesh,
coordf_t line_spacing,
const Vec3d & cube_center,
const Transform3d &rotation_matrix);
2020-08-26 14:51:34 +00:00
};
// Calculate line spacing for
// 1) adaptive cubic infill
// 2) adaptive internal support cubic infill
// Returns zero for a particular infill type if no such infill is to be generated.
std::pair<double, double> adaptive_fill_line_spacing(const PrintObject &print_object);
2020-08-26 14:51:34 +00:00
} // namespace Slic3r
#endif // slic3r_FillAdaptive_hpp_