Example #1
0
        /***************************************************/
        /****              Public Methods               ****/
        /***************************************************/

        public static List <Mesh> Meshes(this XbimShapeInstance instance, Xbim3DModelContext context)
        {
            if (instance == null)
            {
                BH.Engine.Reflection.Compute.RecordError("The meshes could not be extracted because the IFC element is null.");
                return(null);
            }

            if (context == null)
            {
                BH.Engine.Reflection.Compute.RecordError("The meshes could not be extracted because the 3D model context is null.");
                return(null);
            }

            List <Mesh> result;

            //Instance's geometry
            XbimShapeGeometry geometry = context.ShapeGeometry(instance);

            byte[] data = ((IXbimShapeGeometryData)geometry).ShapeData;

            //If you want to get all the faces and trinagulation use this
            using (var stream = new MemoryStream(data))
            {
                using (var reader = new BinaryReader(stream))
                {
                    XbimShapeTriangulation shape = reader.ReadShapeTriangulation();
                    result = shape.Meshes();
                }
            }

            TransformMatrix transform = instance.Transformation.TransformMatrixFromIfc();

            return(result.Select(x => x.Transform(transform)).ToList());
        }
        internal int AddShapeInstance(XbimShapeInstance shapeInstance, int geometryId)
        {
            int id = Interlocked.Increment(ref _instanceCount);

            shapeInstance.ShapeGeometryLabel = geometryId;
            _shapeInstances.TryAdd(id, shapeInstance);
            return(id);
        }
        public void IfcStoreGeometryStoreAddTest()
        {
            using (var model = IfcStore.Open("TestFiles\\SampleHouse4.ifc"))
            {
                var geomStore = model.GeometryStore;
                using (var txn = geomStore.BeginInit())
                {
                    //ADD A GEOMETRY SHAPE
                    var geomData = new XbimShapeGeometry()
                    {
                        IfcShapeLabel  = 1,
                        Format         = XbimGeometryType.BoundingBox,
                        GeometryHash   = 0,
                        LOD            = XbimLOD.LOD100,
                        ReferenceCount = 1,
                        ShapeData      = "2123",
                        BoundingBox    = XbimRect3D.Empty
                    };
                    var shapeGeomLabel = txn.AddShapeGeometry(geomData);

                    //ADD A SHAPE INSTANCE
                    var shapeInstance = new XbimShapeInstance()
                    {
                        ShapeGeometryLabel    = shapeGeomLabel,
                        StyleLabel            = 5,
                        RepresentationContext = 50
                    };

                    var instanceId = txn.AddShapeInstance(shapeInstance, shapeGeomLabel);
                    Assert.IsTrue(instanceId == 1);

                    //ADD A REGIONCOLLECTION
                    var regions = new XbimRegionCollection();
                    regions.ContextLabel = 50;
                    var bb = new XbimRect3D(new XbimPoint3D(1, 1, 1), new XbimVector3D(10, 20, 30));
                    regions.Add(new XbimRegion("region1", bb, 100, XbimMatrix3D.Identity));
                    txn.AddRegions(regions);

                    txn.Commit();
                }
                model.SaveAs("SampleHouse4.xbim", StorageType.Xbim);
                model.Close();
            }
            using (var model = IfcStore.Open(@"SampleHouse4.xbim"))
            {
                var geomStore = model.GeometryStore;
                Assert.IsFalse(geomStore.IsEmpty);
                using (var reader = geomStore.BeginRead())
                {
                    Assert.IsTrue(reader.ContextIds.Any());
                    Assert.IsTrue(reader.ContextRegions.First().ContextLabel == 50);
                    Assert.IsTrue(reader.ShapeGeometries.Count() == 1);
                    Assert.IsTrue(reader.ShapeInstances.Count() == 1);
                    Assert.IsTrue(reader.StyleIds.Count == 1);
                }
                model.Close();
            }
        }
