コード例 #1
0
        public void ExtrudedCircularProfilesTest()
        {
            var xbimGeometryCreator = new XbimGeometryEngine();

            using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                using (var m = IfcStore.Open("SolidTestFiles\\15 - Swept pipes.ifc"))
                {
                    foreach (
                        var cp in
                        m.Instances.OfType <IfcExtrudedAreaSolid>().Where(e => e.SweptArea is IfcCircleProfileDef))
                    {
                        Assert.IsTrue(cp != null, "No Extruded Solid found");
                        Assert.IsTrue(cp.SweptArea is IfcCircleProfileDef, "Incorrect profiledef found");

                        var solid = xbimGeometryCreator.CreateSolid(cp);
                        Assert.IsTrue(eventTrace.Events.Count == 0); //no events should have been raised from this call

                        IfcCsgTests.GeneralTest(solid);
                    }

                    //Assert.IsTrue(solid.Faces.Count() == 10, "T Shaped profiles should have 10 faces");
                }
            }
        }
コード例 #2
0
        public void IfcExtrudedArea_With_IfcArbritraryClosedProfileDef_And_IfcCompositeCurve()
        {
            var xbimGeometryCreator = new XbimGeometryEngine();

            using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                using (var m = new XbimModel())
                {
                    m.CreateFrom("SolidTestFiles\\2- IfcExtrudedAreaSolid-IfcArbitraryClosedProfileDef-IfcCompositeCurve.ifc", null, null, true, true);
                    var eas = m.Instances.OfType <IfcExtrudedAreaSolid>().FirstOrDefault();
                    Assert.IsTrue(eas != null);
                    Assert.IsTrue(eas.SweptArea is IfcArbitraryClosedProfileDef, "Incorrect profile definition");
                    Assert.IsTrue(((IfcArbitraryClosedProfileDef)eas.SweptArea).OuterCurve is IfcCompositeCurve, "Incorrect SweptArea type");

                    var solid = xbimGeometryCreator.CreateSolid(eas);
                    Assert.IsTrue(eventTrace.Events.Count == 0, "Warnings or errors raised in geometry conversion"); //no events should have been raised from this call

                    IfcCsgTests.GeneralTest(solid);

                    //now make the extrusion invalid
                    eas.Depth = 0;
                    solid     = xbimGeometryCreator.CreateSolid(eas);
                    Assert.IsTrue(eventTrace.Events.Count == 1, "An expected error was not raised raised in geometry conversion"); //we should have an event here
                    Assert.IsTrue(Math.Abs(solid.Volume) < m.ModelFactors.Precision);
                    Assert.IsTrue(solid.BoundingBox.IsEmpty);
                    Assert.IsFalse(solid.IsValid);
                }
            }
        }
コード例 #3
0
        public void RectangleProfileDefTest()
        {
            var xbimGeometryCreator = new XbimGeometryEngine();

            using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                using (var m = IfcStore.Open("SolidTestFiles\\1- IfcExtrudedAreaSolid-IfcProfileDef-Parameterised.ifc"))
                {
                    var eas = m.Instances.OfType <IIfcExtrudedAreaSolid>().FirstOrDefault(e => e.SweptArea is IIfcRectangleProfileDef && !(e.SweptArea is IIfcRectangleHollowProfileDef));
                    Assert.IsTrue(eas != null, "No Extruded Solid found");
                    Assert.IsTrue(eas.SweptArea is IIfcRectangleProfileDef, "Incorrect profiledef found");

                    var solid = xbimGeometryCreator.CreateSolid(eas);
                    Assert.IsTrue(eventTrace.Events.Count == 0); //no events should have been raised from this call

                    IfcCsgTests.GeneralTest(solid);
                    Assert.IsTrue(solid.Faces.Count() == 6, "Rectangular profiles should have six faces");

                    ////now make the extrusion invalid
                    //eas.Depth = 0;
                    //solid = XbimGeometryCreator.CreateSolid(eas);
                    //Assert.IsTrue(eventTrace.Events.Count == 1); //we should have an event here
                    //Assert.IsTrue(Math.Abs(solid.Volume) < m.ModelFactors.Precision);
                    //Assert.IsTrue(solid.BoundingBox.IsEmpty);
                    //Assert.IsFalse(solid.IsValid);
                }
            }
        }
コード例 #4
0
        public void TestLogging()
        {
            var loggerFactory = new LoggerFactory().AddConsole(LogLevel.Trace);
            var logger        = loggerFactory.CreateLogger <LoadGeometryEngine>();
            var ge            = new XbimGeometryEngine();

            using (var m = new MemoryModel(new Ifc4.EntityFactoryIfc4()))
            {
                using (var txn = m.BeginTransaction("new"))
                {
                    var pline = m.Instances.New <IfcPolyline>();
                    ge.CreateCurve(pline, logger);
                }
            }
        }
