From 65238a89b10fb18e7f9b647f5026da9276d32d58 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Mon, 10 Jun 2019 17:36:15 +0200 Subject: [PATCH] admesh refactoring: Removed the shared_vertices counter as it is now contained inside v_shared std::vector --- src/admesh/shared.cpp | 14 +++++--------- src/admesh/stl.h | 2 -- src/admesh/util.cpp | 1 - src/libslic3r/Format/3mf.cpp | 6 +++--- src/libslic3r/Format/AMF.cpp | 4 ++-- src/libslic3r/Model.cpp | 2 +- src/libslic3r/TriangleMesh.cpp | 4 ++-- xs/xsp/TriangleMesh.xsp | 4 ++-- 8 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/admesh/shared.cpp b/src/admesh/shared.cpp index a757d8816..e9f075498 100644 --- a/src/admesh/shared.cpp +++ b/src/admesh/shared.cpp @@ -33,7 +33,6 @@ void stl_invalidate_shared_vertices(stl_file *stl) { stl->v_indices.clear(); stl->v_shared.clear(); - stl->stats.shared_vertices = 0; } void stl_generate_shared_vertices(stl_file *stl) @@ -43,7 +42,6 @@ void stl_generate_shared_vertices(stl_file *stl) // Shared vertices (3D coordinates) stl->v_shared.clear(); stl->v_shared.reserve(stl->stats.number_of_facets / 2); - stl->stats.shared_vertices = 0; // A degenerate mesh may contain loops: Traversing a fan will end up in an endless loop // while never reaching the starting face. To avoid these endless loops, traversed faces at each fan traversal @@ -91,7 +89,7 @@ void stl_generate_shared_vertices(stl_file *stl) next_edge = pivot_vertex; } } - stl->v_indices[facet_in_fan_idx].vertex[pivot_vertex] = stl->stats.shared_vertices; + stl->v_indices[facet_in_fan_idx].vertex[pivot_vertex] = stl->v_shared.size() - 1; fan_traversal_facet_visited[facet_in_fan_idx] = fan_traversal_stamp; // next_edge is an index of the starting vertex of the edge, not an index of the opposite vertex to the edge! @@ -128,8 +126,6 @@ void stl_generate_shared_vertices(stl_file *stl) facet_in_fan_idx = next_facet; } } - - ++ stl->stats.shared_vertices; } } } @@ -147,8 +143,8 @@ bool stl_write_off(stl_file *stl, const char *file) } fprintf(fp, "OFF\n"); - fprintf(fp, "%d %d 0\n", stl->stats.shared_vertices, stl->stats.number_of_facets); - for (int i = 0; i < stl->stats.shared_vertices; ++ i) + fprintf(fp, "%d %d 0\n", stl->v_shared.size(), stl->stats.number_of_facets); + for (int i = 0; i < stl->v_shared.size(); ++ i) fprintf(fp, "\t%f %f %f\n", stl->v_shared[i](0), stl->v_shared[i](1), stl->v_shared[i](2)); for (uint32_t i = 0; i < stl->stats.number_of_facets; ++ i) fprintf(fp, "\t3 %d %d %d\n", stl->v_indices[i].vertex[0], stl->v_indices[i].vertex[1], stl->v_indices[i].vertex[2]); @@ -184,7 +180,7 @@ bool stl_write_vrml(stl_file *stl, const char *file) fprintf(fp, "\t\t\tpoint [\n"); int i = 0; - for (; i < (stl->stats.shared_vertices - 1); i++) + for (; i + 1 < stl->v_shared.size(); ++ i) fprintf(fp, "\t\t\t\t%f %f %f,\n", stl->v_shared[i](0), stl->v_shared[i](1), stl->v_shared[i](2)); fprintf(fp, "\t\t\t\t%f %f %f]\n", stl->v_shared[i](0), stl->v_shared[i](1), stl->v_shared[i](2)); fprintf(fp, "\t\t}\n"); @@ -213,7 +209,7 @@ bool stl_write_obj(stl_file *stl, const char *file) return false; } - for (int i = 0; i < stl->stats.shared_vertices; ++ i) + for (size_t i = 0; i < stl->v_shared.size(); ++ i) fprintf(fp, "v %f %f %f\n", stl->v_shared[i](0), stl->v_shared[i](1), stl->v_shared[i](2)); for (uint32_t i = 0; i < stl->stats.number_of_facets; ++ i) fprintf(fp, "f %d %d %d\n", stl->v_indices[i].vertex[0]+1, stl->v_indices[i].vertex[1]+1, stl->v_indices[i].vertex[2]+1); diff --git a/src/admesh/stl.h b/src/admesh/stl.h index 51153ede7..4aee6048f 100644 --- a/src/admesh/stl.h +++ b/src/admesh/stl.h @@ -109,7 +109,6 @@ struct stl_stats { float bounding_diameter; float shortest_edge; float volume; - unsigned number_of_blocks; int connected_edges; int connected_facets_1_edge; int connected_facets_2_edge; @@ -126,7 +125,6 @@ struct stl_stats { int backwards_edges; int normals_fixed; int number_of_parts; - int shared_vertices; }; struct stl_file { diff --git a/src/admesh/util.cpp b/src/admesh/util.cpp index db05cbc09..685b641b4 100644 --- a/src/admesh/util.cpp +++ b/src/admesh/util.cpp @@ -425,7 +425,6 @@ bool stl_validate(stl_file *stl) assert(! stl->neighbors_start.empty()); assert((stl->v_indices.empty()) == (stl->v_shared.empty())); assert(stl->stats.number_of_facets > 0); - assert(stl->v_shared.size() == stl->stats.shared_vertices); assert(stl->v_shared.empty() || stl->v_indices.size() == stl->stats.number_of_facets); #ifdef _DEBUG diff --git a/src/libslic3r/Format/3mf.cpp b/src/libslic3r/Format/3mf.cpp index c3916a14e..d67106656 100644 --- a/src/libslic3r/Format/3mf.cpp +++ b/src/libslic3r/Format/3mf.cpp @@ -1888,17 +1888,17 @@ namespace Slic3r { if (stl.v_shared.empty()) stl_generate_shared_vertices(&stl); - if (stl.stats.shared_vertices == 0) + if (stl.v_shared.empty()) { add_error("Found invalid mesh"); return false; } - vertices_count += stl.stats.shared_vertices; + vertices_count += stl.v_shared.size(); const Transform3d& matrix = volume->get_matrix(); - for (int i = 0; i < stl.stats.shared_vertices; ++i) + for (size_t i = 0; i < stl.v_shared.size(); ++i) { stream << " <" << VERTEX_TAG << " "; Vec3f v = (matrix * stl.v_shared[i].cast()).cast(); diff --git a/src/libslic3r/Format/AMF.cpp b/src/libslic3r/Format/AMF.cpp index f48b5b58c..e81ced3ad 100644 --- a/src/libslic3r/Format/AMF.cpp +++ b/src/libslic3r/Format/AMF.cpp @@ -929,7 +929,7 @@ bool store_amf(const char *path, Model *model, const DynamicPrintConfig *config) if (stl.v_shared.empty()) stl_generate_shared_vertices(&stl); const Transform3d& matrix = volume->get_matrix(); - for (size_t i = 0; i < stl.stats.shared_vertices; ++i) { + for (size_t i = 0; i < stl.v_shared.size(); ++i) { stream << " \n"; stream << " \n"; Vec3f v = (matrix * stl.v_shared[i].cast()).cast(); @@ -939,7 +939,7 @@ bool store_amf(const char *path, Model *model, const DynamicPrintConfig *config) stream << " \n"; stream << " \n"; } - num_vertices += stl.stats.shared_vertices; + num_vertices += stl.v_shared.size(); } stream << " \n"; for (size_t i_volume = 0; i_volume < object->volumes.size(); ++i_volume) { diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index 64fbb9a2a..6da7fc0c3 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -919,7 +919,7 @@ Polygon ModelObject::convex_hull_2d(const Transform3d &trafo_instance) const } } else { // Using the shared vertices should be a bit quicker than using the STL faces. - for (int i = 0; i < stl.stats.shared_vertices; ++ i) { + for (size_t i = 0; i < stl.v_shared.size(); ++ i) { Vec3d p = trafo * stl.v_shared[i].cast(); pts.emplace_back(coord_t(scale_(p.x())), coord_t(scale_(p.y()))); } diff --git a/src/libslic3r/TriangleMesh.cpp b/src/libslic3r/TriangleMesh.cpp index 27163eb57..003affc27 100644 --- a/src/libslic3r/TriangleMesh.cpp +++ b/src/libslic3r/TriangleMesh.cpp @@ -484,8 +484,8 @@ Polygon TriangleMesh::convex_hull() { this->require_shared_vertices(); Points pp; - pp.reserve(this->stl.stats.shared_vertices); - for (int i = 0; i < this->stl.stats.shared_vertices; ++ i) { + pp.reserve(this->stl.v_shared.size()); + for (size_t i = 0; i < this->stl.v_shared.size(); ++ i) { const stl_vertex &v = this->stl.v_shared[i]; pp.emplace_back(Point::new_scale(v(0), v(1))); } diff --git a/xs/xsp/TriangleMesh.xsp b/xs/xsp/TriangleMesh.xsp index 3cfbaa54d..53b052027 100644 --- a/xs/xsp/TriangleMesh.xsp +++ b/xs/xsp/TriangleMesh.xsp @@ -104,8 +104,8 @@ TriangleMesh::vertices() // vertices AV* vertices = newAV(); - av_extend(vertices, THIS->stl.stats.shared_vertices); - for (int i = 0; i < THIS->stl.stats.shared_vertices; i++) { + av_extend(vertices, THIS->stl.v_shared.size()); + for (size_t i = 0; i < THIS->stl.v_shared.size(); i++) { AV* vertex = newAV(); av_store(vertices, i, newRV_noinc((SV*)vertex)); av_extend(vertex, 2);