Exemple #1
0
            public void Remove(FrontierPt _fPt, Delaunay.Triangle.HalfEdge _newEdgeRight)
            {
                var fpLeft  = _fPt.Left;
                var fpRight = _fPt.Right;

                fpLeft.Right = fpRight;
                fpRight.Left = fpLeft;

                fpLeft.EdgeRight = _newEdgeRight;
                CS.m_PolPos[_fPt.VertIdx].thetaGroup.Remove(_fPt);
            }
        private static HashSet <Delaunay.Triangle> RecGetTris(Delaunay.Triangle.HalfEdge _edge, int _depth)
        {
            var tris = new HashSet <Delaunay.Triangle> {
                _edge.Triangle
            };

            if (_depth - 1 == 0)
            {
                return(tris);
            }

            if (_edge.NextEdge.Twin != null)
            {
                tris.UnionWith(RecGetTris(_edge.NextEdge.Twin, _depth - 1));
            }
            if (_edge.NextEdge.NextEdge.Twin != null)
            {
                tris.UnionWith(RecGetTris(_edge.NextEdge.NextEdge.Twin, _depth - 1));
            }

            return(tris);
        }
        public static void Visualize(string _fileName, Delaunay.Triangle.HalfEdge _edge, int _depth = 6)
        {
            if (!Enabled)
            {
                return;
            }
            var trisToRender = new HashSet <Delaunay.Triangle> {
                _edge.Triangle
            };

            if (_edge.Twin != null)
            {
                trisToRender.UnionWith(RecGetTris(_edge.Twin, _depth));
            }

            if (_edge.NextEdge.Twin != null)
            {
                trisToRender.UnionWith(RecGetTris(_edge.NextEdge.Twin, _depth));
            }

            if (_edge.NextEdge.NextEdge.Twin != null)
            {
                trisToRender.UnionWith(RecGetTris(_edge.NextEdge.NextEdge.Twin, _depth));
            }

            var triList = trisToRender.ToList();
            var bounds  = new Rect(Rect.zero);
            var pts     = triList[0].D.Points;
            var tris    = new Vector2[triList.Count * 3];

            for (var tIdx = 0; tIdx < triList.Count; ++tIdx)
            {
                tris[tIdx * 3]     = pts[triList[tIdx].Edge0.OriginIdx];
                tris[tIdx * 3 + 1] = pts[triList[tIdx].Edge1.OriginIdx];
                tris[tIdx * 3 + 2] = pts[triList[tIdx].Edge2.OriginIdx];
            }

            var minX = tris.Min(_tri => _tri.x);
            var maxX = tris.Max(_tri => _tri.x);
            var minY = tris.Min(_tri => _tri.y);
            var maxY = tris.Max(_tri => _tri.y);

            for (var tIdx = 0; tIdx < triList.Count; ++tIdx)
            {
                tris[tIdx] = new Vector2(tris[tIdx].x - minX, tris[tIdx].y - minY);
            }

            var scale  = 2f;
            var extend = 2f;
            var bitmap = new Bitmap((int)((maxX - minX) * extend) * (int)scale,
                                    (int)((maxY - minY) * extend) * (int)scale);

            Func <Vector2, Vector2> getBMPos = _vec =>
            {
                var vx = (_vec.x - minX + extend / 4f) * scale;
                var vy = (_vec.y - minY + extend / 4f) * scale;
                return(new Vector2(vx, vy));
            };

            //Draw Mesh
            foreach (var tri in triList)
            {
                for (var idx = 0; idx < 3; ++idx)
                {
                    var edge = tri.Edge(idx);
                    var x1   = (edge.OriginPos.x - minX + extend / 4f) * scale;
                    var y1   = (edge.OriginPos.y - minY + extend / 4f) * scale;
                    var x2   = (edge.NextEdge.OriginPos.x - minX + extend / 4f) * scale;
                    var y2   = (edge.NextEdge.OriginPos.y - minY + extend / 4f) * scale;

                    using (var g = Graphics.FromImage(bitmap))
                    {
                        g.SmoothingMode     = SmoothingMode.None;
                        g.InterpolationMode = InterpolationMode.Low;
                        g.PixelOffsetMode   = PixelOffsetMode.None;
                        var pen = new Pen(m_ColorMesh);
                        g.DrawLine(pen, x1, y1, x2, y2);

                        if (!showVertIdxs)
                        {
                            continue;
                        }
                        var textRect = new RectangleF(new PointF(x1, y1), new SizeF(60, 20));

                        var txtBrush = new SolidBrush(RandColor(rnd));


                        g.DrawString(edge.OriginIdx.ToString(), new Font("Small Fonts", fontSize), txtBrush,
                                     textRect);
                    }
                }
            }

            //Draw CircumCircles

            /*
             * foreach (var tri in triList)
             * {
             *  var ccos = getBMPos(new Vector2f(tri.CCX, tri.CCY));
             *  var r = (float) Math.Sqrt(tri.CCRSq) * scale;
             *  var rul = new Vector2f(ccos.x - r, ccos.y - r);
             *  var rect = new Rectangle((int)rul.x, (int)rul.y, (int)(2 * r), (int)(2 * r));
             *  using (var g = Graphics.FromImage(bitmap))
             *  {
             *
             *
             *      g.SmoothingMode = SmoothingMode.None;
             *      g.InterpolationMode = InterpolationMode.Low;
             *      g.PixelOffsetMode = PixelOffsetMode.None;
             *
             *      var pen = new Pen(m_ColorCircles);
             *      g.DrawEllipse(pen, (ccos.x - r), (ccos.y - r), r * 2, r * 2);
             *      //g.DrawRectangle(pen, rect);
             *      //g.DrawLine(pen, center.x, center.y, rect.Left, rect.Top);
             *  }
             * }
             */

            var path = AppDomain.CurrentDomain.BaseDirectory + _fileName + ".png";

            bitmap.Save(path);

            //Log Tris
            //LogTri(_fileName + ".txt", triList.ToArray());
        }
Exemple #4
0
 public FrontierPt(Delaunay.Triangle.HalfEdge _edge, CircleSweep _cs)
 {
     EdgeRight = _edge;
     CS        = _cs;
 }