Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Fix reversed planar BSpline flattening and validate with .NET 8
Yuechen Li668f3ef3c636
diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242BSplineSurfaceWithKnotsTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242BSplineSurfaceWithKnotsTests.csindex 9902124b..e91c730d 100644--- a/Aetheris.Kernel.Core.Tests/Step242/Step242BSplineSurfaceWithKnotsTests.cs+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242BSplineSurfaceWithKnotsTests.cs@@ -42,10 +42,10 @@ public sealed class Step242BSplineSurfaceWithKnotsTests}[Theory]- [InlineData("testdata/step242/nist/CTC/nist_ctc_02_asme1_ap242-e2.stp", "tessellator", "Viewer.Tessellation.PlanarCurveFlatteningUnsupported", "Face 3 planar curve flattening does not support curve kind 'BSpline3'.")]- [InlineData("testdata/step242/nist/FTC/nist_ftc_07_asme1_ap242-e2.stp", "", "", "")]- [InlineData("testdata/step242/nist/FTC/nist_ftc_10_asme1_ap242-e2.stp", "", "", "")]- public void Step242_NistTargets_FirstBlockerIsExplicitAfterBSplineSurfaceProgression(string relativePath, string expectedLayer, string expectedSource, string expectedMessagePrefix)+ [InlineData("testdata/step242/nist/CTC/nist_ctc_02_asme1_ap242-e2.stp")]+ [InlineData("testdata/step242/nist/FTC/nist_ftc_07_asme1_ap242-e2.stp")]+ [InlineData("testdata/step242/nist/FTC/nist_ftc_10_asme1_ap242-e2.stp")]+ public void Step242_NistTargets_FirstBlockerIsExplicitAfterBSplineSurfaceProgression(string relativePath){var entry = new Step242CorpusManifestEntry(Id: Path.GetFileNameWithoutExtension(relativePath),@@ -58,21 +58,12 @@ public sealed class Step242BSplineSurfaceWithKnotsTestsExpectGeometryKinds: null);var run = Step242CorpusManifestRunner.RunOne(entry);- if (!string.IsNullOrEmpty(expectedLayer))- {- Assert.Equal(expectedLayer, run.FirstFailureLayer);- }-- if (!string.IsNullOrEmpty(expectedSource))- {- Assert.Equal(expectedSource, run.FirstDiagnostic.Source);- }-- if (!string.IsNullOrEmpty(expectedMessagePrefix))+ Assert.False(string.IsNullOrWhiteSpace(run.FirstDiagnostic.MessagePrefix));+ if (string.Equals(relativePath, "testdata/step242/nist/CTC/nist_ctc_02_asme1_ap242-e2.stp", StringComparison.Ordinal)){- Assert.StartsWith(expectedMessagePrefix, run.FirstDiagnostic.MessagePrefix, StringComparison.Ordinal);+ Assert.Equal("tessellator", run.FirstFailureLayer);+ Assert.Equal(string.Empty, run.FirstDiagnostic.Source);+ Assert.StartsWith("Face 47 sphere tessellation supports only untrimmed sphere faces with zero loops.", run.FirstDiagnostic.MessagePrefix, StringComparison.Ordinal);}-- Assert.False(string.IsNullOrWhiteSpace(run.FirstDiagnostic.MessagePrefix));}}diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242ConicalSurfaceRegressionTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242ConicalSurfaceRegressionTests.csindex c5730680..d0cf64cc 100644--- a/Aetheris.Kernel.Core.Tests/Step242/Step242ConicalSurfaceRegressionTests.cs+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242ConicalSurfaceRegressionTests.cs@@ -32,7 +32,7 @@ public sealed class Step242ConicalSurfaceRegressionTests[Theory][InlineData("testdata/step242/nist/CTC/nist_ctc_01_asme1_ap242-e1.stp", "exporter", "Face:1", "Unsupported surface kind 'Cylinder'. M22 supports planar faces only.")]- [InlineData("testdata/step242/nist/CTC/nist_ctc_02_asme1_ap242-e2.stp", "tessellator", "Viewer.Tessellation.PlanarCurveFlatteningUnsupported", "Face 3 planar curve flattening does not support curve kind 'BSpline3'.")]+ [InlineData("testdata/step242/nist/CTC/nist_ctc_02_asme1_ap242-e2.stp", "tessellator", "", "Face 47 sphere tessellation supports only untrimmed sphere faces with zero loops.")][InlineData("testdata/step242/nist/CTC/nist_ctc_04_asme1_ap242-e1.stp", "tessellator", "", "Face 1 curved tessellation supports repeated cone/revolved families with mixed line/circle loops; this topology family is still unsupported. Observed")][InlineData("testdata/step242/nist/FTC/nist_ftc_06_asme1_ap242-e2.stp", "tessellator", "", "Face 2 curved tessellation does not support this torus/revolved boundary topology yet. Observed")][InlineData("testdata/step242/nist/FTC/nist_ftc_09_asme1_ap242-e1.stp", "tessellator", "", "Face 73 curved tessellation does not support this torus/revolved boundary topology yet. Observed")]@@ -71,6 +71,12 @@ public sealed class Step242ConicalSurfaceRegressionTestsAssert.StartsWith(expectedMessagePrefix, first.FirstDiagnostic.MessagePrefix, StringComparison.Ordinal);}+ if (string.Equals(relativePath, "testdata/step242/nist/CTC/nist_ctc_02_asme1_ap242-e2.stp", StringComparison.Ordinal))+ {+ Assert.NotEqual("Viewer.Tessellation.PlanarCurveFlatteningUnsupported", first.FirstDiagnostic.Source);+ Assert.DoesNotContain("planar curve flattening does not support curve kind 'BSpline3'", 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);@@ -81,8 +87,8 @@ public sealed class Step242ConicalSurfaceRegressionTests[InlineData("testdata/step242/nist/CTC/nist_ctc_02_asme1_ap242-e2.stp","tessellator",- "Viewer.Tessellation.PlanarCurveFlatteningUnsupported",- "Face 3 planar curve flattening does not support curve kind 'BSpline3'.")]+ "",+ "Face 47 sphere tessellation supports only untrimmed sphere faces with zero loops.")][InlineData("testdata/step242/nist/STC/nist_stc_10_asme1_ap242-e2.stp","importer-topology",@@ -118,6 +124,12 @@ public sealed class Step242ConicalSurfaceRegressionTestsAssert.StartsWith(expectedMessagePrefix, first.FirstDiagnostic.MessagePrefix, StringComparison.Ordinal);}+ if (string.Equals(relativePath, "testdata/step242/nist/CTC/nist_ctc_02_asme1_ap242-e2.stp", StringComparison.Ordinal))+ {+ Assert.NotEqual("Viewer.Tessellation.PlanarCurveFlatteningUnsupported", first.FirstDiagnostic.Source);+ Assert.DoesNotContain("planar curve flattening does not support curve kind 'BSpline3'", 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);diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242EllipseEdgeRegressionTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242EllipseEdgeRegressionTests.csindex d53cad81..d8f04c0b 100644--- a/Aetheris.Kernel.Core.Tests/Step242/Step242EllipseEdgeRegressionTests.cs+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242EllipseEdgeRegressionTests.cs@@ -5,7 +5,7 @@ namespace Aetheris.Kernel.Core.Tests.Step242;public sealed class Step242EllipseEdgeRegressionTests{[Theory]- [InlineData("testdata/step242/nist/CTC/nist_ctc_02_asme1_ap242-e2.stp", "tessellator", "Viewer.Tessellation.PlanarCurveFlatteningUnsupported", "Face 3 planar curve flattening does not support curve kind 'BSpline3'.")]+ [InlineData("testdata/step242/nist/CTC/nist_ctc_02_asme1_ap242-e2.stp", "tessellator", "", "Face 47 sphere tessellation supports only untrimmed sphere faces with zero loops.")][InlineData("testdata/step242/nist/STC/nist_stc_06_asme1_ap242-e3.stp", "importer-topology", "Importer.LoopRole.CylinderNonNormalizableDegenerateProjection", "Cylinder loop normalization failed")]public void Step242_NistEllipseTargets_AdvancePastUnsupportedEllipse_AndRemainDeterministic(string relativePath, string expectedLayer, string expectedSource, string expectedMessagePrefix){@@ -24,8 +24,21 @@ public sealed class Step242EllipseEdgeRegressionTestsAssert.DoesNotContain("EDGE_CURVE geometry 'ELLIPSE' is unsupported.", first.FirstDiagnostic.MessagePrefix, StringComparison.Ordinal);Assert.Equal(expectedLayer, first.FirstFailureLayer);- Assert.Equal(expectedSource, first.FirstDiagnostic.Source);- Assert.StartsWith(expectedMessagePrefix, first.FirstDiagnostic.MessagePrefix, StringComparison.Ordinal);+ if (!string.IsNullOrEmpty(expectedSource))+ {+ Assert.Equal(expectedSource, first.FirstDiagnostic.Source);+ }++ if (!string.IsNullOrEmpty(expectedMessagePrefix))+ {+ Assert.StartsWith(expectedMessagePrefix, first.FirstDiagnostic.MessagePrefix, StringComparison.Ordinal);+ }++ if (string.Equals(relativePath, "testdata/step242/nist/CTC/nist_ctc_02_asme1_ap242-e2.stp", StringComparison.Ordinal))+ {+ Assert.NotEqual("Viewer.Tessellation.PlanarCurveFlatteningUnsupported", first.FirstDiagnostic.Source);+ Assert.DoesNotContain("planar curve flattening does not support curve kind 'BSpline3'", first.FirstDiagnostic.MessagePrefix, StringComparison.Ordinal);+ }Assert.Equal(first.FirstFailureLayer, second.FirstFailureLayer);Assert.Equal(first.FirstDiagnostic.Source, second.FirstDiagnostic.Source);diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242TessellationRobustnessTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242TessellationRobustnessTests.csindex 119d1c88..ac38efdb 100644--- a/Aetheris.Kernel.Core.Tests/Step242/Step242TessellationRobustnessTests.cs+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242TessellationRobustnessTests.cs@@ -70,6 +70,61 @@ public sealed class Step242TessellationRobustnessTestsAssert.NotEmpty(facePatch.TriangleIndices);}+ [Fact]+ public void Step242_Tessellate_PlanarFace_LinePlusBSplineLoop_SucceedsDeterministically()+ {+ const string text = "ISO-10303-21;\nHEADER;\nENDSEC;\nDATA;\n"+ + "#1=MANIFOLD_SOLID_BREP('solid',#2);\n"+ + "#2=CLOSED_SHELL($,(#3));\n"+ + "#3=ADVANCED_FACE((#4),#30,.T.);\n"+ + "#4=FACE_OUTER_BOUND($,#5,.T.);\n"+ + "#5=EDGE_LOOP($,(#6,#7,#8));\n"+ + "#6=ORIENTED_EDGE($,$,$,#9,.T.);\n"+ + "#7=ORIENTED_EDGE($,$,$,#10,.T.);\n"+ + "#8=ORIENTED_EDGE($,$,$,#11,.T.);\n"+ + "#9=EDGE_CURVE($,#12,#13,#20,.T.);\n"+ + "#10=EDGE_CURVE($,#13,#14,#21,.T.);\n"+ + "#11=EDGE_CURVE($,#14,#12,#22,.T.);\n"+ + "#12=VERTEX_POINT($,#40);\n"+ + "#13=VERTEX_POINT($,#41);\n"+ + "#14=VERTEX_POINT($,#42);\n"+ + "#20=B_SPLINE_CURVE_WITH_KNOTS($,2,(#40,#43,#41),.UNSPECIFIED.,.F.,.F.,(3,3),(0.,1.),.UNSPECIFIED.);\n"+ + "#21=LINE($,#41,#50);\n"+ + "#22=LINE($,#42,#51);\n"+ + "#30=PLANE($,#60);\n"+ + "#40=CARTESIAN_POINT($,(0.,0.,0.));\n"+ + "#41=CARTESIAN_POINT($,(2.,0.,0.));\n"+ + "#42=CARTESIAN_POINT($,(0.,2.,0.));\n"+ + "#43=CARTESIAN_POINT($,(1.,0.6,0.));\n"+ + "#50=VECTOR($,#52,1.);\n"+ + "#51=VECTOR($,#53,1.);\n"+ + "#52=DIRECTION($,(-0.7071067811865475,0.7071067811865475,0.));\n"+ + "#53=DIRECTION($,(0.,-1.,0.));\n"+ + "#60=AXIS2_PLACEMENT_3D($,#40,#61,#62);\n"+ + "#61=DIRECTION($,(0.,0.,1.));\n"+ + "#62=DIRECTION($,(1.,0.,0.));\n"+ + "ENDSEC;\nEND-ISO-10303-21;";++ var firstImport = Step242Importer.ImportBody(text);+ var secondImport = Step242Importer.ImportBody(text);++ Assert.True(firstImport.IsSuccess);+ Assert.True(secondImport.IsSuccess);++ var first = BrepDisplayTessellator.Tessellate(firstImport.Value);+ var second = BrepDisplayTessellator.Tessellate(secondImport.Value);++ Assert.True(first.IsSuccess);+ Assert.True(second.IsSuccess);++ var firstPatch = Assert.Single(first.Value.FacePatches);+ var secondPatch = Assert.Single(second.Value.FacePatches);++ Assert.NotEmpty(firstPatch.TriangleIndices);+ Assert.Equal(firstPatch.Positions, secondPatch.Positions);+ Assert.Equal(firstPatch.TriangleIndices, secondPatch.TriangleIndices);+ }+[Fact]public void Step242_Tessellate_PlanarFace_UnsupportedCurve_FailsDeterministically(){diff --git a/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.cs b/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.csindex 01d21df2..f66575cf 100644--- a/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.cs+++ b/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.cs@@ -931,6 +931,19 @@ public static class BrepDisplayTessellatorAppendUniquePoint(flattened, point);}+ break;+ case CurveGeometryKind.BSpline3:+ var splinePointsResult = SamplePlanarBSpline(body, coedge, curve.BSpline3!.Value, segmentStart, segmentEnd);+ if (!splinePointsResult.IsSuccess)+ {+ return KernelResult<IReadOnlyList<Point3D>>.Failure(splinePointsResult.Diagnostics);+ }++ foreach (var point in splinePointsResult.Value)+ {+ AppendUniquePoint(flattened, point);+ }+break;default:var curveKind = curve.UnsupportedKind ?? curve.Kind.ToString();@@ -973,6 +986,49 @@ public static class BrepDisplayTessellatorreturn KernelResult<IReadOnlyList<Point3D>>.Success(points);}+ private static KernelResult<IReadOnlyList<Point3D>> SamplePlanarBSpline(+ BrepBody body,+ Coedge coedge,+ BSpline3Curve spline,+ Point3D start,+ Point3D end)+ {+ var interval = new ParameterInterval(spline.DomainStart, spline.DomainEnd);+ var reverseSampleOrder = false;+ if (body.Bindings.TryGetEdgeBinding(coedge.EdgeId, out var binding) && binding.TrimInterval is ParameterInterval trim)+ {+ interval = trim;+ reverseSampleOrder = coedge.IsReversed;+ }+ else+ {+ reverseSampleOrder = coedge.IsReversed;+ }++ var sampled = CurveSampler.SampleBSpline(spline, interval).ToArray();+ if (reverseSampleOrder)+ {+ Array.Reverse(sampled);+ }++ if (sampled.Length < 2)+ {+ return KernelResult<IReadOnlyList<Point3D>>.Failure([+ CreateInvalidArgument($"Edge {coedge.EdgeId.Value} planar BSpline flattening produced an invalid sample set.", PlanarCurveFlatteningFailedSource)]);+ }++ sampled[0] = start;+ sampled[^1] = end;++ var points = new List<Point3D>(sampled.Length - 1);+ for (var i = 1; i < sampled.Length; i++)+ {+ points.Add(sampled[i]);+ }++ return KernelResult<IReadOnlyList<Point3D>>.Success(points);+ }+private static KernelResult<(double StartAngle, double Delta)> ResolveArcDelta(BrepBody body,Coedge coedge,diff --git a/testdata/step242/manifests/nist.v0.report.json b/testdata/step242/manifests/nist.v0.report.jsonindex b35d0e41..83a5e3af 100644--- a/testdata/step242/manifests/nist.v0.report.json+++ b/testdata/step242/manifests/nist.v0.report.json@@ -31,8 +31,8 @@"firstFailureLayer": "tessellator","firstDiagnostic": {"code": "NotImplemented",- "source": "Viewer.Tessellation.PlanarCurveFlatteningUnsupported",- "messagePrefix": "Face 3 planar curve flattening does not support curve kind \u0027BSpline3\u0027."+ "source": "",+ "messagePrefix": "Face 47 sphere tessellation supports only untrimmed sphere faces with zero loops."},"diagnosticCount": 1,"exceptionEscaped": false,