コード例 #5
0
        public void CreateAdvancedBrep()
        {
            var engine = new XbimGeometryEngine();
            var files  = Directory.GetFiles(@"Ifc4TestFiles\NBSAdvancedBreps", "*.ifc");

            foreach (var file in files)
            {
                using (var store = IfcStore.Open(file))
                {
                    foreach (var brep in store.Instances.OfType <IIfcAdvancedBrep>())
                    {
                        var solid = engine.CreateSolid(brep);

                        Assert.IsTrue(solid.Volume > 0, "Breps should have a positive volume");
                    }
                }
            }
        }
コード例 #6
0
        public void CompositeProfileDefTest()
        {
            var xbimGeometryCreator = new XbimGeometryEngine();

            using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                using (var m = IfcStore.Open("SolidTestFiles\\IfcCompositeProfileDefTest.ifc"))
                {
                    var eas = m.Instances.OfType <IIfcExtrudedAreaSolid>().FirstOrDefault(e => e.SweptArea is IIfcCompositeProfileDef);
                    Assert.IsTrue(eas != null, "No Extruded Solid found");
                    Assert.IsTrue(eas.SweptArea is IIfcCompositeProfileDef, "Incorrect profiledef found");

                    var solid = xbimGeometryCreator.CreateSolid(eas);
                    Assert.IsTrue(eventTrace.Events.Count == 0); //no events should have been raised from this call

                    IfcCsgTests.GeneralTest(solid);
                    Assert.IsTrue(solid.Faces.Count() == 40, "IfcCompositeProfileDef profile should have six faces");
                }
            }
        }
コード例 #7
0
        public void IfcExtrudedArea_With_IfcArbritraryClosedProfileDef_And_IfcCompositeCurve()
        {
            var xbimGeometryCreator = new XbimGeometryEngine();

            using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                using (var m = IfcStore.Open("SolidTestFiles\\2- IfcExtrudedAreaSolid-IfcArbitraryClosedProfileDef-IfcCompositeCurve.ifc"))
                {
                    var eas = m.Instances.OfType <IIfcExtrudedAreaSolid>().FirstOrDefault();
                    Assert.IsTrue(eas != null);
                    Assert.IsTrue(eas.SweptArea is IIfcArbitraryClosedProfileDef, "Incorrect profile definition");
                    Assert.IsTrue(((IIfcArbitraryClosedProfileDef)eas.SweptArea).OuterCurve is IIfcCompositeCurve, "Incorrect SweptArea type");

                    var solid = xbimGeometryCreator.CreateSolid(eas);
                    Assert.IsTrue(eventTrace.Events.Count == 0, "Warnings or errors raised in geometry conversion"); //no events should have been raised from this call

                    IfcCsgTests.GeneralTest(solid);
                }
            }
        }
コード例 #8
0
        public void TestDerivedProfileDefWithTShapedParent()
        {
            var xbimGeometryCreator = new XbimGeometryEngine();

            using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                using (var m = IfcStore.Open("SolidTestFiles\\1- IfcExtrudedAreaSolid-IfcProfileDef-Parameterised.ifc"))
                {
                    var eas = m.Instances.OfType <IIfcExtrudedAreaSolid>().FirstOrDefault(e => e.SweptArea is IIfcDerivedProfileDef && ((IIfcDerivedProfileDef)e.SweptArea).ParentProfile is IIfcTShapeProfileDef);
                    Assert.IsTrue(eas != null, "No Extruded Solid found");
                    Assert.IsTrue(eas.SweptArea is IIfcDerivedProfileDef, "Incorrect profiledef found");
                    Assert.IsTrue(((IIfcDerivedProfileDef)eas.SweptArea).ParentProfile is IIfcTShapeProfileDef, "Incorrect parent profiledef found");

                    var solid = xbimGeometryCreator.CreateSolid(eas);
                    Assert.IsTrue(eventTrace.Events.Count == 0); //no events should have been raised from this call

                    IfcCsgTests.GeneralTest(solid);
                    Assert.IsTrue(solid.Faces.Count() == 10, "T Shaped profiles should have 10 faces");
                }
            }
        }
コード例 #9
0
        public void IfcExtrudedArea_With_IfcArbritraryProfileDefWithVoids()
        {
            var xbimGeometryCreator = new XbimGeometryEngine();

            using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                using (var m = IfcStore.Open("SolidTestFiles\\18 - IfcArbritaryClosedProfileDefWithVoids.ifc"))
                {
                    var eas = m.Instances.OfType <IIfcExtrudedAreaSolid>().FirstOrDefault(e => e.SweptArea is IIfcArbitraryProfileDefWithVoids);
                    Assert.IsTrue(eas != null);
                    Assert.IsTrue(eas.SweptArea is IIfcArbitraryProfileDefWithVoids, "Incorrect profile definition");

                    var solid = xbimGeometryCreator.CreateSolid(eas);
                    Assert.IsTrue(eventTrace.Events.Count == 0, "Warnings or errors raised in geometry conversion"); //no events should have been raised from this call

                    IfcCsgTests.GeneralTest(solid);

                    //Assert.IsTrue(solid.Faces.Count() == 6, "IfcPolyline  profiles should have (number of polyline egdes + 2) faces");
                }
            }
        }
