From e4bc3f44f87a9bca7cb559226313f828ac52549d Mon Sep 17 00:00:00 2001 From: Dmitry Garshin Date: Tue, 22 Oct 2024 11:30:48 +0300 Subject: [PATCH] VIS-7230 - limit endless loop in LaplacianMeshSmoother; correctly transfer MaxDegreeOfParallelism argument through code tree --- mesh_ops/LaplacianMeshSmoother.cs | 20 ++++++++++---------- mesh_ops/SmoothedHoleFill.cs | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/mesh_ops/LaplacianMeshSmoother.cs b/mesh_ops/LaplacianMeshSmoother.cs index b350dfe2..727fd223 100644 --- a/mesh_ops/LaplacianMeshSmoother.cs +++ b/mesh_ops/LaplacianMeshSmoother.cs @@ -198,7 +198,7 @@ void UpdateForSolve() // Result must be as large as Mesh.MaxVertexID - public bool SolveMultipleCG(Vector3d[] Result, int maxDegreeOfParallelism, int maxIterations = int.MaxValue) + public bool SolveMultipleCG(Vector3d[] Result, int maxIterations, int maxDegreeOfParallelism) { if (WeightsM == null) Initialize(maxDegreeOfParallelism); // force initialize... @@ -261,7 +261,7 @@ public bool SolveMultipleCG(Vector3d[] Result, int maxDegreeOfParallelism, int m // Result must be as large as Mesh.MaxVertexID - public bool SolveMultipleRHS(Vector3d[] Result, int maxDegreeOfParallelism, int maxIterations = int.MaxValue) + public bool SolveMultipleRHS(Vector3d[] Result, int maxIterations, int maxDegreeOfParallelism) { if (WeightsM == null) Initialize(maxDegreeOfParallelism); // force initialize... @@ -317,23 +317,23 @@ public bool SolveMultipleRHS(Vector3d[] Result, int maxDegreeOfParallelism, int } - public bool Solve(Vector3d[] Result, int maxIterations = int.MaxValue) + public bool Solve(Vector3d[] Result, int maxIterations, int maxDegreeOfParallelism) { // for small problems, faster to use separate CGs? if ( Mesh.VertexCount < 10000 ) - return SolveMultipleCG(Result, maxIterations); + return SolveMultipleCG(Result, maxIterations, maxDegreeOfParallelism); else - return SolveMultipleRHS(Result, maxIterations); + return SolveMultipleRHS(Result, maxIterations, maxDegreeOfParallelism); } - public bool SolveAndUpdateMesh(int maxIterations = int.MaxValue) + public bool SolveAndUpdateMesh(int maxIterations, int maxDegreeOfParallelism) { int N = Mesh.MaxVertexID; Vector3d[] Result = new Vector3d[N]; - if ( Solve(Result, maxIterations) == false ) + if ( Solve(Result, maxIterations, maxDegreeOfParallelism) == false ) return false; for (int i = 0; i < N; ++i ) { if ( Mesh.IsVertex(i) ) { @@ -357,6 +357,8 @@ public static void RegionSmooth(DMesh3 mesh, IEnumerable triangles, int nConstrainLoops, int nIncludeExteriorRings, bool bPreserveExteriorRings, + int maxDegreeOfParallelism, + int maxIterations = int.MaxValue, double borderWeight = 10.0, double interiorWeight = 0.0) { HashSet fixedVerts = new HashSet(); @@ -435,10 +437,8 @@ public static void RegionSmooth(DMesh3 mesh, IEnumerable triangles, } } - smoother.SolveAndUpdateMesh(); + smoother.SolveAndUpdateMesh(maxIterations, maxDegreeOfParallelism); region.BackPropropagateVertices(true); } - - } } diff --git a/mesh_ops/SmoothedHoleFill.cs b/mesh_ops/SmoothedHoleFill.cs index b23f3353..209f25fa 100644 --- a/mesh_ops/SmoothedHoleFill.cs +++ b/mesh_ops/SmoothedHoleFill.cs @@ -179,7 +179,7 @@ public bool Apply(int maxDegreeOfParallelism) void smooth_and_remesh_preserve(MeshFaceSelection tris, bool bFinal, int maxDegreeOfParallelism) { if (EnableLaplacianSmooth) { - LaplacianMeshSmoother.RegionSmooth(Mesh, tris, 2, 2, true); + LaplacianMeshSmoother.RegionSmooth(Mesh, tris, 2, 2, true, maxDegreeOfParallelism, maxIterations: 1000); // limit 1000 iterations to prevent endless loop } if (RemeshAfterSmooth) { @@ -206,7 +206,7 @@ void smooth_and_remesh_preserve(MeshFaceSelection tris, bool bFinal, int maxDegr void smooth_and_remesh(MeshFaceSelection tris, int maxDegreeOfParallelism) { if (EnableLaplacianSmooth) { - LaplacianMeshSmoother.RegionSmooth(Mesh, tris, 2, 2, false); + LaplacianMeshSmoother.RegionSmooth(Mesh, tris, 2, 2, false, maxDegreeOfParallelism, maxIterations: 1000); // limit 1000 iterations to prevent endless loop } if (RemeshAfterSmooth) {