Esempio n. 1
0
        public void MatrixArrayConversion()
        {
            var m = XbimMatrix3D.CreateTranslation(10, 20, 30);

            m.RotateAroundXAxis(Math.PI / 4);
            m.Scale(.05);

            var outM  = m.ToArray(true);
            var rback = XbimMatrix3D.FromArray(outM);

            Assert.AreEqual(rback.M11, m.M11);
            Assert.AreEqual(rback.M12, m.M12);
            Assert.AreEqual(rback.M13, m.M13);
            Assert.AreEqual(rback.M14, m.M14);

            Assert.AreEqual(rback.M21, m.M21);
            Assert.AreEqual(rback.M22, m.M22);
            Assert.AreEqual(rback.M23, m.M23);
            Assert.AreEqual(rback.M24, m.M24);

            Assert.AreEqual(rback.M31, m.M31);
            Assert.AreEqual(rback.M32, m.M32);
            Assert.AreEqual(rback.M33, m.M33);
            Assert.AreEqual(rback.M34, m.M34);

            Assert.AreEqual(rback.OffsetX, m.OffsetX);
            Assert.AreEqual(rback.OffsetY, m.OffsetY);
            Assert.AreEqual(rback.OffsetZ, m.OffsetZ);
            Assert.AreEqual(rback.M44, m.M44);
        }
Esempio n. 2
0
        internal void SetCenterInMeters(XbimVector3D modelTranslation)
        {
            var translation = XbimMatrix3D.CreateTranslation(modelTranslation * OneMeter);
            var scaling     = XbimMatrix3D.CreateScale(1 / OneMeter);

            Transfrom = translation * scaling;
        }
Esempio n. 3
0
        /// <summary>
        /// calculates the tansform to convert models to metres and centre on the most populated region, includes reference models
        /// </summary>
        /// <returns></returns>
        private XbimMatrix3D GetGlobalModelTransform()
        {
            XbimRegion largest = _context.GetLargestRegion();

            XbimRect3D bb = XbimRect3D.Empty;

            if (largest != null)
            {
                bb = new XbimRect3D(largest.Centre, largest.Centre);
            }

            foreach (var refModel in _context.Model.ReferencedModels)
            {
                XbimRegion         r;
                Xbim3DModelContext refContext = new Xbim3DModelContext(refModel.Model);
                r = refContext.GetLargestRegion();
                if (r != null)
                {
                    if (bb.IsEmpty)
                    {
                        bb = new XbimRect3D(r.Centre, r.Centre);
                    }
                    else
                    {
                        bb.Union(r.Centre);
                    }
                }
            }
            XbimPoint3D p = bb.Centroid();
            var         modelTranslation = new XbimVector3D(-p.X, -p.Y, -p.Z);
            double      metreFactor      = 1.0 / _context.Model.ModelFactors.OneMetre;

            return(XbimMatrix3D.CreateTranslation(modelTranslation) * XbimMatrix3D.CreateScale(metreFactor));
        }
Esempio n. 4
0
        /// <summary>
        /// Creates the transform based on the model dimensional unit (oneMeter)
        /// </summary>
        /// <param name="modelTranslation">The translation is expressed in meters.</param>
        internal void PrepareTransform(XbimVector3D modelTranslation)
        {
            var translation = XbimMatrix3D.CreateTranslation(modelTranslation * OneMeter);
            var scaling     = XbimMatrix3D.CreateScale(1 / OneMeter);

            Transform = translation * scaling;
        }
