public void CutNonSolidBrep() { using (var m = IfcStore.Open("SolidTestFiles\\Complex_BRep_Boolean.ifc")) { var fbr = m.Instances[35] as IIfcFacetedBrep; Assert.IsTrue(fbr != null, "No IfcFacetedBRep found"); var bodyShape = (IXbimGeometryObjectSet)_xbimGeometryCreator.Create(fbr); Assert.IsTrue(bodyShape.IsValid, "Invalid IfcFacetedBRep"); var shell = bodyShape.Shells.First; var opening = m.Instances[133218] as IIfcExtrudedAreaSolid; Assert.IsTrue(opening != null, "No IfcExtrudedAreaSolid found"); var window = m.Instances[133212] as IIfcOpeningElement; if (window != null) { var cutShape = (IXbimSolid)_xbimGeometryCreator.Create(opening, (IIfcAxis2Placement3D)((IIfcLocalPlacement)window.ObjectPlacement).RelativePlacement); shell.Cut(cutShape, m.ModelFactors.OneMilliMetre); } } }
public void CutNonSolidBrep() { using (var eventTrace = LoggerFactory.CreateEventTrace()) { using (var m = new XbimModel()) { m.CreateFrom("SolidTestFiles\\Complex_BRep_Boolean.ifc", null, null, true, true); var fbr = m.Instances[35] as IfcFacetedBrep; Assert.IsTrue(fbr != null, "No IfcFacetedBRep found"); var bodyShape = (IXbimShell)((IXbimGeometryObjectSet)_xbimGeometryCreator.Create(fbr)).First(); Assert.IsTrue(bodyShape.IsValid, "Invalid IfcFacetedBRep"); var opening = m.Instances[133218] as IfcExtrudedAreaSolid; Assert.IsTrue(opening != null, "No IfcExtrudedAreaSolid found"); var window = m.Instances[133212] as IfcOpeningElement; var cutShape = (IXbimSolid)_xbimGeometryCreator.Create(opening, (IfcAxis2Placement3D)((IfcLocalPlacement)window.ObjectPlacement).RelativePlacement); var result = bodyShape.Cut(cutShape, m.ModelFactors.OneMilliMetre); } } }
public void BooleanOpeningsTotalSubractionTest() { using (var model = IfcStore.Open(@"Ifc4TestFiles\boolean-complete-subtraction.ifc")) { var ifcWall = model.Instances.OfType <IIfcWall>().FirstOrDefault(); Assert.IsNotNull(ifcWall); var ifcOpening = model.Instances.OfType <IIfcOpeningElement>().FirstOrDefault(); Assert.IsNotNull(ifcOpening); var opening = model.Instances[1133441] as IIfcExtrudedAreaSolid; Assert.IsNotNull(opening); var wall = model.Instances[1133397] as IIfcExtrudedAreaSolid; Assert.IsNotNull(wall); //create it in the right position var geomOpening = _xbimGeometryCreator.Create(opening, (IIfcAxis2Placement3D)((IIfcLocalPlacement)(ifcOpening.ObjectPlacement)).RelativePlacement) as IXbimSolid; Assert.IsNotNull(geomOpening); Assert.IsTrue((geomOpening.Volume > 0)); var geomWall = _xbimGeometryCreator.CreateSolid(wall); Assert.IsTrue((geomWall.Volume > 0)); var result = geomWall.Cut(geomOpening, model.ModelFactors.Precision); Assert.IsTrue(result.Count == 0); } }
public void BIM_Logo_LetterB_Test() { var xbimGeometryCreator = new XbimGeometryEngine(); using (var eventTrace = LoggerFactory.CreateEventTrace()) { using (var m = IfcStore.Open("SolidTestFiles\\BIM Logo-LetterB.ifc")) { var eas = m.Instances[88] as IIfcCsgSolid; Assert.IsTrue(eas != null, "No CSG Solid found"); var solid = xbimGeometryCreator.Create(eas); Assert.IsTrue(solid is IXbimSolid); Assert.IsTrue(eventTrace.Events.Count == 0); //no events should have been raised from this call // IfcCsgTests.GeneralTest(solid); // Assert.IsTrue(solid.Faces.Count() == 15, "Letter B should have 15 faces"); // var xbimTessellator = new XbimTessellator(m,XbimGeometryType.PolyhedronBinary); // Assert.IsTrue(xbimTessellator.CanMesh(solid));//if we can mesh the shape directly just do it // var shapeGeom = xbimTessellator.Mesh(solid); var shapeGeom = xbimGeometryCreator.CreateShapeGeometry((IXbimSolid)solid, m.ModelFactors.Precision, m.ModelFactors.DeflectionTolerance, m.ModelFactors.DeflectionAngle, XbimGeometryType.PolyhedronBinary); } } }
internal IEnumerable <(Type, IXbimGeometryObject)> GetGeometryObjects(IPersistEntity entity, bool useDedicatedCreateMethod, bool acceptOnlySolids = true) { foreach (var(type, methodInfo) in FindGeometryEngineMatch(entity)) { object geometryObject; try { if (useDedicatedCreateMethod && entity is IIfcGeometricRepresentationItem gItem) { geometryObject = engine.Create(gItem, log); } else { geometryObject = methodInfo.Invoke(engine, new object[] { entity, log }); } } catch (Exception e) { log.LogError("Got exception '{0}' with call to '{1}({2})'", e.Message, methodInfo.Name, type.Name); continue; } if (geometryObject is IXbimSolid solid) { yield return(type, solid); } if (geometryObject is IXbimSolidSet solidSet) { yield return(type, solidSet); } else if (!acceptOnlySolids) { yield return(type, geometryObject as IXbimGeometryObject); } } }
public void BIM_Logo_LetterM_Test() { var xbimGeometryCreator = new XbimGeometryEngine(); using (var eventTrace = LoggerFactory.CreateEventTrace()) { using (var m = new XbimModel()) { m.CreateFrom("SolidTestFiles\\BIM Logo-LetterM.ifc", null, null, true, true); var eas = m.Instances[57] as IfcSurfaceCurveSweptAreaSolid; Assert.IsTrue(eas != null, "No IfcSurfaceCurveSweptArea Solid found"); var solid = (IXbimSolid)xbimGeometryCreator.Create(eas); Assert.IsTrue(eventTrace.Events.Count == 0); //no events should have been raised from this call IfcCsgTests.GeneralTest(solid); Assert.IsTrue(solid.Faces.Count() == 26, "Letter M should have 26 faces"); var xbimTessellator = new XbimTessellator(m, XbimGeometryType.PolyhedronBinary); // Assert.IsTrue(xbimTessellator.CanMesh(solid));//if we can mesh the shape directly just do it // var shapeGeom = xbimTessellator.Mesh(solid); var shapeGeom = xbimGeometryCreator.CreateShapeGeometry(solid, m.ModelFactors.Precision, m.ModelFactors.DeflectionTolerance, m.ModelFactors.DeflectionAngle, XbimGeometryType.PolyhedronBinary); } } }
private ProcessResult ProcessFile(string ifcFile, StreamWriter writer, ILogger <BatchProcessor> logger) { RemoveFiles(ifcFile); // using (var eventTrace = LoggerFactory.CreateEventTrace()) { var result = new ProcessResult() { Errors = -1 }; var watch = new Stopwatch(); try { watch.Start(); using (var model = ParseModelFile(ifcFile, Params.Caching, logger)) { var parseTime = watch.ElapsedMilliseconds; var xbimFilename = BuildFileName(ifcFile, ".xbim"); var context = new Xbim3DModelContext(model, logger: logger); if (_params.MaxThreads > 0) { context.MaxThreads = _params.MaxThreads; } // context.CustomMeshingBehaviour = CustomMeshingBehaviour; context.CreateContext(); //} var geomTime = watch.ElapsedMilliseconds - parseTime; //XbimSceneBuilder sb = new XbimSceneBuilder(); //string xbimSceneName = BuildFileName(ifcFile, ".xbimScene"); //sb.BuildGlobalScene(model, xbimSceneName); // sceneTime = watch.ElapsedMilliseconds - geomTime; var header = model.Header; watch.Stop(); var ohs = model.Instances.OfType <IIfcOwnerHistory>().FirstOrDefault(); using (var geomReader = model.GeometryStore.BeginRead()) { result = new ProcessResult { ParseDuration = parseTime, GeometryDuration = geomTime, // SceneDuration = sceneTime, FileName = ifcFile.Remove(0, Params.TestFileRoot.Length).TrimStart('\\'), Entities = model.Instances.Count, IfcSchema = header.FileSchema.Schemas.FirstOrDefault(), IfcDescription = string.Format("{0}, {1}", header.FileDescription.Description.FirstOrDefault(), header.FileDescription.ImplementationLevel), GeometryEntries = geomReader.ShapeInstances.Count(), IfcLength = ReadFileLength(ifcFile), XbimLength = ReadFileLength(xbimFilename), SceneLength = 0, IfcProductEntries = model.Instances.OfType <IIfcProduct>().Count(), IfcSolidGeometries = model.Instances.OfType <IIfcSolidModel>().Count(), IfcMappedGeometries = model.Instances.OfType <IIfcMappedItem>().Count(), BooleanGeometries = model.Instances.OfType <IIfcBooleanResult>().Count(), BReps = model.Instances.OfType <IIfcFaceBasedSurfaceModel>().Count() + model.Instances.OfType <IIfcShellBasedSurfaceModel>().Count() + model.Instances .OfType <IIfcManifoldSolidBrep>().Count(), Application = ohs == null ? "Unknown" : ohs.OwningApplication?.ApplicationFullName.ToString() }; } // Option to save breps of encountered classes by type or entityLabel for debugging purposes if (_params.WriteBreps) { var path = Path.Combine( Path.GetDirectoryName(ifcFile), Path.GetFileName(ifcFile) + ".brep.unclassified"); IXbimGeometryEngine engine = new XbimGeometryEngine(); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } IfcStore s = model as IfcStore; if (s != null) { var ents = new List <IPersistEntity>(); var exportBrepByType = new string[] { "IfcFacetedBrep", // IIfcGeometricRepresentationItem "IfcCsgSolid", "IfcExtrudedAreaSolid", "IfcExtrudedAreaSolidTapered", "IfcFixedReferenceSweptAreaSolid", "IfcRevolvedAreaSolid", "IfcRevolvedAreaSolidTapered", "IfcSurfaceCurveSweptAreaSolid", "IfcSectionedSolidHorizontal", "IfcSweptDiskSolid", "IfcSweptDiskSolidPolygonal", "IfcBooleanResult", "IfcBooleanClippingResult", // composing objects "IfcConnectedFaceSet" }; // ADD Individual entities to extract brep here // ents.Add(s.Instances[69512]); foreach (var type in exportBrepByType) { ents.AddRange(s.Instances.OfType(type, false)); } foreach (var ent in ents) { try { Xbim.Common.Geometry.IXbimGeometryObject created = null; if (ent is IIfcGeometricRepresentationItem igri) { created = engine.Create(igri); } if (ent is IIfcConnectedFaceSet icfs) { created = engine.CreateShell(icfs); } // IIfcConnectedFaceSet if (created != null) { var brep = engine.ToBrep(created); var brepFileName = Path.Combine(path, $"{ent.EntityLabel}.{ent.GetType().Name}.brep"); using (var tw = File.CreateText(brepFileName)) { tw.WriteLine("DBRep_DrawableShape"); tw.WriteLine(brep); } } } catch (Exception ex) { Console.WriteLine($"Error writing brep {ent.EntityLabel}: {ex.Message}"); } } } } if (_params.Caching) { IfcStore s = ((IfcStore)model); if (s != null) { s.SaveAs(xbimFilename, Xbim.IO.StorageType.Xbim); s.Close(); } } } } catch (Exception ex) { logger.LogError(string.Format("Problem converting file: {0}", ifcFile), ex); result.Failed = true; result.GeometryDuration = watch.ElapsedMilliseconds; } return(result); } }
public void TestAllModels() { const string modelDirectory = ""; // enter your model directoy here "@"D:\Users\steve\xBIM\Test Models\Use Cases\Live";# if (string.IsNullOrWhiteSpace(modelDirectory)) { Trace.WriteLine("TestAllModels 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()) { foreach (var rep in m.Instances.OfType <IfcGeometricRepresentationItem>()) { if (rep is IfcAxis2Placement || rep is IfcCartesianPoint || rep is IfcDirection || rep is IfcCartesianTransformationOperator || rep is IfcPlanarExtent || rep is IfcTextLiteralWithExtent || rep is IfcFillAreaStyleHatching ) { continue; } var shape = _xbimGeometryCreator.Create(rep); // var w = new XbimOccWriter(); //IXbimSolidSet solids = shape as IXbimSolidSet; //foreach (var solid in solids) //{ // w.Write(solid, "d:\\xbim\\f" + i++); //} if (!shape.IsValid) { Assert.IsTrue(shape.IsValid, "Invalid shape found"); } var solid = shape as IXbimSolid; if (solid != null) { // w.Write(solid, "d:\\xbim\\x" + rep.EntityLabel.ToString()); IfcCsgTests.GeneralTest((IXbimSolid)shape, true, rep is IfcHalfSpaceSolid, rep.EntityLabel); } } 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"); } } } } }