public void ConvertIfcCylinderToBRepTest() { using (var m = XbimModel.CreateTemporaryModel()) { using (var txn = m.BeginTransaction()) { var cylinder = IfcModelBuilder.MakeRightCircularCylinder(m, 10, 20); var solid = _xbimGeometryCreator.CreateSolid(cylinder); var brep = _xbimGeometryCreator.CreateFacetedBrep(m, solid); var solid2 = _xbimGeometryCreator.CreateSolidSet(brep); txn.Commit(); try { //Uncomment below to see the results in Ifc //m.SaveAs("brep.ifc", XbimStorageType.IFC); } catch (Exception) { Assert.IsTrue(false, "Failed to save the results to Ifc"); } Assert.IsTrue(solid2.Count == 1, "Expected one solid"); IfcCsgTests.GeneralTest(solid2.First); Assert.IsTrue(brep.Outer.CfsFaces.Count == solid2.First.Faces.Count, "Number of faces in round tripped solid is not the same"); } } }
public void BuildSolidFromComplexClosedShell() { using (var m = IfcStore.Open("SolidTestFiles\\ClosedShell_with_errors.ifc")) { var closedShell = m.Instances[2699] as IIfcClosedShell; Assert.IsTrue(closedShell != null, "No closedShell found"); var bodyShape = _xbimGeometryCreator.CreateSolidSet(closedShell); Assert.IsTrue(bodyShape.Count == 1); } }
// // [DeploymentItem(@"TestFiles\Regression\FailingGeom.ifc", "FailingGeom.ifc")] public void IfcHalfspace_FailingGeom() { using (var m = IfcStore.Open("TestFiles\\Regression\\FailingGeom.ifc")) { var extSolid = m.Instances.OfType <IIfcExtrudedAreaSolid>().FirstOrDefault(hs => hs.EntityLabel == 185025); var solid = geomEngine.CreateSolid(extSolid, null); IfcCsgTests.GeneralTest(solid); var mlist = m.Instances.OfType <IIfcBooleanClippingResult>(); foreach (var eas in mlist) { Debug.WriteLine("Todo: " + eas.EntityLabel); } foreach (var eas in mlist) { // var eas = m.Instances.OfType<IIfcBooleanClippingResult>().FirstOrDefault(hs => hs.EntityLabel == 185249); Assert.IsTrue(eas != null, "No IfcBooleanClippingResult found"); var ret = geomEngine.CreateSolidSet(eas, logger); IfcCsgTests.GeneralTest(solid); Debug.WriteLine(eas.EntityLabel + " ok"); if (eas.EntityLabel == 185243) { File.WriteAllText(@"C:\Data\_tmp\185243.v5.brep", solid.ToBRep); } } } }
public void LongRunningBooleanTest() { using (var model = IfcStore.Open(@"Ifc4TestFiles\long-running-boolean.ifc")) { using (var eventTrace = LoggerFactory.CreateEventTrace()) { var ifcWall = model.Instances[39] as IIfcExtrudedAreaSolid; Assert.IsNotNull(ifcWall); var solids = _xbimGeometryCreator.CreateSolidSet(); foreach (var ifcOpening in model.Instances.OfType <IIfcOpeningElement>()) { var firstOrDefault = ifcOpening.Representation.Representations.FirstOrDefault(); Assert.IsNotNull(firstOrDefault); { var opening = firstOrDefault.Items.FirstOrDefault() as IIfcGeometricRepresentationItem; var geomOpening = _xbimGeometryCreator.Create(opening, (IIfcAxis2Placement3D)((IIfcLocalPlacement)(ifcOpening.ObjectPlacement)).RelativePlacement) as IXbimSolid; Assert.IsNotNull(geomOpening); solids.Add(geomOpening); } } var wallGeom = _xbimGeometryCreator.CreateSolid(ifcWall); var result = wallGeom.Cut(solids, model.ModelFactors.Precision); Assert.IsTrue(result.Count > 0); } } }
public void IfcFacetedBRepWithMultipleSolids() { using (var eventTrace = LoggerFactory.CreateEventTrace()) { using (var m = new XbimModel()) { m.CreateFrom("SolidTestFiles\\12 - Multiple FacetedBrep.ifc", null, null, true, true); var fbr = m.Instances[25] as IfcFacetedBrep; Assert.IsTrue(fbr != null, "No IfcFacetedBRep found"); int faceCount = fbr.Outer.CfsFaces.Count; var solids = _xbimGeometryCreator.CreateSolidSet(fbr); Assert.IsTrue(solids.Count == 11, "Expected 11 solids"); foreach (var solid in solids) { IfcCsgTests.GeneralTest(solid, true); } } } }
public void IfcRevolvedArea_To_Sphere() { using (var eventTrace = LoggerFactory.CreateEventTrace()) { using (var m = new XbimModel()) { m.CreateFrom(@"SolidTestFiles\BIM Logo-Coordination View 2 - No M.ifc", null, null, true, true); var ss = m.Instances.OfType <IfcRevolvedAreaSolid>().FirstOrDefault(e => e.EntityLabel == 290); Assert.IsTrue(ss != null, "No Revolved Area found"); // m.ModelFactors.DeflectionAngle = 0.1; // m.ModelFactors.DeflectionTolerance = 0.1; var solid = _xbimGeometryCreator.CreateSolid(ss); Assert.IsTrue(eventTrace.Events.Count == 0); //no events should have been raised from this call var facetedSphere = _xbimGeometryCreator.CreateFacetedBrep(m, solid); var shell = _xbimGeometryCreator.CreateShell(facetedSphere.Outer); var xbimFacetedSphere = _xbimGeometryCreator.CreateSolidSet(facetedSphere); Assert.IsTrue(xbimFacetedSphere.Count == 1); //_xbimGeometryCreator.WriteTriangulation(Console.Out,solid, 0.001,0.5); } } }
public void TestCuttingOpenings() { // var w = new XbimOccWriter(); const string modelDirectory = "";//define where your files to test are @"D:\Users\steve\xBIM\Test Models\Use Cases\Live"; if (string.IsNullOrWhiteSpace(modelDirectory)) { Trace.WriteLine("TestCuttingOpenings tests skipped. Enter a directory where the test models can be found"); return; } var di = new DirectoryInfo(modelDirectory); FileInfo[] toProcess = di.GetFiles("*.IFC", SearchOption.TopDirectoryOnly); foreach (var file in toProcess) { using (var m = new XbimModel()) { m.CreateFrom(file.FullName, null, null, true, true); using (var eventTrace = LoggerFactory.CreateEventTrace()) { var theElements = _xbimGeometryCreator.CreateSolidSet(); var openings = m.Instances.OfType <IfcRelVoidsElement>() .Where( r => r.RelatingBuildingElement.Representation != null && r.RelatedOpeningElement.Representation != null) .Select( f => new { element = f.RelatingBuildingElement, feature = f.RelatedOpeningElement }); var toCut = openings.GroupBy(x => x.element, y => y.feature).ToList(); Parallel.ForEach(toCut, new ParallelOptions(), rel => // foreach (var rel in toCut) { var elem = rel.Key; var elemTransform = elem.Transform(); var elemSolids = _xbimGeometryCreator.CreateSolidSet(); foreach (var rep in elem.Representation.Representations) { if (rep.ContextOfItems.ContextType != null && "Model" == rep.ContextOfItems.ContextType.Value.ToString() && (rep.RepresentationIdentifier.HasValue && rep.RepresentationIdentifier == "Body")) { foreach (var item in rep.Items.OfType <IfcGeometricRepresentationItem>()) { IXbimGeometryObject shape = _xbimGeometryCreator.Create(item); if (!shape.IsValid) { Assert.IsTrue(shape.IsValid, "Invalid shape found in #" + item.EntityLabel); } var solid = shape as IXbimSolid; if (solid != null) { IfcCsgTests.GeneralTest(solid, true, item is IfcHalfSpaceSolid, rep.EntityLabel); solid = (IXbimSolid)solid.Transform(elemTransform); elemSolids.Add(solid); } else if (shape is IXbimSolidSet) { foreach (var subSolid in shape as IXbimSolidSet) { IfcCsgTests.GeneralTest(subSolid, true, item is IfcHalfSpaceSolid, rep.EntityLabel); elemSolids.Add(subSolid.Transform(elemTransform)); } } else if (shape is IXbimGeometryObjectSet) { foreach (var subShape in shape as IXbimGeometryObjectSet) { if (subShape is IXbimSolid) { IfcCsgTests.GeneralTest((IXbimSolid)subShape, true, item is IfcHalfSpaceSolid, rep.EntityLabel); } elemSolids.Add(subShape.Transform(elemTransform)); } } else { Trace.WriteLine("No Solid found #" + item.EntityLabel + " " + shape.GetType().Name); } } } } var openingSolids = _xbimGeometryCreator.CreateSolidSet(); foreach (var opening in rel) { var openingTransform = opening.Transform(); foreach (var openingrep in opening.Representation.Representations) { if (openingrep.ContextOfItems.ContextType != null && "Model" == openingrep.ContextOfItems.ContextType.Value.ToString() && (openingrep.RepresentationIdentifier.HasValue && openingrep.RepresentationIdentifier == "Body")) { foreach ( var openingitem in openingrep.Items.OfType <IfcGeometricRepresentationItem>() ) { IXbimGeometryObject openingshape = _xbimGeometryCreator.Create(openingitem); if (!openingshape.IsValid) { Trace.WriteLine("Invalid shape found in #" + openingitem.EntityLabel); continue; } var openingsolid = openingshape as IXbimSolid; if (openingsolid != null) { IfcCsgTests.GeneralTest((IXbimSolid)openingshape, true, openingitem is IfcHalfSpaceSolid, openingrep.EntityLabel); openingsolid = (IXbimSolid)openingsolid.Transform(openingTransform); openingSolids.Add(openingsolid); } else if (openingshape is IXbimSolidSet) { foreach (var subOpeningSolid in openingshape as IXbimSolidSet) { IfcCsgTests.GeneralTest(subOpeningSolid, true, openingitem is IfcHalfSpaceSolid, openingrep.EntityLabel); openingSolids.Add(subOpeningSolid.Transform(openingTransform)); } } else if (openingshape is IXbimGeometryObjectSet) { foreach (var subShape in openingshape as IXbimGeometryObjectSet) { if (subShape is IXbimSolid) { IfcCsgTests.GeneralTest((IXbimSolid)subShape, true, openingitem is IfcHalfSpaceSolid, openingrep.EntityLabel); } openingSolids.Add(subShape.Transform(openingTransform)); } } else { Trace.WriteLine("No Solid found #" + openingitem.EntityLabel + " " + openingshape.GetType().Name); } } } } } // ReSharper disable once AccessToDisposedClosure var solidResult = elemSolids.Cut(openingSolids, m.ModelFactors.PrecisionBoolean); foreach (var result in solidResult) { IfcCsgTests.GeneralTest(result, true, false, elem.EntityLabel); theElements.Add(result); } } ); // w.Write(theElements, "d:\\xbim\\r"); if (eventTrace.Events.Count > 0) { //var assertNow = false; Trace.WriteLine("Model: " + file.Name); foreach (var err in eventTrace.Events) { Trace.WriteLine(err.Message); //if (err.EventLevel == EventLevel.ERROR) // assertNow = true; } // Assert.IsTrue(assertNow == false, "Error events were raised"); } } } } }