Improve performance when bed are large

This commit is contained in:
SoftFever 2024-05-11 23:26:02 +08:00
parent 98caf561ef
commit 8f77755535
3 changed files with 13 additions and 10 deletions

View file

@ -1307,9 +1307,9 @@ Polygons EdgeGrid::Grid::contours_simplified(coord_t offset, bool fill_holes) co
// 1) Collect the lines.
std::vector<Line> lines;
EndPointMapType start_point_to_line_idx;
for (int r = 0; r <= int(m_rows); ++ r) {
for (int c = 0; c <= int(m_cols); ++ c) {
int addr = (r + 1) * cell_cols + c + 1;
for (coord_t r = 0; r <= coord_t(m_rows); ++ r) {
for (coord_t c = 0; c <= coord_t(m_cols); ++ c) {
size_t addr = (r + 1) * cell_cols + c + 1;
bool left = cell_inside[addr - 1];
bool top = cell_inside[addr - cell_cols];
bool current = cell_inside[addr];

View file

@ -40,7 +40,7 @@
using coord_t = int32_t;
#else
//FIXME At least FillRectilinear2 and std::boost Voronoi require coord_t to be 32bit.
typedef int64_t coord_t;
using coord_t = int64_t;
#endif
using coordf_t = double;

View file

@ -5065,8 +5065,11 @@ std::vector<Vec2f> GLCanvas3D::get_empty_cells(const Vec2f start_point, const Ve
Vec2d vmin(build_volume.min.x(), build_volume.min.y()), vmax(build_volume.max.x(), build_volume.max.y());
BoundingBoxf bbox(vmin, vmax);
std::vector<Vec2f> cells;
std::vector<Vec2f> cells_ret;
auto min_x = start_point.x() - step(0) * int((start_point.x() - bbox.min.x()) / step(0));
auto min_y = start_point.y() - step(1) * int((start_point.y() - bbox.min.y()) / step(1));
cells.reserve(((bbox.max.x() - min_x) / step(0)) * ((bbox.max.y() - min_y) / step(1)));
cells_ret.reserve(cells.size());
for (float x = min_x; x < bbox.max.x() - step(0) / 2; x += step(0))
for (float y = min_y; y < bbox.max.y() - step(1) / 2; y += step(1))
{
@ -5093,9 +5096,9 @@ std::vector<Vec2f> GLCanvas3D::get_empty_cells(const Vec2f start_point, const Ve
for (auto it = cells.begin(); it != cells.end(); )
{
if (inst_hull_2d.contains(Point(scale_(it->x()), scale_(it->y()))))
it = cells.erase(it);
else
if (!inst_hull_2d.contains(Point(scale_(it->x()), scale_(it->y()))))
cells_ret.push_back(*it);
it++;
}
}
@ -5106,8 +5109,8 @@ std::vector<Vec2f> GLCanvas3D::get_empty_cells(const Vec2f start_point, const Ve
start(0) = bbox.center()(0);
start(1) = bbox.center()(1);
}
std::sort(cells.begin(), cells.end(), [start](const Vec2f& cell1, const Vec2f& cell2) {return (cell1 - start).norm() < (cell2 - start).norm(); });
return cells;
std::sort(cells_ret.begin(), cells_ret.end(), [start](const Vec2f& cell1, const Vec2f& cell2) {return (cell1 - start).norm() < (cell2 - start).norm(); });
return cells_ret;
}
Vec2f GLCanvas3D::get_nearest_empty_cell(const Vec2f start_point, const Vec2f step)