Generating polylines from octree
This commit is contained in:
parent
3ac16d9c9c
commit
eaaff4e707
2 changed files with 64 additions and 0 deletions
|
@ -15,7 +15,64 @@ void FillAdaptive::_fill_surface_single(
|
||||||
ExPolygon &expolygon,
|
ExPolygon &expolygon,
|
||||||
Polylines &polylines_out)
|
Polylines &polylines_out)
|
||||||
{
|
{
|
||||||
|
Polylines infill_polylines;
|
||||||
|
this->generate_polylines(this->adapt_fill_octree->root_cube, this->z, this->adapt_fill_octree->origin, infill_polylines);
|
||||||
|
|
||||||
|
// Crop all polylines
|
||||||
|
polylines_out = intersection_pl(infill_polylines, to_polygons(expolygon));
|
||||||
|
}
|
||||||
|
|
||||||
|
void FillAdaptive::generate_polylines(
|
||||||
|
FillAdaptive_Internal::Cube *cube,
|
||||||
|
double z_position,
|
||||||
|
const Vec3d &origin,
|
||||||
|
Polylines &polylines_out)
|
||||||
|
{
|
||||||
|
using namespace FillAdaptive_Internal;
|
||||||
|
|
||||||
|
if(cube == nullptr)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
double z_diff = std::abs(z_position - cube->center.z());
|
||||||
|
|
||||||
|
if (z_diff > cube->properties.height / 2)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (z_diff < cube->properties.line_z_distance)
|
||||||
|
{
|
||||||
|
Point from(
|
||||||
|
scale_((cube->properties.diagonal_length / 2) * (cube->properties.line_z_distance - z_diff) / cube->properties.line_z_distance),
|
||||||
|
scale_(cube->properties.line_xy_distance - ((z_position - (cube->center.z() - cube->properties.line_z_distance)) / sqrt(2))));
|
||||||
|
Point to(-from.x(), from.y());
|
||||||
|
// Relative to cube center
|
||||||
|
|
||||||
|
float rotation_angle = Geometry::deg2rad(120.0);
|
||||||
|
|
||||||
|
for (int dir_idx = 0; dir_idx < 3; dir_idx++)
|
||||||
|
{
|
||||||
|
Vec3d offset = cube->center - origin;
|
||||||
|
Point from_abs(from), to_abs(to);
|
||||||
|
|
||||||
|
from_abs.x() += scale_(offset.x());
|
||||||
|
from_abs.y() += scale_(offset.y());
|
||||||
|
to_abs.x() += scale_(offset.x());
|
||||||
|
to_abs.y() += scale_(offset.y());
|
||||||
|
|
||||||
|
polylines_out.push_back(Polyline(from_abs, to_abs));
|
||||||
|
|
||||||
|
from.rotate(rotation_angle);
|
||||||
|
to.rotate(rotation_angle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(Cube *child : cube->children)
|
||||||
|
{
|
||||||
|
generate_polylines(child, z_position, origin, polylines_out);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FillAdaptive_Internal::Octree* FillAdaptive::build_octree(
|
FillAdaptive_Internal::Octree* FillAdaptive::build_octree(
|
||||||
|
|
|
@ -33,6 +33,11 @@ namespace FillAdaptive_Internal
|
||||||
};
|
};
|
||||||
}; // namespace FillAdaptive_Internal
|
}; // namespace FillAdaptive_Internal
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
//
|
||||||
class FillAdaptive : public Fill
|
class FillAdaptive : public Fill
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -49,6 +54,8 @@ protected:
|
||||||
|
|
||||||
virtual bool no_sort() const { return true; }
|
virtual bool no_sort() const { return true; }
|
||||||
|
|
||||||
|
void generate_polylines(FillAdaptive_Internal::Cube *cube, double z_position, const Vec3d &origin, Polylines &polylines_out);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static FillAdaptive_Internal::Octree* build_octree(
|
static FillAdaptive_Internal::Octree* build_octree(
|
||||||
TriangleMesh &triangleMesh,
|
TriangleMesh &triangleMesh,
|
||||||
|
|
Loading…
Add table
Reference in a new issue