Exemplo n.º 1
0
        private static TopologyData BuildTopology(ObjectId[] objectIds)
        {
            var topoData = new TopologyData();
            var database = objectIds[0].Database;

            using (var tr = database.TransactionManager.StartTransaction())
            {
                var reader = new DwgReader();
                foreach (ObjectId objectId in objectIds)
                {
                    // 如果没有
                    var curve = tr.GetObject(objectId, OpenMode.ForRead) as Curve;
                    if (curve == null || !curve.Visible)
                    {
                        continue;
                    }

                    // 图层关闭,继续,因为有可能是图幅层
                    var layer = (LayerTableRecord)tr.GetObject(curve.LayerId, OpenMode.ForRead);
                    if (layer.IsOff)
                    {
                        continue;
                    }

                    // 目前只处理封闭的和大于3的多边形
                    // http://192.168.0.6:8080/browse/LCLIBCAD-903
                    // 否则会弹出points must form a closed linestring异常
                    if (curve.Closed &&
                        reader.NumberOfVerticesMoreThan3(curve))
                    {
                        var geom = reader.ReadCurveAsPolygon(tr, curve) as IGeometry;
                        geom = geom.Buffer(0);
                        if (!geom.IsValid)
                        {
                            topoData.InvalidObjects.Add(objectId);
                            System.Diagnostics.Trace.WriteLine(geom.ToString());
                        }
                        // 没有包围盒,无法进入空间索引
                        else if (geom.EnvelopeInternal.IsNull)
                        {
                            topoData.WrongEnvelopeObjects.Add(objectId);
                        }
                        else
                        {
                            //geom = SimpleGeometryPrecisionReducer.Reduce(geom, pmFixed3);
                            geom.UserData = objectId;
                            topoData.Quadtree.Insert(geom.EnvelopeInternal, geom);
                            topoData.Geometries.Add(geom);
                            topoData.GeometryDictionary[objectId] = geom;
                        }
                    }
                }

                tr.Commit();
            }

            return(topoData);
        }
Exemplo n.º 2
0
        public static void DrawOverlappingGeometries(TopologyData topoData, PolygonOverlaps overlaps)
        {
            if (!overlaps.GeometryOverlaps.Any())
            {
                return;
            }

            var regions  = new List <Region>();
            var database = overlaps.GeometryOverlaps[0].ThisGeometry.Database;

            // 读取CAD图元,并且绘制出来
            foreach (var overlap in overlaps.GeometryOverlaps)
            {
                regions.Add(overlap.IntersectRegion);
            }

            // 画出来
            PolylineTransientGraphics.CreateTransientRegions(database, regions);
        }
Exemplo n.º 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);
        }