mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-13 01:37:53 -06:00
Merge remote-tracking branch 'origin/eigenize' into sla_base_pool
This commit is contained in:
commit
6e77307880
188 changed files with 3351 additions and 3305 deletions
|
@ -52,20 +52,20 @@ TriangleMesh::TriangleMesh(const Pointf3s &points, const std::vector<Point3>& fa
|
|||
for (int i = 0; i < stl.stats.number_of_facets; i++) {
|
||||
stl_facet facet;
|
||||
|
||||
const Pointf3& ref_f1 = points[facets[i].x];
|
||||
facet.vertex[0].x = ref_f1.x;
|
||||
facet.vertex[0].y = ref_f1.y;
|
||||
facet.vertex[0].z = ref_f1.z;
|
||||
const Pointf3& ref_f1 = points[facets[i](0)];
|
||||
facet.vertex[0].x = ref_f1(0);
|
||||
facet.vertex[0].y = ref_f1(1);
|
||||
facet.vertex[0].z = ref_f1(2);
|
||||
|
||||
const Pointf3& ref_f2 = points[facets[i].y];
|
||||
facet.vertex[1].x = ref_f2.x;
|
||||
facet.vertex[1].y = ref_f2.y;
|
||||
facet.vertex[1].z = ref_f2.z;
|
||||
const Pointf3& ref_f2 = points[facets[i](1)];
|
||||
facet.vertex[1].x = ref_f2(0);
|
||||
facet.vertex[1].y = ref_f2(1);
|
||||
facet.vertex[1].z = ref_f2(2);
|
||||
|
||||
const Pointf3& ref_f3 = points[facets[i].z];
|
||||
facet.vertex[2].x = ref_f3.x;
|
||||
facet.vertex[2].y = ref_f3.y;
|
||||
facet.vertex[2].z = ref_f3.z;
|
||||
const Pointf3& ref_f3 = points[facets[i](2)];
|
||||
facet.vertex[2].x = ref_f3(0);
|
||||
facet.vertex[2].y = ref_f3(1);
|
||||
facet.vertex[2].z = ref_f3(2);
|
||||
|
||||
facet.extra[0] = 0;
|
||||
facet.extra[1] = 0;
|
||||
|
@ -303,9 +303,9 @@ void TriangleMesh::scale(float factor)
|
|||
void TriangleMesh::scale(const Pointf3 &versor)
|
||||
{
|
||||
float fversor[3];
|
||||
fversor[0] = versor.x;
|
||||
fversor[1] = versor.y;
|
||||
fversor[2] = versor.z;
|
||||
fversor[0] = versor(0);
|
||||
fversor[1] = versor(1);
|
||||
fversor[2] = versor(2);
|
||||
stl_scale_versor(&this->stl, fversor);
|
||||
stl_invalidate_shared_vertices(&this->stl);
|
||||
}
|
||||
|
@ -400,9 +400,10 @@ void TriangleMesh::rotate(double angle, Point* center)
|
|||
{
|
||||
if (angle == 0.)
|
||||
return;
|
||||
this->translate(float(-center->x), float(-center->y), 0);
|
||||
Vec2f c = center->cast<float>();
|
||||
this->translate(-c(0), -c(1), 0);
|
||||
stl_rotate_z(&(this->stl), (float)angle);
|
||||
this->translate(float(+center->x), float(+center->y), 0);
|
||||
this->translate(c(0), c(1), 0);
|
||||
}
|
||||
|
||||
bool TriangleMesh::has_multiple_patches() const
|
||||
|
@ -502,7 +503,7 @@ TriangleMesh::split() const
|
|||
int facet_idx = facet_queue.front();
|
||||
facet_queue.pop();
|
||||
if (seen_facets.find(facet_idx) != seen_facets.end()) continue;
|
||||
facets.push_back(facet_idx);
|
||||
facets.emplace_back(facet_idx);
|
||||
for (int j = 0; j <= 2; j++) {
|
||||
facet_queue.push(this->stl.neighbors_start[facet_idx].neighbor[j]);
|
||||
}
|
||||
|
@ -510,7 +511,7 @@ TriangleMesh::split() const
|
|||
}
|
||||
|
||||
TriangleMesh* mesh = new TriangleMesh;
|
||||
meshes.push_back(mesh);
|
||||
meshes.emplace_back(mesh);
|
||||
mesh->stl.stats.type = inmemory;
|
||||
mesh->stl.stats.number_of_facets = facets.size();
|
||||
mesh->stl.stats.original_num_facets = mesh->stl.stats.number_of_facets;
|
||||
|
@ -564,7 +565,7 @@ ExPolygons TriangleMesh::horizontal_projection() const
|
|||
p.points[1] = Point::new_scale(facet->vertex[1].x, facet->vertex[1].y);
|
||||
p.points[2] = Point::new_scale(facet->vertex[2].x, facet->vertex[2].y);
|
||||
p.make_counter_clockwise(); // do this after scaling, as winding order might change while doing that
|
||||
pp.push_back(p);
|
||||
pp.emplace_back(p);
|
||||
}
|
||||
|
||||
// the offset factor was tuned using groovemount.stl
|
||||
|
@ -588,12 +589,12 @@ TriangleMesh::bounding_box() const
|
|||
{
|
||||
BoundingBoxf3 bb;
|
||||
bb.defined = true;
|
||||
bb.min.x = this->stl.stats.min.x;
|
||||
bb.min.y = this->stl.stats.min.y;
|
||||
bb.min.z = this->stl.stats.min.z;
|
||||
bb.max.x = this->stl.stats.max.x;
|
||||
bb.max.y = this->stl.stats.max.y;
|
||||
bb.max.z = this->stl.stats.max.z;
|
||||
bb.min(0) = this->stl.stats.min.x;
|
||||
bb.min(1) = this->stl.stats.min.y;
|
||||
bb.min(2) = this->stl.stats.min.z;
|
||||
bb.max(0) = this->stl.stats.max.x;
|
||||
bb.max(1) = this->stl.stats.max.y;
|
||||
bb.max(2) = this->stl.stats.max.z;
|
||||
return bb;
|
||||
}
|
||||
|
||||
|
@ -813,16 +814,16 @@ void TriangleMeshSlicer::_slice_do(size_t facet_idx, std::vector<IntersectionLin
|
|||
std::swap(a_id, b_id);
|
||||
const stl_vertex *a = &this->v_scaled_shared[a_id];
|
||||
const stl_vertex *b = &this->v_scaled_shared[b_id];
|
||||
il.a.x = a->x;
|
||||
il.a.y = a->y;
|
||||
il.b.x = b->x;
|
||||
il.b.y = b->y;
|
||||
il.a(0) = a->x;
|
||||
il.a(1) = a->y;
|
||||
il.b(0) = b->x;
|
||||
il.b(1) = b->y;
|
||||
il.a_id = a_id;
|
||||
il.b_id = b_id;
|
||||
(*lines)[layer_idx].push_back(il);
|
||||
(*lines)[layer_idx].emplace_back(il);
|
||||
}
|
||||
} else
|
||||
(*lines)[layer_idx].push_back(il);
|
||||
(*lines)[layer_idx].emplace_back(il);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -894,10 +895,10 @@ bool TriangleMeshSlicer::slice_facet(
|
|||
// Two vertices are aligned with the cutting plane, the third vertex is above the cutting plane.
|
||||
line_out->edge_type = feBottom;
|
||||
}
|
||||
line_out->a.x = a->x;
|
||||
line_out->a.y = a->y;
|
||||
line_out->b.x = b->x;
|
||||
line_out->b.y = b->y;
|
||||
line_out->a(0) = a->x;
|
||||
line_out->a(1) = a->y;
|
||||
line_out->b(0) = b->x;
|
||||
line_out->b(1) = b->y;
|
||||
line_out->a_id = a_id;
|
||||
line_out->b_id = b_id;
|
||||
return true;
|
||||
|
@ -907,21 +908,21 @@ bool TriangleMeshSlicer::slice_facet(
|
|||
// Only point a alings with the cutting plane.
|
||||
points_on_layer[num_points_on_layer ++] = num_points;
|
||||
IntersectionPoint &point = points[num_points ++];
|
||||
point.x = a->x;
|
||||
point.y = a->y;
|
||||
point(0) = a->x;
|
||||
point(1) = a->y;
|
||||
point.point_id = a_id;
|
||||
} else if (b->z == slice_z) {
|
||||
// Only point b alings with the cutting plane.
|
||||
points_on_layer[num_points_on_layer ++] = num_points;
|
||||
IntersectionPoint &point = points[num_points ++];
|
||||
point.x = b->x;
|
||||
point.y = b->y;
|
||||
point(0) = b->x;
|
||||
point(1) = b->y;
|
||||
point.point_id = b_id;
|
||||
} else if ((a->z < slice_z && b->z > slice_z) || (b->z < slice_z && a->z > slice_z)) {
|
||||
// A general case. The face edge intersects the cutting plane. Calculate the intersection point.
|
||||
IntersectionPoint &point = points[num_points ++];
|
||||
point.x = b->x + (a->x - b->x) * (slice_z - b->z) / (a->z - b->z);
|
||||
point.y = b->y + (a->y - b->y) * (slice_z - b->z) / (a->z - b->z);
|
||||
point(0) = b->x + (a->x - b->x) * (slice_z - b->z) / (a->z - b->z);
|
||||
point(1) = b->y + (a->y - b->y) * (slice_z - b->z) / (a->z - b->z);
|
||||
point.edge_id = edge_id;
|
||||
}
|
||||
}
|
||||
|
@ -1202,7 +1203,7 @@ void TriangleMeshSlicer::make_loops(std::vector<IntersectionLine> &lines, Polygo
|
|||
// Orient the patched up polygons CCW. This heuristic may close some holes and cavities.
|
||||
double area = 0.;
|
||||
for (size_t i = 0, j = opl.points.size() - 1; i < opl.points.size(); j = i ++)
|
||||
area += double(opl.points[j].x + opl.points[i].x) * double(opl.points[i].y - opl.points[j].y);
|
||||
area += double(opl.points[j](0) + opl.points[i](0)) * double(opl.points[i](1) - opl.points[j](1));
|
||||
if (area < 0)
|
||||
std::reverse(opl.points.begin(), opl.points.end());
|
||||
loops->emplace_back(std::move(opl.points));
|
||||
|
@ -1229,9 +1230,9 @@ void TriangleMeshSlicer::make_expolygons_simple(std::vector<IntersectionLine> &l
|
|||
if (loop->area() >= 0.) {
|
||||
ExPolygon ex;
|
||||
ex.contour = *loop;
|
||||
slices->push_back(ex);
|
||||
slices->emplace_back(ex);
|
||||
} else {
|
||||
holes.push_back(*loop);
|
||||
holes.emplace_back(*loop);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1322,8 +1323,8 @@ void TriangleMeshSlicer::make_expolygons(const Polygons &loops, ExPolygons* slic
|
|||
//std::vector<double> area;
|
||||
//std::vector<size_t> sorted_area; // vector of indices
|
||||
//for (Polygons::const_iterator loop = loops.begin(); loop != loops.end(); ++ loop) {
|
||||
// area.push_back(loop->area());
|
||||
// sorted_area.push_back(loop - loops.begin());
|
||||
// area.emplace_back(loop->area());
|
||||
// sorted_area.emplace_back(loop - loops.begin());
|
||||
//}
|
||||
//
|
||||
//// outer first
|
||||
|
@ -1338,7 +1339,7 @@ void TriangleMeshSlicer::make_expolygons(const Polygons &loops, ExPolygons* slic
|
|||
// would do the same, thus repeating the calculation */
|
||||
// Polygons::const_iterator loop = loops.begin() + *loop_idx;
|
||||
// if (area[*loop_idx] > +EPSILON)
|
||||
// p_slices.push_back(*loop);
|
||||
// p_slices.emplace_back(*loop);
|
||||
// else if (area[*loop_idx] < -EPSILON)
|
||||
// //FIXME This is arbitrary and possibly very slow.
|
||||
// // If the hole is inside a polygon, then there is no need to diff.
|
||||
|
@ -1396,12 +1397,12 @@ void TriangleMeshSlicer::cut(float z, TriangleMesh* upper, TriangleMesh* lower)
|
|||
if (this->slice_facet(scaled_z, *facet, facet_idx, min_z, max_z, &line)) {
|
||||
// Save intersection lines for generating correct triangulations.
|
||||
if (line.edge_type == feTop) {
|
||||
lower_lines.push_back(line);
|
||||
lower_lines.emplace_back(line);
|
||||
} else if (line.edge_type == feBottom) {
|
||||
upper_lines.push_back(line);
|
||||
upper_lines.emplace_back(line);
|
||||
} else if (line.edge_type != feHorizontal) {
|
||||
lower_lines.push_back(line);
|
||||
upper_lines.push_back(line);
|
||||
lower_lines.emplace_back(line);
|
||||
upper_lines.emplace_back(line);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1492,8 +1493,8 @@ void TriangleMeshSlicer::cut(float z, TriangleMesh* upper, TriangleMesh* lower)
|
|||
facet.normal.y = 0;
|
||||
facet.normal.z = -1;
|
||||
for (size_t i = 0; i <= 2; ++i) {
|
||||
facet.vertex[i].x = unscale(p.points[i].x);
|
||||
facet.vertex[i].y = unscale(p.points[i].y);
|
||||
facet.vertex[i].x = unscale(p.points[i](0));
|
||||
facet.vertex[i].y = unscale(p.points[i](1));
|
||||
facet.vertex[i].z = z;
|
||||
}
|
||||
stl_add_facet(&upper->stl, &facet);
|
||||
|
@ -1518,8 +1519,8 @@ void TriangleMeshSlicer::cut(float z, TriangleMesh* upper, TriangleMesh* lower)
|
|||
facet.normal.y = 0;
|
||||
facet.normal.z = 1;
|
||||
for (size_t i = 0; i <= 2; ++i) {
|
||||
facet.vertex[i].x = unscale(polygon->points[i].x);
|
||||
facet.vertex[i].y = unscale(polygon->points[i].y);
|
||||
facet.vertex[i].x = unscale(polygon->points[i](0));
|
||||
facet.vertex[i].y = unscale(polygon->points[i](1));
|
||||
facet.vertex[i].z = z;
|
||||
}
|
||||
stl_add_facet(&lower->stl, &facet);
|
||||
|
@ -1560,8 +1561,8 @@ TriangleMesh make_cylinder(double r, double h, double fa) {
|
|||
std::vector<Point3> facets;
|
||||
|
||||
// 2 special vertices, top and bottom center, rest are relative to this
|
||||
vertices.push_back(Pointf3(0.0, 0.0, 0.0));
|
||||
vertices.push_back(Pointf3(0.0, 0.0, h));
|
||||
vertices.emplace_back(Pointf3(0.0, 0.0, 0.0));
|
||||
vertices.emplace_back(Pointf3(0.0, 0.0, h));
|
||||
|
||||
// adjust via rounding to get an even multiple for any provided angle.
|
||||
double angle = (2*PI / floor(2*PI / fa));
|
||||
|
@ -1571,26 +1572,24 @@ TriangleMesh make_cylinder(double r, double h, double fa) {
|
|||
// top and bottom.
|
||||
// Special case: Last line shares 2 vertices with the first line.
|
||||
unsigned id = vertices.size() - 1;
|
||||
vertices.push_back(Pointf3(sin(0) * r , cos(0) * r, 0));
|
||||
vertices.push_back(Pointf3(sin(0) * r , cos(0) * r, h));
|
||||
vertices.emplace_back(Pointf3(sin(0) * r , cos(0) * r, 0));
|
||||
vertices.emplace_back(Pointf3(sin(0) * r , cos(0) * r, h));
|
||||
for (double i = 0; i < 2*PI; i+=angle) {
|
||||
Pointf3 b(0, r, 0);
|
||||
Pointf3 t(0, r, h);
|
||||
b.rotate(i, Pointf3(0,0,0));
|
||||
t.rotate(i, Pointf3(0,0,h));
|
||||
vertices.push_back(b);
|
||||
vertices.push_back(t);
|
||||
Pointf p(0, r);
|
||||
p.rotate(i);
|
||||
vertices.emplace_back(Pointf3(p(0), p(1), 0.));
|
||||
vertices.emplace_back(Pointf3(p(0), p(1), h));
|
||||
id = vertices.size() - 1;
|
||||
facets.push_back(Point3( 0, id - 1, id - 3)); // top
|
||||
facets.push_back(Point3(id, 1, id - 2)); // bottom
|
||||
facets.push_back(Point3(id, id - 2, id - 3)); // upper-right of side
|
||||
facets.push_back(Point3(id, id - 3, id - 1)); // bottom-left of side
|
||||
facets.emplace_back(Point3( 0, id - 1, id - 3)); // top
|
||||
facets.emplace_back(Point3(id, 1, id - 2)); // bottom
|
||||
facets.emplace_back(Point3(id, id - 2, id - 3)); // upper-right of side
|
||||
facets.emplace_back(Point3(id, id - 3, id - 1)); // bottom-left of side
|
||||
}
|
||||
// Connect the last set of vertices with the first.
|
||||
facets.push_back(Point3( 2, 0, id - 1));
|
||||
facets.push_back(Point3( 1, 3, id));
|
||||
facets.push_back(Point3(id, 3, 2));
|
||||
facets.push_back(Point3(id, 2, id - 1));
|
||||
facets.emplace_back(Point3( 2, 0, id - 1));
|
||||
facets.emplace_back(Point3( 1, 3, id));
|
||||
facets.emplace_back(Point3(id, 3, 2));
|
||||
facets.emplace_back(Point3(id, 2, id - 1));
|
||||
|
||||
TriangleMesh mesh(vertices, facets);
|
||||
return mesh;
|
||||
|
@ -1613,29 +1612,25 @@ TriangleMesh make_sphere(double rho, double fa) {
|
|||
// Ring to be scaled to generate the steps of the sphere
|
||||
std::vector<double> ring;
|
||||
for (double i = 0; i < 2*PI; i+=angle) {
|
||||
ring.push_back(i);
|
||||
ring.emplace_back(i);
|
||||
}
|
||||
const size_t steps = ring.size();
|
||||
const double increment = (double)(1.0 / (double)steps);
|
||||
|
||||
// special case: first ring connects to 0,0,0
|
||||
// insert and form facets.
|
||||
vertices.push_back(Pointf3(0.0, 0.0, -rho));
|
||||
vertices.emplace_back(Pointf3(0.0, 0.0, -rho));
|
||||
size_t id = vertices.size();
|
||||
for (size_t i = 0; i < ring.size(); i++) {
|
||||
// Fixed scaling
|
||||
const double z = -rho + increment*rho*2.0;
|
||||
// radius of the circle for this step.
|
||||
const double r = sqrt(abs(rho*rho - z*z));
|
||||
Pointf3 b(0, r, z);
|
||||
b.rotate(ring[i], Pointf3(0,0,z));
|
||||
vertices.push_back(b);
|
||||
if (i == 0) {
|
||||
facets.push_back(Point3(1, 0, ring.size()));
|
||||
} else {
|
||||
facets.push_back(Point3(id, 0, id - 1));
|
||||
}
|
||||
id++;
|
||||
Pointf b(0, r);
|
||||
b.rotate(ring[i]);
|
||||
vertices.emplace_back(Pointf3(b(0), b(1), z));
|
||||
facets.emplace_back((i == 0) ? Point3(1, 0, ring.size()) : Point3(id, 0, id - 1));
|
||||
++ id;
|
||||
}
|
||||
|
||||
// General case: insert and form facets for each step, joining it to the ring below it.
|
||||
|
@ -1644,16 +1639,16 @@ TriangleMesh make_sphere(double rho, double fa) {
|
|||
const double r = sqrt(abs(rho*rho - z*z));
|
||||
|
||||
for (size_t i = 0; i < ring.size(); i++) {
|
||||
Pointf3 b(0, r, z);
|
||||
b.rotate(ring[i], Pointf3(0,0,z));
|
||||
vertices.push_back(b);
|
||||
Pointf b(0, r);
|
||||
b.rotate(ring[i]);
|
||||
vertices.emplace_back(Pointf3(b(0), b(1), z));
|
||||
if (i == 0) {
|
||||
// wrap around
|
||||
facets.push_back(Point3(id + ring.size() - 1 , id, id - 1));
|
||||
facets.push_back(Point3(id, id - ring.size(), id - 1));
|
||||
facets.emplace_back(Point3(id + ring.size() - 1 , id, id - 1));
|
||||
facets.emplace_back(Point3(id, id - ring.size(), id - 1));
|
||||
} else {
|
||||
facets.push_back(Point3(id , id - ring.size(), (id - 1) - ring.size()));
|
||||
facets.push_back(Point3(id, id - 1 - ring.size() , id - 1));
|
||||
facets.emplace_back(Point3(id , id - ring.size(), (id - 1) - ring.size()));
|
||||
facets.emplace_back(Point3(id, id - 1 - ring.size() , id - 1));
|
||||
}
|
||||
id++;
|
||||
}
|
||||
|
@ -1662,13 +1657,13 @@ TriangleMesh make_sphere(double rho, double fa) {
|
|||
|
||||
// special case: last ring connects to 0,0,rho*2.0
|
||||
// only form facets.
|
||||
vertices.push_back(Pointf3(0.0, 0.0, rho));
|
||||
vertices.emplace_back(Pointf3(0.0, 0.0, rho));
|
||||
for (size_t i = 0; i < ring.size(); i++) {
|
||||
if (i == 0) {
|
||||
// third vertex is on the other side of the ring.
|
||||
facets.push_back(Point3(id, id - ring.size(), id - 1));
|
||||
facets.emplace_back(Point3(id, id - ring.size(), id - 1));
|
||||
} else {
|
||||
facets.push_back(Point3(id, id - ring.size() + i, id - ring.size() + (i - 1)));
|
||||
facets.emplace_back(Point3(id, id - ring.size() + i, id - ring.size() + (i - 1)));
|
||||
}
|
||||
}
|
||||
id++;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue