Move support cubic infill to separate class.

Support infill is enabled in the GUI.
This commit is contained in:
Lukáš Hejl 2020-09-10 16:53:08 +02:00
parent 8fb9b290b2
commit f49144a9ef
10 changed files with 90 additions and 30 deletions

View file

@ -318,7 +318,7 @@ void export_group_fills_to_svg(const char *path, const std::vector<SurfaceFill>
#endif
// friend to Layer
void Layer::make_fills(FillAdaptive_Internal::Octree* adaptive_fill_octree)
void Layer::make_fills(FillAdaptive_Internal::Octree* adaptive_fill_octree, FillAdaptive_Internal::Octree* support_fill_octree)
{
for (LayerRegion *layerm : m_regions)
layerm->fills.clear();
@ -346,6 +346,7 @@ void Layer::make_fills(FillAdaptive_Internal::Octree* adaptive_fill_octree)
f->z = this->print_z;
f->angle = surface_fill.params.angle;
f->adapt_fill_octree = adaptive_fill_octree;
f->support_fill_octree = support_fill_octree;
// calculate flow spacing for infill pattern generation
bool using_internal_flow = ! surface_fill.surface.is_solid() && ! surface_fill.params.flow.bridge;

View file

@ -35,7 +35,7 @@ std::pair<double, double> adaptive_fill_line_spacing(const PrintObject &print_ob
const PrintRegionConfig &config = region->config();
bool nonempty = config.fill_density > 0;
bool has_adaptive_infill = nonempty && config.fill_pattern == ipAdaptiveCubic;
bool has_support_infill = nonempty && false; // config.fill_pattern == icSupportCubic;
bool has_support_infill = nonempty && config.fill_pattern == ipSupportCubic;
region_fill_data.push_back(RegionFillData({
has_adaptive_infill ? Tristate::Maybe : Tristate::No,
has_support_infill ? Tristate::Maybe : Tristate::No,
@ -90,22 +90,32 @@ std::pair<double, double> adaptive_fill_line_spacing(const PrintObject &print_ob
return std::make_pair(adaptive_line_spacing, support_line_spacing);
}
void FillAdaptive::_fill_surface_single(
const FillParams &params,
unsigned int thickness_layers,
const std::pair<float, Point> &direction,
ExPolygon &expolygon,
Polylines &polylines_out)
void FillAdaptive::_fill_surface_single(const FillParams & params,
unsigned int thickness_layers,
const std::pair<float, Point> &direction,
ExPolygon & expolygon,
Polylines & polylines_out)
{
if(this->adapt_fill_octree != nullptr)
this->generate_infill(params, thickness_layers, direction, expolygon, polylines_out, this->adapt_fill_octree);
}
void FillAdaptive::generate_infill(const FillParams & params,
unsigned int thickness_layers,
const std::pair<float, Point> &direction,
ExPolygon & expolygon,
Polylines & polylines_out,
FillAdaptive_Internal::Octree *octree)
{
Vec3d rotation = Vec3d((5.0 * M_PI) / 4.0, Geometry::deg2rad(215.264), M_PI / 6.0);
Transform3d rotation_matrix = Geometry::assemble_transform(Vec3d::Zero(), rotation, Vec3d::Ones(), Vec3d::Ones());
// Store grouped lines by its direction (multiple of 120°)
std::vector<Lines> infill_lines_dir(3);
this->generate_infill_lines(this->adapt_fill_octree->root_cube.get(),
this->z, this->adapt_fill_octree->origin, rotation_matrix,
infill_lines_dir, this->adapt_fill_octree->cubes_properties,
int(this->adapt_fill_octree->cubes_properties.size()) - 1);
this->generate_infill_lines(octree->root_cube.get(),
this->z, octree->origin, rotation_matrix,
infill_lines_dir, octree->cubes_properties,
int(octree->cubes_properties.size()) - 1);
Polylines all_polylines;
all_polylines.reserve(infill_lines_dir[0].size() * 3);
@ -382,7 +392,7 @@ void FillAdaptive_Internal::Octree::propagate_point(
Octree::propagate_point(point, child, (depth - 1), cubes_properties);
}
std::unique_ptr<FillAdaptive_Internal::Octree> FillAdaptive::build_octree_for_adaptive_support(
std::unique_ptr<FillAdaptive_Internal::Octree> FillSupportCubic::build_octree_for_adaptive_support(
TriangleMesh & triangle_mesh,
coordf_t line_spacing,
const Vec3d & cube_center,
@ -497,4 +507,14 @@ std::unique_ptr<FillAdaptive_Internal::Octree> FillAdaptive::build_octree_for_ad
return octree;
}
void FillSupportCubic::_fill_surface_single(const FillParams & params,
unsigned int thickness_layers,
const std::pair<float, Point> &direction,
ExPolygon & expolygon,
Polylines & polylines_out)
{
if (this->support_fill_octree != nullptr)
this->generate_infill(params, thickness_layers, direction, expolygon, polylines_out, this->support_fill_octree);
}
} // namespace Slic3r

View file

@ -81,6 +81,13 @@ protected:
static void connect_lines(Lines &lines, Line new_line);
void generate_infill(const FillParams & params,
unsigned int thickness_layers,
const std::pair<float, Point> &direction,
ExPolygon & expolygon,
Polylines & polylines_out,
FillAdaptive_Internal::Octree *octree);
public:
static std::unique_ptr<FillAdaptive_Internal::Octree> build_octree(
TriangleMesh &triangle_mesh,
@ -93,7 +100,26 @@ public:
const AABBTreeIndirect::Tree3f &distance_tree,
const TriangleMesh & triangle_mesh,
int depth);
};
class FillSupportCubic : public FillAdaptive
{
public:
virtual ~FillSupportCubic() = default;
protected:
virtual Fill* clone() const { return new FillSupportCubic(*this); };
virtual bool no_sort() const { return true; }
virtual void _fill_surface_single(
const FillParams &params,
unsigned int thickness_layers,
const std::pair<float, Point> &direction,
ExPolygon &expolygon,
Polylines &polylines_out);
public:
static std::unique_ptr<FillAdaptive_Internal::Octree> build_octree_for_adaptive_support(
TriangleMesh & triangle_mesh,
coordf_t line_spacing,

View file

@ -39,6 +39,7 @@ Fill* Fill::new_from_type(const InfillPattern type)
case ipHilbertCurve: return new FillHilbertCurve();
case ipOctagramSpiral: return new FillOctagramSpiral();
case ipAdaptiveCubic: return new FillAdaptive();
case ipSupportCubic: return new FillSupportCubic();
default: throw std::invalid_argument("unknown type");
}
}

View file

@ -73,7 +73,10 @@ public:
// In scaled coordinates. Bounding box of the 2D projection of the object.
BoundingBox bounding_box;
// Octree builds on mesh for usage in the adaptive cubic infill
FillAdaptive_Internal::Octree* adapt_fill_octree = nullptr;
// Octree builds on mesh for usage in the support cubic infill
FillAdaptive_Internal::Octree* support_fill_octree = nullptr;
public:
virtual ~Fill() {}

View file

@ -138,8 +138,8 @@ public:
return false;
}
void make_perimeters();
void make_fills() { this->make_fills(nullptr); };
void make_fills(FillAdaptive_Internal::Octree* adaptive_fill_octree);
void make_fills() { this->make_fills(nullptr, nullptr); };
void make_fills(FillAdaptive_Internal::Octree* adaptive_fill_octree, FillAdaptive_Internal::Octree* support_fill_octree);
void make_ironing();
void export_region_slices_to_svg(const char *path) const;

View file

@ -239,7 +239,7 @@ private:
void discover_horizontal_shells();
void combine_infill();
void _generate_support_material();
std::unique_ptr<FillAdaptive_Internal::Octree> prepare_adaptive_infill_data();
std::pair<std::unique_ptr<FillAdaptive_Internal::Octree>, std::unique_ptr<FillAdaptive_Internal::Octree>> prepare_adaptive_infill_data();
// XYZ in scaled coordinates
Vec3crd m_size;

View file

@ -882,6 +882,7 @@ void PrintConfigDef::init_fff_params()
def->enum_values.push_back("archimedeanchords");
def->enum_values.push_back("octagramspiral");
def->enum_values.push_back("adaptivecubic");
def->enum_values.push_back("supportcubic");
def->enum_labels.push_back(L("Rectilinear"));
def->enum_labels.push_back(L("Grid"));
def->enum_labels.push_back(L("Triangles"));
@ -896,6 +897,7 @@ void PrintConfigDef::init_fff_params()
def->enum_labels.push_back(L("Archimedean Chords"));
def->enum_labels.push_back(L("Octagram Spiral"));
def->enum_labels.push_back(L("Adaptive Cubic"));
def->enum_labels.push_back(L("Support Cubic"));
def->set_default_value(new ConfigOptionEnum<InfillPattern>(ipStars));
def = this->add("first_layer_acceleration", coFloat);

View file

@ -39,7 +39,7 @@ enum AuthorizationType {
enum InfillPattern : int {
ipRectilinear, ipMonotonous, ipGrid, ipTriangles, ipStars, ipCubic, ipLine, ipConcentric, ipHoneycomb, ip3DHoneycomb,
ipGyroid, ipHilbertCurve, ipArchimedeanChords, ipOctagramSpiral, ipAdaptiveCubic, ipCount,
ipGyroid, ipHilbertCurve, ipArchimedeanChords, ipOctagramSpiral, ipAdaptiveCubic, ipSupportCubic, ipCount,
};
enum class IroningType {
@ -140,6 +140,7 @@ template<> inline const t_config_enum_values& ConfigOptionEnum<InfillPattern>::g
keys_map["archimedeanchords"] = ipArchimedeanChords;
keys_map["octagramspiral"] = ipOctagramSpiral;
keys_map["adaptivecubic"] = ipAdaptiveCubic;
keys_map["supportcubic"] = ipSupportCubic;
}
return keys_map;
}

View file

@ -372,15 +372,15 @@ void PrintObject::infill()
this->prepare_infill();
if (this->set_started(posInfill)) {
std::unique_ptr<FillAdaptive_Internal::Octree> octree = this->prepare_adaptive_infill_data();
auto [adaptive_fill_octree, support_fill_octree] = this->prepare_adaptive_infill_data();
BOOST_LOG_TRIVIAL(debug) << "Filling layers in parallel - start";
tbb::parallel_for(
tbb::blocked_range<size_t>(0, m_layers.size()),
[this, &octree](const tbb::blocked_range<size_t>& range) {
[this, &adaptive_fill_octree, &support_fill_octree](const tbb::blocked_range<size_t>& range) {
for (size_t layer_idx = range.begin(); layer_idx < range.end(); ++ layer_idx) {
m_print->throw_if_canceled();
m_layers[layer_idx]->make_fills(octree.get());
m_layers[layer_idx]->make_fills(adaptive_fill_octree.get(), support_fill_octree.get());
}
}
);
@ -433,14 +433,18 @@ void PrintObject::generate_support_material()
}
}
#define ADAPTIVE_SUPPORT
#define ADAPTIVE_SUPPORT_SIMPLE
//#define ADAPTIVE_SUPPORT_SIMPLE
std::unique_ptr<FillAdaptive_Internal::Octree> PrintObject::prepare_adaptive_infill_data()
std::pair<std::unique_ptr<FillAdaptive_Internal::Octree>, std::unique_ptr<FillAdaptive_Internal::Octree>> PrintObject::prepare_adaptive_infill_data()
{
using namespace FillAdaptive_Internal;
auto [adaptive_line_spacing, support_line_spacing] = adaptive_fill_line_spacing(*this);
if (adaptive_line_spacing == 0.)
return std::unique_ptr<FillAdaptive_Internal::Octree>{};
std::unique_ptr<Octree> adaptive_fill_octree = {}, support_fill_octree = {};
if (adaptive_line_spacing == 0. && support_line_spacing == 0.)
return std::make_pair(std::move(adaptive_fill_octree), std::move(support_fill_octree));
TriangleMesh mesh = this->model_object()->raw_mesh();
mesh.transform(m_trafo, true);
@ -490,11 +494,13 @@ std::unique_ptr<FillAdaptive_Internal::Octree> PrintObject::prepare_adaptive_inf
// Rotate mesh and build octree on it with axis-aligned (standart base) cubes
mesh.transform(rotation_matrix);
#if defined(ADAPTIVE_SUPPORT) && !defined(ADAPTIVE_SUPPORT_SIMPLE)
return FillAdaptive::build_octree_for_adaptive_support(mesh, adaptive_line_spacing, rotation_matrix * mesh_origin, rotation_matrix);
#else
return FillAdaptive::build_octree(mesh, adaptive_line_spacing, rotation_matrix * mesh_origin);
#endif
if (adaptive_line_spacing != 0.)
adaptive_fill_octree = FillAdaptive::build_octree(mesh, adaptive_line_spacing, rotation_matrix * mesh_origin);
if (support_line_spacing != 0.)
support_fill_octree = FillSupportCubic::build_octree_for_adaptive_support(mesh, support_line_spacing, rotation_matrix * mesh_origin, rotation_matrix);
return std::make_pair(std::move(adaptive_fill_octree), std::move(support_fill_octree));
}
void PrintObject::clear_layers()