From ffafe74259aac68ee2bc2782dda162aaa577109c Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Fri, 12 Jan 2024 23:09:43 -0500 Subject: [PATCH] Add convenience methods addVertex/prependVertex taking Vertex3d (#4932) --- src/core/SurfaceNode.cc | 8 ++++---- src/core/primitives.cc | 10 +++++----- src/geometry/PolySetBuilder.cc | 10 ++++++++++ src/geometry/PolySetBuilder.h | 2 ++ src/geometry/cgal/Polygon2d-CGAL.cc | 2 +- src/geometry/cgal/cgalutils-mesh.cc | 2 +- src/geometry/cgal/cgalutils-polyhedron.cc | 2 +- src/geometry/cgal/cgalutils.cc | 16 ++++++++-------- src/geometry/roof_vd.cc | 2 +- src/io/import_3mf.cc | 4 ++-- src/io/import_amf.cc | 2 +- src/io/import_stl.cc | 2 +- 12 files changed, 37 insertions(+), 25 deletions(-) diff --git a/src/core/SurfaceNode.cc b/src/core/SurfaceNode.cc index b5d21d35ed2..c0ca27591d4 100644 --- a/src/core/SurfaceNode.cc +++ b/src/core/SurfaceNode.cc @@ -307,13 +307,13 @@ std::unique_ptr SurfaceNode::createGeometry() const if (columns > 1 && lines > 1) { builder.appendPoly(2 * (columns - 1) + 2 * (lines - 1) ); for (int i = 0; i < columns - 1; ++i) - builder.prependVertex(builder.vertexIndex(Vector3d(ox + i, oy + 0, min_val))); + builder.prependVertex(Vector3d(ox + i, oy + 0, min_val)); for (int i = 0; i < lines - 1; ++i) - builder.prependVertex(builder.vertexIndex(Vector3d(ox + columns - 1, oy + i, min_val))); + builder.prependVertex(Vector3d(ox + columns - 1, oy + i, min_val)); for (int i = columns - 1; i > 0; i--) - builder.prependVertex(builder.vertexIndex(Vector3d(ox + i, oy + lines - 1, min_val))); + builder.prependVertex(Vector3d(ox + i, oy + lines - 1, min_val)); for (int i = lines - 1; i > 0; i--) - builder.prependVertex(builder.vertexIndex(Vector3d(ox + 0, oy + i, min_val))); + builder.prependVertex(Vector3d(ox + 0, oy + i, min_val)); } return builder.build(); diff --git a/src/core/primitives.cc b/src/core/primitives.cc index b29c4a96a95..7461146b677 100644 --- a/src/core/primitives.cc +++ b/src/core/primitives.cc @@ -214,7 +214,7 @@ std::unique_ptr SphereNode::createGeometry() const builder.appendPoly(fragments); for (int i = 0; i < fragments; ++i) - builder.appendVertex(builder.vertexIndex(Vector3d(ring[0].points[i][0], ring[0].points[i][1], ring[0].z))); + builder.appendVertex(Vector3d(ring[0].points[i][0], ring[0].points[i][1], ring[0].z)); for (int i = 0; i < rings - 1; ++i) { auto r1 = &ring[i]; @@ -247,7 +247,7 @@ std::unique_ptr SphereNode::createGeometry() const builder.appendPoly(fragments); for (int i = 0; i < fragments; ++i) { - builder.prependVertex( builder.vertexIndex(Vector3d(ring[rings - 1].points[i][0], ring[rings - 1].points[i][1], ring[rings - 1].z))); + builder.prependVertex(Vector3d(ring[rings - 1].points[i][0], ring[rings - 1].points[i][1], ring[rings - 1].z)); } return builder.build(); @@ -314,7 +314,7 @@ std::unique_ptr CylinderNode::createGeometry() const if (r1 == r2) { builder.appendPoly(4); for(int k=0;k<4;k++) - builder.prependVertex(builder.vertexIndex(Vector3d(circle1[k&2?j:i][0], circle1[k&2?j:i][1], (k+1)&2?z2:z1))); + builder.prependVertex(Vector3d(circle1[k&2?j:i][0], circle1[k&2?j:i][1], (k+1)&2?z2:z1)); } else { if (r1 > 0) { builder.appendPoly({ @@ -336,13 +336,13 @@ std::unique_ptr CylinderNode::createGeometry() const if (this->r1 > 0) { builder.appendPoly(fragments); for (int i = 0; i < fragments; ++i) - builder.prependVertex(builder.vertexIndex(Vector3d(circle1[i][0], circle1[i][1], z1))); + builder.prependVertex(Vector3d(circle1[i][0], circle1[i][1], z1)); } if (this->r2 > 0) { builder.appendPoly(fragments); for (int i = 0; i < fragments; ++i) - builder.appendVertex(builder.vertexIndex(Vector3d(circle2[i][0], circle2[i][1], z2))); + builder.appendVertex(Vector3d(circle2[i][0], circle2[i][1], z2)); } return builder.build(); diff --git a/src/geometry/PolySetBuilder.cc b/src/geometry/PolySetBuilder.cc index bbf25afb838..74d3d9ad4bd 100644 --- a/src/geometry/PolySetBuilder.cc +++ b/src/geometry/PolySetBuilder.cc @@ -120,11 +120,21 @@ void PolySetBuilder::appendVertex(int ind) indices_.back().push_back(ind); } +void PolySetBuilder::appendVertex(const Vector3d &v) +{ + appendVertex(vertexIndex(v)); +} + void PolySetBuilder::prependVertex(int ind) { indices_.back().insert(indices_.back().begin(), ind); } +void PolySetBuilder::prependVertex(const Vector3d &v) +{ + prependVertex(vertexIndex(v)); +} + void PolySetBuilder::append(const PolySet& ps) { for (const auto& poly : ps.indices) { diff --git a/src/geometry/PolySetBuilder.h b/src/geometry/PolySetBuilder.h index 6397d64ecd7..a6705ce5ca5 100644 --- a/src/geometry/PolySetBuilder.h +++ b/src/geometry/PolySetBuilder.h @@ -23,7 +23,9 @@ class PolySetBuilder void appendGeometry(const std::shared_ptr& geom); void appendPoly(const std::vector& v); void appendVertex(int n); + void appendVertex(const Vector3d &v); void prependVertex(int n); + void prependVertex(const Vector3d &v); std::unique_ptr build(); private: Reindexer vertices_; diff --git a/src/geometry/cgal/Polygon2d-CGAL.cc b/src/geometry/cgal/Polygon2d-CGAL.cc index 71efb02633f..b0578720eb2 100644 --- a/src/geometry/cgal/Polygon2d-CGAL.cc +++ b/src/geometry/cgal/Polygon2d-CGAL.cc @@ -123,7 +123,7 @@ std::unique_ptr Polygon2d::tessellate() const if (fit->info().in_domain()) { builder.appendPoly(3); for (int i = 0; i < 3; ++i) { - builder.appendVertex(builder.vertexIndex(Vector3d(fit->vertex(i)->point()[0], fit->vertex(i)->point()[1], 0))); + builder.appendVertex(Vector3d(fit->vertex(i)->point()[0], fit->vertex(i)->point()[1], 0)); } } } diff --git a/src/geometry/cgal/cgalutils-mesh.cc b/src/geometry/cgal/cgalutils-mesh.cc index 5f4749fcc73..893d73a6f83 100644 --- a/src/geometry/cgal/cgalutils-mesh.cc +++ b/src/geometry/cgal/cgalutils-mesh.cc @@ -59,7 +59,7 @@ std::unique_ptr createPolySetFromMesh(const TriangleMesh& mesh) double x = CGAL::to_double(v.x()); double y = CGAL::to_double(v.y()); double z = CGAL::to_double(v.z()); - builder.appendVertex(builder.vertexIndex(Vector3d(x, y, z))); + builder.appendVertex(Vector3d(x, y, z)); } } return builder.build(); diff --git a/src/geometry/cgal/cgalutils-polyhedron.cc b/src/geometry/cgal/cgalutils-polyhedron.cc index 7f06fe1ca8c..640dcfd565b 100644 --- a/src/geometry/cgal/cgalutils-polyhedron.cc +++ b/src/geometry/cgal/cgalutils-polyhedron.cc @@ -296,7 +296,7 @@ std::unique_ptr createPolySetFromPolyhedron(const Polyhedron& p) double x = CGAL::to_double(v.point().x()); double y = CGAL::to_double(v.point().y()); double z = CGAL::to_double(v.point().z()); - builder.appendVertex(builder.vertexIndex(Vector3d(x, y, z))); + builder.appendVertex(Vector3d(x, y, z)); } while (hc != hc_end); } return builder.build(); diff --git a/src/geometry/cgal/cgalutils.cc b/src/geometry/cgal/cgalutils.cc index 186eb15f5ac..295011b99e9 100644 --- a/src/geometry/cgal/cgalutils.cc +++ b/src/geometry/cgal/cgalutils.cc @@ -378,12 +378,12 @@ std::unique_ptr createPolySetFromNefPolyhedron3(const CGAL::Nef_polyhed PolySetBuilder builder(verts.size(),allTriangles.size()); std::vector indMap; - for(int i=0;i getGeometryAsPolySet(const std::shared_ptr(3); if (!N->isEmpty()) { if (auto ps = CGALUtils::createPolySetFromNefPolyhedron3(*N->p3)) { - ps->setConvexity(N->getConvexity()); - return ps; + ps->setConvexity(N->getConvexity()); + return ps; } LOG(message_group::Error, "Nef->PolySet failed."); } diff --git a/src/geometry/roof_vd.cc b/src/geometry/roof_vd.cc index b4d17f07c1f..b240a359a64 100644 --- a/src/geometry/roof_vd.cc +++ b/src/geometry/roof_vd.cc @@ -371,7 +371,7 @@ std::unique_ptr voronoi_diagram_roof(const Polygon2d& poly, double fa, for (const IndexedFace& triangle : tess->indices) { std::vector roof; for (int tvind : triangle) { - Vector3d tv=tess->vertices[tvind]; + Vector3d tv=tess->vertices[tvind]; Vector2d v; v << tv[0], tv[1]; if (!(inner_faces.heights.find(v) != inner_faces.heights.end())) { diff --git a/src/io/import_3mf.cc b/src/io/import_3mf.cc index 4d968c05fe1..059522476ce 100644 --- a/src/io/import_3mf.cc +++ b/src/io/import_3mf.cc @@ -157,7 +157,7 @@ std::unique_ptr import_3mf(const std::string& filename, const Location if (lib3mf_meshobject_getvertex(object, triangle.m_nIndices[i], &vertex) != LIB3MF_OK) { return import_3mf_error(model, object_it); } - builder.appendVertex(builder.vertexIndex(Vector3d(vertex.m_fPosition[0], vertex.m_fPosition[1], vertex.m_fPosition[2]))); + builder.appendVertex(Vector3d(vertex.m_fPosition[0], vertex.m_fPosition[1], vertex.m_fPosition[2])); } } @@ -316,7 +316,7 @@ std::unique_ptr import_3mf(const std::string& filename, const Location for(int i=0;i<3;i++) { Lib3MF::sPosition vertex = object->GetVertex(triangle.m_Indices[i]); - builder.appendVertex(builder.vertexIndex(Vector3d(vertex.m_Coordinates[0], vertex.m_Coordinates[1], vertex.m_Coordinates[2]))); + builder.appendVertex(Vector3d(vertex.m_Coordinates[0], vertex.m_Coordinates[1], vertex.m_Coordinates[2])); } } diff --git a/src/io/import_amf.cc b/src/io/import_amf.cc index 55b3e56ce5c..15311b988fa 100644 --- a/src/io/import_amf.cc +++ b/src/io/import_amf.cc @@ -158,7 +158,7 @@ void AmfImporter::end_triangle(AmfImporter *importer, const xmlChar *) importer->builder->appendPoly(3); for(int i=0;i<3;i++) // TODO set vertex array first - importer->builder->appendVertex(importer->builder->vertexIndex(Vector3d(v[idx[i]].x(), v[idx[i]].y(), v[idx[i]].z()))); + importer->builder->appendVertex(Vector3d(v[idx[i]].x(), v[idx[i]].y(), v[idx[i]].z())); } void AmfImporter::processNode(xmlTextReaderPtr reader) diff --git a/src/io/import_stl.cc b/src/io/import_stl.cc index 382a20eb8f2..7f6f6b9a92a 100644 --- a/src/io/import_stl.cc +++ b/src/io/import_stl.cc @@ -147,7 +147,7 @@ std::unique_ptr import_stl(const std::string& filename, const Location& if (++i == 3) { builder.appendPoly(3); for(int j=0;j<3;j++) - builder.appendVertex(builder.vertexIndex(Vector3d(vdata[j][0], vdata[j][1], vdata[j][2]))); + builder.appendVertex(Vector3d(vdata[j][0], vdata[j][1], vdata[j][2])); } } catch (const boost::bad_lexical_cast& blc) { AsciiError("can't parse vertex");