Example #1
0
        public static void FindOverlapingPolylines(ObjectId[] objectIds)
        {
            // 1. 建立拓扑关系
            var topoData = BuildTopology(objectIds);

            // 2. 清理掉所有的临时图形
            PolylineTransientGraphics.ClearTransientGraphics();

            var findOverlap = new FindOverlap();

            // 3. 查找重叠的几何图元
            var polygonOverlaps = FindOverlappingGeometries(findOverlap, topoData, objectIds);

            // 4. 画出所有几何图元
            DrawOverlappingGeometries(topoData, polygonOverlaps);

            findOverlap.ReleaseRegions();

            // 5. 输出到窗口
            var document = Application.DocumentManager.MdiActiveDocument;

            document.Editor.WriteMessage(String.Format("一共有{0}处重叠", polygonOverlaps.GeometryOverlaps.Count));

            OutputMessage(polygonOverlaps.CannotCreateRegions, "不能造区");
            OutputMessage(polygonOverlaps.CannotBooleanRegions, "不能作布尔运算");
            OutputMessage(topoData.WrongEnvelopeObjects, "包围盒计算错误,可能有重复点");
            OutputMessage(topoData.InvalidObjects, "内部拓扑错误");
        }
Example #2
0
        public static PolygonOverlaps FindPolygonOverlaps(ObjectId[] objectIds)
        {
            // 1. 建立拓扑关系
            var topoData    = BuildTopology(objectIds);
            var findOverlap = new FindOverlap();

            // 3. 查找重叠的几何图元
            var polygonOverlaps = FindOverlappingGeometries(findOverlap, topoData, objectIds);

            return(polygonOverlaps);
        }
Example #3
0
        private static PolygonOverlaps FindOverlappingGeometries(FindOverlap findOverlap, TopologyData topoData, ObjectId[] objectIds)
        {
            var overlap      = new PolygonOverlaps();
            var handledPairs = new HashSet <string>();
            var count        = 0;

            foreach (var geom in topoData.Geometries)
            {
                // 先用NTS建立拓扑,初查,哪些是重叠的,非常快速。
                var nearGeoms = GetNearGeometries(geom, topoData.Quadtree);
                var thisObjId = (ObjectId)geom.UserData;

                var ids = new ObjectIdCollection();
                foreach (var geometry in nearGeoms)
                {
                    var nearObjId = (ObjectId)geometry.UserData;
                    if (nearObjId != thisObjId)
                    {
                        // 记录当前处理的object对,这样避免重复计算一对相邻的多边形
                        var handle  = thisObjId + "_" + nearObjId;
                        var handle2 = nearObjId + "_" + thisObjId;

                        //var thisGeometry = topoData.GeometryDictionary[thisObjId];
                        if (!handledPairs.Contains(handle) && !handledPairs.Contains(handle2))
                        {
                            // 先记录下来,处理过的,后面就不再处理了
                            handledPairs.Add(handle);
                            // var nearGeometry = topoData.GeometryDictionary[nearObjId];
                            try
                            {
                                //var intersect = thisGeometry.Overlaps(nearGeometry);
                                //if (intersect)
                                {
                                    count++;
                                    // 在NTS里面也许是接边的也算重叠的
                                    // 再通过ACAD面域的计算,相交,如果有交集,则认为是有重叠的,而且画出交集。
                                    var regionIntersection = CadUtils.GetIntersectionPart(thisObjId, nearObjId);

                                    //var region = findOverlap.GetIntersectionPart(thisObjId, nearObjId);
                                    if (regionIntersection != null)
                                    {
                                        // 相交了,有相交的Region
                                        if (regionIntersection.ObjectId1.IsNull)
                                        {
                                            ids.Add(nearObjId);
                                            overlap.GeometryOverlaps.Add(new GeometryOverlap()
                                            {
                                                ThisGeometry    = thisObjId,
                                                ThatGeometry    = nearObjId,
                                                IntersectRegion = regionIntersection.Region
                                            });
                                        }
                                        // 没有相交,可能是造区错误
                                        else if (regionIntersection.ObjectId1.IsNull)
                                        {
                                            overlap.CannotCreateRegions.Add(regionIntersection.ObjectId1);
                                        }
                                        // Object1/Object2
                                        // 造区直接boolean运算发生错误
                                        // 面域上的布尔运算失败 不同体顶点的重合 face_face_ints
                                        else if (!regionIntersection.ObjectId1.IsNull && !regionIntersection.ObjectId2.IsNull)
                                        {
                                            overlap.CannotBooleanRegions.Add(
                                                new KeyValuePair <ObjectId, ObjectId>(regionIntersection.ObjectId1,
                                                                                      regionIntersection.ObjectId2));
                                        }
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                System.Diagnostics.Trace.WriteLine(ex.Message);
                            }
                        }
                    }
                }
            }
            System.Diagnostics.Trace.WriteLine(count);
            return(overlap);
        }