adding new implicit meshing option

This commit is contained in:
Lars Brubaker 2021-06-21 18:11:28 -07:00
parent a8c0addcd2
commit 3f53189dba
4 changed files with 37 additions and 15 deletions

View file

@ -29,6 +29,7 @@ either expressed or implied, of the FreeBSD Project.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
@ -50,6 +51,14 @@ namespace MatterHackers.PolygonMesh
Intersect
}
public enum IplicitSurfaceMesh
{
[Description("Faster but less accurate")]
Grid,
[Description("Slower but more accurate")]
Exact
};
public enum ProcessingModes
{
Exact,
@ -71,6 +80,7 @@ namespace MatterHackers.PolygonMesh
public static Mesh DoArray(IEnumerable<(Mesh mesh, Matrix4X4 matrix)> items,
CsgModes operation,
bool exactSurface,
ProcessingModes processingMode,
IProgress<ProgressStatus> reporter,
CancellationToken cancellationToken)
@ -134,7 +144,7 @@ namespace MatterHackers.PolygonMesh
break;
}
var marchingCells = resolution;
var implicitCells = resolution * 4;
var implicitCells = exactSurface ? 0 : resolution * 4;
var implicitMeshs = new List<BoundedImplicitFunction3d>();
foreach (var item in items)
@ -404,20 +414,23 @@ namespace MatterHackers.PolygonMesh
var meshA3 = meshCopy.ToDMesh3();
// Interesting experiment, this produces an extreamely accurate surface representation but is quite slow (even though fast) compared to voxel lookups.
#if false
DMeshAABBTree3 meshAABBTree3 = new DMeshAABBTree3(meshA3, true);
meshAABBTree3.FastWindingNumber(Vector3d.Zero); // build approximation
return new MWNImplicit()
// Interesting experiment, this produces an extremely accurate surface representation but is quite slow (even though fast) compared to voxel lookups.
if (numCells == 0)
{
MeshAABBTree3 = meshAABBTree3
};
#endif
double meshCellsize = meshA3.CachedBounds.MaxDim / numCells;
var signedDistance = new MeshSignedDistanceGrid(meshA3, meshCellsize);
signedDistance.Compute();
return new DenseGridTrilinearImplicit(signedDistance.Grid, signedDistance.GridOrigin, signedDistance.CellSize);
DMeshAABBTree3 meshAABBTree3 = new DMeshAABBTree3(meshA3, true);
meshAABBTree3.FastWindingNumber(Vector3d.Zero); // build approximation
return new MWNImplicit()
{
MeshAABBTree3 = meshAABBTree3
};
}
else
{
double meshCellsize = meshA3.CachedBounds.MaxDim / numCells;
var signedDistance = new MeshSignedDistanceGrid(meshA3, meshCellsize);
signedDistance.Compute();
return new DenseGridTrilinearImplicit(signedDistance.Grid, signedDistance.GridOrigin, signedDistance.CellSize);
}
}
}
}

View file

@ -28,6 +28,7 @@ either expressed or implied, of the FreeBSD Project.
*/
using System;
using System.ComponentModel;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@ -52,6 +53,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
[EnumDisplay(Mode = EnumDisplayAttribute.PresentationMode.Buttons)]
public BooleanProcessing.ProcessingModes Processing { get; set; } = BooleanProcessing.ProcessingModes.Exact;
[EnumDisplay(Mode = EnumDisplayAttribute.PresentationMode.Buttons)]
public BooleanProcessing.IplicitSurfaceMesh MeshAnalysis { get; set; }
public override Task Rebuild()
{
this.DebugDepth("Rebuild");
@ -111,6 +115,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
var items = participants.Select(i => (i.Mesh, i.WorldMatrix(SourceContainer)));
var resultsMesh = BooleanProcessing.DoArray(items,
BooleanProcessing.CsgModes.Union,
MeshAnalysis == BooleanProcessing.IplicitSurfaceMesh.Exact,
Processing,
reporter,
cancellationToken);

View file

@ -52,6 +52,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
[EnumDisplay(Mode = EnumDisplayAttribute.PresentationMode.Buttons)]
public BooleanProcessing.ProcessingModes Processing { get; set; } = BooleanProcessing.ProcessingModes.Exact;
[EnumDisplay(Mode = EnumDisplayAttribute.PresentationMode.Buttons)]
public BooleanProcessing.IplicitSurfaceMesh MeshAnalysis { get; set; }
public override Task Rebuild()
{
this.DebugDepth("Rebuild");
@ -111,6 +114,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
var items = participants.Select(i => (i.Mesh, i.WorldMatrix(SourceContainer)));
var resultsMesh = BooleanProcessing.DoArray(items,
BooleanProcessing.CsgModes.Intersect,
MeshAnalysis == BooleanProcessing.IplicitSurfaceMesh.Exact,
Processing,
reporter,
cancellationToken);

@ -1 +1 @@
Subproject commit 860e5f886fd8a0cc45c595b0417c84d13b5ef310
Subproject commit 503b73e80b06db075a0b3572498c916ff816b77e