Updates in the C++ infill code.

This commit is contained in:
bubnikv 2016-09-13 11:26:38 +02:00
parent b2a6f43923
commit a5b7f14dfa
14 changed files with 645 additions and 305 deletions

View file

@ -1,3 +1,6 @@
#include <stdio.h>
#include "../ClipperUtils.hpp"
#include "../Surface.hpp"
#include "FillBase.hpp"
@ -24,7 +27,8 @@ Fill* Fill::new_from_type(const std::string &type)
if (type == "line")
return new FillLine();
if (type == "grid")
return new FillGrid();
// return new FillGrid();
return new FillGrid2();
if (type == "archimedeanchords")
return new FillArchimedeanChords();
if (type == "hilbertcurve")
@ -35,16 +39,39 @@ Fill* Fill::new_from_type(const std::string &type)
return NULL;
}
coord_t Fill::adjust_solid_spacing(const coord_t width, const coord_t distance)
Polylines Fill::fill_surface(const Surface *surface, const FillParams &params)
{
coord_t number_of_lines = coord_t(coordf_t(width) / coordf_t(distance)) + 1;
coord_t extra_space = width % distance;
return (number_of_lines <= 1) ?
distance :
distance + extra_space / (number_of_lines - 1);
// Perform offset.
Slic3r::ExPolygons expp;
offset(surface->expolygon, &expp, -0.5*scale_(this->spacing));
// Create the infills for each of the regions.
Polylines polylines_out;
for (size_t i = 0; i < expp.size(); ++ i)
_fill_surface_single(
params,
surface->thickness_layers,
_infill_direction(surface),
expp[i],
polylines_out);
return polylines_out;
}
std::pair<float, Point> FillWithDirection::infill_direction(const Surface *surface) const
// Calculate a new spacing to fill width with possibly integer number of lines,
// the first and last line being centered at the interval ends.
//FIXME Vojtech: This
// This function possibly increases the spacing, never decreases,
// and for a narrow width the increase in spacing may become severe!
coord_t Fill::_adjust_solid_spacing(const coord_t width, const coord_t distance)
{
coord_t number_of_intervals = coord_t(coordf_t(width) / coordf_t(distance));
return (number_of_intervals == 0) ?
distance :
(width / number_of_intervals);
}
// Returns orientation of the infill and the reference point of the infill pattern.
// For a normal print, the reference point is the center of a bounding box of the STL.
std::pair<float, Point> Fill::_infill_direction(const Surface *surface) const
{
// set infill angle
float out_angle = this->angle;
@ -55,10 +82,20 @@ std::pair<float, Point> FillWithDirection::infill_direction(const Surface *surfa
out_angle = 0.f;
}
// Bounding box is the bounding box of a perl object Slic3r::Print::Object (c++ object Slic3r::PrintObject)
// The bounding box is only undefined in unit tests.
Point out_shift = empty(this->bounding_box) ?
surface->expolygon.contour.bounding_box().center() :
this->bounding_box.center();
#if 0
if (empty(this->bounding_box)) {
printf("Fill::_infill_direction: empty bounding box!");
} else {
printf("Fill::_infill_direction: reference point %d, %d\n", out_shift.x, out_shift.y);
}
#endif
if (surface->bridge_angle >= 0) {
// use bridge angle
//FIXME Vojtech: Add a debugf?
@ -71,7 +108,7 @@ std::pair<float, Point> FillWithDirection::infill_direction(const Surface *surfa
// alternate fill direction
out_angle += this->_layer_angle(this->layer_id / surface->thickness_layers);
} else {
printf("Layer_ID undefined!\n");
// printf("Layer_ID undefined!\n");
}
out_angle += float(M_PI/2.);