ENH: add paint-on support on vertical faces

Add paint-on support on vertical faces of slender rods

ENH STUDIO-970/1285
FIX STUDIO-1183

Change-Id: I36b398f9c1c1341bce080ec3d454dcc6e6f991e8
(cherry picked from commit 65ee2c8d74284b21bfd34a1059e2005998d749c5)
This commit is contained in:
MusangKing 2022-11-17 22:55:17 +08:00 committed by Lane.Wei
parent e61e6c3c95
commit aa0dbac351
3 changed files with 30 additions and 7 deletions

View file

@ -2798,6 +2798,10 @@ static void project_triangles_to_slabs(ConstLayerPtrsAdaptor layers, const index
void PrintObject::project_and_append_custom_facets(
bool seam, EnforcerBlockerType type, std::vector<Polygons>& out) const
{
// BBS: Approve adding enforcer support on vertical faces
SlabSlicingConfig config;
config.isVertical = true;
for (const ModelVolume* mv : this->model_object()->volumes)
if (mv->is_model_part()) {
const indexed_triangle_set custom_facets = seam
@ -2811,7 +2815,7 @@ void PrintObject::project_and_append_custom_facets(
else {
std::vector<Polygons> projected;
// Support blockers or enforcers. Project downward facing painted areas upwards to their respective slicing plane.
slice_mesh_slabs(custom_facets, zs_from_layers(this->layers()), this->trafo_centered() * mv->get_matrix(), nullptr, &projected, [](){});
slice_mesh_slabs(custom_facets, zs_from_layers(this->layers()), this->trafo_centered() * mv->get_matrix(), nullptr, &projected, [](){}, config);
// Merge these projections with the output, layer by layer.
assert(! projected.empty());
assert(out.empty() || out.size() == projected.size());

View file

@ -753,7 +753,9 @@ inline std::pair<SlabLines, SlabLines> slice_slabs_make_lines(
const std::vector<float> &zs,
bool top,
bool bottom,
const ThrowOnCancel throw_on_cancel_fn)
const ThrowOnCancel throw_on_cancel_fn,
// BBS: solve conflicts (see declaration) and most elegant way I can get
SlabSlicingConfig config)
{
std::pair<SlabLines, SlabLines> out;
SlabLines &lines_top = out.first;
@ -772,7 +774,7 @@ inline std::pair<SlabLines, SlabLines> slice_slabs_make_lines(
tbb::parallel_for(
tbb::blocked_range<int>(0, int(indices.size())),
[&vertices, &indices, &face_neighbors, &face_edge_ids, num_edges, &face_orientation, &zs, top, bottom, &lines_top, &lines_bottom, &lines_mutex_top, &lines_mutex_bottom, throw_on_cancel_fn]
[&vertices, &indices, &face_neighbors, &face_edge_ids, num_edges, &face_orientation, &zs, top, bottom, &lines_top, &lines_bottom, &lines_mutex_top, &lines_mutex_bottom, throw_on_cancel_fn, &config]
(const tbb::blocked_range<int> &range) {
for (int face_idx = range.begin(); face_idx < range.end(); ++ face_idx) {
if ((face_idx & 0x0ffff) == 0)
@ -790,7 +792,8 @@ inline std::pair<SlabLines, SlabLines> slice_slabs_make_lines(
}
slice_facet_with_slabs<true>(vertices, indices, face_idx, neighbors, edge_ids, num_edges, zs, lines_top, lines_mutex_top);
}
if (bottom && (fo == FaceOrientation::Down || fo == FaceOrientation::Degenerate)) {
// BBS: add vertical faces option
if (bottom && (fo == FaceOrientation::Down || (config.isVertical && fo == FaceOrientation::Vertical) || fo == FaceOrientation::Degenerate)) {
Vec3i neighbors = face_neighbors[face_idx];
// Reset neighborship of this triangle in case the other triangle is oriented backwards from this one.
for (int i = 0; i < 3; ++ i)
@ -1895,7 +1898,8 @@ void slice_mesh_slabs(
const Transform3d &trafo,
std::vector<Polygons> *out_top,
std::vector<Polygons> *out_bottom,
std::function<void()> throw_on_cancel)
std::function<void()> throw_on_cancel,
SlabSlicingConfig config)
{
BOOST_LOG_TRIVIAL(debug) << "slice_mesh_slabs to polygons";
@ -1974,7 +1978,7 @@ void slice_mesh_slabs(
std::vector<Vec3i> face_edge_ids = its_face_edge_ids(mesh, face_neighbors, true, &num_edges);
std::pair<SlabLines, SlabLines> lines = slice_slabs_make_lines(
vertices_transformed, mesh.indices, face_neighbors, face_edge_ids, num_edges, face_orientation, zs,
out_top != nullptr, out_bottom != nullptr, throw_on_cancel);
out_top != nullptr, out_bottom != nullptr, throw_on_cancel, config);
throw_on_cancel();

View file

@ -46,6 +46,19 @@ struct MeshSlicingParamsEx : public MeshSlicingParams
double resolution { 0 };
};
// BBS: MusangKing - NEW: add paint-on support on vertical-faces
// this SlabSlicingConfig aiming to distinguish if slice_slabs_make_lines() outputs lines by slab_slicing on vertical faces
// e.g., for support enforcer operation: isVertical = true; for other color painting operations: isVertical = false (default).
// solve conflicts STUDIO-1183/970/1285
struct SlabSlicingConfig
{
SlabSlicingConfig()
: isVertical(false)
{}
bool isVertical;
};
// All the following slicing functions shall produce consistent results with the same mesh, same transformation matrix and slicing parameters.
// Namely, slice_mesh_slabs() shall produce consistent results with slice_mesh() and slice_mesh_ex() in the sense, that projections made by
// slice_mesh_slabs() shall fall onto slicing planes produced by slice_mesh().
@ -107,7 +120,9 @@ void slice_mesh_slabs(
const Transform3d &trafo,
std::vector<Polygons> *out_top,
std::vector<Polygons> *out_bottom,
std::function<void()> throw_on_cancel);
std::function<void()> throw_on_cancel,
// BBS: MusangKing
SlabSlicingConfig config = SlabSlicingConfig());
// Project mesh upwards pointing surfaces / downwards pointing surfaces into 2D polygons.
void project_mesh(