Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VIS-7230 - limit endless loop in LaplacianMeshSmoother; correctly transfer MaxDegreeOfParallelism argument through code tree #54

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading