Exclude_area

This commit is contained in:
sunsets
2024-02-03 10:37:29 +08:00
parent ec446edb36
commit bc68a07f47
20 changed files with 309 additions and 151 deletions

View File

@@ -8,7 +8,9 @@
namespace Slic3r {
BuildVolume::BuildVolume(const std::vector<Vec2d> &bed_shape, const double max_print_height) : m_bed_shape(bed_shape), m_max_print_height(max_print_height)
//B52
BuildVolume::BuildVolume(const std::vector<Vec2d> &bed_shape, const double max_print_height, const std::vector<Vec2d> &exclude_bed_shape)
: m_bed_shape(bed_shape), m_max_print_height(max_print_height),m_exclude_bed_shape(exclude_bed_shape)
{
assert(max_print_height >= 0);
@@ -22,11 +24,16 @@ BuildVolume::BuildVolume(const std::vector<Vec2d> &bed_shape, const double max_p
BoundingBoxf bboxf = get_extents(bed_shape);
m_bboxf = BoundingBoxf3{ to_3d(bboxf.min, 0.), to_3d(bboxf.max, max_print_height) };
//B52
if (bed_shape.size() >= 4 && std::abs((m_area - double(m_bbox.size().x()) * double(m_bbox.size().y()))) < sqr(SCALED_EPSILON)) {
// Square print bed, use the bounding box for collision detection.
m_type = Type::Rectangle;
m_circle.center = 0.5 * (m_bbox.min.cast<double>() + m_bbox.max.cast<double>());
m_circle.radius = 0.5 * m_bbox.size().cast<double>().norm();
} else if (exclude_bed_shape.size()>3) {
m_type = Type::Rectangle;
m_circle.center = 0.5 * (m_bbox.min.cast<double>() + m_bbox.max.cast<double>());
m_circle.radius = 0.5 * m_bbox.size().cast<double>().norm();
} else if (bed_shape.size() > 3) {
// Circle was discretized, formatted into text with limited accuracy, thus the circle was deformed.
// RANSAC is slightly more accurate than the iterative Taubin / Newton method with such an input.
@@ -304,19 +311,49 @@ BuildVolume::ObjectState BuildVolume::object_state(const indexed_triangle_set& i
}
}
//B52
BuildVolume::ObjectState BuildVolume::volume_state_bbox(const BoundingBoxf3& volume_bbox, bool ignore_bottom) const
{
assert(m_type == Type::Rectangle);
BoundingBox3Base<Vec3d> build_volume = this->bounding_volume().inflated(SceneEpsilon);
std::vector<BoundingBox3Base<Vec3d>> exclude_build_volume;
for (int i = 1; i < m_exclude_bed_shape.size(); i += 7) {
std::vector<Vec2d> tem_exclude_bed_shap;
for (int j = 1; j < 6; j++)
tem_exclude_bed_shap.push_back(m_exclude_bed_shape[i + j]);
BoundingBoxf tem_bboxf = get_extents(tem_exclude_bed_shap);
auto tem_exclude_bboxf = BoundingBoxf3{to_3d(tem_bboxf.min, 0.), to_3d(tem_bboxf.max, m_max_print_height)};
BoundingBox3Base<Vec3d> tem_build_volume = tem_exclude_bboxf.inflated(SceneEpsilon);
exclude_build_volume.push_back(tem_build_volume);
}
bool is_contain = false;
bool is_intersect = false;
for (const auto &tem_build_volume : exclude_build_volume) {
if (tem_build_volume.contains(volume_bbox)) {
is_contain=true;
is_intersect = false;
break;
}
else if (tem_build_volume.intersects(volume_bbox)) {
is_contain = false;
is_intersect = true;
}
}
if (m_max_print_height == 0.0)
build_volume.max.z() = std::numeric_limits<double>::max();
if (ignore_bottom)
build_volume.min.z() = -std::numeric_limits<double>::max();
return build_volume.max.z() <= - SceneEpsilon ? ObjectState::Below :
is_contain ? ObjectState::Outside :
is_intersect ? ObjectState::Outside :
build_volume.contains(volume_bbox) ? ObjectState::Inside :
build_volume.intersects(volume_bbox) ? ObjectState::Colliding : ObjectState::Outside;
build_volume.intersects(volume_bbox) ? ObjectState::Colliding :
ObjectState::Outside;
}
//B52
bool BuildVolume::all_paths_inside(const GCodeProcessorResult& paths, const BoundingBoxf3& paths_bbox, bool ignore_bottom) const
{
auto move_valid = [](const GCodeProcessorResult::MoveVertex &move) {
@@ -332,7 +369,32 @@ bool BuildVolume::all_paths_inside(const GCodeProcessorResult& paths, const Boun
build_volume.max.z() = std::numeric_limits<double>::max();
if (ignore_bottom)
build_volume.min.z() = -std::numeric_limits<double>::max();
return build_volume.contains(paths_bbox);
std::vector<BoundingBox3Base<Vec3d>> exclude_build_volume;
for (int i = 1; i < m_exclude_bed_shape.size(); i += 7) {
std::vector<Vec2d> tem_exclude_bed_shap;
for (int j = 1; j < 5; j++)
tem_exclude_bed_shap.push_back(m_exclude_bed_shape[i + j]);
BoundingBoxf tem_bboxf = get_extents(tem_exclude_bed_shap);
auto tem_exclude_bboxf = BoundingBoxf3{to_3d(tem_bboxf.min, 0.), to_3d(tem_bboxf.max, m_max_print_height)};
BoundingBox3Base<Vec3d> tem_build_volume = tem_exclude_bboxf.inflated(SceneEpsilon);
exclude_build_volume.push_back(tem_build_volume);
}
bool is_contain = false;
bool is_intersect = false;
for (const auto &tem_build_volume : exclude_build_volume) {
if (tem_build_volume.contains(paths_bbox)) {
is_contain = true;
is_intersect = false;
break;
} else if (tem_build_volume.intersects(paths_bbox)) {
is_contain = false;
is_intersect = true;
}
}
return (build_volume.contains(paths_bbox) && !is_contain && !is_intersect);
}
case Type::Circle:
{

View File

@@ -34,10 +34,13 @@ public:
// Initialized to empty, all zeros, Invalid.
BuildVolume() {}
// Initialize from PrintConfig::bed_shape and PrintConfig::max_print_height
BuildVolume(const std::vector<Vec2d> &bed_shape, const double max_print_height);
//B52
BuildVolume(const std::vector<Vec2d> &bed_shape, const double max_print_height, const std::vector<Vec2d> &exclude_bed_shape);
// Source data, unscaled coordinates.
const std::vector<Vec2d>& bed_shape() const { return m_bed_shape; }
//B52
const std::vector<Vec2d>& exclude_bed_shape() const { return m_exclude_bed_shape; }
double max_print_height() const { return m_max_print_height; }
// Derived data
@@ -101,6 +104,8 @@ public:
private:
// Source definition of the print bed geometry (PrintConfig::bed_shape)
std::vector<Vec2d> m_bed_shape;
//B52
std::vector<Vec2d> m_exclude_bed_shape;
// Source definition of the print volume height (PrintConfig::max_print_height)
double m_max_print_height;

View File

@@ -536,8 +536,8 @@ static std::vector<std::string> s_Preset_printer_options {
"default_print_profile", "inherits",
"remaining_times", "silent_mode",
"machine_limits_usage", "thumbnails", "thumbnails_format",
//Y20
"bed_exclude_area_0", "bed_exclude_area_1",
//Y20 //B52
"bed_exclude_area",
//Y16
"chamber_temperature", "auxiliary_fan", "chamber_fan"
};
@@ -655,7 +655,9 @@ static std::vector<std::string> s_Preset_sla_printer_options {
//FIXME the print host keys are left here just for conversion from the Printer preset to Physical Printer preset.
"print_host", "printhost_apikey", "printhost_cafile",
"printer_notes",
"inherits"
"inherits",
//B52
"bed_exclude_area",
};
const std::vector<std::string>& Preset::print_options() { return s_Preset_print_options; }
@@ -1348,9 +1350,8 @@ static const std::set<std::string> independent_from_extruder_number_options = {
"filament_ramming_parameters",
"gcode_substitutions",
"post_process",
//Y20
"bed_exclude_area_0",
"bed_exclude_area_1",
//Y20 //B52
"bed_exclude_area",
};
bool PresetCollection::is_independent_from_extruder_number_option(const std::string& opt_key)

View File

@@ -60,9 +60,8 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n
"autoemit_temperature_commands",
"avoid_crossing_perimeters",
"avoid_crossing_perimeters_max_detour",
//Y20
"bed_exclude_area_0",
"bed_exclude_area_1",
//Y20 //B52
"bed_exclude_area",
"bed_shape",
"bed_temperature",
"before_layer_gcode",

View File

@@ -281,14 +281,9 @@ void PrintConfigDef::init_common_params()
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionPoints{ Vec2d(0, 0), Vec2d(200, 0), Vec2d(200, 200), Vec2d(0, 200) });
//Y20
def = this->add("bed_exclude_area_0", coPoints);
def->label = L("Bed exclude area 1");
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionPoints{ Vec2d(0, 0) });
def = this->add("bed_exclude_area_1", coPoints);
def->label = L("Bed exclude area 2");
//Y20 //B52
def = this->add("bed_exclude_area", coPoints);
def->label = L("Bed exclude area");
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionPoints{ Vec2d(0, 0) });

View File

@@ -800,9 +800,8 @@ PRINT_CONFIG_CLASS_DERIVED_DEFINE(
((ConfigOptionBool, avoid_crossing_perimeters))
((ConfigOptionFloatOrPercent, avoid_crossing_perimeters_max_detour))
((ConfigOptionPoints, bed_shape))
//Y20
((ConfigOptionPoints, bed_exclude_area_0))
((ConfigOptionPoints, bed_exclude_area_1))
//Y20 //B52
((ConfigOptionPoints, bed_exclude_area))
((ConfigOptionInts, bed_temperature))
//Y16
((ConfigOptionBool, chamber_temperature))

View File

@@ -3619,9 +3619,12 @@ void fff_tree_support_generate(PrintObject &print_object, std::function<void()>
break;
++idx;
}
FFFTreeSupport::generate_support_areas(*print_object.print(),
BuildVolume(Pointfs{ Vec2d{ -300., -300. }, Vec2d{ -300., +300. }, Vec2d{ +300., +300. }, Vec2d{ +300., -300. } }, 0.), { idx },
throw_on_cancel);
//B52
FFFTreeSupport::generate_support_areas(*print_object.print(),
BuildVolume(Pointfs{Vec2d{-300., -300.}, Vec2d{-300., +300.}, Vec2d{+300., +300.},
Vec2d{+300., -300.}},
0., Pointfs{Vec2d{0., 0.}}),
{idx}, throw_on_cancel);
}
} // namespace Slic3r