parent
0a0ad1ef10
commit
01dec1bd5c
@ -497,7 +497,7 @@ void TreeModelVolumes::calculateCollision(const coord_t radius, const LayerIndex
|
|||||||
const bool calculate_placable = m_support_rests_on_model && radius == 0;
|
const bool calculate_placable = m_support_rests_on_model && radius == 0;
|
||||||
LayerPolygonCache data_placeable;
|
LayerPolygonCache data_placeable;
|
||||||
if (calculate_placable)
|
if (calculate_placable)
|
||||||
data_placeable.allocate(data.idx_begin, data.idx_end);
|
data_placeable.allocate(data.begin(), data.end());
|
||||||
|
|
||||||
for (size_t outline_idx : layer_outline_indices)
|
for (size_t outline_idx : layer_outline_indices)
|
||||||
if (const std::vector<Polygons> &outlines = m_layer_outlines[outline_idx].second; ! outlines.empty()) {
|
if (const std::vector<Polygons> &outlines = m_layer_outlines[outline_idx].second; ! outlines.empty()) {
|
||||||
@ -517,9 +517,9 @@ void TreeModelVolumes::calculateCollision(const coord_t radius, const LayerIndex
|
|||||||
// 1) Calculate offsets of collision areas in parallel.
|
// 1) Calculate offsets of collision areas in parallel.
|
||||||
LayerPolygonCache collision_areas_offsetted;
|
LayerPolygonCache collision_areas_offsetted;
|
||||||
collision_areas_offsetted.allocate(
|
collision_areas_offsetted.allocate(
|
||||||
std::max<LayerIndex>(0, data.idx_begin - z_distance_bottom_layers),
|
std::max<LayerIndex>(0, data.begin() - z_distance_bottom_layers),
|
||||||
std::min<LayerIndex>(outlines.size(), data.idx_end + z_distance_top_layers));
|
std::min<LayerIndex>(outlines.size(), data.end() + z_distance_top_layers));
|
||||||
tbb::parallel_for(tbb::blocked_range<LayerIndex>(collision_areas_offsetted.idx_begin, collision_areas_offsetted.idx_end),
|
tbb::parallel_for(tbb::blocked_range<LayerIndex>(collision_areas_offsetted.begin(), collision_areas_offsetted.end()),
|
||||||
[&outlines, &machine_border = std::as_const(m_machine_border), offset_value = radius + xy_distance, &collision_areas_offsetted, &throw_on_cancel]
|
[&outlines, &machine_border = std::as_const(m_machine_border), offset_value = radius + xy_distance, &collision_areas_offsetted, &throw_on_cancel]
|
||||||
(const tbb::blocked_range<LayerIndex> &range) {
|
(const tbb::blocked_range<LayerIndex> &range) {
|
||||||
for (LayerIndex layer_idx = range.begin(); layer_idx != range.end(); ++ layer_idx) {
|
for (LayerIndex layer_idx = range.begin(); layer_idx != range.end(); ++ layer_idx) {
|
||||||
@ -536,7 +536,7 @@ void TreeModelVolumes::calculateCollision(const coord_t radius, const LayerIndex
|
|||||||
|
|
||||||
// 2) Sum over top / bottom ranges.
|
// 2) Sum over top / bottom ranges.
|
||||||
const bool processing_last_mesh = outline_idx == layer_outline_indices.size();
|
const bool processing_last_mesh = outline_idx == layer_outline_indices.size();
|
||||||
tbb::parallel_for(tbb::blocked_range<LayerIndex>(data.idx_begin, data.idx_end),
|
tbb::parallel_for(tbb::blocked_range<LayerIndex>(data.begin(), data.end()),
|
||||||
[&collision_areas_offsetted, &outlines, &machine_border = m_machine_border, &anti_overhang = m_anti_overhang, radius,
|
[&collision_areas_offsetted, &outlines, &machine_border = m_machine_border, &anti_overhang = m_anti_overhang, radius,
|
||||||
xy_distance, z_distance_bottom_layers, z_distance_top_layers, min_resolution = m_min_resolution, &data, processing_last_mesh, &throw_on_cancel]
|
xy_distance, z_distance_bottom_layers, z_distance_top_layers, min_resolution = m_min_resolution, &data, processing_last_mesh, &throw_on_cancel]
|
||||||
(const tbb::blocked_range<LayerIndex>& range) {
|
(const tbb::blocked_range<LayerIndex>& range) {
|
||||||
@ -600,7 +600,7 @@ void TreeModelVolumes::calculateCollision(const coord_t radius, const LayerIndex
|
|||||||
// 3) Optionally calculate placables.
|
// 3) Optionally calculate placables.
|
||||||
if (calculate_placable) {
|
if (calculate_placable) {
|
||||||
// Now calculate the placable areas.
|
// Now calculate the placable areas.
|
||||||
tbb::parallel_for(tbb::blocked_range<LayerIndex>(std::max(z_distance_bottom_layers + 1, data.idx_begin), data.idx_end),
|
tbb::parallel_for(tbb::blocked_range<LayerIndex>(std::max(z_distance_bottom_layers + 1, data.begin()), data.end()),
|
||||||
[&collision_areas_offsetted, &outlines, &anti_overhang = m_anti_overhang, processing_last_mesh,
|
[&collision_areas_offsetted, &outlines, &anti_overhang = m_anti_overhang, processing_last_mesh,
|
||||||
min_resolution = m_min_resolution, z_distance_bottom_layers, xy_distance, &data_placeable, &throw_on_cancel]
|
min_resolution = m_min_resolution, z_distance_bottom_layers, xy_distance, &data_placeable, &throw_on_cancel]
|
||||||
(const tbb::blocked_range<LayerIndex>& range) {
|
(const tbb::blocked_range<LayerIndex>& range) {
|
||||||
|
@ -332,23 +332,26 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// Caching polygons for a range of layers.
|
// Caching polygons for a range of layers.
|
||||||
struct LayerPolygonCache {
|
class LayerPolygonCache {
|
||||||
std::vector<Polygons> polygons;
|
public:
|
||||||
LayerIndex idx_begin;
|
|
||||||
LayerIndex idx_end;
|
|
||||||
|
|
||||||
void allocate(LayerIndex aidx_begin, LayerIndex aidx_end) {
|
void allocate(LayerIndex aidx_begin, LayerIndex aidx_end) {
|
||||||
this->idx_begin = aidx_begin;
|
m_idx_begin = aidx_begin;
|
||||||
this->idx_end = aidx_end;
|
m_idx_end = aidx_end;
|
||||||
this->polygons.assign(aidx_end - aidx_begin, {});
|
m_polygons.assign(aidx_end - aidx_begin, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
LayerIndex begin() const { return idx_begin; }
|
LayerIndex begin() const { return m_idx_begin; }
|
||||||
LayerIndex end() const { return idx_end; }
|
LayerIndex end() const { return m_idx_end; }
|
||||||
size_t size() const { return polygons.size(); }
|
size_t size() const { return m_polygons.size(); }
|
||||||
|
|
||||||
bool has(LayerIndex idx) const { return idx >= idx_begin && idx < idx_end; }
|
bool has(LayerIndex idx) const { return idx >= m_idx_begin && idx < m_idx_end; }
|
||||||
Polygons& operator[](LayerIndex idx) { return polygons[idx + idx_begin]; }
|
Polygons& operator[](LayerIndex idx) { assert(idx >= m_idx_begin && idx < m_idx_end); return m_polygons[idx - m_idx_begin]; }
|
||||||
|
std::vector<Polygons>& polygons_mutable() { return m_polygons; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<Polygons> m_polygons;
|
||||||
|
LayerIndex m_idx_begin;
|
||||||
|
LayerIndex m_idx_end;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -388,9 +391,9 @@ private:
|
|||||||
}
|
}
|
||||||
void insert(LayerPolygonCache &&in, coord_t radius) {
|
void insert(LayerPolygonCache &&in, coord_t radius) {
|
||||||
std::lock_guard<std::mutex> guard(m_mutex);
|
std::lock_guard<std::mutex> guard(m_mutex);
|
||||||
LayerIndex i = in.idx_begin;
|
LayerIndex i = in.begin();
|
||||||
allocate_layers(i + LayerIndex(in.size()));
|
allocate_layers(i + LayerIndex(in.size()));
|
||||||
for (auto &d : in.polygons)
|
for (auto &d : in.polygons_mutable())
|
||||||
m_data[i ++].emplace(radius, std::move(d));
|
m_data[i ++].emplace(radius, std::move(d));
|
||||||
}
|
}
|
||||||
/*!
|
/*!
|
||||||
|
Loading…
Reference in New Issue
Block a user