/// <summary>
        /// Renders the mesh.
        /// </summary>
        public void Render(Graphics g, Projection zoom)
        {
            this.zoom = zoom;

            if (mesh.Edges != null)
            {
                this.RenderSelectedTriangle(g);
                this.RenderEdges(g);
                this.RenderTriangleIds(g);
            }
            else if (mesh.Triangles != null)
            {
                this.RenderTriangles(g);
            }

            if (mesh.Segments != null)
            {
                this.RenderSegments(g);
            }

            RenderSelectedEdge(g);

            if (mesh.Vertices != null)
            {
                this.RenderPoints(g);
            }
        }
        public void Initialize(IRenderControl control, IRenderer renderer)
        {
            this.zoom = new Projection(control.ClientRectangle);

            this.context = new RenderContext(zoom, ColorManager.Default());

            this.renderer = renderer;
            this.renderer.Context = context;

            this.control = control;
            this.control.Initialize();
            this.control.Renderer = renderer;
        }
        /// <summary>
        /// Initialize the graphics buffer (should be called in the forms load event).
        /// </summary>
        public void Initialize(Mesh mesh)
        {
            renderer = new TopologyRenderer(mesh);

            zoom = new Projection(this.ClientRectangle);
            //zoom.ClipMargin = 10.0f;

            var b = mesh.Bounds;
            zoom.Initialize(new BoundingBox((float)b.Left, (float)b.Right,
                (float)b.Bottom, (float)b.Top));

            InitializeBuffer();

            initialized = true;

            this.Render();
        }
        public RenderContext(Projection zoom, ColorManager colorManager)
        {
            bounds = new BoundingBox();

            renderLayers = new List<IRenderLayer>(6);

            renderLayers.Add(new RenderLayer()); // 0 = mesh (filled)
            renderLayers.Add(new RenderLayer()); // 1 = mesh (wireframe)
            renderLayers.Add(new RenderLayer()); // 2 = polygon
            renderLayers.Add(new RenderLayer()); // 3 = points
            renderLayers.Add(new RenderLayer()); // 4 = voronoi overlay
            renderLayers.Add(new RenderLayer()); // 5 = vector field
            renderLayers.Add(new RenderLayer()); // 6 = contour lines

            RenderLayers[1].IsEnabled = true;
            RenderLayers[2].IsEnabled = true;
            RenderLayers[3].IsEnabled = true;

            this.zoom = zoom;
            this.colorManager = colorManager;
        }