Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Support dual closed-circle cylinder trim family
Yuechen Li0a2fb5156f91
diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242CylinderTrimDualSingleCoedgeClosedCircleRegressionTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242CylinderTrimDualSingleCoedgeClosedCircleRegressionTests.csnew file mode 100644index 00000000..3f9fd51c--- /dev/null+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242CylinderTrimDualSingleCoedgeClosedCircleRegressionTests.cs@@ -0,0 +1,155 @@+using Aetheris.Kernel.Core.Brep;+using Aetheris.Kernel.Core.Brep.Tessellation;+using Aetheris.Kernel.Core.Geometry;+using Aetheris.Kernel.Core.Geometry.Surfaces;+using Aetheris.Kernel.Core.Step242;+using Aetheris.Kernel.Core.Topology;++namespace Aetheris.Kernel.Core.Tests.Step242;++public sealed class Step242CylinderTrimDualSingleCoedgeClosedCircleRegressionTests+{+ [Theory]+ [InlineData("testdata/step242/nist/CTC/nist_ctc_05_asme1_ap242-e1.stp")]+ [InlineData("testdata/step242/nist/FTC/nist_ftc_11_asme1_ap242-e2.stp")]+ public void Step242_Targets_ContainDualSingleCoedgeClosedCircleCylinderFamily(string relativePath)+ {+ var fullPath = Path.Combine(Step242CorpusManifestRunner.RepoRoot(), relativePath.Replace('/', Path.DirectorySeparatorChar));+ var import = Step242Importer.ImportBody(File.ReadAllText(fullPath));+ Assert.True(import.IsSuccess);++ var body = import.Value;+ var matches = body.Topology.Faces+ .Select(face => (FaceId: face.Id, Surface: body.GetFaceSurface(face.Id)))+ .Where(pair => pair.Surface.Kind == SurfaceGeometryKind.Cylinder)+ .Where(pair => IsDualSingleCoedgeClosedCircleCylinderFamily(body, pair.FaceId, pair.Surface.Cylinder!.Value, out _))+ .ToArray();++ Assert.NotEmpty(matches);+ }++ [Fact]+ public void Step242_Ctc05_AdvancesThroughDualSingleCoedgeClosedCircleFamily_Deterministically()+ {+ const string relativePath = "testdata/step242/nist/CTC/nist_ctc_05_asme1_ap242-e1.stp";+ var first = Step242CorpusManifestRunner.RunOne(new Step242CorpusManifestEntry("ctc05", relativePath, "nist-regression", null, null, null, null, null));+ var second = Step242CorpusManifestRunner.RunOne(new Step242CorpusManifestEntry("ctc05", relativePath, "nist-regression", null, null, null, null, null));++ Assert.Equal("success", first.Status);+ Assert.Equal(string.Empty, first.FirstFailureLayer);+ Assert.Equal(first.Status, second.Status);+ Assert.Equal(first.FirstFailureLayer, second.FirstFailureLayer);+ Assert.Equal(first.FirstDiagnostic.Source, second.FirstDiagnostic.Source);+ Assert.Equal(first.FirstDiagnostic.MessagePrefix, second.FirstDiagnostic.MessagePrefix);+ }++ [Fact]+ public void Step242_Ftc11_AdvancesPastCylinderTrimDegenerate_ToNextExplicitBlocker_Deterministically()+ {+ const string relativePath = "testdata/step242/nist/FTC/nist_ftc_11_asme1_ap242-e2.stp";+ var first = Step242CorpusManifestRunner.RunOne(new Step242CorpusManifestEntry("ftc11", relativePath, "nist-regression", null, null, null, null, null));+ var second = Step242CorpusManifestRunner.RunOne(new Step242CorpusManifestEntry("ftc11", relativePath, "nist-regression", null, null, null, null, null));++ Assert.Equal("tessellator", first.FirstFailureLayer);+ Assert.NotEqual("Viewer.Tessellation.CylinderTrimDegenerate", first.FirstDiagnostic.Source);+ Assert.Equal("Viewer.Tessellation.PlanarPolygonDegenerate", first.FirstDiagnostic.Source);+ Assert.StartsWith("Face 10 planar loop is degenerate and cannot be triangulated.", first.FirstDiagnostic.MessagePrefix, StringComparison.Ordinal);++ Assert.Equal(first.FirstFailureLayer, second.FirstFailureLayer);+ Assert.Equal(first.FirstDiagnostic.Source, second.FirstDiagnostic.Source);+ Assert.Equal(first.FirstDiagnostic.MessagePrefix, second.FirstDiagnostic.MessagePrefix);+ }++ [Fact]+ public void Step242_Stc06_AlsoMatchesDualSingleCoedgeClosedCircleCylinderFamily_AndNowAdvances()+ {+ const string relativePath = "testdata/step242/nist/STC/nist_stc_06_asme1_ap242-e3.stp";+ var fullPath = Path.Combine(Step242CorpusManifestRunner.RepoRoot(), relativePath.Replace('/', Path.DirectorySeparatorChar));+ var import = Step242Importer.ImportBody(File.ReadAllText(fullPath));+ Assert.True(import.IsSuccess);++ var body = import.Value;+ var hasFamilyMatch = body.Topology.Faces+ .Select(face => (FaceId: face.Id, Surface: body.GetFaceSurface(face.Id)))+ .Where(pair => pair.Surface.Kind == SurfaceGeometryKind.Cylinder)+ .Any(pair => IsDualSingleCoedgeClosedCircleCylinderFamily(body, pair.FaceId, pair.Surface.Cylinder!.Value, out _));+ Assert.True(hasFamilyMatch);++ var first = Step242CorpusManifestRunner.RunOne(new Step242CorpusManifestEntry("stc06", relativePath, "nist-regression", null, null, null, null, null));+ Assert.Equal("success", first.Status);+ Assert.Equal(string.Empty, first.FirstFailureLayer);+ }++ private static bool IsDualSingleCoedgeClosedCircleCylinderFamily(BrepBody body, FaceId faceId, CylinderSurface cylinder, out double centerAxialDelta)+ {+ const double fullWrapTolerance = 1e-3d;+ const double axisAlignmentTolerance = 1e-4d;+ const double centerAxisOffsetTolerance = 1e-4d;+ const double radiusTolerance = 1e-4d;+ const double minSpan = 1e-8d;++ centerAxialDelta = 0d;+ var loopIds = body.GetLoopIds(faceId);+ if (loopIds.Count != 2)+ {+ return false;+ }++ var axis = cylinder.Axis.ToVector();+ var axialCenters = new List<double>(capacity: 2);+ foreach (var loopId in loopIds)+ {+ var coedgeIds = body.GetCoedgeIds(loopId);+ if (coedgeIds.Count != 1)+ {+ return false;+ }++ var coedge = body.Topology.GetCoedge(coedgeIds[0]);+ var curve = body.GetEdgeCurve(coedge.EdgeId);+ if (curve.Kind != CurveGeometryKind.Circle3)+ {+ return false;+ }++ if (!body.TryGetEdgeVertices(coedge.EdgeId, out var startVertexId, out var endVertexId) || startVertexId != endVertexId)+ {+ return false;+ }++ if (!body.Bindings.TryGetEdgeBinding(coedge.EdgeId, out var edgeBinding)+ || edgeBinding.TrimInterval is not ParameterInterval trimInterval+ || !double.IsFinite(trimInterval.Start)+ || !double.IsFinite(trimInterval.End)+ || double.Abs((trimInterval.End - trimInterval.Start) - (2d * double.Pi)) > fullWrapTolerance)+ {+ return false;+ }++ var circle = curve.Circle3!.Value;+ var axisDot = circle.Normal.ToVector().Dot(axis);+ if (double.Abs(double.Abs(axisDot) - 1d) > axisAlignmentTolerance)+ {+ return false;+ }++ var centerOffset = circle.Center - cylinder.Origin;+ var axialCenter = centerOffset.Dot(axis);+ var radialOffset = (centerOffset - (axis * axialCenter)).Length;+ if (radialOffset > (cylinder.Radius * centerAxisOffsetTolerance))+ {+ return false;+ }++ if (double.Abs(circle.Radius - cylinder.Radius) > (cylinder.Radius * radiusTolerance))+ {+ return false;+ }++ axialCenters.Add(axialCenter);+ }++ centerAxialDelta = double.Abs(axialCenters[1] - axialCenters[0]);+ return centerAxialDelta > minSpan;+ }+}diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242RevolvedTopologyFamilyRegressionTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242RevolvedTopologyFamilyRegressionTests.csindex 4a6614f0..505fb237 100644--- a/Aetheris.Kernel.Core.Tests/Step242/Step242RevolvedTopologyFamilyRegressionTests.cs+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242RevolvedTopologyFamilyRegressionTests.cs@@ -86,7 +86,7 @@ public sealed class Step242RevolvedTopologyFamilyRegressionTestsAssert.DoesNotContain("unsupported subfamily 'circle-only seam reused loop'", first.FirstDiagnostic.MessagePrefix, StringComparison.Ordinal);Assert.DoesNotContain("requires exactly one loop", first.FirstDiagnostic.MessagePrefix, StringComparison.Ordinal);- Assert.StartsWith("Cylindrical face tessellation derived a degenerate trim patch.", first.FirstDiagnostic.MessagePrefix, StringComparison.Ordinal);+ Assert.Equal("No diagnostics.", first.FirstDiagnostic.MessagePrefix);}[Theory]diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242SphericalTrimSingleCoedgeDiagnosticsTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242SphericalTrimSingleCoedgeDiagnosticsTests.csindex 96585c1c..3ec3ce8b 100644--- a/Aetheris.Kernel.Core.Tests/Step242/Step242SphericalTrimSingleCoedgeDiagnosticsTests.cs+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242SphericalTrimSingleCoedgeDiagnosticsTests.cs@@ -53,9 +53,9 @@ public sealed class Step242SphericalTrimSingleCoedgeDiagnosticsTestsvar first = Step242CorpusManifestRunner.RunOne(entry);var second = Step242CorpusManifestRunner.RunOne(entry);- Assert.Equal("tessellator", first.FirstFailureLayer);- Assert.Equal("Viewer.Tessellation.CylinderTrimDegenerate", first.FirstDiagnostic.Source);- Assert.StartsWith("Cylindrical face tessellation derived a degenerate trim patch.", first.FirstDiagnostic.MessagePrefix, StringComparison.Ordinal);+ Assert.Equal(string.Empty, first.FirstFailureLayer);+ Assert.Equal("Audit.None", first.FirstDiagnostic.Source);+ Assert.Equal("No diagnostics.", first.FirstDiagnostic.MessagePrefix);Assert.Equal(first.FirstFailureLayer, second.FirstFailureLayer);Assert.Equal(first.FirstDiagnostic.Source, second.FirstDiagnostic.Source);diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242UnsupportedSurfaceForHolesRegressionTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242UnsupportedSurfaceForHolesRegressionTests.csindex 99b92c8a..44d1ef20 100644--- a/Aetheris.Kernel.Core.Tests/Step242/Step242UnsupportedSurfaceForHolesRegressionTests.cs+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242UnsupportedSurfaceForHolesRegressionTests.cs@@ -5,13 +5,6 @@ namespace Aetheris.Kernel.Core.Tests.Step242;public sealed class Step242UnsupportedSurfaceForHolesRegressionTests{[Theory]- [InlineData(- "testdata/step242/nist/CTC/nist_ctc_05_asme1_ap242-e1.stp",- "tessellator",- "Importer.LoopRole.UnsupportedSurfaceForHoles",- "Viewer.Tessellation.CylinderTrimDegenerate",- "Cylindrical face tessellation derived a degenerate trim patch.")]-[InlineData("testdata/step242/nist/FTC/nist_ftc_08_asme1_ap242-e2.stp","tessellator",@@ -22,15 +15,8 @@ public sealed class Step242UnsupportedSurfaceForHolesRegressionTests"testdata/step242/nist/FTC/nist_ftc_11_asme1_ap242-e2.stp","tessellator","Topology.GraphValidator",- "Viewer.Tessellation.CylinderTrimDegenerate",- "Cylindrical face tessellation derived a degenerate trim patch.")]-- [InlineData(- "testdata/step242/nist/STC/nist_stc_06_asme1_ap242-e3.stp",- "tessellator",- "Importer.LoopRole.UnsupportedSurfaceForHoles",- "Viewer.Tessellation.CylinderTrimDegenerate",- "Cylindrical face tessellation derived a degenerate trim patch.")]+ "Viewer.Tessellation.PlanarPolygonDegenerate",+ "Face 10 planar loop is degenerate and cannot be triangulated.")]public void Step242_NistTargets_AdvancePastGenericUnsupportedSurfaceForHoles_Deterministically(string relativePath,diff --git a/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.cs b/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.csindex a0f09864..0577ec61 100644--- a/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.cs+++ b/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.cs@@ -23,6 +23,7 @@ public static class BrepDisplayTessellatorprivate const string CylinderTrimAxialSpanDegenerateMultiCoedgeSource = "Viewer.Tessellation.CylinderTrimAxialSpanDegenerate.MultiCoedge";private const string CylinderTrimAxialSpanDegenerateSingleCoedgeNearFullWrapBridgeSource = "Viewer.Tessellation.CylinderTrimAxialSpanDegenerate.SingleCoedgeNearFullWrapBridge";private const string CylinderTrimAmbiguousUsedShorterSpanSource = "Viewer.Tessellation.CylinderTrimAmbiguousUsedShorterSpan";+ private const string CylinderTrimDualSingleCoedgeClosedCircleSource = "Viewer.Tessellation.CylinderTrim.DualSingleCoedgeClosedCircle";private const string CurvedTopologyUnsupportedSource = "Viewer.Tessellation.CurvedTopologyUnsupported";private const string BSplineSurfaceTrimUnsupportedSource = "Viewer.Tessellation.BSplineSurfaceTrimUnsupported";private const string SphereTrimSingleCoedgeLatitudeCapSource = "Viewer.Tessellation.SphereTrim.SingleCoedgeLatitudeCap";@@ -2135,6 +2136,12 @@ public static class BrepDisplayTessellatorif (!best.HasValue){+ var dualCirclePatch = TryResolveDualSingleCoedgeClosedCircleCylinderTrimPatch(body, faceId, cylinder, loopIds, axis, minSpan);+ if (dualCirclePatch.IsSuccess)+ {+ return dualCirclePatch;+ }+if (bestAxialSpanDegenerate.HasValue && loopIds.Count == 1){var isSingleCoedge = bestAxialSpanDegenerate.Value.CoedgeCount == 1;@@ -2205,6 +2212,94 @@ public static class BrepDisplayTessellatordiagnostics);}+ private static KernelResult<(double UStart, double UEnd, double VStart, double VEnd)> TryResolveDualSingleCoedgeClosedCircleCylinderTrimPatch(+ BrepBody body,+ FaceId faceId,+ CylinderSurface cylinder,+ IReadOnlyList<LoopId> loopIds,+ Vector3D axis,+ double minSpan)+ {+ const double fullWrapTolerance = 1e-3d;+ const double axisAlignmentTolerance = 1e-4d;+ const double centerAxisOffsetTolerance = 1e-4d;+ const double radiusTolerance = 1e-4d;++ if (loopIds.Count != 2)+ {+ return KernelResult<(double, double, double, double)>.Failure(Array.Empty<KernelDiagnostic>());+ }++ var loops = new List<(LoopId LoopId, EdgeId EdgeId, double AxialCenter)>();+ foreach (var loopId in loopIds)+ {+ var coedgeIds = body.GetCoedgeIds(loopId);+ if (coedgeIds.Count != 1)+ {+ return KernelResult<(double, double, double, double)>.Failure(Array.Empty<KernelDiagnostic>());+ }++ var coedge = body.Topology.GetCoedge(coedgeIds[0]);+ var curve = body.GetEdgeCurve(coedge.EdgeId);+ if (curve.Kind != CurveGeometryKind.Circle3)+ {+ return KernelResult<(double, double, double, double)>.Failure(Array.Empty<KernelDiagnostic>());+ }++ if (!body.TryGetEdgeVertices(coedge.EdgeId, out var startVertexId, out var endVertexId) || startVertexId != endVertexId)+ {+ return KernelResult<(double, double, double, double)>.Failure(Array.Empty<KernelDiagnostic>());+ }++ if (!body.Bindings.TryGetEdgeBinding(coedge.EdgeId, out var edgeBinding)+ || edgeBinding.TrimInterval is not ParameterInterval trimInterval+ || !double.IsFinite(trimInterval.Start)+ || !double.IsFinite(trimInterval.End)+ || double.Abs((trimInterval.End - trimInterval.Start) - (2d * double.Pi)) > fullWrapTolerance)+ {+ return KernelResult<(double, double, double, double)>.Failure(Array.Empty<KernelDiagnostic>());+ }++ var circle = curve.Circle3!.Value;+ var axisDot = circle.Normal.ToVector().Dot(cylinder.Axis.ToVector());+ if (double.Abs(double.Abs(axisDot) - 1d) > axisAlignmentTolerance)+ {+ return KernelResult<(double, double, double, double)>.Failure(Array.Empty<KernelDiagnostic>());+ }++ var centerOffset = circle.Center - cylinder.Origin;+ var axialCenter = centerOffset.Dot(axis);+ var radialOffset = (centerOffset - (axis * axialCenter)).Length;+ if (radialOffset > (cylinder.Radius * centerAxisOffsetTolerance))+ {+ return KernelResult<(double, double, double, double)>.Failure(Array.Empty<KernelDiagnostic>());+ }++ if (double.Abs(circle.Radius - cylinder.Radius) > (cylinder.Radius * radiusTolerance))+ {+ return KernelResult<(double, double, double, double)>.Failure(Array.Empty<KernelDiagnostic>());+ }++ loops.Add((loopId, coedge.EdgeId, axialCenter));+ }++ var first = loops[0];+ var second = loops[1];+ var vStart = System.Math.Min(first.AxialCenter, second.AxialCenter);+ var vEnd = System.Math.Max(first.AxialCenter, second.AxialCenter);+ var axialSpan = vEnd - vStart;+ if (axialSpan <= minSpan)+ {+ return KernelResult<(double, double, double, double)>.Failure(Array.Empty<KernelDiagnostic>());+ }++ return KernelResult<(double, double, double, double)>.Success(+ (0d, 2d * double.Pi, vStart, vEnd),+ [CreateValidationWarning(+ $"Face {faceId.Value} cylindrical trim classified as dual single-coedge closed-circle loops with zero per-loop axial span and center axial separation {axialSpan:R} (loops {first.LoopId.Value}/{second.LoopId.Value}, edges {first.EdgeId.Value}/{second.EdgeId.Value}).",+ CylinderTrimDualSingleCoedgeClosedCircleSource)]);+ }+private static bool TryResolveBridgeTwinSurfaceKind(BrepBody body, FaceId sourceFaceId, EdgeId edgeId, out SurfaceGeometryKind? twinSurfaceKind){twinSurfaceKind = null;diff --git a/testdata/step242/manifests/nist.v0.report.json b/testdata/step242/manifests/nist.v0.report.jsonindex 6bef5ca5..f6099dfa 100644--- a/testdata/step242/manifests/nist.v0.report.json+++ b/testdata/step242/manifests/nist.v0.report.json@@ -99,14 +99,14 @@"fileId": "testdata_step242_nist_CTC_nist_ctc_05_asme1_ap242-e1","path": "testdata/step242/nist/CTC/nist_ctc_05_asme1_ap242-e1.stp","sizeBytes": 863826,- "status": "importFail",- "firstFailureLayer": "tessellator",+ "status": "success",+ "firstFailureLayer": "","firstDiagnostic": {- "code": "InvalidArgument",- "source": "Viewer.Tessellation.CylinderTrimDegenerate",- "messagePrefix": "Cylindrical face tessellation derived a degenerate trim patch."+ "code": "Unknown",+ "source": "Audit.None",+ "messagePrefix": "No diagnostics."},- "diagnosticCount": 1,+ "diagnosticCount": 0,"exceptionEscaped": false,"topologyCounts": {"vertices": 239,@@ -114,10 +114,10 @@"faces": 156},"tessellationCounts": {- "facePatches": 0,- "edgePolylines": 0+ "facePatches": 156,+ "edgePolylines": 331},- "canonicalSha256": null+ "canonicalSha256": "a874ae135bd12d3cd9eed0b479853ca5db2146d93ff24fa106e6343cf7a25365"},{"fileId": "testdata_step242_nist_FTC_nist_ftc_06_asme1_ap242-e2",@@ -271,8 +271,8 @@"firstFailureLayer": "tessellator","firstDiagnostic": {"code": "InvalidArgument",- "source": "Viewer.Tessellation.CylinderTrimDegenerate",- "messagePrefix": "Cylindrical face tessellation derived a degenerate trim patch."+ "source": "Viewer.Tessellation.PlanarPolygonDegenerate",+ "messagePrefix": "Face 10 planar loop is degenerate and cannot be triangulated."},"diagnosticCount": 1,"exceptionEscaped": false,@@ -291,14 +291,14 @@"fileId": "testdata_step242_nist_STC_nist_stc_06_asme1_ap242-e3","path": "testdata/step242/nist/STC/nist_stc_06_asme1_ap242-e3.stp","sizeBytes": 993459,- "status": "importFail",- "firstFailureLayer": "tessellator",+ "status": "success",+ "firstFailureLayer": "","firstDiagnostic": {- "code": "InvalidArgument",- "source": "Viewer.Tessellation.CylinderTrimDegenerate",- "messagePrefix": "Cylindrical face tessellation derived a degenerate trim patch."+ "code": "Unknown",+ "source": "Audit.None",+ "messagePrefix": "No diagnostics."},- "diagnosticCount": 1,+ "diagnosticCount": 0,"exceptionEscaped": false,"topologyCounts": {"vertices": 225,@@ -306,10 +306,10 @@"faces": 144},"tessellationCounts": {- "facePatches": 0,- "edgePolylines": 0+ "facePatches": 144,+ "edgePolylines": 310},- "canonicalSha256": null+ "canonicalSha256": "4f7b738853058eb8590b02aca67d6ce4e47988b7139282a20db88e21a40071fc"},{"fileId": "testdata_step242_nist_STC_nist_stc_07_asme1_ap242-e3",