コード例 #1
0
 public static System.Windows.Point fromMyPointToSystemPoint(Point point)
 {
     return(new System.Windows.Point(point.X, point.Y));
 }
コード例 #2
0
        protected override void ProcessContext(Canvas canvas, List <Point> points)
        {
            if (points.Count < 3)
            {
                return;
            }

            var options = new ConstraintOptions();

            options.ConformingDelaunay = true;

            var quality = new QualityOptions();

            quality.MinimumAngle = MinAngel;
            quality.MaximumArea  = MaxSquare;

            var polygon = new TriangleNet.Geometry.Polygon();

            points.ForEach(p => polygon.Add(new Vertex(p.X, p.Y)));
            for (int i = 0; i < points.Count - 1; i++)
            {
                polygon.Add(new Segment(new Vertex(points[i].X, points[i].Y), new Vertex(points[i + 1].X, points[i + 1].Y)));
            }
            Point last  = points.LastOrDefault();
            Point first = points.FirstOrDefault();

            polygon.Add(new Segment(new Vertex(last.X, last.Y), new Vertex(first.X, first.Y)));
            var mesh = polygon.Triangulate(options, quality);

            this.mesh = mesh;
            if (mesh != null)
            {
                mesh.Refine(quality, true);
            }
            this.mesh.Renumber();
            foreach (ITriangle triangle in mesh.Triangles)
            {
                Point p1 = new Point
                {
                    X  = (triangle.GetVertex(0).X + 1) * 100,
                    Y  = (triangle.GetVertex(0).Y + 1) * 100,
                    ID = triangle.GetVertex(0).ID
                };
                Point p2 = new Point
                {
                    X  = (triangle.GetVertex(1).X + 1) * 100,
                    Y  = (triangle.GetVertex(1).Y + 1) * 100,
                    ID = triangle.GetVertex(1).ID
                };
                Point p3 = new Point
                {
                    X  = (triangle.GetVertex(2).X + 1) * 100,
                    Y  = (triangle.GetVertex(2).Y + 1) * 100,
                    ID = triangle.GetVertex(2).ID
                };
                Triangle myTriangle = new Triangle
                {
                    Points = new List <Point> {
                        p1, p2, p3
                    },
                    SegmentId = triangle.ID
                };

                myTriangle.Stroke      = Brushes.Black;
                myTriangle.MouseEnter += (sender, e) => { MouseEnterAction(sender, e); };
                myTriangle.MouseLeave += (sender, e) => { MouseLeaveAction(sender, e); };
                myTriangle.MouseDown  += (sender, e) => { MouseUp(sender, e); };
                if (canvas != null)
                {
                    canvas.Children.Add(myTriangle);
                }
            }
        }