mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-12-01 09:22:58 -05:00
Give the Solid Drag Model's Flat Faces the Top and Bottom Surface Colours
This commit is contained in:
1 parent
7f9bd80ebd
commit
dac25fd5b0
15 files changed
+264
-23
No files matched your search
@@ -47,6 +47,8 @@ void Layers::update(const PathVertex& vertex, uint32_t vertex_id)
|
||||
item.contains_colorprint_options |= is_colorprint_option(vertex);
|
||||
item.has_infill = is_infill(vertex);
|
||||
item.has_sparse_infill = vertex.type == EMoveType::Extrude && vertex.role == EGCodeExtrusionRole::InternalInfill;
|
||||
if (vertex.is_extrusion())
|
||||
item.roles = role_bit(vertex.role);
|
||||
}
|
||||
else {
|
||||
Item& item = m_items.back();
|
||||
@@ -59,6 +61,8 @@ void Layers::update(const PathVertex& vertex, uint32_t vertex_id)
|
||||
item.contains_colorprint_options |= is_colorprint_option(vertex);
|
||||
item.has_infill |= is_infill(vertex);
|
||||
item.has_sparse_infill |= vertex.type == EMoveType::Extrude && vertex.role == EGCodeExtrusionRole::InternalInfill;
|
||||
if (vertex.is_extrusion())
|
||||
item.roles |= role_bit(vertex.role);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,6 +55,10 @@ public:
|
||||
bool layer_has_sparse_infill(std::size_t layer_id) const {
|
||||
return (layer_id < m_items.size()) ? m_items[layer_id].has_sparse_infill : false;
|
||||
}
|
||||
// whether the layer has an extrusion of the role
|
||||
bool layer_has_role(std::size_t layer_id, EGCodeExtrusionRole role) const {
|
||||
return (layer_id < m_items.size()) ? (m_items[layer_id].roles & role_bit(role)) != 0 : false;
|
||||
}
|
||||
// Whether each layer's infill closes every object printed on it, as the caller knows it from
|
||||
// the objects the moves belong to: bit 0 as seen from above, bit 1 as seen from below, see
|
||||
// GCodeInputData::layers_closed. Ignored unless there is one entry per layer.
|
||||
@@ -92,7 +96,11 @@ private:
|
||||
bool has_sparse_infill{ false };
|
||||
bool closed_from_above{ false };
|
||||
bool closed_from_below{ false };
|
||||
// one bit per extrusion role printed on the layer, see role_bit()
|
||||
uint32_t roles{ 0 };
|
||||
};
|
||||
static_assert(static_cast<std::size_t>(EGCodeExtrusionRole::COUNT) <= 32, "Item::roles holds one bit per role");
|
||||
static uint32_t role_bit(EGCodeExtrusionRole role) { return uint32_t(1) << static_cast<uint32_t>(role); }
|
||||
|
||||
std::vector<Item> m_items;
|
||||
Range m_view_range;
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <cstddef>
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
#include <algorithm>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define STDVEC_MEMSIZE(NAME, TYPE) NAME.capacity() * ((sizeof(TYPE) + __alignof(TYPE) - 1) / __alignof(TYPE)) * __alignof(TYPE)
|
||||
@@ -58,6 +59,49 @@ std::optional<std::size_t> collect_role_samples(const std::vector<PathVertex>& v
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
// Up to max_count of the interval's layers that pass has_role(), spread evenly over them from the
|
||||
// first such layer to the last; the caller bounds the interval by the layer count. A role printed
|
||||
// on a few layers only, as top surfaces and bridges are, is so sampled where it was printed rather
|
||||
// than missed between samples.
|
||||
template<typename HasRole>
|
||||
std::vector<std::size_t> pick_sample_layers(const Interval& layers, std::size_t max_count, const HasRole& has_role)
|
||||
{
|
||||
std::vector<std::size_t> with_role;
|
||||
for (std::size_t id = layers[0]; id <= layers[1]; ++id) {
|
||||
if (has_role(id))
|
||||
with_role.push_back(id);
|
||||
}
|
||||
const std::size_t count = with_role.size();
|
||||
const std::size_t steps = std::min(count, max_count);
|
||||
std::vector<std::size_t> picked;
|
||||
picked.reserve(steps);
|
||||
for (std::size_t step = 0; step < steps; ++step)
|
||||
picked.push_back(with_role[(steps > 1) ? step * (count - 1) / (steps - 1) : 0]);
|
||||
return picked;
|
||||
}
|
||||
// Samples the role over the interval's layers through sample_layer(), which returns an id to stop
|
||||
// at, as the first extrusion of a view that grades by nothing, and collects samples otherwise:
|
||||
// the layers pick_sample_layers() picks, then, while has_samples() is false, the interval's other
|
||||
// layers with the role in order, since on a plate of several objects the layers another object
|
||||
// has the role on can take every pick. The walk stops at the first layer that yields samples, so
|
||||
// its median comes from that layer alone.
|
||||
template<typename HasRole, typename SampleLayer, typename HasSamples>
|
||||
std::optional<std::size_t> sample_role_layers(const Interval& layers, std::size_t max_count, const HasRole& has_role,
|
||||
const SampleLayer& sample_layer, const HasSamples& has_samples)
|
||||
{
|
||||
const std::vector<std::size_t> picked = pick_sample_layers(layers, max_count, has_role);
|
||||
for (const std::size_t layer_id : picked) {
|
||||
if (const std::optional<std::size_t> first = sample_layer(layer_id); first.has_value())
|
||||
return first;
|
||||
}
|
||||
for (std::size_t layer_id = layers[0]; !has_samples() && layer_id <= layers[1]; ++layer_id) {
|
||||
if (!has_role(layer_id) || std::binary_search(picked.begin(), picked.end(), layer_id))
|
||||
continue;
|
||||
if (const std::optional<std::size_t> first = sample_layer(layer_id); first.has_value())
|
||||
return first;
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
} // namespace libvgcode
|
||||
|
||||
|
||||
@@ -1835,25 +1835,31 @@ std::optional<float> ViewerImpl::get_vertex_value(const PathVertex& v) const
|
||||
|
||||
// The extrusion of the role that stands for the layers, or the vertex count. A view that grades
|
||||
// by a value takes the length-weighted median of it over the role's extrusions in up to
|
||||
// VERTEX_SAMPLE_LAYERS layers spread evenly over the interval, so that neither the ramp a wall
|
||||
// starts on nor one odd layer sets the colour; any other view takes the first extrusion found.
|
||||
// A layer's vertices lie between its first and last ids, with those of other layers among them
|
||||
// in a print by object. Only the extrusions that end inside the box count, so that one object's
|
||||
// walls can be told from another's on the same layers.
|
||||
// VERTEX_SAMPLE_LAYERS of the interval's layers that have the role, spread evenly over them, so
|
||||
// that neither the ramp a wall starts on nor one odd layer sets the colour, or, where none of
|
||||
// those has the role inside the box, in the first other layer that has; any other view takes the
|
||||
// first extrusion found, see sample_role_layers(). A layer's vertices lie between its first and
|
||||
// last ids, with those of other layers among them in a print by object. Only the extrusions that
|
||||
// end inside the box count, so that one object's walls can be told from another's on the same
|
||||
// layers.
|
||||
size_t ViewerImpl::find_extrusion_vertex(const Interval& layers, EGCodeExtrusionRole role, const XYBox& box) const
|
||||
{
|
||||
if (m_layers.empty() || layers[0] > layers[1])
|
||||
return m_vertices.size();
|
||||
const Interval range = { layers[0], std::min(layers[1], m_layers.count() - 1) };
|
||||
std::vector<std::pair<float, float>> samples;
|
||||
std::vector<size_t> ids;
|
||||
const size_t count = (layers[1] >= layers[0]) ? layers[1] - layers[0] + 1 : 0;
|
||||
const size_t steps = std::min(count, VERTEX_SAMPLE_LAYERS);
|
||||
const auto value_of = [this](const PathVertex& v) { return get_vertex_value(v); };
|
||||
for (size_t step = 0; step < steps; ++step) {
|
||||
const size_t layer_id = layers[0] + ((steps > 1) ? step * (count - 1) / (steps - 1) : 0);
|
||||
const std::optional<size_t> first = collect_role_samples(m_vertices, m_layers.get_layer_vertex_range(layer_id),
|
||||
const auto has_role = [this, role](size_t layer_id) { return m_layers.layer_has_role(layer_id, role); };
|
||||
const auto sample_layer = [&](size_t layer_id) {
|
||||
return collect_role_samples(m_vertices, m_layers.get_layer_vertex_range(layer_id),
|
||||
static_cast<uint32_t>(layer_id), role, box, value_of, samples, ids);
|
||||
if (first.has_value())
|
||||
return *first;
|
||||
}
|
||||
};
|
||||
const auto has_samples = [&samples]() { return !samples.empty(); };
|
||||
const std::optional<size_t> first = sample_role_layers(range, VERTEX_SAMPLE_LAYERS, has_role, sample_layer,
|
||||
has_samples);
|
||||
if (first.has_value())
|
||||
return *first;
|
||||
return samples.empty() ? m_vertices.size() : ids[weighted_median_index(samples)];
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user