New sparse infill: "stars" - David's star shaped infill.

This is very similar to a "triangles" infill, but maximum two lines
intersect at a single point.

added utility function get_extents_vector()
This commit is contained in:
bubnikv 2016-11-09 15:39:12 +01:00
parent eb0ab38618
commit 317e9131e8
10 changed files with 52 additions and 3 deletions

View file

@ -587,6 +587,15 @@ BoundingBox get_extents_rotated(const ExPolygons &expolygons, double angle)
return bbox;
}
extern std::vector<BoundingBox> get_extents_vector(const ExPolygons &polygons)
{
std::vector<BoundingBox> out;
out.reserve(polygons.size());
for (ExPolygons::const_iterator it = polygons.begin(); it != polygons.end(); ++ it)
out.push_back(get_extents(*it));
return out;
}
bool remove_sticks(ExPolygon &poly)
{
return remove_sticks(poly.contour) || remove_sticks(poly.holes);

View file

@ -271,6 +271,7 @@ extern BoundingBox get_extents(const ExPolygon &expolygon);
extern BoundingBox get_extents(const ExPolygons &expolygons);
extern BoundingBox get_extents_rotated(const ExPolygon &poly, double angle);
extern BoundingBox get_extents_rotated(const ExPolygons &polygons, double angle);
extern std::vector<BoundingBox> get_extents_vector(const ExPolygons &polygons);
extern bool remove_sticks(ExPolygon &poly);

View file

@ -25,6 +25,7 @@ Fill* Fill::new_from_type(const InfillPattern type)
case ipLine: return new FillLine();
case ipGrid: return new FillGrid2();
case ipTriangles: return new FillTriangles();
case ipStars: return new FillStars();
case ipCubic: return new FillCubic();
// case ipGrid: return new FillGrid();
case ipArchimedeanChords: return new FillArchimedeanChords();

View file

@ -49,7 +49,7 @@ public:
// in radians, ccw, 0 = East
float angle;
// In scaled coordinates. Maximum lenght of a perimeter segment connecting two infill lines.
// Used by the FillRectilinear2, FillGrid2, FillTriangles and FillCubic.
// Used by the FillRectilinear2, FillGrid2, FillTriangles, FillStars and FillCubic.
// If left to zero, the links will not be limited.
coord_t link_max_length;
// In scaled coordinates. Used by the concentric infill pattern to clip the loops to create extrusion paths.

View file

@ -1517,12 +1517,26 @@ Polylines FillTriangles::fill_surface(const Surface *surface, const FillParams &
Polylines polylines_out;
if (! fill_surface_by_lines(surface, params2, 0.f, 0., polylines_out) ||
! fill_surface_by_lines(surface, params2, float(M_PI / 3.), 0., polylines_out) ||
! fill_surface_by_lines(surface, params2, float(2. * M_PI / 3.), 0., polylines_out)) {
! fill_surface_by_lines(surface, params2, float(2. * M_PI / 3.), 0.5 * this->spacing / params2.density, polylines_out)) {
printf("FillTriangles::fill_surface() failed to fill a region.\n");
}
return polylines_out;
}
Polylines FillStars::fill_surface(const Surface *surface, const FillParams &params)
{
// Each linear fill covers 1/3 of the target coverage.
FillParams params2 = params;
params2.density *= 0.333333333f;
Polylines polylines_out;
if (! fill_surface_by_lines(surface, params2, 0.f, 0., polylines_out) ||
! fill_surface_by_lines(surface, params2, float(M_PI / 3.), 0., polylines_out) ||
! fill_surface_by_lines(surface, params2, float(2. * M_PI / 3.), 0., polylines_out)) {
printf("FillStars::fill_surface() failed to fill a region.\n");
}
return polylines_out;
}
Polylines FillCubic::fill_surface(const Surface *surface, const FillParams &params)
{
// Each linear fill covers 1/3 of the target coverage.

View file

@ -41,6 +41,17 @@ protected:
virtual float _layer_angle(size_t idx) const { return 0.f; }
};
class FillStars : public FillRectilinear2
{
public:
virtual ~FillStars() {}
virtual Polylines fill_surface(const Surface *surface, const FillParams &params);
protected:
// The grid fill will keep the angle constant between the layers, see the implementation of Slic3r::Fill.
virtual float _layer_angle(size_t idx) const { return 0.f; }
};
class FillCubic : public FillRectilinear2
{
public:

View file

@ -328,6 +328,15 @@ BoundingBox get_extents_rotated(const Polygons &polygons, double angle)
return bb;
}
extern std::vector<BoundingBox> get_extents_vector(const Polygons &polygons)
{
std::vector<BoundingBox> out;
out.reserve(polygons.size());
for (Polygons::const_iterator it = polygons.begin(); it != polygons.end(); ++ it)
out.push_back(get_extents(*it));
return out;
}
static inline bool is_stick(const Point &p1, const Point &p2, const Point &p3)
{
Point v1 = p2 - p1;

View file

@ -52,6 +52,7 @@ extern BoundingBox get_extents(const Polygon &poly);
extern BoundingBox get_extents(const Polygons &polygons);
extern BoundingBox get_extents_rotated(const Polygon &poly, double angle);
extern BoundingBox get_extents_rotated(const Polygons &polygons, double angle);
extern std::vector<BoundingBox> get_extents_vector(const Polygons &polygons);
// Remove sticks (tentacles with zero area) from the polygon.
extern bool remove_sticks(Polygon &poly);

View file

@ -397,6 +397,7 @@ PrintConfigDef::PrintConfigDef()
def->enum_values.push_back("rectilinear");
def->enum_values.push_back("grid");
def->enum_values.push_back("triangles");
def->enum_values.push_back("stars");
def->enum_values.push_back("cubic");
def->enum_values.push_back("line");
def->enum_values.push_back("concentric");
@ -408,6 +409,7 @@ PrintConfigDef::PrintConfigDef()
def->enum_labels.push_back("Rectilinear");
def->enum_labels.push_back("Grid");
def->enum_labels.push_back("Triangles");
def->enum_labels.push_back("Stars");
def->enum_labels.push_back("Cubic");
def->enum_labels.push_back("Line");
def->enum_labels.push_back("Concentric");

View file

@ -30,7 +30,7 @@ enum GCodeFlavor {
};
enum InfillPattern {
ipRectilinear, ipGrid, ipTriangles, ipCubic, ipLine, ipConcentric, ipHoneycomb, ip3DHoneycomb,
ipRectilinear, ipGrid, ipTriangles, ipStars, ipCubic, ipLine, ipConcentric, ipHoneycomb, ip3DHoneycomb,
ipHilbertCurve, ipArchimedeanChords, ipOctagramSpiral,
};
@ -59,6 +59,7 @@ template<> inline t_config_enum_values ConfigOptionEnum<InfillPattern>::get_enum
keys_map["rectilinear"] = ipRectilinear;
keys_map["grid"] = ipGrid;
keys_map["triangles"] = ipTriangles;
keys_map["stars"] = ipStars;
keys_map["cubic"] = ipCubic;
keys_map["line"] = ipLine;
keys_map["concentric"] = ipConcentric;