コード例 #10
0
        public void IfcExtrudedArea_With_IfcArbritraryClosedProfileDef_And_IfcPolyline()
        {
            var xbimGeometryCreator = new XbimGeometryEngine();

            using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                using (var m = IfcStore.Open("SolidTestFiles\\1- IfcExtrudedAreaSolid-IfcProfileDef-Parameterised.ifc"))
                {
                    var eas = m.Instances.OfType <IIfcExtrudedAreaSolid>().FirstOrDefault(e => e.SweptArea is IIfcArbitraryClosedProfileDef && ((IIfcArbitraryClosedProfileDef)e.SweptArea).OuterCurve is IIfcPolyline);
                    Assert.IsTrue(eas != null);
                    Assert.IsTrue(eas.SweptArea is IIfcArbitraryClosedProfileDef, "Incorrect profile definition");
                    Assert.IsTrue(((IIfcArbitraryClosedProfileDef)eas.SweptArea).OuterCurve is IIfcPolyline, "Incorrect SweptArea outer curve type");

                    var solid = xbimGeometryCreator.CreateSolid(eas);
                    Assert.IsTrue(eventTrace.Events.Count == 0, "Warnings or errors raised in geometry conversion"); //no events should have been raised from this call

                    IfcCsgTests.GeneralTest(solid);
                    var plineCount = ((IIfcPolyline)((IIfcArbitraryClosedProfileDef)eas.SweptArea).OuterCurve).Points.Count() - 1;
                    Assert.IsTrue(solid.Faces.Count() == plineCount + 2, "IfcPolyline  profiles should have (number of polyline egdes + 2) faces");
                }
            }
        }
コード例 #11
0
        public void TestCircleProfileDef()
        {
            var xbimGeometryCreator = new XbimGeometryEngine();

            using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                using (var m = new XbimModel())
                {
                    m.CreateFrom("SolidTestFiles\\3- IfcExtrudedAreaSolid-IfcCircularProfileDef.ifc", null, null, true, true);
                    var eas = m.Instances.OfType <IfcExtrudedAreaSolid>().FirstOrDefault(e => e.SweptArea is IfcCircleProfileDef);
                    Assert.IsTrue(eas != null, "No Extruded Solid found");
                    Assert.IsTrue(eas.SweptArea is IfcCircleProfileDef, "Incorrect profiledef found");


                    var solid = xbimGeometryCreator.CreateSolid(eas);
                    Assert.IsTrue(eventTrace.Events.Count == 0); //no events should have been raised from this call

                    IfcCsgTests.GeneralTest(solid);
                    Assert.IsTrue(solid.Faces.Count() == 3, "Circular  profiles should have 3 faces");
                }
            }
        }
コード例 #12
0
        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);
                }
            }
        }
コード例 #13
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);
                }
            }
        }
コード例 #14
0
        public void SimpleLoad()
        {
            var ge = new XbimGeometryEngine();

            Assert.IsNotNull(ge);
        }
コード例 #15
0
        /// <summary>
        /// This function centralises the extraction of a product placement, but it needs the support of XbimPlacementTree and an XbimGeometryEngine
        /// We should probably find a conceptual place for it somewhere in the scene, where these are cached.
        /// </summary>
        public static XbimMatrix3D GetTransform(IIfcProduct product, XbimPlacementTree tree, XbimGeometryEngine engine)
        {
            XbimMatrix3D placementTransform = XbimMatrix3D.Identity;

            if (product.ObjectPlacement is IIfcLocalPlacement)
            {
                placementTransform = tree[product.ObjectPlacement.EntityLabel];
            }
            else if (product.ObjectPlacement is IIfcGridPlacement)
            {
                placementTransform = engine.ToMatrix3D((IIfcGridPlacement)product.ObjectPlacement, null);
            }
            return(placementTransform);
        }
コード例 #16
0
 public LocationAndTransformationTests()
 {
     _geomEngine = new XbimGeometryEngine();
 }
コード例 #17
0
 public void LoadGeometry()
 {
     _geom    = new XbimGeometryEngine();
     _context = new Xbim3DModelContext(_model);
     _context.CreateContext();
 }
コード例 #18
0
 public void Unload()
 {
     _geom = null;
     _model.Close();
 }
コード例 #19
0
 public GeometryValidator(ILoggerFactory loggerFactory)
 {
     log    = loggerFactory.CreateLogger <XbimGeometryEngine>();
     engine = new XbimGeometryEngine(log);
 }
コード例 #20
0
        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);
            }
        }
コード例 #21
0
 static public void Cleanup()
 {
     loggerFactory = null;
     geomEngine    = null;
     logger        = null;
 }
コード例 #22
0
 static public void Initialise(TestContext context)
 {
     loggerFactory = new LoggerFactory().AddConsole(LogLevel.Trace);
     geomEngine    = new XbimGeometryEngine();
     logger        = loggerFactory.CreateLogger <Ifc4GeometryTests>();
 }