Exemplo n.º 1
0
        public override void Check(IEnumerable <ObjectId> selectedObjectIds)
        {
            var watch = Stopwatch.StartNew();

            if (!selectedObjectIds.Any())
            {
                return;
            }

            var database = Editor.Document.Database;

            using (var transaction = database.TransactionManager.StartTransaction())
            {
                var curve2dBspBuilder = new Curve2dBspBuilder(selectedObjectIds, transaction);
                _crossingInfos = curve2dBspBuilder.SearchDuplicateEntities();

                transaction.Commit();
            }

            //int count = 0;
            //foreach (var curveCrossingInfo in _crossingInfos)
            //{
            //    count += curveCrossingInfo.IntersectPoints.Length;
            //}
            //Editor.WriteMessage("\n共{0}个交点", count);

            // the code that you want to measure comes here
            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;

            Editor.WriteMessage("\n查找重复实体花费时间{0}毫秒", elapsedMs);
        }
Exemplo n.º 2
0
        public static Dictionary <ObjectId, List <Point3d> > CalculateIntersection(IEnumerable <ObjectId> objectIds,
                                                                                   bool includeInline, Database database)
        {
            IEnumerable <IntersectionInfo> intersections = null;
            // 调低计算精度,否则有些交叉因为精度问题算不出来
            var oldTolerance = DoubleExtensions.STolerance;

            DoubleExtensions.STolerance = 1e-05;
            using (var tolerance = new SafeToleranceOverride(DoubleExtensions.STolerance))
                using (var transaction = database.TransactionManager.StartTransaction())
                {
                    // Build curve bsp tree and search all intersections
                    var curve2dBspBuilder = new Curve2dBspBuilder(objectIds, transaction);
                    intersections = curve2dBspBuilder.SearchRealIntersections(includeInline: includeInline);
                    transaction.Commit();
                }
            // 恢复默认的计算精度值
            DoubleExtensions.STolerance = oldTolerance;

            // Group intersections by object id.
            var group = new Dictionary <ObjectId, List <Point3d> >();

            foreach (var intersection in intersections)
            {
                if (!group.ContainsKey(intersection.SourceId))
                {
                    group[intersection.SourceId] = new List <Point3d>();
                }
                var points = group[intersection.SourceId];
                if (!points.Contains(intersection.IntersectPoint))
                {
                    points.Add(intersection.IntersectPoint);
                }

                if (intersection.SourceId == intersection.TargetId)
                {
                    continue;
                }

                if (!group.ContainsKey(intersection.TargetId))
                {
                    group[intersection.TargetId] = new List <Point3d>();
                }
                points = group[intersection.TargetId];
                if (!points.Contains(intersection.IntersectPoint))
                {
                    points.Add(intersection.IntersectPoint);
                }
            }
            return(group);
        }