Example #1
0
        /// <summary>
        /// 图形的内缩小
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ElasticityTestBtn_Click(object sender, RoutedEventArgs e)
        {
            List <Geometry2D> gss   = this.drawingKernel.GeometryShapes;
            List <Line2D>     lines = new List <Line2D>();

            foreach (var g in gss)
            {
                if (g is DrawingKernel.Geometries.Primitives.LineGeometry)
                {
                    DrawingKernel.Geometries.Primitives.LineGeometry line = g as DrawingKernel.Geometries.Primitives.LineGeometry;
                    lines.Add(Line2D.Create(line.Start, line.End));
                }
                if (g.GeometryId == "tp")
                {
                    this.drawingKernel.RemoveGeometryShape(g);
                }
            }
            //查找封闭区域
            List <List <Line2D> > nn = GraphicAlgorithm.ClosedLookup(lines, true, true);

            if (nn != null && nn.Count > 0)
            {
                List <Line2D> nt = nn[0];

                List <Line2D> wtn = GraphicAlgorithm.Elastic(nt, -20);

                PolygonGeometry pg = new PolygonGeometry();
                wtn.ForEach(y => { pg.PPoints.Add(y.Start); });
                pg.FillColor  = KernelProperty.GetRandomColor();
                pg.GeometryId = "tp";
                this.drawingKernel.AddShape(pg);
            }
        }
Example #2
0
        private void ClosetTestBtn2_Click(object sender, RoutedEventArgs e)
        {
            //封闭区域测试
            List <Geometry2D> gss = this.drawingKernel.GeometryShapes;

            List <Line2D> lines = new List <Line2D>();

            //转换图形
            foreach (var g in gss)
            {
                if (g is DrawingKernel.Geometries.Primitives.LineGeometry)
                {
                    DrawingKernel.Geometries.Primitives.LineGeometry line = g as DrawingKernel.Geometries.Primitives.LineGeometry;
                    lines.Add(Line2D.Create(line.Start, line.End));
                }
                if (g.GeometryId == "tp")
                {
                    this.drawingKernel.RemoveGeometryShape(g);
                }
            }
            //查找封闭区域
            List <List <Line2D> > nn = GraphicAlgorithm.ClosedLookup(lines, false, true);

            if (nn != null)
            {
                nn.ForEach(x =>
                {
                    PolygonGeometry pg = new PolygonGeometry();
                    x.ForEach(y => { pg.PPoints.Add(y.Start); });
                    pg.FillColor  = KernelProperty.GetRandomColor();
                    pg.GeometryId = "tp";
                    this.drawingKernel.AddShape(pg);
                });
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="allLines">         //allLines是连续的线</param>
        public List <List <Line3D> > FindAllFloorOutLines(List <Line3D> allLines)
        {
            //  List<Line3D> resultDecomposedLinesTT = DecomposeLines(allLines);

            List <Line3D> resultDecomposedLines = new List <Line3D>();

            DecomposeCurves(allLines, resultDecomposedLines);


            //查找外框线
            List <Line3D> sortOutLines = GraphicAlgorithm.ClosedLookup(allLines, true, false).FirstOrDefault();

            List <Line3D> decomposedOutlines = new List <Line3D>();

            foreach (var line in resultDecomposedLines)
            {
                if (IsLineContained(line, sortOutLines))
                {
                    decomposedOutlines.Add(line);
                }
            }

            decomposedOutlines = decomposedOutlines.SortLinesByCounterClockwise(Vector3D.BasisZ);


            List <List <Line3D> > curveArrarys = new List <List <Line3D> >();
            List <Line3D>         usedLines    = new List <Line3D>();

            FindLineArrarys(resultDecomposedLines, decomposedOutlines, usedLines, curveArrarys);

            return(curveArrarys);
        }
        /// <summary>
        /// 进行矩形划分出任意多个矩形元素
        /// </summary>
        /// <param name="lines"></param>
        /// <returns></returns>
        public List <List <Line2D> > Division(List <Line2D> lines)
        {
            if (lines != null && lines.Count > 4)
            {
                //首先要把所有的线打断
                List <Line2D> decomposesLines = GraphicAlgorithm.Decompose(lines);
                //查找最大的封闭区域,且不需要打断
                List <List <Line2D> > large = GraphicAlgorithm.ClosedLookup(decomposesLines, true, false);

                if (large != null && large.Count > 0)
                {
                    //获取所有外部的线段
                    List <Line2D> outerSide = large.FirstOrDefault();

                    //获取所有无端点的线段
                    List <Line2D> weeds = GraphicAlgorithm.WeedLess(decomposesLines);

                    //获取内部线段,要去掉
                    //List<Line2D> innerSide = GraphicAlgorithm.RejectLines(decomposesLines,);
                }
            }
            return(null);
        }
        /// <summary>
        /// 获取重合区域的图形
        /// </summary>
        /// <param name="clines"></param>
        /// <param name="outLines"></param>
        /// <returns></returns>
        private List <List <Line2D> > GetSuperposition(List <Line2D> clines, List <Line2D> outLines)
        {
            List <Line2D> mgslines = new List <Line2D>(clines);

            mgslines.AddRange(outLines);
            //查找到所有最小的封闭区域
            var closelines = GraphicAlgorithm.ClosedLookup(mgslines, false, true);

            List <List <Line2D> > closeIntersets = new List <List <Line2D> >();

            //只要指定区域的一个点,不在任何一个给定的图形内部,则剔除
            closelines.ForEach(x => {
                List <List <Line2D> > nlines = null;
                int r1 = Check(x, clines, out nlines);
                int r2 = Check(x, outLines, out nlines);

                if (r1 == 1 && r2 == 1)
                {
                    closeIntersets.Add(x);
                }
            });

            return(closeIntersets);
        }