예제 #1
0
 public XbimRegion(string name, XbimRect3D bounds, int population)
 {
     this.Name       = name;
     this.Size       = new XbimVector3D(bounds.SizeX, bounds.SizeY, bounds.SizeZ);
     this.Centre     = bounds.Centroid();
     this.Population = population;
 }
예제 #2
0
        /// <summary>
        /// Adds the given object to the octree.
        /// </summary>
        /// <param name="o"></param>
        /// <param name="bBox"></param>
        public XbimOctree <T> Add(T o, XbimRect3D bBox)
        {
            double      radius = bBox.Radius();
            XbimPoint3D centre = bBox.Centroid();

            if (this.bounds.Contains(bBox))
            {
                return(this.Add(o, bBox, centre, radius));
            }
            return(null);
        }
예제 #3
0
        /// <summary>
        /// Get the space name holding the element
        /// </summary>
        /// <param name="el">IfcElement to get containing space for</param>
        /// <returns>Space name</returns>
        internal string GetSpaceHoldingElement(IfcElement el)
        {
            //see if we have space information, if not fill information list
            if (SpaceBoundingBoxInfo.Count == 0)
            {
                if (ifcSpaces == null)
                {
                    ifcSpaces = Model.Instances.OfType <IfcSpace>().ToList();
                }

                //get Geometry for spaces
                SpaceBoundingBoxInfo = Model.GetGeometryData(XbimGeometryType.BoundingBox)
                                       .Where(bb => bb.IfcTypeId == IfcMetaData.IfcTypeId(typeof(IfcSpace)))
                                       .Select(bb => new SpaceInfo
                {
                    Rectangle = XbimRect3D.FromArray(bb.ShapeData),
                    Matrix    = XbimMatrix3D.FromArray(bb.DataArray2),
                    Name      = ifcSpaces.Where(sp => (sp.EntityLabel == bb.IfcProductLabel)).Select(sp => sp.Name.ToString()).FirstOrDefault()
                }).ToList();
            }


            string spaceName = string.Empty;

            //only if we have any space information
            if (SpaceBoundingBoxInfo.Any())
            {
                //find the IfcElement Bounding Box and To WCS Matrix
                XbimGeometryData elGeoData = Model.GetGeometryData(el, XbimGeometryType.BoundingBox).FirstOrDefault();
                //check to see if we have any geometry within the file
                if (elGeoData == null)
                {
                    return(string.Empty); //No geometry
                }
                XbimRect3D   elBoundBox    = XbimRect3D.FromArray(elGeoData.ShapeData);
                XbimMatrix3D elWorldMatrix = XbimMatrix3D.FromArray(elGeoData.DataArray2);
                //Get object space top and bottom points of the bounding box
                List <XbimPoint3D> elBoxPts = new List <XbimPoint3D>();
                elBoxPts.Add(new XbimPoint3D(elBoundBox.X, elBoundBox.Y, elBoundBox.Z));
                elBoxPts.Add(new XbimPoint3D(elBoundBox.X + elBoundBox.SizeX, elBoundBox.Y + elBoundBox.SizeY, elBoundBox.Z + elBoundBox.SizeZ));
                elBoxPts.Add(elBoundBox.Centroid());

                //convert points of the bounding box to WCS
                IEnumerable <XbimPoint3D> elBoxPtsWCS = elBoxPts.Select(pt => elWorldMatrix.Transform(pt));
                //see if we hit any spaces
                spaceName = GetSpaceFromPoints(elBoxPtsWCS);
                //if we failed to get space on min points then use the remaining corner points
                if (string.IsNullOrEmpty(spaceName))
                {
                    XbimPoint3D elMinPt = elBoxPts[0];
                    XbimPoint3D elMaxPt = elBoxPts[1];
                    //elBoxPts.Clear(); //already tested points in list so clear them

                    //Extra testing on remaining corner points on the top and bottom plains
                    elBoxPts.Add(new XbimPoint3D(elMaxPt.X, elMaxPt.Y, elMinPt.Z));
                    elBoxPts.Add(new XbimPoint3D(elMaxPt.X, elMinPt.Y, elMinPt.Z));
                    elBoxPts.Add(new XbimPoint3D(elMinPt.X, elMaxPt.Y, elMinPt.Z));
                    elBoxPts.Add(new XbimPoint3D((elMaxPt.X - elMinPt.X) / 2.0, (elMaxPt.Y - elMinPt.Y) / 2.0, elMinPt.Z)); //centre face point

                    elBoxPts.Add(new XbimPoint3D(elMinPt.X, elMinPt.Y, elMaxPt.Z));
                    elBoxPts.Add(new XbimPoint3D(elMaxPt.X, elMinPt.Y, elMaxPt.Z));
                    elBoxPts.Add(new XbimPoint3D(elMinPt.X, elMaxPt.Y, elMaxPt.Z));
                    elBoxPts.Add(new XbimPoint3D((elMaxPt.X - elMinPt.X) / 2.0, (elMaxPt.Y - elMinPt.Y) / 2.0, elMaxPt.Z)); //centre face point
                    //convert points of the bounding box to WCS
                    elBoxPtsWCS = elBoxPts.Select(pt => elWorldMatrix.Transform(pt));
                    //see if we hit any spaces
                    spaceName = GetSpaceFromPoints(elBoxPtsWCS);
                }
                if (string.IsNullOrEmpty(spaceName))
                {
                    //Get tolerance size from element, 1% of smallest side size
                    double tol = elBoundBox.SizeX * 0.001;
                    if ((elBoundBox.SizeY * 0.001) < tol)
                    {
                        tol = elBoundBox.SizeY * 0.001;
                    }
                    if ((elBoundBox.SizeZ * 0.001) < tol)
                    {
                        tol = elBoundBox.SizeZ * 0.001;
                    }
                    if ((tol == 0.0) && //if tol 0.0
                        ((Context.WorkBookUnits.LengthUnit.Equals("meters", StringComparison.OrdinalIgnoreCase)) ||
                         (Context.WorkBookUnits.LengthUnit.Equals("metres", StringComparison.OrdinalIgnoreCase))
                        )
                        )
                    {
                        tol = 0.001;
                    }

                    spaceName = GetSpaceFromClosestPoints(elBoxPtsWCS, tol);
                }
            }
            return(spaceName);
        }
        private void ProcessTree()
        {
            double maxSize    = SamplerUtil.Max(_boundingBox.SizeX, _boundingBox.SizeY, _boundingBox.SizeZ);
            double _looseNess = 1.2;

            _tree = new XbimOctree <int>(maxSize / _looseNess, ScaleOrder, _looseNess, _boundingBox.Centroid());

            foreach (int label in _bboxBuffer.Keys)
            {
                _tree.Add(label, _bboxBuffer[label]);
            }

            XbimRect3D treeBox = _tree.ContentBounds();

            if (SamplerUtil.BBoxEqual(treeBox, _boundingBox))
            {
                log.Info("Tree was successfully populated");
            }
            else
            {
                log.Error("Tree bounds do not match the boundingbox of the model !");
            }
        }
        public IfcElementSignature(IfcElement elem, Xbim3DModelContext geometryContext)
        {
            XbimMatrix3D m3D = XbimMatrix3D.Identity;

            if (elem.ObjectPlacement != null)
            {
                m3D = elem.ObjectPlacement.ToMatrix3D();
            }
            var geomManager = elem.ModelOf.GeometryManager;

            ShapeId = 0;
            //get the 3D shape
            var shapes = geometryContext.ShapeInstancesOf(elem);

            if (shapes.Any())
            {
                XbimRect3D r3D = XbimRect3D.Empty;
                foreach (var shape in shapes)
                {
                    if (r3D.IsEmpty)
                    {
                        r3D = shape.BoundingBox;
                    }
                    else
                    {
                        r3D.Union(shape.BoundingBox);
                    }
                }
                XbimPoint3D p3D = r3D.Centroid();
                p3D = m3D.Transform(p3D);
                BoundingSphereRadius = r3D.Length() / 2;
                CentroidX            = p3D.X;
                CentroidY            = p3D.Y;
                CentroidZ            = p3D.Z;
            }
            //get the defining type
            IfcTypeObject     ot       = elem.GetDefiningType();
            IfcMaterialSelect material = elem.GetMaterial();
            //sort out property definitions
            List <IfcPropertySet> psets = elem.GetAllPropertySets();

            PropertyCount = psets.SelectMany(p => p.HasProperties).Count();
            psets.Sort(new PropertySetNameComparer());
            foreach (var pset in psets)
            {
                PropertySetNamesKey ^= pset.Name.GetHashCode();
            }
            List <IfcPropertySingleValue> props = psets.SelectMany(p => p.HasProperties).OfType <IfcPropertySingleValue>().ToList();

            props.Sort(new PropertySingleValueNameComparer());
            foreach (var prop in props)
            {
                PropertyNamesKey ^= prop.Name.GetHashCode();
            }
            props.Sort(new PropertySingleValueValueComparer());
            foreach (var prop in props)
            {
                PropertyValuesKey ^= prop.NominalValue.GetHashCode();
            }
            ModelID       = elem.EntityLabel;
            SchemaType    = elem.GetType().Name;
            DefinedTypeId = (ot == null ? "" : ot.GlobalId.ToPart21);
            GlobalId      = elem.GlobalId;
            OwningUser    = elem.OwnerHistory.LastModifyingUser != null?elem.OwnerHistory.LastModifyingUser.ToString() : elem.OwnerHistory.OwningUser.ToString();

            Name               = elem.Name ?? "";
            Description        = elem.Description ?? "";
            HasAssignmentsKey  = elem.HasAssignments.Count();
            IsDecomposedByKey  = elem.IsDecomposedBy.Count();
            DecomposesKey      = elem.Decomposes.Count();
            HasAssociationsKey = elem.HasAssociations.Count();
            ObjectType         = elem.ObjectType ?? "";
            MaterialName       = material == null ? "" : material.Name;
            ReferencedByKey    = elem.ReferencedBy.Count();
            Tag = elem.Tag ?? "";
            HasStructuralMemberKey    = elem.HasStructuralMember.Count();
            FillsVoidsKey             = elem.FillsVoids.Count();
            ConnectedToKey            = elem.ConnectedTo.Count();
            HasCoveringsKey           = elem.HasCoverings.Count();
            HasProjectionsKey         = elem.HasProjections.Count();
            ReferencedInStructuresKey = elem.ReferencedInStructures.Count();
            HasPortsKey                = elem.HasPorts.Count();
            HasOpeningsKey             = elem.HasOpenings.Count();
            IsConnectionRealizationKey = elem.IsConnectionRealization.Count();
            ProvidesBoundariesKey      = elem.ProvidesBoundaries.Count();
            ConnectedFromKey           = elem.ConnectedFrom.Count();
            ContainedInStructureKey    = elem.ContainedInStructure.Count();
        }