Skip to content

Commit

Permalink
Merge pull request #54 from SoftSmile-Inc/VIS-7230_fix_endless_loop_i…
Browse files Browse the repository at this point in the history
…n_smoothing

VIS-7230 - limit endless loop in LaplacianMeshSmoother; correctly transfer MaxDegreeOfParallelism argument through code tree
  • Loading branch information
dmitry-garshin authored Nov 18, 2024
2 parents e072fd6 + e4bc3f4 commit 6b288e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions mesh_ops/LaplacianMeshSmoother.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down Expand Up @@ -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...
Expand Down Expand Up @@ -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) ) {
Expand All @@ -357,6 +357,8 @@ public static void RegionSmooth(DMesh3 mesh, IEnumerable<int> triangles,
int nConstrainLoops,
int nIncludeExteriorRings,
bool bPreserveExteriorRings,
int maxDegreeOfParallelism,
int maxIterations = int.MaxValue,
double borderWeight = 10.0, double interiorWeight = 0.0)
{
HashSet<int> fixedVerts = new HashSet<int>();
Expand Down Expand Up @@ -435,10 +437,8 @@ public static void RegionSmooth(DMesh3 mesh, IEnumerable<int> triangles,
}
}

smoother.SolveAndUpdateMesh();
smoother.SolveAndUpdateMesh(maxIterations, maxDegreeOfParallelism);
region.BackPropropagateVertices(true);
}


}
}
4 changes: 2 additions & 2 deletions mesh_ops/SmoothedHoleFill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 6b288e1

Please sign in to comment.