Esempio n. 5
0
        /// <summary>
        /// If translation is defined, returns matrix translated by the vector
        /// </summary>
        /// <param name="matrix">Input matrix</param>
        /// <param name="translation">Translation</param>
        /// <returns>Translated matrix</returns>
        private static XbimMatrix3D Translate(XbimMatrix3D matrix, IVector3D translation)
        {
            if (translation == null)
            {
                return(matrix);
            }
            var translationMatrix = XbimMatrix3D.CreateTranslation(translation.X, translation.Y, translation.Z);

            return(XbimMatrix3D.Multiply(matrix, translationMatrix));
        }
        private void worker_DoWork_IFC4(IfcStore xModel, List <Xbim.Ifc4.UtilityResource.IfcGloballyUniqueId> elementIdsList)
        {
            // Loop through Entities and visualze them in the viewport
            var res = new HashSet <Xbim.Ifc4.UtilityResource.IfcGloballyUniqueId>(elementIdsList);

            List <ModelUIElement3D> elementList = new List <ModelUIElement3D>();

            foreach (var item in xModel.Instances.OfType <Xbim.Ifc4.Kernel.IfcProduct>())
            {
                if (res.Contains(item.GlobalId))
                {
                    XbimModelPositioningCollection ModelPositions = new XbimModelPositioningCollection();

                    short userDefinedId = 0;
                    xModel.UserDefinedId = userDefinedId;


                    ModelPositions.AddModel(xModel.ReferencingModel);

                    if (xModel.IsFederation)
                    {
                        foreach (var refModel in xModel.ReferencedModels)
                        {
                            refModel.Model.UserDefinedId = ++userDefinedId;
                            var v = refModel.Model as IfcStore;
                            if (v != null)
                            {
                                ModelPositions.AddModel(v.ReferencingModel);
                            }
                        }
                    }
                    var ModelBounds = ModelPositions.GetEnvelopeInMeters();

                    var          p = ModelBounds.Centroid();
                    var          _modelTranslation = new XbimVector3D(-p.X, -p.Y, -p.Z);
                    var          oneMeter          = xModel.ModelFactors.OneMetre;
                    var          translation       = XbimMatrix3D.CreateTranslation(_modelTranslation * oneMeter);
                    var          scaling           = XbimMatrix3D.CreateScale(1 / oneMeter);
                    XbimMatrix3D Transform         = translation * scaling;


                    var m = new MeshGeometry3D();
                    GetGeometryFromXbimModel_IFC4(m, item, Transform);
                    var mat = GetStyleFromXbimModel_IFC4(item);

                    var mb = new MeshBuilder(false, false);


                    var element = VisualizeMesh_IFC4(mb, m, mat, item);
                    elementList.Add(element);
                }

                // Show whole building with opacity 0.03
                else
                {
                    XbimModelPositioningCollection ModelPositions = new XbimModelPositioningCollection();

                    short userDefinedId = 0;
                    xModel.UserDefinedId = userDefinedId;


                    ModelPositions.AddModel(xModel.ReferencingModel);

                    if (xModel.IsFederation)
                    {
                        foreach (var refModel in xModel.ReferencedModels)
                        {
                            refModel.Model.UserDefinedId = ++userDefinedId;
                            var v = refModel.Model as IfcStore;
                            if (v != null)
                            {
                                ModelPositions.AddModel(v.ReferencingModel);
                            }
                        }
                    }
                    var ModelBounds = ModelPositions.GetEnvelopeInMeters();

                    var          p = ModelBounds.Centroid();
                    var          _modelTranslation = new XbimVector3D(-p.X, -p.Y, -p.Z);
                    var          oneMeter          = xModel.ModelFactors.OneMetre;
                    var          translation       = XbimMatrix3D.CreateTranslation(_modelTranslation * oneMeter);
                    var          scaling           = XbimMatrix3D.CreateScale(1 / oneMeter);
                    XbimMatrix3D Transform         = translation * scaling;
                    var          m = new MeshGeometry3D();
                    GetGeometryFromXbimModel_IFC4(m, item, Transform);
                    var mat = GetStyleFromXbimModel_IFC4(item, 0.03);

                    var mb = new MeshBuilder(false, false);

                    var element = VisualizeMesh_IFC4(mb, m, mat, item);
                    elementList.Add(element);
                }
            }
            foreach (var element in elementList)
            {
                if (element != null)
                {
                    _viewPort.Children.Add(element);
                }
            }
        }