public void ScaledPositioningBoxes()
        {
            // this test is currently failing because some core functions do not work on old geometry models
            // it has to be decided if the function needs to be implemented for v3.1 models as well.
            //
            var m = new List <XbimModel>();

            var m0 = new XbimModel();

            m0.Open(@"Scale\P1_cm.xBIM");
            m.Add(m0);

            var m1 = new XbimModel();

            m1.Open(@"Scale\P2_cm.xBIM");
            m.Add(m1);

            var m2 = new XbimModel();

            m2.Open(@"Scale\P2_mm.xBIM");
            m.Add(m2);

            var m3 = new XbimModel();

            m3.Open(@"Scale\GeomV1\P2_mm.xBIM");
            m.Add(m3);

            // var p = new List<XbimModelPositioning>();
            var r = new List <XbimRect3D>();

            foreach (var xbimModel in m)
            {
                var tmp = new XbimModelPositioning(xbimModel);
                r.Add(tmp.GetLargestRegionRectInMeters());
            }

            HaveSameSize(r[1], r[2]);
            HaveSameSize(r[1], r[3]);
            // HaveSameSize(r[0], r[2]);
            // HaveSameSize(r[0], r[3]);

            HaveSameLocation(r[1], r[2]);
            HaveSameLocation(r[1], r[3]);
            // NeedToBeSame(r[1], r[0]);
            // NeedToBeSame(r[0], r[3]);

            foreach (var xbimModel in m)
            {
                xbimModel.Close();
            }
        }
Пример #2
0
        public void ScaledPositioningBoxes()
        {
            var m = new List <XbimModel>();

            var m0 = new XbimModel();

            m0.Open(@"Scale\P1_cm.xBIM");
            m.Add(m0);

            var m1 = new XbimModel();

            m1.Open(@"Scale\P2_cm.xBIM");
            m.Add(m1);

            var m2 = new XbimModel();

            m2.Open(@"Scale\P2_mm.xBIM");
            m.Add(m2);

            var m3 = new XbimModel();

            m3.Open(@"Scale\GeomV1\P2_mm.xBIM");
            m.Add(m3);

            //var p = new List<XbimModelPositioning>();
            var r = new List <XbimRect3D>();

            foreach (var xbimModel in m)
            {
                var tmp = new XbimModelPositioning(xbimModel);
                // p.Add(tmp);
                r.Add(tmp.GetLargestRegionRectInMeters());
            }

            HaveSameSize(r[1], r[2]);
            HaveSameSize(r[1], r[3]);
            //HaveSameSize(r[0], r[2]);
            // HaveSameSize(r[0], r[3]);

            HaveSameLocation(r[1], r[2]);
            HaveSameLocation(r[1], r[3]);
            // NeedToBeSame(r[1], r[0]);
            //NeedToBeSame(r[0], r[3]);

            foreach (var xbimModel in m)
            {
                xbimModel.Close();
            }
        }
Пример #3
0
        public BimStore3DModel Load(string fileName)
        {
            var bimStoreItems = new Dictionary <IPersistEntity, List <Tuple <MeshGeometry3D, MaterialModel, XbimMatrix3D> > > (); //ID - ifcProductLabel

            var ifcModel = IfcStore.Open(fileName, null, null,
                                         (progress, state) => { reportProgress?.Invoke(progress, state); },
                                         XbimDBAccess.Exclusive);

            //Prepare
            var modelPosition = new XbimModelPositioning(ifcModel);
            var context       = new Xbim3DModelContext(ifcModel);

            context.CreateContext();

            //Clear materials
            MaterialManager.Clear();

            var materialsByStyleId = new Dictionary <int, MaterialModel>();

            var excludedTypes = GenerateDefaultExclusions(ifcModel, DefaultExcludedTypes);

            using (var geometryStore = ifcModel.ReferencingModel.GeometryStore)
            {
                using (var geometryReader = geometryStore.BeginRead())
                {
                    var shapeInstances = GetShapeInstancesToRender(geometryReader, excludedTypes);

                    foreach (var shapeInstance in shapeInstances)
                    {
                        #region Material

                        var styleId = shapeInstance.StyleLabel > 0
                            ? shapeInstance.StyleLabel
                            : shapeInstance.IfcTypeId * -1;

                        MaterialModel material;
                        if (!materialsByStyleId.ContainsKey(styleId))
                        {
                            material = MaterialModelCreator.Create(ifcModel, shapeInstance.IfcTypeId);
                            materialsByStyleId.Add(styleId, material);
                            MaterialManager.Add(material);
                        }
                        else
                        {
                            material = materialsByStyleId[styleId];
                        }

                        #endregion

                        #region Geometry

                        IXbimShapeGeometryData shapeGeometry =
                            geometryReader.ShapeGeometry(shapeInstance.ShapeGeometryLabel);

                        var geometry3D = new MeshGeometry3D();
                        switch ((XbimGeometryType)shapeGeometry.Format)
                        {
                        case XbimGeometryType.PolyhedronBinary:
                            geometry3D.Read(shapeGeometry.ShapeData);
                            break;

                        case XbimGeometryType.Polyhedron:
                            geometry3D.Read(((XbimShapeGeometry)shapeGeometry).ShapeData);
                            break;
                        }

                        #endregion

                        var ifcProduct = ifcModel.Model.Instances.FirstOrDefault(i => i.EntityLabel == shapeInstance.IfcProductLabel);

                        if (ifcProduct != null)
                        {
                            if (!bimStoreItems.ContainsKey(ifcProduct))
                            {
                                bimStoreItems.Add(ifcProduct, new List <Tuple <MeshGeometry3D, MaterialModel, XbimMatrix3D> >(new []
                                {
                                    new Tuple <MeshGeometry3D, MaterialModel, XbimMatrix3D>(geometry3D, material, XbimMatrix3D.Multiply(modelPosition.Transform, shapeInstance.Transformation)),
                                }));
                            }
                            else
                            {
                                bimStoreItems[ifcProduct].Add(new Tuple <MeshGeometry3D, MaterialModel, XbimMatrix3D>(geometry3D, material, XbimMatrix3D.Multiply(modelPosition.Transform, shapeInstance.Transformation)));
                            }
                        }
                    }
                }
            }

            //Generate model
            var bimStore3D = new BimStore3DModel(context.Model as IfcStore);

            foreach (var bimStoreItem in bimStoreItems)
            {
                bimStore3D.Add(
                    new BimStoreItem3DModel(bimStoreItem.Key,
                                            new List <BimGeometry3DModel>(
                                                bimStoreItem.Value.Select(x =>
                                                                          new BimGeometry3DModel(
                                                                              x.Item1.ToMeshModel(),
                                                                              x.Item2,
                                                                              x.Item3.ToMatrix3D())))));
            }

            return(bimStore3D);
        }