From 17893f963014036d9ff5587f342923334cc052e6 Mon Sep 17 00:00:00 2001 From: "Renato Silveira (LT)" Date: Mon, 18 Nov 2024 23:33:55 -0300 Subject: [PATCH 1/3] fix degenerated faces --- Xbim.Geometry.Engine.Interop.Tests/MyTests.cs | 12 ++++++++++ Xbim.Geometry.Engine/XbimOccShape.cpp | 24 +++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 Xbim.Geometry.Engine.Interop.Tests/MyTests.cs diff --git a/Xbim.Geometry.Engine.Interop.Tests/MyTests.cs b/Xbim.Geometry.Engine.Interop.Tests/MyTests.cs new file mode 100644 index 000000000..0ea58c868 --- /dev/null +++ b/Xbim.Geometry.Engine.Interop.Tests/MyTests.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Xbim.Geometry.Engine.Interop.Tests +{ + internal class MyTests + { + } +} diff --git a/Xbim.Geometry.Engine/XbimOccShape.cpp b/Xbim.Geometry.Engine/XbimOccShape.cpp index 5f07db078..cdacfd079 100644 --- a/Xbim.Geometry.Engine/XbimOccShape.cpp +++ b/Xbim.Geometry.Engine/XbimOccShape.cpp @@ -356,6 +356,9 @@ namespace Xbim List^>^ tessellations = gcnew List^>(faceCount); bool isPolyhedron = true; array^ hasSeams = gcnew array(faceCount); + + bool foundDegenerate = false; + //we check if the shape is a faceted poltgon, i.e. all faces are planar and all edges are linear, if so then we do not need to use OCC meshing which is general purpose and a little slower than LibMesh for (int f = 1; f <= faceMap.Extent(); f++) { @@ -524,7 +527,9 @@ namespace Xbim { array^ outerContour = gcnew array(numberEdges); BRepTools_WireExplorer exp(outerWire, face); - for (int j = 0; exp.More(); exp.Next()) + + int j = 0; + for (j = 0; exp.More(); exp.Next()) { gp_Pnt p = BRep_Tool::Pnt(exp.CurrentVertex()); outerContour[j].Position.X = p.X(); @@ -532,7 +537,15 @@ namespace Xbim outerContour[j].Position.Z = p.Z(); j++; } - tess->AddContour(outerContour); //the original winding is correct as we have oriented the wire to the face in BRepTools_WireExplorer + + if (j == numberEdges) + { + tess->AddContour(outerContour); //the original winding is correct as we have oriented the wire to the face in BRepTools_WireExplorer + } + else + { + foundDegenerate = true; + } } } @@ -559,6 +572,13 @@ namespace Xbim } } } + + if (foundDegenerate) + { + foundDegenerate = false; + continue; + } + tess->Tessellate(Xbim::Tessellator::WindingRule::EvenOdd, Xbim::Tessellator::ElementType::Polygons, 3); if (tess->ElementCount > 0) //we have some triangles { From 9d54c8094dc84585277c455ea247d2bb32461925 Mon Sep 17 00:00:00 2001 From: "Renato Silveira (LT)" Date: Tue, 19 Nov 2024 11:17:24 -0300 Subject: [PATCH 2/3] change tests --- Xbim.Geometry.Engine.Interop.Tests/MyTests.cs | 109 +++++++++++++++++- 1 file changed, 105 insertions(+), 4 deletions(-) diff --git a/Xbim.Geometry.Engine.Interop.Tests/MyTests.cs b/Xbim.Geometry.Engine.Interop.Tests/MyTests.cs index 0ea58c868..5026ee0e6 100644 --- a/Xbim.Geometry.Engine.Interop.Tests/MyTests.cs +++ b/Xbim.Geometry.Engine.Interop.Tests/MyTests.cs @@ -1,12 +1,113 @@ using System; -using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Linq; -using System.Text; -using System.Threading.Tasks; +using FluentAssertions; +using Xbim.Ifc; +using Xbim.ModelGeometry.Scene; +using System.Diagnostics; + namespace Xbim.Geometry.Engine.Interop.Tests { - internal class MyTests + [TestClass] + public class MyTests { + [TestMethod] + public void Ifc_MyTest_IssueR23() + { + using (var m = IfcStore.Open(@"C:\LT\Dev\IFC_Issues\B1_AR_R23.ifc")) + { + var context = new Xbim3DModelContext(m); + context.CreateContext(); + + var numShapes = context.ShapeGeometries().ToArray().Length; + Console.WriteLine("numShapes: " + numShapes); + numShapes.Should().NotBe(0); + } + } + + [TestMethod] + public void Ifc_MyTest_IssueBLK35B() + { + using (var m = IfcStore.Open(@"C:\LT\Dev\IFC_Issues\CS_BLK35B_CCKN1C1718_-.ifc")) + { + var context = new Xbim3DModelContext(m); + context.CreateContext(); + + var numShapes = context.ShapeGeometries().ToArray().Length; + Console.WriteLine("numShapes: " + numShapes); + numShapes.Should().NotBe(0); + } + } + + [TestMethod] + public void Ifc4_MyTest_DegeneratedPoint() + { + var stopwatch = new Stopwatch(); + + Console.WriteLine("Testing Small"); + Console.WriteLine("- Trying to open..."); + + stopwatch.Start(); + using (var m = IfcStore.Open(@"C:\LT\Dev\IFC_Issues\rua_degenerada_na_origem.ifc")) + { + Console.WriteLine(" done (" + stopwatch.Elapsed + "ms)."); + + m.Instances.Count.Should().NotBe(0); + + Console.WriteLine(" Instances found: " + m.Instances.Count); + Console.WriteLine(" - Creating context..."); + stopwatch.Restart(); + + var context = new Xbim3DModelContext(m); + context.CreateContext(); + + Console.WriteLine(" done (" + stopwatch.Elapsed + "ms)."); + stopwatch.Restart(); + + var shapes = context.ShapeGeometries().ToArray(); + Console.WriteLine("numShapes: " + shapes.Length); + + foreach (var shape in shapes) + { + var vertices = shape.Vertices.ToArray(); + + for (int i = 0; i < vertices.Length; ++i) + { + if (vertices[i].X.Equals(0.0)) + { + Console.WriteLine("shape.Format: " + shape.Format); + Console.WriteLine("Vertices: " + vertices.Length); + + Console.WriteLine("vertex[" + i + "]: " + vertices[i]); + Console.WriteLine("ZERO"); + } + } + + var faces = shape.Faces.ToArray(); + + foreach (var face in faces) + { + var v0 = vertices[face.Indices.ElementAt(0)]; + var v1 = vertices[face.Indices.ElementAt(1)]; + var v2 = vertices[face.Indices.ElementAt(2)]; + + if (v0.X.Equals(0.0) + || v1.X.Equals(0.0) + || v2.X.Equals(0.0)) + { + Console.WriteLine(" - FACE WITH (0,0,0): "); + } + } + } + + var numShapes = context.ShapeGeometries().ToArray().Length; + + + Console.WriteLine(" Shapes found: " + numShapes); + numShapes.Should().NotBe(0); + Console.WriteLine(" done (" + stopwatch.Elapsed + "ms)."); + } + } } } From 4a11262e876d33cb528fe4bb1ed7c69ee22b61b1 Mon Sep 17 00:00:00 2001 From: Renato Silveira Date: Tue, 19 Nov 2024 17:15:29 -0300 Subject: [PATCH 3/3] remove my tests --- Xbim.Geometry.Engine.Interop.Tests/MyTests.cs | 113 ------------------ 1 file changed, 113 deletions(-) delete mode 100644 Xbim.Geometry.Engine.Interop.Tests/MyTests.cs diff --git a/Xbim.Geometry.Engine.Interop.Tests/MyTests.cs b/Xbim.Geometry.Engine.Interop.Tests/MyTests.cs deleted file mode 100644 index 5026ee0e6..000000000 --- a/Xbim.Geometry.Engine.Interop.Tests/MyTests.cs +++ /dev/null @@ -1,113 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Linq; -using FluentAssertions; -using Xbim.Ifc; -using Xbim.ModelGeometry.Scene; -using System.Diagnostics; - - -namespace Xbim.Geometry.Engine.Interop.Tests -{ - [TestClass] - public class MyTests - { - [TestMethod] - public void Ifc_MyTest_IssueR23() - { - using (var m = IfcStore.Open(@"C:\LT\Dev\IFC_Issues\B1_AR_R23.ifc")) - { - var context = new Xbim3DModelContext(m); - context.CreateContext(); - - var numShapes = context.ShapeGeometries().ToArray().Length; - Console.WriteLine("numShapes: " + numShapes); - numShapes.Should().NotBe(0); - } - } - - [TestMethod] - public void Ifc_MyTest_IssueBLK35B() - { - using (var m = IfcStore.Open(@"C:\LT\Dev\IFC_Issues\CS_BLK35B_CCKN1C1718_-.ifc")) - { - var context = new Xbim3DModelContext(m); - context.CreateContext(); - - var numShapes = context.ShapeGeometries().ToArray().Length; - Console.WriteLine("numShapes: " + numShapes); - numShapes.Should().NotBe(0); - } - } - - [TestMethod] - public void Ifc4_MyTest_DegeneratedPoint() - { - var stopwatch = new Stopwatch(); - - Console.WriteLine("Testing Small"); - Console.WriteLine("- Trying to open..."); - - stopwatch.Start(); - using (var m = IfcStore.Open(@"C:\LT\Dev\IFC_Issues\rua_degenerada_na_origem.ifc")) - { - Console.WriteLine(" done (" + stopwatch.Elapsed + "ms)."); - - m.Instances.Count.Should().NotBe(0); - - Console.WriteLine(" Instances found: " + m.Instances.Count); - Console.WriteLine(" - Creating context..."); - stopwatch.Restart(); - - var context = new Xbim3DModelContext(m); - context.CreateContext(); - - Console.WriteLine(" done (" + stopwatch.Elapsed + "ms)."); - stopwatch.Restart(); - - var shapes = context.ShapeGeometries().ToArray(); - Console.WriteLine("numShapes: " + shapes.Length); - - foreach (var shape in shapes) - { - var vertices = shape.Vertices.ToArray(); - - for (int i = 0; i < vertices.Length; ++i) - { - if (vertices[i].X.Equals(0.0)) - { - Console.WriteLine("shape.Format: " + shape.Format); - Console.WriteLine("Vertices: " + vertices.Length); - - Console.WriteLine("vertex[" + i + "]: " + vertices[i]); - Console.WriteLine("ZERO"); - } - } - - var faces = shape.Faces.ToArray(); - - foreach (var face in faces) - { - var v0 = vertices[face.Indices.ElementAt(0)]; - var v1 = vertices[face.Indices.ElementAt(1)]; - var v2 = vertices[face.Indices.ElementAt(2)]; - - if (v0.X.Equals(0.0) - || v1.X.Equals(0.0) - || v2.X.Equals(0.0)) - { - Console.WriteLine(" - FACE WITH (0,0,0): "); - } - } - } - - var numShapes = context.ShapeGeometries().ToArray().Length; - - - Console.WriteLine(" Shapes found: " + numShapes); - numShapes.Should().NotBe(0); - Console.WriteLine(" done (" + stopwatch.Elapsed + "ms)."); - } - } - } -}