Exemplo n.º 1
0
        /// <summary>
        /// Renders the voronoi diagram.
        /// </summary>
        public void Render(Graphics g, ScreenTrans zoom, RenderParameter renderColors)
        {
            this.renderColors = renderColors;

            var points = data.VoronoiPoints;
            var edges  = data.VoronoiEdges;

            if (points != null && edges != null)
            {
                uint   k;
                PointF p0, p1;
                int    n = edges.Length / 2;

                for (int i = 0; i < n; i++)
                {
                    // First endpoint of voronoi edge
                    k  = edges[2 * i];
                    p0 = new PointF(points[2 * k], points[2 * k + 1]);

                    // Second endpoint of voronoi edge
                    k  = edges[2 * i + 1];
                    p1 = new PointF(points[2 * k], points[2 * k + 1]);

                    // Render the edge
                    if (zoom.ViewportContains(p0.X, p0.Y) ||
                        zoom.ViewportContains(p1.X, p1.Y))
                    {
                        p0 = zoom.WorldToScreen(p0.X, p0.Y);
                        p1 = zoom.WorldToScreen(p1.X, p1.Y);

                        g.DrawLine(renderColors.VoronoiLine, p0, p1);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void RenderPoints(Graphics g)
        {
            int    i, k, n;
            PointF pt;

            float[] pts = data.Points;

            // Draw input points
            n = data.NumberOfInputPoints;
            for (i = 0; i < n; i++)
            {
                k = 2 * i;
                if (ignoreBounds || zoom.ViewportContains(pts[k], pts[k + 1]))
                {
                    pt = zoom.WorldToScreen(pts[k], pts[k + 1]);
                    g.FillEllipse(renderColors.Point, pt.X - 1.5f, pt.Y - 1.5f, 3, 3);
                }
            }

            // Draw Steiner points
            n = pts.Length / 2;
            for (; i < n; i++)
            {
                k = 2 * i;
                if (ignoreBounds || zoom.ViewportContains(pts[k], pts[k + 1]))
                {
                    pt = zoom.WorldToScreen(pts[k], pts[k + 1]);
                    g.FillEllipse(renderColors.SteinerPoint, pt.X - 1.5f, pt.Y - 1.5f, 3, 3);
                }
            }
        }