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); } } }
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); } }