예제 #1
0
        /// <summary>
        /// Get the space name if any of the points are within the space
        /// </summary>
        /// <param name="PtsWCS">list of points</param>
        /// <param name="SpaceBoundingBoxInfo"></param>
        /// <returns>Space name</returns>
        internal static string GetSpaceFromPoints(IEnumerable <XbimPoint3D> PtsWCS, IEnumerable <SpaceInfo> SpaceBoundingBoxInfo)
        {
            //holder for space names, could be more then one so a list is used
            List <string> spaceNames = new List <string>();

            foreach (SpaceInfo spGeoData in SpaceBoundingBoxInfo)
            {
                //get each space bounding box and To WCS Matrix
                XbimRect3D   spBoundBox    = spGeoData.Rectangle;
                XbimMatrix3D spWorldMatrix = spGeoData.Matrix;
                String       spName        = spGeoData.Name;
                //we need to transform the element max and min points back into the spaces Object Space so we can test on Bounding Box rectangle
                spWorldMatrix.Invert();
                IEnumerable <XbimPoint3D> elBoxPtsOCS = PtsWCS.Select(pt => spWorldMatrix.Transform(pt));
                //check if element space object points are contained fully within the space bounding box rectangle
                IEnumerable <XbimPoint3D> hitPts = elBoxPtsOCS.Where(pt => spBoundBox.Contains(pt));
                if (hitPts.Any() &&
                    (hitPts.Count() == elBoxPtsOCS.Count())
                    )
                {
                    spaceNames.Add(spName);
                    break;             //all element point are contained in one space so kill loop
                }
                else if (hitPts.Any()) //one or more point is contained in space and continue in case we have an element over several spaces
                {
                    if (!spaceNames.Contains(spName))
                    {
                        spaceNames.Add(spName);
                    }
                }
            }
            if (spaceNames.Count > 0)
            {
                return(string.Join(", ", spaceNames));
            }
            else
            {
                return(string.Empty);
            }
        }