From 1f9c785286f5c61dc51e6b11b73fb83aec0e9d1b Mon Sep 17 00:00:00 2001 From: alemuntoni Date: Wed, 22 Sep 2021 14:47:45 +0200 Subject: [PATCH] unique remove t-vertices filter --- .../filter_clean/cleanfilter.cpp | 792 ++++++++++-------- src/meshlabplugins/filter_clean/cleanfilter.h | 111 ++- 2 files changed, 501 insertions(+), 402 deletions(-) diff --git a/src/meshlabplugins/filter_clean/cleanfilter.cpp b/src/meshlabplugins/filter_clean/cleanfilter.cpp index ef87699ed..cf9930a9b 100644 --- a/src/meshlabplugins/filter_clean/cleanfilter.cpp +++ b/src/meshlabplugins/filter_clean/cleanfilter.cpp @@ -1,39 +1,39 @@ -/**************************************************************************** -* MeshLab o o * -* An extendible mesh processor o o * -* _ O _ * -* Copyright(C) 2005, 2006 \/)\/ * -* Visual Computing Lab /\/| * -* ISTI - Italian National Research Council | * -* \ * -* All rights reserved. * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU General Public License as published by * -* the Free Software Foundation; either version 2 of the License, or * -* (at your option) any later version. * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * -* for more details. * -* * -****************************************************************************/ +/***************************************************************************** + * MeshLab o o * + * An extendible mesh processor o o * + * _ O _ * + * Copyright(C) 2005-2021 \/)\/ * + * Visual Computing Lab /\/| * + * ISTI - Italian National Research Council | * + * \ * + * All rights reserved. * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * + * for more details. * + * * + ****************************************************************************/ #include "cleanfilter.h" +#include #include +#include #include #include -#include #include -#include using namespace std; using namespace vcg; -int SnapVertexBorder(CMeshO &m, Scalarm threshold,vcg::CallBackPos * cb); +int SnapVertexBorder(CMeshO& m, Scalarm threshold, vcg::CallBackPos* cb); CleanFilter::CleanFilter() { @@ -42,8 +42,7 @@ CleanFilter::CleanFilter() FP_REMOVE_WRT_Q, FP_REMOVE_ISOLATED_COMPLEXITY, FP_REMOVE_ISOLATED_DIAMETER, - FP_REMOVE_TVERTEX_FLIP, - FP_REMOVE_TVERTEX_COLLAPSE, + FP_REMOVE_TVERTEX, FP_SNAP_MISMATCHED_BORDER, FP_REMOVE_DUPLICATE_FACE, FP_REMOVE_FOLD_FACE, @@ -54,18 +53,18 @@ CleanFilter::CleanFilter() FP_REMOVE_DUPLICATED_VERTEX, FP_REMOVE_FACE_ZERO_AREA, FP_MERGE_CLOSE_VERTEX, - FP_MERGE_WEDGE_TEX - }; + FP_MERGE_WEDGE_TEX}; - for(ActionIDType tt : types()) + for (ActionIDType tt : types()) actionList.push_back(new QAction(filterName(tt), this)); - + QCoreApplication* app = QCoreApplication::instance(); if (app != nullptr) getFilterAction(FP_SNAP_MISMATCHED_BORDER)->setShortcut(QKeySequence("ALT+`")); } -CleanFilter::~CleanFilter() { +CleanFilter::~CleanFilter() +{ } QString CleanFilter::pluginName() const @@ -75,25 +74,24 @@ QString CleanFilter::pluginName() const QString CleanFilter::filterName(ActionIDType filter) const { - switch(filter) - { - case FP_BALL_PIVOTING: return QString("Surface Reconstruction: Ball Pivoting"); - case FP_REMOVE_WRT_Q: return QString("Remove Vertices wrt Quality"); - case FP_REMOVE_ISOLATED_DIAMETER: return QString("Remove Isolated pieces (wrt Diameter)"); - case FP_REMOVE_ISOLATED_COMPLEXITY: return QString("Remove Isolated pieces (wrt Face Num.)"); - case FP_REMOVE_TVERTEX_FLIP: return QString("Remove T-Vertices by Edge Flip"); - case FP_REMOVE_TVERTEX_COLLAPSE: return QString("Remove T-Vertices by Edge Collapse"); - case FP_SNAP_MISMATCHED_BORDER: return QString("Snap Mismatched Borders"); - case FP_MERGE_CLOSE_VERTEX: return QString("Merge Close Vertices"); - case FP_MERGE_WEDGE_TEX: return QString("Merge Wedge Texture Coord"); - case FP_REMOVE_DUPLICATE_FACE: return QString("Remove Duplicate Faces"); - case FP_REMOVE_FOLD_FACE: return QString("Remove Isolated Folded Faces by Edge Flip"); - case FP_REMOVE_NON_MANIF_EDGE: return QString("Repair non Manifold Edges by removing faces"); - case FP_REMOVE_NON_MANIF_EDGE_SPLIT: return QString("Repair non Manifold Edges by splitting vertices"); - case FP_REMOVE_NON_MANIF_VERT: return QString("Repair non Manifold Vertices by splitting"); - case FP_REMOVE_UNREFERENCED_VERTEX: return QString("Remove Unreferenced Vertices"); - case FP_REMOVE_DUPLICATED_VERTEX: return QString("Remove Duplicate Vertices"); - case FP_REMOVE_FACE_ZERO_AREA: return QString("Remove Zero Area Faces"); + switch (filter) { + case FP_BALL_PIVOTING: return QString("Surface Reconstruction: Ball Pivoting"); + case FP_REMOVE_WRT_Q: return QString("Remove Vertices wrt Quality"); + case FP_REMOVE_ISOLATED_DIAMETER: return QString("Remove Isolated pieces (wrt Diameter)"); + case FP_REMOVE_ISOLATED_COMPLEXITY: return QString("Remove Isolated pieces (wrt Face Num.)"); + case FP_REMOVE_TVERTEX: return QString("Remove T-Vertices"); + case FP_SNAP_MISMATCHED_BORDER: return QString("Snap Mismatched Borders"); + case FP_MERGE_CLOSE_VERTEX: return QString("Merge Close Vertices"); + case FP_MERGE_WEDGE_TEX: return QString("Merge Wedge Texture Coord"); + case FP_REMOVE_DUPLICATE_FACE: return QString("Remove Duplicate Faces"); + case FP_REMOVE_FOLD_FACE: return QString("Remove Isolated Folded Faces by Edge Flip"); + case FP_REMOVE_NON_MANIF_EDGE: return QString("Repair non Manifold Edges by removing faces"); + case FP_REMOVE_NON_MANIF_EDGE_SPLIT: + return QString("Repair non Manifold Edges by splitting vertices"); + case FP_REMOVE_NON_MANIF_VERT: return QString("Repair non Manifold Vertices by splitting"); + case FP_REMOVE_UNREFERENCED_VERTEX: return QString("Remove Unreferenced Vertices"); + case FP_REMOVE_DUPLICATED_VERTEX: return QString("Remove Duplicate Vertices"); + case FP_REMOVE_FACE_ZERO_AREA: return QString("Remove Zero Area Faces"); default: assert(0); } return QString("error!"); @@ -101,50 +99,93 @@ QString CleanFilter::filterName(ActionIDType filter) const QString CleanFilter::filterInfo(ActionIDType filterId) const { - switch(filterId) - { - case FP_BALL_PIVOTING : return QString("Given a point cloud with normals it reconstructs a surface using the Ball Pivoting Algorithm." - "Starting with a seed triangle, the BPA algorithm pivots a ball of the given radius around the already formed edges" - "until it touches another point, forming another triangle. The process continues until all reachable edges have been tried." - "This surface reconstruction algorithm uses the existing points without creating new ones. Works better with uniformly sampled point clouds. " - "If needed first perform a poisson disk subsampling of the point cloud.
" - "Bernardini F., Mittleman J., Rushmeier H., Silva C., Taubin G.
" - "The ball-pivoting algorithm for surface reconstruction.
" - "IEEE TVCG 1999"); - case FP_REMOVE_ISOLATED_COMPLEXITY: return QString("Delete isolated connected components composed by a limited number of triangles"); - case FP_REMOVE_ISOLATED_DIAMETER: return QString("Delete isolated connected components whose diameter is smaller than the specified constant"); - case FP_REMOVE_WRT_Q: return QString("Delete all the vertices with a quality lower smaller than the specified constant"); - case FP_REMOVE_TVERTEX_COLLAPSE : return QString("Delete t-vertices from the mesh by collapsing the shortest of the incident edges"); - case FP_REMOVE_TVERTEX_FLIP : return QString("Delete t-vertices by flipping the opposite edge on the degenerate face if the triangulation quality improves"); - case FP_SNAP_MISMATCHED_BORDER : return QString("Try to snap together adjacent borders that are slightly mismatched.
" - "This situation can happen on badly triangulated adjacent patches defined by high order surfaces.
" - "For each border vertex the filter snap it onto the closest boundary edge only if it is closest of edge_length*threshold. When vertex is snapped the corresponding face is split and a new vertex is created."); - case FP_MERGE_CLOSE_VERTEX : return QString("Merge together all the vertices that are nearer than the specified threshold. Like a unify duplicated vertices but with some tolerance."); - case FP_MERGE_WEDGE_TEX : return QString("Merge together per-wedge texture coords that are very close. Used to correct apparent texture seams that can arise from numerical approximations when saving in ascii formats."); - case FP_REMOVE_DUPLICATE_FACE : return QString("Delete all the duplicate faces. Two faces are considered equal if they are composed by the same set of vertices, regardless of the order of the vertices."); - case FP_REMOVE_FOLD_FACE : return QString("Delete all the single folded faces. A face is considered folded if its normal is opposite to all the adjacent faces. It is removed by flipping it against the face f adjacent along the edge e such that the vertex opposite to e fall inside f"); - case FP_REMOVE_NON_MANIF_EDGE : return QString("For each non Manifold edge it iteratively deletes the smallest area face until it becomes 2-Manifold."); - case FP_REMOVE_NON_MANIF_EDGE_SPLIT:return QString("Remove all non manifold edges splitting vertices. Each non manifold edges chain will become a border"); - case FP_REMOVE_NON_MANIF_VERT : return QString("Split non Manifold vertices until it becomes 2-Manifold."); - case FP_REMOVE_UNREFERENCED_VERTEX: return QString("Check for every vertex on the mesh: if it is NOT referenced by a face, removes it"); - case FP_REMOVE_DUPLICATED_VERTEX: return QString("Check for every vertex on the mesh: if there are two vertices with same coordinates they are merged into a single one."); - case FP_REMOVE_FACE_ZERO_AREA: return QString("Remove null faces (the one with area equal to zero)"); + switch (filterId) { + case FP_BALL_PIVOTING: + return QString( + "Given a point cloud with normals it reconstructs a surface using the Ball Pivoting " + "Algorithm." + "Starting with a seed triangle, the BPA algorithm pivots a ball of the given radius " + "around the already formed edges until it touches another point, forming another " + "triangle. The process continues until all reachable edges have been tried. This " + "surface reconstruction algorithm uses the existing points without creating new ones. " + "Works better with uniformly sampled point clouds. If needed first perform a poisson " + "disk subsampling of the point cloud.
" + "Bernardini F., Mittleman J., Rushmeier H., Silva C., Taubin G.
" + "The ball-pivoting algorithm for surface reconstruction.
" + "IEEE TVCG 1999"); + case FP_REMOVE_ISOLATED_COMPLEXITY: + return QString( + "Delete isolated connected components composed by a limited number of triangles"); + case FP_REMOVE_ISOLATED_DIAMETER: + return QString( + "Delete isolated connected components whose diameter is smaller than the specified " + "constant"); + case FP_REMOVE_WRT_Q: + return QString( + "Delete all the vertices with a quality lower smaller than the specified constant"); + case FP_REMOVE_TVERTEX: + return QString( + "Delete t-vertices from the mesh by edge collapse (collapsing the shortest of the " + "incident edges) or edge flip (flipping the opposite edge on the degenerate face if " + "the triangulation quality improves)."); + case FP_SNAP_MISMATCHED_BORDER: + return QString( + "Try to snap together adjacent borders that are slightly mismatched.
" + "This situation can happen on badly triangulated adjacent patches defined by high " + "order surfaces.
For each border vertex the filter snap it onto the closest " + "boundary edge only if it is closest of edge_length*threshold. When vertex is " + "snapped the corresponding face is split and a new vertex is created."); + case FP_MERGE_CLOSE_VERTEX: + return QString( + "Merge together all the vertices that are nearer than the specified threshold. Like a " + "unify duplicated vertices but with some tolerance."); + case FP_MERGE_WEDGE_TEX: + return QString( + "Merge together per-wedge texture coords that are very close. Used to correct apparent " + "texture seams that can arise from numerical approximations when saving in ascii " + "formats."); + case FP_REMOVE_DUPLICATE_FACE: + return QString( + "Delete all the duplicate faces. Two faces are considered equal if they are composed " + "by the same set of vertices, regardless of the order of the vertices."); + case FP_REMOVE_FOLD_FACE: + return QString( + "Delete all the single folded faces. A face is considered folded if its normal is " + "opposite to all the adjacent faces. It is removed by flipping it against the face f " + "adjacent along the edge e such that the vertex opposite to e fall inside f"); + case FP_REMOVE_NON_MANIF_EDGE: + return QString( + "For each non Manifold edge it iteratively deletes the smallest area face until it " + "becomes 2-Manifold."); + case FP_REMOVE_NON_MANIF_EDGE_SPLIT: + return QString( + "Remove all non manifold edges splitting vertices. Each non manifold edges chain will " + "become a border"); + case FP_REMOVE_NON_MANIF_VERT: + return QString("Split non Manifold vertices until it becomes 2-Manifold."); + case FP_REMOVE_UNREFERENCED_VERTEX: + return QString( + "Check for every vertex on the mesh: if it is NOT referenced by a face, removes it"); + case FP_REMOVE_DUPLICATED_VERTEX: + return QString( + "Check for every vertex on the mesh: if there are two vertices with same coordinates " + "they are merged into a single one."); + case FP_REMOVE_FACE_ZERO_AREA: + return QString("Remove null faces (the one with area equal to zero)"); default: assert(0); } return QString("error!"); } -CleanFilter::FilterClass CleanFilter::getClass(const QAction *a) const +CleanFilter::FilterClass CleanFilter::getClass(const QAction* a) const { - switch(ID(a)) - { - case FP_REMOVE_WRT_Q : - case FP_REMOVE_ISOLATED_DIAMETER : - case FP_REMOVE_ISOLATED_COMPLEXITY : - case FP_REMOVE_TVERTEX_COLLAPSE : - case FP_REMOVE_TVERTEX_FLIP : - case FP_REMOVE_FOLD_FACE : - case FP_MERGE_CLOSE_VERTEX : + switch (ID(a)) { + case FP_REMOVE_WRT_Q: + case FP_REMOVE_ISOLATED_DIAMETER: + case FP_REMOVE_ISOLATED_COMPLEXITY: + case FP_REMOVE_TVERTEX: + case FP_REMOVE_FOLD_FACE: + case FP_MERGE_CLOSE_VERTEX: case FP_REMOVE_DUPLICATE_FACE: case FP_SNAP_MISMATCHED_BORDER: case FP_REMOVE_NON_MANIF_EDGE: @@ -153,34 +194,34 @@ CleanFilter::FilterClass CleanFilter::getClass(const QAction *a) const case FP_REMOVE_FACE_ZERO_AREA: case FP_REMOVE_UNREFERENCED_VERTEX: case FP_REMOVE_DUPLICATED_VERTEX: - case FP_BALL_PIVOTING: return FilterPlugin::Remeshing; - case FP_MERGE_WEDGE_TEX: return FilterPlugin::FilterClass(FilterPlugin::Cleaning + FilterPlugin::Texture); - default : assert(0); + case FP_BALL_PIVOTING: return FilterPlugin::Remeshing; + case FP_MERGE_WEDGE_TEX: + return FilterPlugin::FilterClass(FilterPlugin::Cleaning + FilterPlugin::Texture); + default: assert(0); } return FilterPlugin::Generic; } -int CleanFilter::getRequirements(const QAction *action) +int CleanFilter::getRequirements(const QAction* action) { - switch(ID(action)) - { + switch (ID(action)) { case FP_REMOVE_WRT_Q: - case FP_BALL_PIVOTING: return MeshModel::MM_VERTMARK; + case FP_BALL_PIVOTING: return MeshModel::MM_VERTMARK; case FP_REMOVE_ISOLATED_COMPLEXITY: - case FP_REMOVE_ISOLATED_DIAMETER: return MeshModel::MM_FACEFACETOPO | MeshModel::MM_FACEMARK; - case FP_REMOVE_TVERTEX_COLLAPSE: return MeshModel::MM_VERTMARK; - case FP_REMOVE_TVERTEX_FLIP: return MeshModel::MM_FACEFACETOPO | MeshModel::MM_VERTMARK; - case FP_REMOVE_NON_MANIF_EDGE: return MeshModel::MM_FACEFACETOPO | MeshModel::MM_VERTMARK; - case FP_REMOVE_NON_MANIF_EDGE_SPLIT: return MeshModel::MM_FACEFACETOPO | MeshModel::MM_VERTMARK; - case FP_REMOVE_NON_MANIF_VERT: return MeshModel::MM_FACEFACETOPO | MeshModel::MM_VERTMARK; - case FP_SNAP_MISMATCHED_BORDER: return MeshModel::MM_FACEFACETOPO | MeshModel::MM_VERTMARK| MeshModel::MM_FACEMARK; - case FP_REMOVE_FOLD_FACE: return MeshModel::MM_FACEFACETOPO | MeshModel::MM_VERTMARK; + case FP_REMOVE_ISOLATED_DIAMETER: return MeshModel::MM_FACEFACETOPO | MeshModel::MM_FACEMARK; + case FP_REMOVE_TVERTEX: return MeshModel::MM_FACEFACETOPO | MeshModel::MM_VERTMARK; + case FP_REMOVE_NON_MANIF_EDGE: return MeshModel::MM_FACEFACETOPO | MeshModel::MM_VERTMARK; + case FP_REMOVE_NON_MANIF_EDGE_SPLIT: return MeshModel::MM_FACEFACETOPO | MeshModel::MM_VERTMARK; + case FP_REMOVE_NON_MANIF_VERT: return MeshModel::MM_FACEFACETOPO | MeshModel::MM_VERTMARK; + case FP_SNAP_MISMATCHED_BORDER: + return MeshModel::MM_FACEFACETOPO | MeshModel::MM_VERTMARK | MeshModel::MM_FACEMARK; + case FP_REMOVE_FOLD_FACE: return MeshModel::MM_FACEFACETOPO | MeshModel::MM_VERTMARK; case FP_MERGE_CLOSE_VERTEX: - case FP_REMOVE_DUPLICATE_FACE: return MeshModel::MM_NONE; - case FP_MERGE_WEDGE_TEX: return MeshModel::MM_VERTFACETOPO | MeshModel::MM_WEDGTEXCOORD; - case FP_REMOVE_UNREFERENCED_VERTEX: return MeshModel::MM_NONE; - case FP_REMOVE_DUPLICATED_VERTEX: return MeshModel::MM_NONE; - case FP_REMOVE_FACE_ZERO_AREA: return MeshModel::MM_NONE; + case FP_REMOVE_DUPLICATE_FACE: return MeshModel::MM_NONE; + case FP_MERGE_WEDGE_TEX: return MeshModel::MM_VERTFACETOPO | MeshModel::MM_WEDGTEXCOORD; + case FP_REMOVE_UNREFERENCED_VERTEX: return MeshModel::MM_NONE; + case FP_REMOVE_DUPLICATED_VERTEX: return MeshModel::MM_NONE; + case FP_REMOVE_FACE_ZERO_AREA: return MeshModel::MM_NONE; default: assert(0); } return 0; @@ -188,14 +229,12 @@ int CleanFilter::getRequirements(const QAction *action) int CleanFilter::postCondition(const QAction* action) const { - switch (ID(action)) - { + switch (ID(action)) { case FP_BALL_PIVOTING: case FP_REMOVE_WRT_Q: case FP_REMOVE_ISOLATED_DIAMETER: case FP_REMOVE_ISOLATED_COMPLEXITY: - case FP_REMOVE_TVERTEX_FLIP: - case FP_REMOVE_TVERTEX_COLLAPSE: + case FP_REMOVE_TVERTEX: case FP_SNAP_MISMATCHED_BORDER: case FP_MERGE_CLOSE_VERTEX: case FP_MERGE_WEDGE_TEX: @@ -206,264 +245,345 @@ int CleanFilter::postCondition(const QAction* action) const case FP_REMOVE_UNREFERENCED_VERTEX: case FP_REMOVE_DUPLICATED_VERTEX: case FP_REMOVE_FACE_ZERO_AREA: - case FP_REMOVE_NON_MANIF_EDGE_SPLIT: return MeshModel::MM_GEOMETRY_AND_TOPOLOGY_CHANGE; + case FP_REMOVE_NON_MANIF_EDGE_SPLIT: return MeshModel::MM_GEOMETRY_AND_TOPOLOGY_CHANGE; } return MeshModel::MM_ALL; } -RichParameterList CleanFilter::initParameterList(const QAction *action, const MeshDocument &md) +RichParameterList CleanFilter::initParameterList(const QAction* action, const MeshDocument& md) { - RichParameterList parlst; - pair qualityRange; - switch(ID(action)) - { - case FP_BALL_PIVOTING : - parlst.addParam(RichAbsPerc("BallRadius",0.0f,0.0f,md.mm()->cm.bbox.Diag(),"Pivoting Ball radius (0 autoguess)","The radius of the ball pivoting (rolling) over the set of points. Gaps that are larger than the ball radius will not be filled; similarly the small pits that are smaller than the ball radius will be filled.")); - parlst.addParam(RichFloat("Clustering",20.0f,"Clustering radius (% of ball radius)","To avoid the creation of too small triangles, if a vertex is found too close to a previous one, it is clustered/merged with it.")); - parlst.addParam(RichFloat("CreaseThr", 90.0f,"Angle Threshold (degrees)","If we encounter a crease angle that is too large we should stop the ball rolling")); - parlst.addParam(RichBool("DeleteFaces",false,"Delete initial set of faces","if true all the initial faces of the mesh are deleted and the whole surface is rebuilt from scratch. Otherwise the current faces are used as a starting point. Useful if you run the algorithm multiple times with an increasing ball radius.")); + RichParameterList parlst; + pair qualityRange; + switch (ID(action)) { + case FP_BALL_PIVOTING: + parlst.addParam(RichAbsPerc( + "BallRadius", + 0.0f, + 0.0f, + md.mm()->cm.bbox.Diag(), + "Pivoting Ball radius (0 autoguess)", + "The radius of the ball pivoting (rolling) over the set of points. Gaps that are " + "larger than the ball radius will not be filled; similarly the small pits that are " + "smaller than the ball radius will be filled.")); + parlst.addParam(RichFloat( + "Clustering", + 20.0f, + "Clustering radius (% of ball radius)", + "To avoid the creation of too small triangles, if a vertex is found too close to a " + "previous one, it is clustered/merged with it.")); + parlst.addParam(RichFloat( + "CreaseThr", + 90.0f, + "Angle Threshold (degrees)", + "If we encounter a crease angle that is too large we should stop the ball rolling")); + parlst.addParam(RichBool( + "DeleteFaces", + false, + "Delete initial set of faces", + "if true all the initial faces of the mesh are deleted and the whole surface is " + "rebuilt from scratch. Otherwise the current faces are used as a starting point. " + "Useful if you run the algorithm multiple times with an increasing ball radius.")); break; case FP_REMOVE_ISOLATED_DIAMETER: - parlst.addParam(RichAbsPerc("MinComponentDiag",md.mm()->cm.bbox.Diag()/10.0f,0.0f,md.mm()->cm.bbox.Diag(),"Enter max diameter of isolated pieces","Delete all the connected components (floating pieces) with a diameter smaller than the specified one")); - parlst.addParam(RichBool("removeUnref", true, "Remove unfreferenced vertices", "if true, the unreferenced vertices remaining after the face deletion are removed.")); + parlst.addParam(RichAbsPerc( + "MinComponentDiag", + md.mm()->cm.bbox.Diag() / 10.0f, + 0.0f, + md.mm()->cm.bbox.Diag(), + "Enter max diameter of isolated pieces", + "Delete all the connected components (floating pieces) with a diameter smaller than " + "the specified one")); + parlst.addParam(RichBool( + "removeUnref", + true, + "Remove unfreferenced vertices", + "if true, the unreferenced vertices remaining after the face deletion are removed.")); break; case FP_REMOVE_ISOLATED_COMPLEXITY: - parlst.addParam(RichInt("MinComponentSize",25,"Enter minimum conn. comp size:","Delete all the connected components (floating pieces) composed by a number of triangles smaller than the specified one")); - parlst.addParam(RichBool("removeUnref", true, "Remove unfreferenced vertices", "if true, the unreferenced vertices remaining after the face deletion are removed.")); + parlst.addParam(RichInt( + "MinComponentSize", + 25, + "Enter minimum conn. comp size:", + "Delete all the connected components (floating pieces) composed by a number of " + "triangles smaller than the specified one")); + parlst.addParam(RichBool( + "removeUnref", + true, + "Remove unfreferenced vertices", + "if true, the unreferenced vertices remaining after the face deletion are removed.")); break; case FP_REMOVE_WRT_Q: - qualityRange=tri::Stat::ComputePerVertexQualityMinMax(md.mm()->cm); - parlst.addParam(RichAbsPerc("MaxQualityThr",(float)1.0, qualityRange.first, qualityRange.second,"Delete all vertices with quality under:")); + qualityRange = tri::Stat::ComputePerVertexQualityMinMax(md.mm()->cm); + parlst.addParam(RichAbsPerc( + "MaxQualityThr", + (float) 1.0, + qualityRange.first, + qualityRange.second, + "Delete all vertices with quality under:")); break; - case FP_MERGE_CLOSE_VERTEX: - parlst.addParam(RichAbsPerc("Threshold",md.mm()->cm.bbox.Diag()/10000.0f,0.0f,md.mm()->cm.bbox.Diag()/100.0f,"Merging distance","All the vertices that closer than this threshold are merged together. Use very small values, default values is 1/10000 of bounding box diagonal. ")); + case FP_MERGE_CLOSE_VERTEX: + parlst.addParam(RichAbsPerc( + "Threshold", + md.mm()->cm.bbox.Diag() / 10000.0f, + 0.0f, + md.mm()->cm.bbox.Diag() / 100.0f, + "Merging distance", + "All the vertices that closer than this threshold are merged together. Use very small " + "values, default values is 1/10000 of bounding box diagonal. ")); break; - case FP_MERGE_WEDGE_TEX : - parlst.addParam(RichFloat("MergeThr",1.0f/10000.0f,"Merging Threshold","All the per-wedge texture coords that are on the same vertex and are distant less then the given threshold are merged together. It can be used to remove the fake texture seams that arise from error. Distance is in texture space (the default, 1e-4, corresponds to one texel on a 10kx10x texture) ")); + case FP_MERGE_WEDGE_TEX: + parlst.addParam(RichFloat( + "MergeThr", + 1.0f / 10000.0f, + "Merging Threshold", + "All the per-wedge texture coords that are on the same vertex and are distant less " + "then the given threshold are merged together. It can be used to remove the fake " + "texture seams that arise from error. Distance is in texture space (the default, 1e-4, " + "corresponds to one texel on a 10kx10x texture) ")); break; case FP_SNAP_MISMATCHED_BORDER: - parlst.addParam(RichFloat("EdgeDistRatio",1/100.0f,"Edge Distance Ratio", "Collapse edge when the edge / distance ratio is greater than this value. E.g. for default value 1000 two straight border edges are collapsed if the central vertex dist from the straight line composed by the two edges less than a 1/1000 of the sum of the edges length. Larger values enforce that only vertices very close to the line are removed.")); - parlst.addParam(RichBool("UnifyVertices",true,"UnifyVertices","if true the snap vertices are weld together.")); - break; - case FP_REMOVE_TVERTEX_COLLAPSE : - case FP_REMOVE_TVERTEX_FLIP : parlst.addParam(RichFloat( - "Threshold", 40, "Ratio", "Detects faces where the base/height ratio is lower than this value")); + "EdgeDistRatio", + 1 / 100.0f, + "Edge Distance Ratio", + "Collapse edge when the edge / distance ratio is greater than this value. E.g. for " + "default value 1000 two straight border edges are collapsed if the central vertex dist " + "from the straight line composed by the two edges less than a 1/1000 of the sum of the " + "edges length. Larger values enforce that only vertices very close to the line are " + "removed.")); parlst.addParam(RichBool( - "Repeat", true, "Iterate until convergence", "Iterates the algorithm until it reaches convergence")); + "UnifyVertices", + true, + "UnifyVertices", + "if true the snap vertices are weld together.")); break; - case FP_REMOVE_NON_MANIF_VERT : - parlst.addParam(RichFloat("VertDispRatio", 0, "Vertex Displacement Ratio", "This parameter denote the ratio ⍺ of displacement of a vertex. When a vertex v is split, it is moved towards the barycenter b of the FF connected faces sharing it of a (v-b)*⍺. When ⍺ is zero vertex is not displaced. When ⍺ is 0.5 the new vertex is half away toward the barycenter of the face. Reasonable values are in the [0 .. 0.1] range. ")); + case FP_REMOVE_TVERTEX: + parlst.addParam(RichEnum( + "method", + 0, + {"Edge Collapse", "Edge Flip"}, + "Method", + "Selects wether to remove t-vertices by edge collapse or edge flip.")); + parlst.addParam(RichFloat( + "Threshold", + 40, + "Ratio", + "Detects faces where the base/height ratio is lower than this value")); + parlst.addParam(RichBool( + "Repeat", + true, + "Iterate until convergence", + "Iterates the algorithm until it reaches convergence")); + break; + case FP_REMOVE_NON_MANIF_VERT: + parlst.addParam(RichFloat( + "VertDispRatio", + 0, + "Vertex Displacement Ratio", + "This parameter denote the ratio ⍺ of displacement of a vertex. When a vertex v " + "is split, it is moved towards the barycenter b of the FF connected faces " + "sharing it of a (v-b)*⍺. When ⍺ is zero vertex is not displaced. When ⍺ " + "is 0.5 the new vertex is half away toward the barycenter of the face. Reasonable " + "values are in the [0 .. 0.1] range.")); break; default: break; // do not add any parameter for the other filters } return parlst; } -std::map CleanFilter::applyFilter(const QAction *filter, const RichParameterList & par, MeshDocument &md, unsigned int& postConditionMask, vcg::CallBackPos * cb) +std::map CleanFilter::applyFilter( + const QAction* filter, + const RichParameterList& par, + MeshDocument& md, + unsigned int& postConditionMask, + vcg::CallBackPos* cb) { - MeshModel &m=*(md.mm()); - switch(ID(filter)) - { - case FP_BALL_PIVOTING: - { + MeshModel& m = *(md.mm()); + switch (ID(filter)) { + case FP_BALL_PIVOTING: { vcg::tri::Allocator::CompactEveryVector(m.cm); - Scalarm Radius = par.getAbsPerc("BallRadius"); - Scalarm Clustering = par.getFloat("Clustering") / 100.0f; - Scalarm CreaseThr = math::ToRad(par.getFloat("CreaseThr")); - bool DeleteFaces = par.getBool("DeleteFaces"); - if(DeleteFaces) - { - m.cm.fn=0; + Scalarm Radius = par.getAbsPerc("BallRadius"); + Scalarm Clustering = par.getFloat("Clustering") / 100.0f; + Scalarm CreaseThr = math::ToRad(par.getFloat("CreaseThr")); + bool DeleteFaces = par.getBool("DeleteFaces"); + if (DeleteFaces) { + m.cm.fn = 0; m.cm.face.resize(0); } m.updateDataMask(MeshModel::MM_VERTFACETOPO); - int startingFn=m.cm.fn; + int startingFn = m.cm.fn; tri::BallPivoting pivot(m.cm, Radius, Clustering, CreaseThr); // the main processing pivot.BuildMesh(cb); m.clearDataMask(MeshModel::MM_FACEFACETOPO); - log("Reconstructed surface. Added %i faces",m.cm.fn-startingFn); + log("Reconstructed surface. Added %i faces", m.cm.fn - startingFn); } break; - case FP_REMOVE_ISOLATED_DIAMETER: - { - Scalarm minCC= par.getAbsPerc("MinComponentDiag"); - std::pair delInfo= tri::Clean::RemoveSmallConnectedComponentsDiameter(m.cm,minCC); + case FP_REMOVE_ISOLATED_DIAMETER: { + Scalarm minCC = par.getAbsPerc("MinComponentDiag"); + std::pair delInfo = + tri::Clean::RemoveSmallConnectedComponentsDiameter(m.cm, minCC); log("Removed %i connected components out of %i", delInfo.second, delInfo.first); - if (par.getBool("removeUnref")) - { + if (par.getBool("removeUnref")) { int delvert = tri::Clean::RemoveUnreferencedVertex(m.cm); log("Removed %d unreferenced vertices", delvert); } m.updateBoxAndNormals(); - }break; - case FP_REMOVE_ISOLATED_COMPLEXITY: - { - int minCC= par.getInt("MinComponentSize"); - std::pair delInfo=tri::Clean::RemoveSmallConnectedComponentsSize(m.cm,minCC); + } break; + case FP_REMOVE_ISOLATED_COMPLEXITY: { + int minCC = par.getInt("MinComponentSize"); + std::pair delInfo = + tri::Clean::RemoveSmallConnectedComponentsSize(m.cm, minCC); log("Removed %i connected components out of %i", delInfo.second, delInfo.first); - if (par.getBool("removeUnref")) - { + if (par.getBool("removeUnref")) { int delvert = tri::Clean::RemoveUnreferencedVertex(m.cm); log("Removed %d unreferenced vertices", delvert); } m.updateBoxAndNormals(); } break; - case FP_REMOVE_WRT_Q: - { - int deletedFN=0; - int deletedVN=0; - Scalarm val=par.getAbsPerc("MaxQualityThr"); + case FP_REMOVE_WRT_Q: { + int deletedFN = 0; + int deletedVN = 0; + Scalarm val = par.getAbsPerc("MaxQualityThr"); CMeshO::VertexIterator vi; - for(vi=m.cm.vert.begin();vi!=m.cm.vert.end();++vi) - if(!(*vi).IsD() && (*vi).Q()::DeleteVertex(m.cm, *vi); deletedVN++; } CMeshO::FaceIterator fi; - for(fi=m.cm.face.begin();fi!=m.cm.face.end();++fi) if(!(*fi).IsD()) - if((*fi).V(0)->IsD() ||(*fi).V(1)->IsD() ||(*fi).V(2)->IsD() ) - { - tri::Allocator::DeleteFace(m.cm, *fi); - deletedFN++; - } + for (fi = m.cm.face.begin(); fi != m.cm.face.end(); ++fi) + if (!(*fi).IsD()) + if ((*fi).V(0)->IsD() || (*fi).V(1)->IsD() || (*fi).V(2)->IsD()) { + tri::Allocator::DeleteFace(m.cm, *fi); + deletedFN++; + } m.clearDataMask(MeshModel::MM_FACEFACETOPO); - log("Deleted %i vertices and %i faces with a quality lower than %f", deletedVN,deletedFN,val); + log("Deleted %i vertices and %i faces with a quality lower than %f", + deletedVN, + deletedFN, + val); m.updateBoxAndNormals(); } break; - case FP_REMOVE_TVERTEX_COLLAPSE : - { - bool hadFF = false; - bool hadVF = false; - if (m.hasDataMask(MeshModel::MM_FACEFACETOPO)){ - m.clearDataMask(MeshModel::MM_FACEFACETOPO); - hadFF = true; - } - if (m.hasDataMask(MeshModel::MM_VERTFACETOPO)){ - m.clearDataMask(MeshModel::MM_VERTFACETOPO); - hadVF = true; - } + case FP_REMOVE_TVERTEX: { + int total = 0; Scalarm threshold = par.getFloat("Threshold"); - bool repeat = par.getBool("Repeat"); - int total = tri::Clean::RemoveTVertexByCollapse(m.cm, threshold, repeat); - log("Successfully removed %d t-vertices", total); - if (hadFF) - m.updateDataMask(MeshModel::MM_FACEFACETOPO); - if (hadVF) - m.updateDataMask(MeshModel::MM_VERTFACETOPO); - } break; + bool repeat = par.getBool("Repeat"); + if (par.getEnum("method") == 0) { // edge collapse + bool hadFF = false; + bool hadVF = false; + if (m.hasDataMask(MeshModel::MM_FACEFACETOPO)) { + m.clearDataMask(MeshModel::MM_FACEFACETOPO); + hadFF = true; + } + if (m.hasDataMask(MeshModel::MM_VERTFACETOPO)) { + m.clearDataMask(MeshModel::MM_VERTFACETOPO); + hadVF = true; + } + total = tri::Clean::RemoveTVertexByCollapse(m.cm, threshold, repeat); - case FP_REMOVE_TVERTEX_FLIP : - { - if (vcg::tri::Clean::CountNonManifoldEdgeFF(m.cm) > 0 || - vcg::tri::Clean::CountNonManifoldVertexFF(m.cm) > 0){ - throw MLException("Non manifold mesh. Please clean the mesh first."); + if (hadFF) + m.updateDataMask(MeshModel::MM_FACEFACETOPO); + if (hadVF) + m.updateDataMask(MeshModel::MM_VERTFACETOPO); + } + else { // edge flip + if (vcg::tri::Clean::CountNonManifoldEdgeFF(m.cm) > 0 || + vcg::tri::Clean::CountNonManifoldVertexFF(m.cm) > 0) { + throw MLException("Non manifold mesh. Please clean the mesh first."); + } + total = tri::Clean::RemoveTVertexByFlip(m.cm, threshold, repeat); } - Scalarm threshold = par.getFloat("Threshold"); - bool repeat = par.getBool("Repeat"); - int total = tri::Clean::RemoveTVertexByFlip(m.cm, threshold, repeat); log("Successfully removed %d t-vertices", total); } break; - case FP_MERGE_WEDGE_TEX : - { + case FP_MERGE_WEDGE_TEX: { Scalarm threshold = par.getFloat("MergeThr"); tri::UpdateTopology::VertexFace(m.cm); int total = tri::UpdateTexture::WedgeTexMergeClose(m.cm, threshold); - log("Successfully merged %d wedge tex coord distant less than %f", total,threshold); + log("Successfully merged %d wedge tex coord distant less than %f", total, threshold); } break; - case FP_MERGE_CLOSE_VERTEX : - { + case FP_MERGE_CLOSE_VERTEX: { Scalarm threshold = par.getAbsPerc("Threshold"); - int total = tri::Clean::MergeCloseVertex(m.cm, threshold); + int total = tri::Clean::MergeCloseVertex(m.cm, threshold); log("Successfully merged %d vertices", total); } break; - case FP_REMOVE_DUPLICATE_FACE : - { + case FP_REMOVE_DUPLICATE_FACE: { int total = tri::Clean::RemoveDuplicateFace(m.cm); log("Successfully deleted %d duplicated faces", total); } break; - case FP_REMOVE_FOLD_FACE: - { + case FP_REMOVE_FOLD_FACE: { m.updateDataMask(MeshModel::MM_FACECOLOR); int total = tri::Clean::RemoveFaceFoldByFlip(m.cm); log("Successfully flipped %d folded faces", total); m.updateBoxAndNormals(); } break; - case FP_REMOVE_NON_MANIF_EDGE : - { + case FP_REMOVE_NON_MANIF_EDGE: { int total = tri::Clean::RemoveNonManifoldFace(m.cm); log("Successfully removed %d non-manifold faces", total); m.updateBoxAndNormals(); } break; - case FP_REMOVE_NON_MANIF_EDGE_SPLIT : - { + case FP_REMOVE_NON_MANIF_EDGE_SPLIT: { int total = tri::Clean::SplitManifoldComponents(m.cm); log("Successfully split the mesh into %d edge manifold components", total); m.updateBoxAndNormals(); if (m.hasDataMask(MeshModel::MM_WEDGTEXCOORD)) - postConditionMask = MeshModel::MM_GEOMETRY_AND_TOPOLOGY_CHANGE | MeshModel::MM_WEDGTEXCOORD; + postConditionMask = + MeshModel::MM_GEOMETRY_AND_TOPOLOGY_CHANGE | MeshModel::MM_WEDGTEXCOORD; } break; - case FP_REMOVE_NON_MANIF_VERT : - { + case FP_REMOVE_NON_MANIF_VERT: { Scalarm threshold = par.getFloat("VertDispRatio"); - int total = tri::Clean::SplitNonManifoldVertex(m.cm,threshold); + int total = tri::Clean::SplitNonManifoldVertex(m.cm, threshold); log("Successfully split %d non manifold vertices faces", total); m.updateBoxAndNormals(); } break; - case FP_REMOVE_FACE_ZERO_AREA: - { + case FP_REMOVE_FACE_ZERO_AREA: { int nullFaces = tri::Clean::RemoveFaceOutOfRangeArea(m.cm, 0); log("Removed %d null faces", nullFaces); m.clearDataMask(MeshModel::MM_FACEFACETOPO); } break; - case FP_REMOVE_UNREFERENCED_VERTEX: - { + case FP_REMOVE_UNREFERENCED_VERTEX: { int delvert = tri::Clean::RemoveUnreferencedVertex(m.cm); log("Removed %d unreferenced vertices", delvert); - if (delvert != 0) m.updateBoxAndNormals(); + if (delvert != 0) + m.updateBoxAndNormals(); } break; - case FP_REMOVE_DUPLICATED_VERTEX: - { + case FP_REMOVE_DUPLICATED_VERTEX: { int delvert = tri::Clean::RemoveDuplicateVertex(m.cm); log("Removed %d duplicated vertices", delvert); - if (delvert != 0) m.updateBoxAndNormals(); + if (delvert != 0) + m.updateBoxAndNormals(); m.clearDataMask(MeshModel::MM_FACEFACETOPO); m.clearDataMask(MeshModel::MM_VERTFACETOPO); } break; - case FP_SNAP_MISMATCHED_BORDER : - { + case FP_SNAP_MISMATCHED_BORDER: { Scalarm threshold = par.getFloat("EdgeDistRatio"); - int total = SnapVertexBorder(m.cm, threshold,cb); + int total = SnapVertexBorder(m.cm, threshold, cb); log("Successfully Split %d faces to snap", total); m.clearDataMask(MeshModel::MM_FACEFACETOPO); m.clearDataMask(MeshModel::MM_VERTFACETOPO); } break; - default : - wrongActionCalled(filter); // unknown filter; + default: wrongActionCalled(filter); // unknown filter; } return std::map(); } - -int SnapVertexBorder(CMeshO &m, Scalarm threshold, vcg::CallBackPos * cb) +int SnapVertexBorder(CMeshO& m, Scalarm threshold, vcg::CallBackPos* cb) { tri::Allocator::CompactEveryVector(m); @@ -471,73 +591,67 @@ int SnapVertexBorder(CMeshO &m, Scalarm threshold, vcg::CallBackPos * cb) tri::UpdateFlags::FaceBorderFromFF(m); tri::UpdateFlags::VertexBorderFromFaceBorder(m); tri::UpdateNormal::PerVertexNormalizedPerFaceNormalized(m); - typedef GridStaticPtr MetroMeshFaceGrid; - MetroMeshFaceGrid unifGridFace; - typedef tri::FaceTmark MarkerFace; - MarkerFace markerFunctor(&m); - vcg::face::PointDistanceBaseFunctor PDistFunct; + typedef GridStaticPtr MetroMeshFaceGrid; + MetroMeshFaceGrid unifGridFace; + typedef tri::FaceTmark MarkerFace; + MarkerFace markerFunctor(&m); + vcg::face::PointDistanceBaseFunctor PDistFunct; tri::UpdateFlags::FaceClearV(m); - unifGridFace.Set(m.face.begin(),m.face.end()); + unifGridFace.Set(m.face.begin(), m.face.end()); - int faceFound; - int K = 20; - Point3m startPt; - float maxDist = m.bbox.Diag()/20; - vector splitVertVec; + int faceFound; + int K = 20; + Point3m startPt; + float maxDist = m.bbox.Diag() / 20; + vector splitVertVec; vector splitFaceVec; - vector splitEdgeVec; - for(CMeshO::VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi) - if((*vi).IsB()) - { - cb((int(tri::Index(m,*vi)) * 100) / m.vn,"Snapping vertices"); + vector splitEdgeVec; + for (CMeshO::VertexIterator vi = m.vert.begin(); vi != m.vert.end(); ++vi) + if ((*vi).IsB()) { + cb((int(tri::Index(m, *vi)) * 100) / m.vn, "Snapping vertices"); vector faceVec; - vector distVec; - vector pointVec; - Point3m u; - startPt = (*vi).P(); - faceFound = unifGridFace.GetKClosest(PDistFunct,markerFunctor, K, startPt,maxDist, faceVec, distVec, pointVec); + vector distVec; + vector pointVec; + Point3m u; + startPt = (*vi).P(); + faceFound = unifGridFace.GetKClosest( + PDistFunct, markerFunctor, K, startPt, maxDist, faceVec, distVec, pointVec); CMeshO::FacePointer bestFace = 0; - float localThr, bestDist = std::numeric_limits::max(); - Point3m bestPoint; - int bestEdge; + float localThr, bestDist = std::numeric_limits::max(); + Point3m bestPoint; + int bestEdge; // qDebug("Found %i face for vertex %i",faceFound,vi-m.vert.begin()); - for(int i=0;icN(),pointVec[i],u); - // qDebug(" face %i face for vertex %5.3f %5.3f %5.3f dist %5.3f (%c %c %c)",fp-&*m.face.begin(),u[0],u[1],u[2],distVec[i],IsBorder(*fp,0)?'b':' ',IsBorder(*fp,1)?'b':' ',IsBorder(*fp,2)?'b':' '); - for(int j=0;j<3;++j) - { - if(IsBorder(*fp,j) && !fp->IsV()) - { - if( u[(j+0)%3] > epsilonBig && - u[(j+1)%3] > epsilonBig && - u[(j+2)%3] < epsilonSmall ) - { - if(distVec[i] < bestDist) - { - bestDist=distVec[i]; - //bestPoint=pointVec[i]; - bestPoint=(*vi).cP(); - bestFace=fp; - bestEdge=j; + for (int i = 0; i < faceFound; ++i) { + const float epsilonSmall = float(1e-5); + const float epsilonBig = float(1e-2); + CMeshO::FacePointer fp = faceVec[i]; + InterpolationParameters(*fp, fp->cN(), pointVec[i], u); + // qDebug(" face %i face for vertex %5.3f %5.3f %5.3f dist %5.3f (%c %c + // %c)",fp-&*m.face.begin(),u[0],u[1],u[2],distVec[i],IsBorder(*fp,0)?'b':' + // ',IsBorder(*fp,1)?'b':' ',IsBorder(*fp,2)?'b':' '); + for (int j = 0; j < 3; ++j) { + if (IsBorder(*fp, j) && !fp->IsV()) { + if (u[(j + 0) % 3] > epsilonBig && u[(j + 1) % 3] > epsilonBig && + u[(j + 2) % 3] < epsilonSmall) { + if (distVec[i] < bestDist) { + bestDist = distVec[i]; + // bestPoint=pointVec[i]; + bestPoint = (*vi).cP(); + bestFace = fp; + bestEdge = j; } } } } } // end for each faceFound - if(bestFace) - { - localThr = threshold*Distance(bestFace->P0(bestEdge),bestFace->P1(bestEdge)); - if(bestDist < localThr && !bestFace->IsV()) - { + if (bestFace) { + localThr = threshold * Distance(bestFace->P0(bestEdge), bestFace->P1(bestEdge)); + if (bestDist < localThr && !bestFace->IsV()) { bestFace->SetV(); - (*vi).C()= Color4b::Blue; - //bestFace->C()=Color4b::LightBlue; + (*vi).C() = Color4b::Blue; + // bestFace->C()=Color4b::LightBlue; (*vi).SetS(); splitVertVec.push_back(bestPoint); splitEdgeVec.push_back(bestEdge); @@ -546,8 +660,8 @@ int SnapVertexBorder(CMeshO &m, Scalarm threshold, vcg::CallBackPos * cb) } } // end for all border vertices tri::Allocator::PointerUpdater pu; - CMeshO::VertexIterator firstVert = tri::Allocator::AddVertices(m,splitVertVec.size()); - CMeshO::FaceIterator firstface = tri::Allocator::AddFaces(m,splitVertVec.size(),pu); + CMeshO::VertexIterator firstVert = tri::Allocator::AddVertices(m, splitVertVec.size()); + CMeshO::FaceIterator firstface = tri::Allocator::AddFaces(m, splitVertVec.size(), pu); // // ^ ^ // / \ / | \ . @@ -558,11 +672,10 @@ int SnapVertexBorder(CMeshO &m, Scalarm threshold, vcg::CallBackPos * cb) // V0 ------------------V2 V0 -------fv---------V2 // i - for(size_t i=0;iP() = splitVertVec[i]; - int eInd = splitEdgeVec[i]; - CMeshO::FacePointer fp = splitFaceVec[i]; + for (size_t i = 0; i < splitVertVec.size(); ++i) { + firstVert->P() = splitVertVec[i]; + int eInd = splitEdgeVec[i]; + CMeshO::FacePointer fp = splitFaceVec[i]; pu.Update(fp); firstface->V(0) = &*firstVert; firstface->V(1) = fp->V2(eInd); @@ -578,7 +691,6 @@ int SnapVertexBorder(CMeshO &m, Scalarm threshold, vcg::CallBackPos * cb) return int(splitVertVec.size()); } - // // ^----------------- // / | \ / @@ -590,51 +702,43 @@ int SnapVertexBorder(CMeshO &m, Scalarm threshold, vcg::CallBackPos * cb) // i // -int DeleteCollinearBorder(CMeshO &m, float threshold) +int DeleteCollinearBorder(CMeshO& m, float threshold) { - int total=0; + int total = 0; CMeshO::FaceIterator fi; - for(fi=m.face.begin();fi!=m.face.end();++fi) - { - if(!(*fi).IsD()) - { - for(int i=0;i<3;++i) - { - if(face::IsBorder(*fi,i) && !face::IsBorder(*fi,(i+1)%3)) - { - CMeshO::VertexPointer V0= (*fi).V0(i); - CMeshO::VertexPointer V1= (*fi).V1(i); - CMeshO::VertexPointer V2=0; - CMeshO::FacePointer fadj = (*fi).FFp((i+1)%3); - int adjBordInd = (*fi).FFi((i+1)%3); - if(fadj->V1(adjBordInd) == V1) + for (fi = m.face.begin(); fi != m.face.end(); ++fi) { + if (!(*fi).IsD()) { + for (int i = 0; i < 3; ++i) { + if (face::IsBorder(*fi, i) && !face::IsBorder(*fi, (i + 1) % 3)) { + CMeshO::VertexPointer V0 = (*fi).V0(i); + CMeshO::VertexPointer V1 = (*fi).V1(i); + CMeshO::VertexPointer V2 = 0; + CMeshO::FacePointer fadj = (*fi).FFp((i + 1) % 3); + int adjBordInd = (*fi).FFi((i + 1) % 3); + if (fadj->V1(adjBordInd) == V1) V2 = fadj->V2(adjBordInd); else continue; // non coerent face ordering. - if(face::IsBorder(*fadj,(adjBordInd+1)%3)) - { + if (face::IsBorder(*fadj, (adjBordInd + 1) % 3)) { // the colinearity test; - Point3m pp; + Point3m pp; CMeshO::ScalarType dist; - SegmentPointDistance(Segment3m(V0->cP(),V2->cP()),V1->cP(),pp,dist); - if(dist* threshold < Distance(V0->cP(),V2->cP()) ) - { - (*fi).V1(i)=V2; - if(face::IsBorder(*fadj,(adjBordInd+2)%3)) - { - (*fi).FFp((i+1)%3)=&*fi; - (*fi).FFi((i+1)%3)=(i+1)%3; + SegmentPointDistance(Segment3m(V0->cP(), V2->cP()), V1->cP(), pp, dist); + if (dist * threshold < Distance(V0->cP(), V2->cP())) { + (*fi).V1(i) = V2; + if (face::IsBorder(*fadj, (adjBordInd + 2) % 3)) { + (*fi).FFp((i + 1) % 3) = &*fi; + (*fi).FFi((i + 1) % 3) = (i + 1) % 3; } - else - { - CMeshO::FacePointer fj = fadj->FFp((adjBordInd+2)%3); - int ij = fadj->FFi((adjBordInd+2)%3); - (*fi).FFp((i+1)%3)= fj; - (*fi).FFi((i+1)%3)= ij; - fj->FFp(ij)=&*fi; - fj->FFi(ij)=(i+1)%3; + else { + CMeshO::FacePointer fj = fadj->FFp((adjBordInd + 2) % 3); + int ij = fadj->FFi((adjBordInd + 2) % 3); + (*fi).FFp((i + 1) % 3) = fj; + (*fi).FFi((i + 1) % 3) = ij; + fj->FFp(ij) = &*fi; + fj->FFi(ij) = (i + 1) % 3; } - tri::Allocator::DeleteFace(m,*fadj); + tri::Allocator::DeleteFace(m, *fadj); total++; } } diff --git a/src/meshlabplugins/filter_clean/cleanfilter.h b/src/meshlabplugins/filter_clean/cleanfilter.h index e6374e0a9..2e05d9303 100644 --- a/src/meshlabplugins/filter_clean/cleanfilter.h +++ b/src/meshlabplugins/filter_clean/cleanfilter.h @@ -1,25 +1,25 @@ -/**************************************************************************** -* MeshLab o o * -* A versatile mesh processing toolbox o o * -* _ O _ * -* Copyright(C) 2005 \/)\/ * -* Visual Computing Lab /\/| * -* ISTI - Italian National Research Council | * -* \ * -* All rights reserved. * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU General Public License as published by * -* the Free Software Foundation; either version 2 of the License, or * -* (at your option) any later version. * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * -* for more details. * -* * -****************************************************************************/ +/***************************************************************************** + * MeshLab o o * + * A versatile mesh processing toolbox o o * + * _ O _ * + * Copyright(C) 2005-2021 \/)\/ * + * Visual Computing Lab /\/| * + * ISTI - Italian National Research Council | * + * \ * + * All rights reserved. * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * + * for more details. * + * * + ****************************************************************************/ #ifndef __CLEAN_FILTER_H__ #define __CLEAN_FILTER_H__ @@ -33,30 +33,25 @@ class CleanFilter : public QObject, public FilterPlugin MESHLAB_PLUGIN_IID_EXPORTER(FILTER_PLUGIN_IID) Q_INTERFACES(FilterPlugin) - public: - /* naming convention : - - FP -> Filter Plugin - - name of the plugin separated by _ - */ - enum { - FP_BALL_PIVOTING, - FP_REMOVE_ISOLATED_COMPLEXITY, - FP_REMOVE_ISOLATED_DIAMETER, - FP_REMOVE_WRT_Q, - FP_REMOVE_TVERTEX_FLIP, - FP_SNAP_MISMATCHED_BORDER, - FP_REMOVE_TVERTEX_COLLAPSE, - FP_REMOVE_FOLD_FACE, - FP_REMOVE_DUPLICATE_FACE, - FP_REMOVE_NON_MANIF_EDGE, - FP_REMOVE_NON_MANIF_EDGE_SPLIT, - FP_REMOVE_NON_MANIF_VERT, - FP_REMOVE_UNREFERENCED_VERTEX, - FP_REMOVE_DUPLICATED_VERTEX, - FP_REMOVE_FACE_ZERO_AREA, - FP_MERGE_CLOSE_VERTEX, - FP_MERGE_WEDGE_TEX - } ; +public: + enum { + FP_BALL_PIVOTING, + FP_REMOVE_ISOLATED_COMPLEXITY, + FP_REMOVE_ISOLATED_DIAMETER, + FP_REMOVE_WRT_Q, + FP_REMOVE_TVERTEX, + FP_SNAP_MISMATCHED_BORDER, + FP_REMOVE_FOLD_FACE, + FP_REMOVE_DUPLICATE_FACE, + FP_REMOVE_NON_MANIF_EDGE, + FP_REMOVE_NON_MANIF_EDGE_SPLIT, + FP_REMOVE_NON_MANIF_VERT, + FP_REMOVE_UNREFERENCED_VERTEX, + FP_REMOVE_DUPLICATED_VERTEX, + FP_REMOVE_FACE_ZERO_AREA, + FP_MERGE_CLOSE_VERTEX, + FP_MERGE_WEDGE_TEX + }; CleanFilter(); ~CleanFilter(); @@ -65,18 +60,18 @@ class CleanFilter : public QObject, public FilterPlugin QString filterName(ActionIDType filter) const; QString filterInfo(ActionIDType filter) const; - FilterClass getClass(const QAction*) const; - int getRequirements(const QAction*); - int postCondition(const QAction* ) const; - int getPreConditions(const QAction *) const { return MeshModel::MM_NONE; } - RichParameterList initParameterList(const QAction*, const MeshDocument &/*m*/); - std::map applyFilter(const QAction* action, const RichParameterList & /*parent*/, MeshDocument &md, unsigned int& postConditionMask, vcg::CallBackPos * cb); - FilterArity filterArity(const QAction *) const {return SINGLE_MESH;} + FilterClass getClass(const QAction*) const; + int getRequirements(const QAction*); + int postCondition(const QAction*) const; + int getPreConditions(const QAction*) const { return MeshModel::MM_NONE; } + RichParameterList initParameterList(const QAction*, const MeshDocument& /*m*/); + std::map applyFilter( + const QAction* action, + const RichParameterList& /*parent*/, + MeshDocument& md, + unsigned int& postConditionMask, + vcg::CallBackPos* cb); + FilterArity filterArity(const QAction*) const { return SINGLE_MESH; } }; - - - - - #endif