Example #4
0
        private static void getgeometry(XbimShapeInstance shape, Xbim3DModelContext m_context, int entityLabel, int number_of_shapes)
        {
            XbimShapeTriangulation mesh = null;

            var geometry = m_context.ShapeGeometry(shape);


            Console.WriteLine($"{"\n"}{GetIndent(11)}{"--Geometry Type: " + geometry.Format}");


            var ms = new MemoryStream(((IXbimShapeGeometryData)geometry).ShapeData);
            var br = new BinaryReader(ms);

            mesh = br.ReadShapeTriangulation();
            mesh = mesh.Transform(((XbimShapeInstance)shape).Transformation);

            var facesfound = mesh.Faces.ToList();


            var number_of_faces = facesfound.Count();

            Console.WriteLine($"{"\n"}{GetIndent(11)}{"  -----No. of faces on the shape #" + shape.IfcProductLabel + ": " + number_of_faces}");

            //used for an ID for each face
            int face_index = 0;
            //used for the total number of triangles
            int number_of_triangles = 0;

            //write the Faces element with its count
            xmlWriter.WriteStartElement("Faces");
            xmlWriter.WriteAttributeString("NumFaces", number_of_faces.ToString());

            foreach (XbimFaceTriangulation f in facesfound)
            {
                number_of_triangles = f.TriangleCount;
                Console.WriteLine($"{"\n"}{GetIndent(13)}{"  -----Triangle count on face: " + f.GetType() + " :mesh is  " + number_of_triangles}");



                face_index++;

                composetrianglesets(f, mesh, entityLabel, facesfound.Count(), face_index, number_of_triangles, number_of_shapes);
            }

            //this ends the faces element in the xml file
            xmlWriter.WriteEndElement();



            //Console.WriteLine($"{"\n"}{GetIndent(13)}{" -----Vertices of the shape: #" + shape.IfcProductLabel}");
            //foreach (var v in mesh.Vertices.ToList())
            //{
            //    Console.WriteLine($"{GetIndent(13)}{" --vertex_" + mesh.Vertices.ToList().IndexOf(v) + " : " + Math.Round((double)v.X, 2) + " | " + Math.Round((double)v.Y, 2) + " | " + Math.Round((double)v.Z, 2)}");

            //}

            Console.WriteLine("\n");
        }
Example #5
0
        private static float[] GetTransformInMeters(IModel model, XbimShapeInstance shapeInstance)
        {
            var arr = shapeInstance.Transformation.ToFloatArray();

            arr[12] /= (float)model.ModelFactors.OneMeter;
            arr[13] /= (float)model.ModelFactors.OneMeter;
            arr[14] /= (float)model.ModelFactors.OneMeter;
            return(arr);
        }
Example #6
0
        private static void getgeometry(XbimShapeInstance shape, Xbim3DModelContext m_context, int entityLabel, int number_OF_Walls)
        {
            XbimShapeTriangulation mesh = null;

            var geometry = m_context.ShapeGeometry(shape);

            //Console.WriteLine("====" + geometry.GetType());
            Console.WriteLine($"{"\n"}{GetIndent(11)}{"--Geometry Type: " + geometry.Format}");


            var ms = new MemoryStream(((IXbimShapeGeometryData)geometry).ShapeData);
            var br = new BinaryReader(ms);

            mesh = br.ReadShapeTriangulation();
            mesh = mesh.Transform(((XbimShapeInstance)shape).Transformation);

            var facesfound = mesh.Faces.ToList();



            Console.WriteLine($"{"\n"}{GetIndent(11)}{"  -----No. of faces on the shape #" + shape.IfcProductLabel + ": " + facesfound.Count()}");
            int FaceNum        = 0;
            int Triangle_Count = 0;

            //xmlWriter.WriteElementString("Faces", facesfound.Count().ToString());
            xmlWriter.WriteStartElement("Faces");
            xmlWriter.WriteAttributeString("NumFaces", facesfound.Count().ToString());

            foreach (XbimFaceTriangulation f in facesfound)
            {
                Triangle_Count = f.TriangleCount;
                Console.WriteLine($"{"\n"}{GetIndent(13)}{"  -----Triangle count on face: " + f.GetType() + " :mesh is  " +Triangle_Count}");


                //foreach (var fi in f.Indices)
                //{
                //    Console.WriteLine($"{GetIndent(13)}{" -> " + fi}");

                //}
                FaceNum++;

                composetrianglesets(f, mesh, entityLabel, facesfound.Count(), FaceNum, Triangle_Count, number_OF_Walls);
            }
            //this is for the faces NUmber
            xmlWriter.WriteEndElement();
            // xmlWriter.WriteWhitespace("\n");
            //Console.WriteLine($"{"\n"}{GetIndent(13)}{" -----Vertices of the shape: #" + shape.IfcProductLabel}");
            //foreach (var v in mesh.Vertices.ToList())
            //{
            //    Console.WriteLine($"{GetIndent(13)}{" --vertex_" + mesh.Vertices.ToList().IndexOf(v) + " : " + Math.Round((double)v.X, 2) + " | " + Math.Round((double)v.Y, 2) + " | " + Math.Round((double)v.Z, 2)}");

            //}

            Console.WriteLine("\n");
        }
        public void EsentGeometryStoreReopenAddTest()
        {
            var db  = Guid.NewGuid().ToString() + ".xbim";
            var ifc = "TestFiles\\4walls1floorSite.ifc";
            var p   = new EsentModelProvider {
                DatabaseFileName = db
            };
            var s = p.GetXbimSchemaVersion(ifc);

            using (var m = p.Open(ifc, s)) { p.Close(m); }

            using (var model = IfcStore.Open(db, accessMode: XbimDBAccess.ReadWrite))
            {
                var geomStore = model.GeometryStore;
                using (var txn = geomStore.BeginInit())
                {
                    //ADD A GEOMETRY SHAPE
                    var geomData = new XbimShapeGeometry()
                    {
                        IfcShapeLabel  = 1,
                        Format         = XbimGeometryType.BoundingBox,
                        GeometryHash   = 0,
                        LOD            = XbimLOD.LOD100,
                        ReferenceCount = 1,
                        ShapeData      = "2123",
                        BoundingBox    = XbimRect3D.Empty
                    };
                    var shapeGeomLabel = txn.AddShapeGeometry(geomData);

                    //ADD A SHAPE INSTANCE
                    var shapeInstance = new XbimShapeInstance()
                    {
                        ShapeGeometryLabel    = shapeGeomLabel,
                        StyleLabel            = 5,
                        RepresentationContext = 50
                    };

                    var instanceId = txn.AddShapeInstance(shapeInstance, shapeGeomLabel);
                    Assert.IsTrue(instanceId == 1);

                    //ADD A REGIONCOLLECTION
                    var regions = new XbimRegionCollection
                    {
                        ContextLabel = 50
                    };
                    var bb = new XbimRect3D(new XbimPoint3D(1, 1, 1), new XbimVector3D(10, 20, 30));
                    regions.Add(new XbimRegion("region1", bb, 100, XbimMatrix3D.Identity));
                    txn.AddRegions(regions);

                    txn.Commit();
                }
                model.SaveAs("SampleHouse4.xbim", StorageType.Xbim);
                model.Close();
            }
        }
Example #8
0
        public void EsentGeometryStoreMultiThreadTest()
        {
            using (var model = IfcStore.Create(null, XbimSchemaVersion.Ifc4, XbimStoreType.EsentDatabase))
            {
                var store = model.GeometryStore;
                using (var txn = store.BeginInit())
                {
                    Parallel.For(0, 100, i =>
                    {
                        //ADD A GEOMETRY SHAPE
                        var geomData = new XbimShapeGeometry()
                        {
                            IfcShapeLabel  = 1,
                            Format         = XbimGeometryType.BoundingBox,
                            GeometryHash   = 0,
                            LOD            = XbimLOD.LOD100,
                            ReferenceCount = 1,
                            ShapeData      = "2123",
                            BoundingBox    = XbimRect3D.Empty
                        };
                        var shapeInstance = new XbimShapeInstance()
                        {
                            ShapeGeometryLabel = i + 1
                        };
                        var shapeGeomLabel = txn.AddShapeGeometry(geomData);
                        var instanceId     = txn.AddShapeInstance(shapeInstance, shapeGeomLabel);
                    });

                    Parallel.For(0, 100, i =>
                    {
                        //ADD A SHAPE INSTANCE
                        var shapeInstance = new XbimShapeInstance()
                        {
                            ShapeGeometryLabel = i + 1
                        };

                        var instanceId = txn.AddShapeInstance(shapeInstance, i + 1);
                    });

                    //ADD A REGIONCOLLECTION
                    var regions = new XbimRegionCollection {
                        ContextLabel = 50
                    };
                    regions.Add(new XbimRegion("region1", XbimRect3D.Empty, 100, XbimMatrix3D.Identity));
                    txn.AddRegions(regions);

                    txn.Commit();
                }
                model.Close();
            }
        }
        /// <summary>
        /// Retrieves all shape instances for the given context
        /// </summary>
        /// <param name="contextId"></param>
        /// <returns></returns>
        public IEnumerable <XbimShapeInstance> ShapeInstancesOfContext(int contextId)
        {
            IXbimShapeInstanceData shapeInstance = new XbimShapeInstance();

            if (_shapeInstanceCursor.TrySeekShapeInstance(contextId, ref shapeInstance))
            {
                do
                {
                    yield return((XbimShapeInstance)shapeInstance);

                    shapeInstance = new XbimShapeInstance();
                } while (_shapeInstanceCursor.TryMoveNextShapeInstance(ref shapeInstance));
            }
        }
Example #10
0
            internal bool RemoveDone(XbimShapeInstance shape)
            {
                bool removed = _requiredShapesInstances.Remove(LabelShapeInstance(shape));

                if (CountOpenInstances > 0)
                {   // Only if we are not done yet
                    if (null == _doneShapeGeometryLabels)
                    {
                        _doneShapeGeometryLabels = new List <int>();
                    }
                    _doneShapeGeometryLabels.Add(shape.ShapeGeometryLabel);
                }
                return(removed);
            }
 public MyBimShapeInstance(int product, short type, int instanceLabel, int styleLabel, XbimMatrix3D matrix = default)
 {
     this.productLabel   = product;
     this.typeId         = type;
     this.instanceLabel  = instanceLabel;
     this.styleLabel     = styleLabel;
     this.triangulations = new List <MyBimTriangulation>();
     transform           = matrix;
     xbimShapeInstance   = new XbimShapeInstance(this.instanceLabel)
     {
         IfcProductLabel = productLabel,
         IfcTypeId       = typeId,
         StyleLabel      = this.styleLabel,
         Transformation  = transform
     };
 }
        public void ResourceReleaseTest()
        {
            using (var model = IfcStore.Open("TestFiles\\SampleHouse4.ifc", null, 0))
            {
                using (var txn = model.GeometryStore.BeginInit())
                {
                    //ADD A GEOMETRY SHAPE
                    var geomData = new XbimShapeGeometry()
                    {
                        IfcShapeLabel  = 1,
                        Format         = XbimGeometryType.BoundingBox,
                        GeometryHash   = 0,
                        LOD            = XbimLOD.LOD100,
                        ReferenceCount = 1,
                        ShapeData      = "2123",
                        BoundingBox    = XbimRect3D.Empty
                    };
                    var shapeGeomLabel = txn.AddShapeGeometry(geomData);

                    //ADD A SHAPE INSTANCE
                    var shapeInstance = new XbimShapeInstance()
                    {
                        ShapeGeometryLabel    = shapeGeomLabel,
                        StyleLabel            = 5,
                        RepresentationContext = 50
                    };

                    var instanceId = txn.AddShapeInstance(shapeInstance, shapeGeomLabel);
                    Assert.IsTrue(instanceId == 1);

                    //ADD A REGIONCOLLECTION
                    var regions = new XbimRegionCollection();
                    regions.ContextLabel = 50;
                    var bb = new XbimRect3D(new XbimPoint3D(1, 1, 1), new XbimVector3D(10, 20, 30));
                    regions.Add(new XbimRegion("region1", bb, 100, XbimMatrix3D.Identity));
                    txn.AddRegions(regions);
                    txn.Commit();
                }
                int c = model.Instances.OfType <IfcDoor>().Count();
                model.Close();
            }
            Thread.SpinWait(200);

            // TODO:: ISSUE HERE... when the whole suite of tests is run then the count could be greater than,
            // even if they are reduced correctly
            Assert.IsTrue(IO.Esent.EsentModel.ModelOpenCount == 0);
        }
        public IEnumerable <XbimShapeInstance> ShapeInstancesOfEntity(int entityLabel)
        {
            IXbimShapeInstanceData shapeInstance = new XbimShapeInstance();

            if (_shapeInstanceCursor.TrySeekShapeInstanceOfProduct(entityLabel, ref shapeInstance))
            {
                do
                {
                    if (_contextIds.Contains(shapeInstance.RepresentationContext))
                    {
                        yield return((XbimShapeInstance)shapeInstance);

                        shapeInstance = new XbimShapeInstance();
                    }
                } while (_shapeInstanceCursor.TryMoveNextShapeInstance(ref shapeInstance));
            }
        }
Example #14
0
        // Creates a transform
        private Dto.Scene.Transform CreateTransform(IfcSceneExportSummary s, XbimShapeInstance shape)
        {
            // Context transformation (relative offset shift => make final transform relative to context shift)
            var contextWcs = s.TransformOf(shape.RepresentationContext) ?? XbimMatrix3D.Identity;

            switch (s.AppliedSettings.Transforming)
            {
            case SceneTransformationStrategy.Matrix:
                return((shape.Transformation * contextWcs).ToRotation(s.Scale));

            case SceneTransformationStrategy.Quaternion:
                return((shape.Transformation * contextWcs).ToQuaternion(s.Scale));

            default:
                throw new NotImplementedException($"Missing implementation for '{s.AppliedSettings.Transforming}'");
            }
        }
        public void InMemoryGeometryStoreMultiThreadTest()
        {
            using (var model = new IO.Memory.MemoryModel(new EntityFactory()))
            {
                var store = model.GeometryStore;
                using (var txn = store.BeginInit())
                {
                    Parallel.For(0, 100, i =>
                    {
                        //ADD A GEOMETRY SHAPE
                        var geomData = new XbimShapeGeometry()
                        {
                            IfcShapeLabel  = 1,
                            Format         = XbimGeometryType.BoundingBox,
                            GeometryHash   = 0,
                            LOD            = XbimLOD.LOD100,
                            ReferenceCount = 1,
                            ShapeData      = "2123",
                            BoundingBox    = XbimRect3D.Empty
                        };
                        var shapeGeomLabel = txn.AddShapeGeometry(geomData);
                    });

                    Parallel.For(0, 100, i =>
                    {
                        //ADD A SHAPE INSTANCE
                        var shapeInstance = new XbimShapeInstance()
                        {
                            ShapeGeometryLabel = i + 1
                        };

                        var instanceId = txn.AddShapeInstance(shapeInstance, i + 1);
                    });

                    //ADD A REGIONCOLLECTION
                    var regions = new XbimRegionCollection {
                        ContextLabel = 50
                    };
                    regions.Add(new XbimRegion("region1", XbimRect3D.Empty, 100));
                    txn.AddRegions(regions);

                    txn.Commit();
                }
            }
        }
        public IEnumerable <XbimShapeInstance> ShapeInstancesOfEntityType(int entityTypeId)
        {
            IXbimShapeInstanceData shapeInstance = new XbimShapeInstance();

            if (_shapeInstanceCursor.TrySeekProductType((short)entityTypeId, ref shapeInstance))
            {
                do
                {
                    if (_contextIds.Contains(shapeInstance.RepresentationContext))
                    {
                        yield return((XbimShapeInstance)shapeInstance);

                        shapeInstance = new XbimShapeInstance();
                    }
                } while (_shapeInstanceCursor.TryMoveNextShapeInstance(ref shapeInstance) &&
                         shapeInstance.IfcTypeId == entityTypeId);
            }
        }
        public IEnumerable <XbimShapeInstance> ShapeInstancesOfStyle(int styleLabel)
        {
            IXbimShapeInstanceData shapeInstance = new XbimShapeInstance();

            foreach (var context in _contextIds)
            {
                if (_shapeInstanceCursor.TrySeekSurfaceStyle(context, styleLabel, ref shapeInstance))
                {
                    do
                    {
                        yield return((XbimShapeInstance)shapeInstance);

                        shapeInstance = new XbimShapeInstance();
                    } while (_shapeInstanceCursor.TryMoveNextShapeInstance(ref shapeInstance) &&
                             shapeInstance.StyleLabel == styleLabel);
                }
            }
        }
        public IEnumerable <XbimShapeInstance> ShapeInstancesOfGeometry(int geometryLabel)
        {
            IXbimShapeInstanceData shapeInstance = new XbimShapeInstance();

            if (_shapeInstanceCursor.TrySeekShapeInstanceOfGeometry(geometryLabel, ref shapeInstance))
            {
                do
                {
                    if (!_contextIds.Contains(shapeInstance.RepresentationContext))
                    {
                        continue;
                    }
                    yield return((XbimShapeInstance)shapeInstance);

                    shapeInstance = new XbimShapeInstance();
                } while (_shapeInstanceCursor.TryMoveNextShapeInstance(ref shapeInstance));
            }
        }
Example #19
0
        internal void AddShape(IGeometryStoreReader geomReader, XbimShapeInstance shapeInstance, CoordinatesMode mode)
        {
            // XbimMatrix3D modelTransform = XbimMatrix3D.Identity;
            IXbimShapeGeometryData shapeGeom = geomReader.ShapeGeometry(shapeInstance.ShapeGeometryLabel);

            if (shapeGeom.Format != (byte)XbimGeometryType.PolyhedronBinary)
            {
                return;
            }
            // var transform = XbimMatrix3D.Multiply(, modelTransform);
            if (mode == CoordinatesMode.IncludeShapeTransform)
            {
                AddMesh(shapeGeom.ShapeData, shapeInstance.Transformation);
            }
            else
            {
                AddMesh(shapeGeom.ShapeData);
            }
        }
Example #20
0
        private static void getgeometry(XbimShapeInstance shape, Xbim3DModelContext m_context)
        {
            XbimShapeTriangulation mesh = null;

            var geometry = m_context.ShapeGeometry(shape);

            //Console.WriteLine("====" + geometry.GetType());
            Console.WriteLine($"{"\n"}{GetIndent(11)}{"--Geometry Type: " + geometry.Format}");


            var ms = new MemoryStream(((IXbimShapeGeometryData)geometry).ShapeData);
            var br = new BinaryReader(ms);

            mesh = br.ReadShapeTriangulation();
            mesh = mesh.Transform(((XbimShapeInstance)shape).Transformation);

            var facesfound = mesh.Faces.ToList();

            Console.WriteLine($"{"\n"}{GetIndent(11)}{"  -----No. of faces on the shape #" + shape.IfcProductLabel + ": " + facesfound.Count()}");

            foreach (XbimFaceTriangulation f in facesfound)
            {
                Console.WriteLine($"{"\n"}{GetIndent(13)}{"  -----Triangle count on face: " + f.GetType() + " :mesh is  " + f.TriangleCount}");
                //foreach (var fi in f.Indices)
                //{
                //    Console.WriteLine($"{GetIndent(13)}{" -> " + fi}");

                //}
                composetrianglesets(f, mesh);
            }

            //Console.WriteLine($"{"\n"}{GetIndent(13)}{" -----Vertices of the shape: #" + shape.IfcProductLabel}");
            //foreach (var v in mesh.Vertices.ToList())
            //{
            //    Console.WriteLine($"{GetIndent(13)}{" --vertex_" + mesh.Vertices.ToList().IndexOf(v) + " : " + Math.Round((double)v.X, 2) + " | " + Math.Round((double)v.Y, 2) + " | " + Math.Round((double)v.Z, 2)}");

            //}

            Console.WriteLine("\n");
        }
Example #21
0
 public int AddShapeInstance(XbimShapeInstance shapeInstance, int geometryId)
 {
     lock (_shapeInstanceCursor)
     {
         SetInstanceContext();
         try
         {
             long remainder = _instanceCount % TransactionBatchSize; //pulse transactions
             if (remainder == TransactionBatchSize - 1)
             {
                 _shapeInstanceTransaction.Commit();
                 _shapeInstanceTransaction.Begin();
             }
             _instanceCount++;
             shapeInstance.ShapeGeometryLabel = geometryId;
             return(_shapeInstanceCursor.AddInstance(shapeInstance));
         }
         finally
         {
             ResetInstanceContext();
         }
     }
 }
Example #22
0
        // Creates a new representation context
        private Representation GetOrCreateRepresentation(IfcSceneExportSummary s, XbimShapeInstance shape, TesselationPackage pkg)
        {
            var(context, contextWcs) = s.RepresentationContext(shape.RepresentationContext);
            var representation = pkg.Representations.FirstOrDefault(r => r.Context.Equals(context.Name));
            // left expansion & concatenation in xbim !
            var aabb = shape.BoundingBox.ToABox(s.Scale, p => (shape.Transformation * contextWcs).Transform(p));

            if (null == representation)
            {   // Create new representation
                representation = new Representation
                {
                    Context     = context.Name,
                    BoundingBox = new BoundingBox {
                        ABox = aabb
                    }
                };
                pkg.Representations.Add(representation);
            }
            else
            {   // Union bounding boxes
                representation.BoundingBox.ABox = representation.BoundingBox.ABox.UnionWith(aabb);
            }
            return(representation);
        }
Example #23
0
 private static void getgeometry(XbimShapeInstance si, Xbim3DModelContext mod_context)
 {
     throw new NotImplementedException();
 }
Example #24
0
        public void EsentGeometryStoreReadTest()
        {
            using (var model = IO.Esent.EsentModel.CreateTemporaryModel(ef4))
            {
                var store = model.GeometryStore;
                using (var txn = store.BeginInit())
                {
                    //ADD A GEOMETRY SHAPE
                    var geomData = new XbimShapeGeometry()
                    {
                        IfcShapeLabel  = 1,
                        Format         = XbimGeometryType.BoundingBox,
                        GeometryHash   = 0,
                        LOD            = XbimLOD.LOD300,
                        ReferenceCount = 1,
                        ShapeData      = "2123",
                        BoundingBox    = XbimRect3D.Empty
                    };
                    var shapeGeomLabel = txn.AddShapeGeometry(geomData);

                    //ADD A SHAPE INSTANCE
                    var shapeInstance = new XbimShapeInstance()
                    {
                        ShapeGeometryLabel = shapeGeomLabel, RepresentationContext = 50
                    };

                    var instanceId = txn.AddShapeInstance(shapeInstance, shapeGeomLabel);
                    Assert.IsTrue(instanceId == 1);

                    //ADD 2 REGIONCOLLECTIONS
                    var regions = new XbimRegionCollection {
                        ContextLabel = 50
                    };
                    regions.Add(new XbimRegion("region1", XbimRect3D.Empty, 100, XbimMatrix3D.Identity));
                    txn.AddRegions(regions);
                    regions = new XbimRegionCollection {
                        ContextLabel = 51
                    };
                    regions.Add(new XbimRegion("region2", XbimRect3D.Empty, 100, XbimMatrix3D.Identity));
                    txn.AddRegions(regions);
                    txn.Commit();
                }

                //start to read
                using (var reader = store.BeginRead())
                {
                    Assert.IsTrue(reader.ContextRegions.Count() == 2, "Incorrect number of regions retrieved");
                    var regionsList = reader.ContextRegions.ToList();
                    var contextIds  = reader.ContextIds.ToList();
                    for (int i = 0; i < reader.ContextRegions.Count(); i++)
                    {
                        Assert.IsTrue(regionsList[i].ContextLabel == 50 + i);
                        Assert.IsTrue(contextIds[i] == 50 + i);
                    }
                    Assert.IsTrue(reader.ShapeGeometries.Count() == 1, "Should have returned one shape geometry");
                    Assert.IsTrue(reader.ShapeGeometries.First().LOD == XbimLOD.LOD300);
                    Assert.IsTrue(reader.ShapeInstances.Count() == 1, "Should have returned one shape instance");
                    Assert.IsTrue(reader.ShapeInstances.First().RepresentationContext == 50);
                    Assert.IsTrue(reader.ShapeInstancesOfContext(50).Count() == 1);
                }
                model.Close();
            }
        }
Example #25
0
        public void IfcStoreGeometryGeometryClearTest()
        {
            using (var model = new IO.Esent.EsentModel(ef4))
            {
                model.CreateFrom("SampleHouse4.ifc", null, null, true);
                var store = model.GeometryStore;
                using (var txn = store.BeginInit())
                {
                    //ADD A GEOMETRY SHAPE
                    var geomData = new XbimShapeGeometry()
                    {
                        IfcShapeLabel  = 1,
                        Format         = XbimGeometryType.BoundingBox,
                        GeometryHash   = 0,
                        LOD            = XbimLOD.LOD100,
                        ReferenceCount = 1,
                        ShapeData      = "2123",
                        BoundingBox    = XbimRect3D.Empty
                    };
                    var shapeGeomLabel = txn.AddShapeGeometry(geomData);

                    //ADD A SHAPE INSTANCE
                    var shapeInstance = new XbimShapeInstance()
                    {
                        ShapeGeometryLabel = shapeGeomLabel
                    };

                    var instanceId = txn.AddShapeInstance(shapeInstance, shapeGeomLabel);
                    Assert.IsTrue(instanceId == 1);

                    //ADD A REGIONCOLLECTION
                    var regions = new XbimRegionCollection {
                        ContextLabel = 50
                    };
                    regions.Add(new XbimRegion("region1", XbimRect3D.Empty, 100, XbimMatrix3D.Identity));
                    txn.AddRegions(regions);

                    txn.Commit();
                }
                //now redo which should clear the geoemtry
                using (var txn = store.BeginInit())
                {
                    Assert.IsNotNull(txn);
                    //ADD A GEOMETRY SHAPE
                    var geomData = new XbimShapeGeometry()
                    {
                        IfcShapeLabel  = 1,
                        Format         = XbimGeometryType.BoundingBox,
                        GeometryHash   = 0,
                        LOD            = XbimLOD.LOD100,
                        ReferenceCount = 1,
                        ShapeData      = "2123",
                        BoundingBox    = XbimRect3D.Empty
                    };
                    var shapeGeomLabel = txn.AddShapeGeometry(geomData);

                    //ADD A SHAPE INSTANCE
                    var shapeInstance = new XbimShapeInstance()
                    {
                        ShapeGeometryLabel = shapeGeomLabel
                    };

                    var instanceId = txn.AddShapeInstance(shapeInstance, shapeGeomLabel);
                    Assert.IsTrue(instanceId == 1); //if this is 2 it has failed to clear

                    //ADD A REGIONCOLLECTION
                    var regions = new XbimRegionCollection {
                        ContextLabel = 50
                    };
                    regions.Add(new XbimRegion("region1", XbimRect3D.Empty, 100, XbimMatrix3D.Identity));
                    txn.AddRegions(regions);

                    txn.Commit();
                }
                model.Close();
            }
        }
Example #26
0
 public int AddShapeInstance(XbimShapeInstance shapeInstance, int geometryId)
 {
     return(_inMemoryGeometryStore.AddShapeInstance(shapeInstance, geometryId));
 }
Example #27
0
        public void EsentGeometryStoreBatchTest()
        {
            using (var model = new IO.Esent.EsentModel(ef4))
            {
                model.CreateFrom("SampleHouse4.ifc", null, null, true);
                var store = model.GeometryStore;
                using (var txn = store.BeginInit())
                {
                    for (int i = 0; i < 100; i++)
                    {
                        //ADD A GEOMETRY SHAPE
                        var geomData = new XbimShapeGeometry()
                        {
                            IfcShapeLabel  = 1,
                            Format         = XbimGeometryType.BoundingBox,
                            GeometryHash   = 0,
                            LOD            = XbimLOD.LOD100,
                            ReferenceCount = 1,
                            ShapeData      = "2123",
                            BoundingBox    = XbimRect3D.Empty
                        };
                        var shapeGeomLabel = txn.AddShapeGeometry(geomData);
                    }
                    for (int i = 0; i < 100; i++)
                    {
                        //ADD A SHAPE INSTANCE
                        var shapeInstance = new XbimShapeInstance()
                        {
                            ShapeGeometryLabel = i + 1
                        };

                        var instanceId = txn.AddShapeInstance(shapeInstance, i + 1);
                        Assert.IsTrue(instanceId == i + 1);
                    }
                    for (int i = 0; i < 100; i++)
                    {
                        //ADD A SHAPE INSTANCE
                        var shapeInstance = new XbimShapeInstance()
                        {
                            ShapeGeometryLabel = i + 1
                        };

                        var instanceId = txn.AddShapeInstance(shapeInstance, i + 1);
                        Assert.IsTrue(instanceId == i + 101);
                    }
                    for (int i = 0; i < 100; i++)
                    {
                        //ADD A SHAPE INSTANCE
                        var shapeInstance = new XbimShapeInstance()
                        {
                            ShapeGeometryLabel = i + 1
                        };

                        var instanceId = txn.AddShapeInstance(shapeInstance, i + 1);
                        Assert.IsTrue(instanceId == i + 201);
                    }
                    //ADD A REGIONCOLLECTION
                    var regions = new XbimRegionCollection {
                        ContextLabel = 50
                    };
                    regions.Add(new XbimRegion("region1", XbimRect3D.Empty, 100, XbimMatrix3D.Identity));
                    txn.AddRegions(regions);

                    txn.Commit();
                }
                model.Close();
            }
        }
 public XbimShapeGeometry ShapeGeometryOfInstance(XbimShapeInstance shapeInstance)
 {
     return(ShapeGeometry(shapeInstance.ShapeGeometryLabel));
 }
Example #29
0
        internal static List <Data> Run(Xbim.Ifc.IfcStore model)
        {
            // Specify elements
            List <Xbim.Ifc2x3.Interfaces.IIfcWall> allWalls =
                model.Instances.OfType <Xbim.Ifc2x3.Interfaces.IIfcWall>().ToList(); int a = allWalls.Count();

            List <Xbim.Ifc2x3.Interfaces.IIfcOpeningElement> allOpenigs =
                model.Instances.OfType <Xbim.Ifc2x3.Interfaces.IIfcOpeningElement>().ToList(); int b = allOpenigs.Count();

            List <Xbim.Ifc2x3.Interfaces.IIfcBeamType> allBeams =
                model.Instances.OfType <Xbim.Ifc2x3.Interfaces.IIfcBeamType>().ToList(); int c = allBeams.Count();

            List <Xbim.Ifc2x3.Interfaces.IIfcColumnType> allColumns =
                model.Instances.OfType <Xbim.Ifc2x3.Interfaces.IIfcColumnType>().ToList(); int d = allColumns.Count();

            List <Xbim.Ifc2x3.Interfaces.IIfcElement> ifcElements =
                model.Instances.OfType <Xbim.Ifc2x3.Interfaces.IIfcElement>().ToList(); int e = ifcElements.Count();


            // Extract geometry
            var context = new Xbim3DModelContext(model);

            context.CreateContext();
            var instances = context.ShapeInstances().ToList();
            IEnumerator <XbimShapeInstance> allShapeInstances = instances.GetEnumerator();

            List <Data> allData = new List <Data>();

            while (allShapeInstances.MoveNext())
            {
                // get data from shape instance
                XbimShapeInstance xbimShapeInstance        = allShapeInstances.Current;
                Xbim.Ifc2x3.Interfaces.IIfcElement element = ifcElements.FirstOrDefault(x => x.EntityLabel == xbimShapeInstance.IfcProductLabel);
                string name = element.Name;
                string id   = element.GlobalId;

                var ro          = xbimShapeInstance.Transformation;
                var translation = ro.Translation;
                var decompose   = ro.Decompose(out XbimVector3D scale, out XbimQuaternion rot, out XbimVector3D trans);

                Matrix <double> matrixData = DenseMatrix.OfArray(new double[, ] {
                    { ro.M11, ro.M12, ro.M13, ro.M14 },
                    { ro.M21, ro.M22, ro.M23, ro.M24 },
                    { ro.M31, ro.M32, ro.M33, ro.M34 },
                    { ro.OffsetX, ro.OffsetY, ro.OffsetZ, ro.M44 }
                });
                matrixData = matrixData.Transpose();
                Console.WriteLine(matrixData.ToString());
                XbimRect3D  rect = xbimShapeInstance.BoundingBox;
                XbimPoint3D Min  = rect.Min;
                XbimPoint3D Max  = rect.Max;
                Data        data = new Data
                                   (
                    name,
                    id,
                    new BoundingBox(new XYZ(Min.X, Min.Y, Min.Z), new XYZ(Max.X, Max.Y, Max.Z)),
                    new XYZ(translation.X, translation.Y, translation.Z),
                    matrixData
                                   );
                allData.Add(data);
            }

            return(allData);
        }
Example #30
0
 internal string LabelShapeInstance(XbimShapeInstance s) => $"{s.ShapeGeometryLabel}/{s.InstanceLabel}";