From 97a521fd23772ac2561dad3128f02c354ee1f0ca Mon Sep 17 00:00:00 2001 From: jmespadero Date: Fri, 5 Nov 2021 10:43:29 +0100 Subject: [PATCH] Edge orientation coherence Sort edges in output of IntersectionPlaneMesh() to remove duplicate vertex and maintain orientation coherence in the edges. Before this change, the vertex list contains duplicates and the edge list is not sorted, so there is no easy way to build the polylines of the cut. Calling RemoveDuplicateVertex() will produce a edge list with no coherence, like this example: ``` edge [0 1] goes from [0.12843863 0.38690682 0.1] to [0.13383933 0.3839188 0.1] edge [2 3] goes from [0.14307424 0.38100217 0.1] to [0.13592989 0.38318165 0.1] edge [3 1] goes from [0.13592989 0.38318165 0.1] to [0.13383933 0.3839188 0.1] ``` The output is correct, but somehow confusing because edges in the polyline(s) are not in order. After the proposed change, the output will be: ``` edge [0 1] goes from [0.12843863 0.38690682 0.1] to [0.13383933 0.3839188 0.1] edge [1 3] goes from [0.13383933 0.3839188 0.1] to [0.13592989 0.38318165 0.1] edge [3 2] goes from [0.13592989 0.38318165 0.1] to [0.14307424 0.38100217 0.1] ``` --- vcg/complex/algorithms/intersection.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/vcg/complex/algorithms/intersection.h b/vcg/complex/algorithms/intersection.h index b0c8cab9..3277ee5a 100644 --- a/vcg/complex/algorithms/intersection.h +++ b/vcg/complex/algorithms/intersection.h @@ -195,6 +195,26 @@ bool IntersectionPlaneMesh(TriMeshType & m, } tri::Allocator :: template DeletePerVertexAttribute < ScalarType >(m,qH); + //Clean-up: Remove duplicate vertex + tri::Clean::RemoveDuplicateVertex(em); + + //Clean-up: Sort edges ensuring orientation coherence + for(size_t j=1; j < em.edge.size(); j++) + { + auto &n=em.edge[j-1].V(1); + for(size_t i=j; i< em.edge.size(); i++) + { + auto & ei=em.edge[i]; + if (ei.V(1) == n) + std::swap(ei.V(0), ei.V(1)); + if (ei.V(0) == n) + { + std::swap(em.edge[j], em.edge[i]); + break; + } + } + } + return true; }