mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 16:57:53 -06:00
Changing the internal representation of Point / Pointf / Point3 / Pointf3 to Eigen Matrix types, first step
This commit is contained in:
parent
077680b806
commit
86da661097
60 changed files with 1228 additions and 1206 deletions
|
@ -198,7 +198,7 @@ namespace Slic3r { namespace Geometry {
|
|||
static bool
|
||||
sort_points (Point a, Point b)
|
||||
{
|
||||
return (a.x < b.x) || (a.x == b.x && a.y < b.y);
|
||||
return (a.x() < b.x()) || (a.x() == b.x() && a.y() < b.y());
|
||||
}
|
||||
|
||||
/* This implementation is based on Andrew's monotone chain 2D convex hull algorithm */
|
||||
|
@ -349,30 +349,30 @@ struct ArrangeItem {
|
|||
coordf_t weight;
|
||||
bool operator<(const ArrangeItem &other) const {
|
||||
return weight < other.weight ||
|
||||
((weight == other.weight) && (pos.y < other.pos.y || (pos.y == other.pos.y && pos.x < other.pos.x)));
|
||||
((weight == other.weight) && (pos.y() < other.pos.y() || (pos.y() == other.pos.y() && pos.x() < other.pos.x())));
|
||||
}
|
||||
};
|
||||
|
||||
Pointfs arrange(size_t num_parts, const Pointf &part_size, coordf_t gap, const BoundingBoxf* bed_bounding_box)
|
||||
{
|
||||
// Use actual part size (the largest) plus separation distance (half on each side) in spacing algorithm.
|
||||
const Pointf cell_size(part_size.x + gap, part_size.y + gap);
|
||||
const Pointf cell_size(part_size.x() + gap, part_size.y() + gap);
|
||||
|
||||
const BoundingBoxf bed_bbox = (bed_bounding_box != NULL && bed_bounding_box->defined) ?
|
||||
*bed_bounding_box :
|
||||
// Bogus bed size, large enough not to trigger the unsufficient bed size error.
|
||||
BoundingBoxf(
|
||||
Pointf(0, 0),
|
||||
Pointf(cell_size.x * num_parts, cell_size.y * num_parts));
|
||||
Pointf(cell_size.x() * num_parts, cell_size.y() * num_parts));
|
||||
|
||||
// This is how many cells we have available into which to put parts.
|
||||
size_t cellw = size_t(floor((bed_bbox.size().x + gap) / cell_size.x));
|
||||
size_t cellh = size_t(floor((bed_bbox.size().y + gap) / cell_size.y));
|
||||
size_t cellw = size_t(floor((bed_bbox.size().x() + gap) / cell_size.x()));
|
||||
size_t cellh = size_t(floor((bed_bbox.size().y() + gap) / cell_size.y()));
|
||||
if (num_parts > cellw * cellh)
|
||||
CONFESS(PRINTF_ZU " parts won't fit in your print area!\n", num_parts);
|
||||
|
||||
// Get a bounding box of cellw x cellh cells, centered at the center of the bed.
|
||||
Pointf cells_size(cellw * cell_size.x - gap, cellh * cell_size.y - gap);
|
||||
Pointf cells_size(cellw * cell_size.x() - gap, cellh * cell_size.y() - gap);
|
||||
Pointf cells_offset(bed_bbox.center() - 0.5 * cells_size);
|
||||
BoundingBoxf cells_bb(cells_offset, cells_size + cells_offset);
|
||||
|
||||
|
@ -380,19 +380,19 @@ Pointfs arrange(size_t num_parts, const Pointf &part_size, coordf_t gap, const B
|
|||
std::vector<ArrangeItem> cellsorder(cellw * cellh, ArrangeItem());
|
||||
for (size_t j = 0; j < cellh; ++ j) {
|
||||
// Center of the jth row on the bed.
|
||||
coordf_t cy = linint(j + 0.5, 0., double(cellh), cells_bb.min.y, cells_bb.max.y);
|
||||
coordf_t cy = linint(j + 0.5, 0., double(cellh), cells_bb.min.y(), cells_bb.max.y());
|
||||
// Offset from the bed center.
|
||||
coordf_t yd = cells_bb.center().y - cy;
|
||||
coordf_t yd = cells_bb.center().y() - cy;
|
||||
for (size_t i = 0; i < cellw; ++ i) {
|
||||
// Center of the ith column on the bed.
|
||||
coordf_t cx = linint(i + 0.5, 0., double(cellw), cells_bb.min.x, cells_bb.max.x);
|
||||
coordf_t cx = linint(i + 0.5, 0., double(cellw), cells_bb.min.x(), cells_bb.max.x());
|
||||
// Offset from the bed center.
|
||||
coordf_t xd = cells_bb.center().x - cx;
|
||||
coordf_t xd = cells_bb.center().x() - cx;
|
||||
// Cell with a distance from the bed center.
|
||||
ArrangeItem &ci = cellsorder[j * cellw + i];
|
||||
// Cell center
|
||||
ci.pos.x = cx;
|
||||
ci.pos.y = cy;
|
||||
ci.pos.x() = cx;
|
||||
ci.pos.y() = cy;
|
||||
// Square distance of the cell center to the bed center.
|
||||
ci.weight = xd * xd + yd * yd;
|
||||
}
|
||||
|
@ -405,7 +405,7 @@ Pointfs arrange(size_t num_parts, const Pointf &part_size, coordf_t gap, const B
|
|||
Pointfs positions;
|
||||
positions.reserve(num_parts);
|
||||
for (std::vector<ArrangeItem>::const_iterator it = cellsorder.begin(); it != cellsorder.end(); ++ it)
|
||||
positions.push_back(Pointf(it->pos.x - 0.5 * part_size.x, it->pos.y - 0.5 * part_size.y));
|
||||
positions.push_back(Pointf(it->pos.x() - 0.5 * part_size.x(), it->pos.y() - 0.5 * part_size.y()));
|
||||
return positions;
|
||||
}
|
||||
#else
|
||||
|
@ -430,26 +430,26 @@ arrange(size_t total_parts, const Pointf &part_size, coordf_t dist, const Boundi
|
|||
Pointf part = part_size;
|
||||
|
||||
// use actual part size (the largest) plus separation distance (half on each side) in spacing algorithm
|
||||
part.x += dist;
|
||||
part.y += dist;
|
||||
part.x() += dist;
|
||||
part.y() += dist;
|
||||
|
||||
Pointf area;
|
||||
if (bb != NULL && bb->defined) {
|
||||
area = bb->size();
|
||||
} else {
|
||||
// bogus area size, large enough not to trigger the error below
|
||||
area.x = part.x * total_parts;
|
||||
area.y = part.y * total_parts;
|
||||
area.x() = part.x() * total_parts;
|
||||
area.y() = part.y() * total_parts;
|
||||
}
|
||||
|
||||
// this is how many cells we have available into which to put parts
|
||||
size_t cellw = floor((area.x + dist) / part.x);
|
||||
size_t cellh = floor((area.y + dist) / part.y);
|
||||
size_t cellw = floor((area.x() + dist) / part.x());
|
||||
size_t cellh = floor((area.y() + dist) / part.y());
|
||||
if (total_parts > (cellw * cellh))
|
||||
return false;
|
||||
|
||||
// total space used by cells
|
||||
Pointf cells(cellw * part.x, cellh * part.y);
|
||||
Pointf cells(cellw * part.x(), cellh * part.y());
|
||||
|
||||
// bounding box of total space used by cells
|
||||
BoundingBoxf cells_bb;
|
||||
|
@ -458,8 +458,8 @@ arrange(size_t total_parts, const Pointf &part_size, coordf_t dist, const Boundi
|
|||
|
||||
// center bounding box to area
|
||||
cells_bb.translate(
|
||||
(area.x - cells.x) / 2,
|
||||
(area.y - cells.y) / 2
|
||||
(area.x() - cells.x()) / 2,
|
||||
(area.y() - cells.y()) / 2
|
||||
);
|
||||
|
||||
// list of cells, sorted by distance from center
|
||||
|
@ -468,15 +468,15 @@ arrange(size_t total_parts, const Pointf &part_size, coordf_t dist, const Boundi
|
|||
// work out distance for all cells, sort into list
|
||||
for (size_t i = 0; i <= cellw-1; ++i) {
|
||||
for (size_t j = 0; j <= cellh-1; ++j) {
|
||||
coordf_t cx = linint(i + 0.5, 0, cellw, cells_bb.min.x, cells_bb.max.x);
|
||||
coordf_t cy = linint(j + 0.5, 0, cellh, cells_bb.min.y, cells_bb.max.y);
|
||||
coordf_t cx = linint(i + 0.5, 0, cellw, cells_bb.min.x(), cells_bb.max.x());
|
||||
coordf_t cy = linint(j + 0.5, 0, cellh, cells_bb.min.y(), cells_bb.max.y());
|
||||
|
||||
coordf_t xd = fabs((area.x / 2) - cx);
|
||||
coordf_t yd = fabs((area.y / 2) - cy);
|
||||
coordf_t xd = fabs((area.x() / 2) - cx);
|
||||
coordf_t yd = fabs((area.y() / 2) - cy);
|
||||
|
||||
ArrangeItem c;
|
||||
c.pos.x = cx;
|
||||
c.pos.y = cy;
|
||||
c.pos.x() = cx;
|
||||
c.pos.y() = cy;
|
||||
c.index_x = i;
|
||||
c.index_y = j;
|
||||
c.dist = xd * xd + yd * yd - fabs((cellw / 2) - (i + 0.5));
|
||||
|
@ -533,13 +533,13 @@ arrange(size_t total_parts, const Pointf &part_size, coordf_t dist, const Boundi
|
|||
coordf_t cx = c.item.index_x - lx;
|
||||
coordf_t cy = c.item.index_y - ty;
|
||||
|
||||
positions.push_back(Pointf(cx * part.x, cy * part.y));
|
||||
positions.push_back(Pointf(cx * part.x(), cy * part.y()));
|
||||
}
|
||||
|
||||
if (bb != NULL && bb->defined) {
|
||||
for (Pointfs::iterator p = positions.begin(); p != positions.end(); ++p) {
|
||||
p->x += bb->min.x;
|
||||
p->y += bb->min.y;
|
||||
p->x() += bb->min.x();
|
||||
p->y() += bb->min.y();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -676,10 +676,10 @@ static inline void dump_voronoi_to_svg(const Lines &lines, /* const */ voronoi_d
|
|||
const bool primaryEdgesOnly = false;
|
||||
|
||||
BoundingBox bbox = BoundingBox(lines);
|
||||
bbox.min.x -= coord_t(1. / SCALING_FACTOR);
|
||||
bbox.min.y -= coord_t(1. / SCALING_FACTOR);
|
||||
bbox.max.x += coord_t(1. / SCALING_FACTOR);
|
||||
bbox.max.y += coord_t(1. / SCALING_FACTOR);
|
||||
bbox.min.x() -= coord_t(1. / SCALING_FACTOR);
|
||||
bbox.min.y() -= coord_t(1. / SCALING_FACTOR);
|
||||
bbox.max.x() += coord_t(1. / SCALING_FACTOR);
|
||||
bbox.max.y() += coord_t(1. / SCALING_FACTOR);
|
||||
|
||||
::Slic3r::SVG svg(path, bbox);
|
||||
|
||||
|
@ -689,7 +689,7 @@ static inline void dump_voronoi_to_svg(const Lines &lines, /* const */ voronoi_d
|
|||
// bbox.scale(1.2);
|
||||
// For clipping of half-lines to some reasonable value.
|
||||
// The line will then be clipped by the SVG viewer anyway.
|
||||
const double bbox_dim_max = double(bbox.max.x - bbox.min.x) + double(bbox.max.y - bbox.min.y);
|
||||
const double bbox_dim_max = double(bbox.max.x() - bbox.min.x()) + double(bbox.max.y() - bbox.min.y());
|
||||
// For the discretization of the Voronoi parabolic segments.
|
||||
const double discretization_step = 0.0005 * bbox_dim_max;
|
||||
|
||||
|
@ -697,8 +697,8 @@ static inline void dump_voronoi_to_svg(const Lines &lines, /* const */ voronoi_d
|
|||
std::vector<Voronoi::Internal::segment_type> segments;
|
||||
for (Lines::const_iterator it = lines.begin(); it != lines.end(); ++ it)
|
||||
segments.push_back(Voronoi::Internal::segment_type(
|
||||
Voronoi::Internal::point_type(double(it->a.x), double(it->a.y)),
|
||||
Voronoi::Internal::point_type(double(it->b.x), double(it->b.y))));
|
||||
Voronoi::Internal::point_type(double(it->a.x()), double(it->a.y())),
|
||||
Voronoi::Internal::point_type(double(it->b.x()), double(it->b.y()))));
|
||||
|
||||
// Color exterior edges.
|
||||
for (voronoi_diagram<double>::const_edge_iterator it = vd.edges().begin(); it != vd.edges().end(); ++it)
|
||||
|
@ -712,7 +712,7 @@ static inline void dump_voronoi_to_svg(const Lines &lines, /* const */ voronoi_d
|
|||
}
|
||||
// Draw the input polygon.
|
||||
for (Lines::const_iterator it = lines.begin(); it != lines.end(); ++it)
|
||||
svg.draw(Line(Point(coord_t(it->a.x), coord_t(it->a.y)), Point(coord_t(it->b.x), coord_t(it->b.y))), inputSegmentColor, inputSegmentLineWidth);
|
||||
svg.draw(Line(Point(coord_t(it->a.x()), coord_t(it->a.y())), Point(coord_t(it->b.x()), coord_t(it->b.y()))), inputSegmentColor, inputSegmentLineWidth);
|
||||
|
||||
#if 1
|
||||
// Draw voronoi vertices.
|
||||
|
@ -828,8 +828,8 @@ public:
|
|||
Lines2VDSegments(const Lines &alines) : lines(alines) {}
|
||||
typename VD::segment_type operator[](size_t idx) const {
|
||||
return typename VD::segment_type(
|
||||
typename VD::point_type(typename VD::coord_type(lines[idx].a.x), typename VD::coord_type(lines[idx].a.y)),
|
||||
typename VD::point_type(typename VD::coord_type(lines[idx].b.x), typename VD::coord_type(lines[idx].b.y)));
|
||||
typename VD::point_type(typename VD::coord_type(lines[idx].a.x()), typename VD::coord_type(lines[idx].a.y())),
|
||||
typename VD::point_type(typename VD::coord_type(lines[idx].b.x()), typename VD::coord_type(lines[idx].b.y())));
|
||||
}
|
||||
private:
|
||||
const Lines &lines;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue