Changing the internal representation of Point / Pointf / Point3 / Pointf3 to Eigen Matrix types, first step

This commit is contained in:
bubnikv 2018-08-14 18:33:26 +02:00
parent 077680b806
commit 86da661097
60 changed files with 1228 additions and 1206 deletions

View file

@ -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].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_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].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_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].z()];
facet.vertex[2].x = ref_f3.x();
facet.vertex[2].y = ref_f3.y();
facet.vertex[2].z = ref_f3.z();
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.x();
fversor[1] = versor.y();
fversor[2] = versor.z();
stl_scale_versor(&this->stl, fversor);
stl_invalidate_shared_vertices(&this->stl);
}
@ -400,9 +400,9 @@ void TriangleMesh::rotate(double angle, Point* center)
{
if (angle == 0.)
return;
this->translate(float(-center->x), float(-center->y), 0);
this->translate(float(-center->x()), float(-center->y()), 0);
stl_rotate_z(&(this->stl), (float)angle);
this->translate(float(+center->x), float(+center->y), 0);
this->translate(float(+center->x()), float(+center->y()), 0);
}
bool TriangleMesh::has_multiple_patches() const
@ -588,12 +588,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.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;
return bb;
}
@ -813,10 +813,10 @@ 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.x() = a->x;
il.a.y() = a->y;
il.b.x() = b->x;
il.b.y() = b->y;
il.a_id = a_id;
il.b_id = b_id;
(*lines)[layer_idx].push_back(il);
@ -894,10 +894,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.x() = a->x;
line_out->a.y() = a->y;
line_out->b.x() = b->x;
line_out->b.y() = b->y;
line_out->a_id = a_id;
line_out->b_id = b_id;
return true;
@ -907,21 +907,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.x() = a->x;
point.y() = 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.x() = b->x;
point.y() = 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.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.edge_id = edge_id;
}
}
@ -1202,7 +1202,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].x() + opl.points[i].x()) * double(opl.points[i].y() - opl.points[j].y());
if (area < 0)
std::reverse(opl.points.begin(), opl.points.end());
loops->emplace_back(std::move(opl.points));
@ -1492,8 +1492,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].x());
facet.vertex[i].y = unscale(p.points[i].y());
facet.vertex[i].z = z;
}
stl_add_facet(&upper->stl, &facet);
@ -1518,8 +1518,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].x());
facet.vertex[i].y = unscale(polygon->points[i].y());
facet.vertex[i].z = z;
}
stl_add_facet(&lower->stl, &facet);