Example #1
0
        /// <summary>
        /// Export a mesh to SVG format.
        /// </summary>
        /// <param name="mesh">The current mesh.</param>
        /// <param name="filename">The SVG filename.</param>
        /// <param name="width">The desired width of the image.</param>
        /// <param name="regions">Enable rendering of regions.</param>
        /// <param name="points">Enable rendering of points.</param>
        public void Export(IMesh mesh, string filename, int width,
                           bool regions = false, bool points = true)
        {
            // Check file name
            if (string.IsNullOrWhiteSpace(filename))
            {
                filename = string.Format("mesh-{0}.svg", DateTime.Now.ToString("yyyy-M-d-hh-mm-ss"));
            }

            if (!filename.EndsWith(".svg"))
            {
                filename = Path.ChangeExtension(filename, ".svg");
            }

            if (width < 200)
            {
                width = 200;
            }

            var bounds = mesh.Bounds;

            float margin = 0.05f * (float)bounds.Width;

            scale = width / ((float)bounds.Width + 2 * margin);

            int x_offset = -(int)((bounds.Left - margin) * scale - 0.5);
            int y_offset = (int)((bounds.Top + margin) * scale + 0.5);

            int height = (int)((bounds.Height + 2 * margin) * scale + 0.5);

            using (var svg = new FormattingStreamWriter(filename))
            {
                svg.WriteLine("<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\"");
                svg.WriteLine("\twidth=\"{0}px\" height=\"{1}px\"", width, height);
                svg.WriteLine("\tviewBox=\"0 0 {0} {1}\">", width, height);

                svg.WriteLine("<g transform=\"translate({0}, {1}) scale(1,-1)\">", x_offset, y_offset);

                DrawTriangles(svg, mesh, regions, false);
                //DrawEdges(svg, mesh);

                DrawSegments(svg, mesh);

                if (points)
                {
                    DrawPoints(svg, mesh, false);
                }

                svg.WriteLine("</g>");

                svg.WriteLine("</svg>");
            }
        }
Example #2
0
        /// <summary>
        /// Export the mesh to SVG format.
        /// </summary>
        /// <param name="mesh">The current mesh.</param>
        /// <param name="filename">The SVG filename.</param>
        /// <param name="width">The desired width of the image.</param>
        public void Export(Mesh mesh, string filename, int width)
        {
            // Check file name
            if (String.IsNullOrWhiteSpace(filename))
            {
                filename = String.Format("mesh-{0}.svg", DateTime.Now.ToString("yyyy-M-d-hh-mm-ss"));
            }

            if (!filename.EndsWith(".svg"))
            {
                filename = Path.ChangeExtension(filename, ".svg");
            }

            if (width < 200)
            {
                width = 200;
            }

            var bounds = mesh.Bounds;

            float margin = 0.05f * (float)bounds.Width;

            scale = width / ((float)bounds.Width + 2 * margin);

            int x_offset = -(int)((bounds.Left - margin) * scale);
            int y_offset = (int)((bounds.Top + margin) * scale);

            int height = (int)((bounds.Height + 2 * margin) * scale);

            using (var svg = new FormattingStreamWriter(filename))
            {
                svg.WriteLine("<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\"");
                svg.WriteLine("\twidth=\"{0}px\" height=\"{1}px\"", width, height);
                svg.WriteLine("\tviewBox=\"0 0 {0} {1}\">", width, height);

                svg.WriteLine("<g transform=\"translate({0}, {1}) scale(1,-1)\">", x_offset, y_offset);

                DrawTriangles(svg, mesh, false);
                //DrawEdges(svg, mesh);

                DrawSegments(svg, mesh);

                DrawPoints(svg, mesh, false);

                svg.WriteLine("</g>");

                svg.WriteLine("</svg>");
            }
        }
Example #3
0
        public void AddComment(string comment, int line = 1)
        {
            for (int i = 0; i < line; i++)
            {
                _w.WriteLine("%");
            }

            var t = comment.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < t.Length; i++)
            {
                _w.WriteLine("% " + t[i]);
            }

            for (int i = 0; i < line; i++)
            {
                _w.WriteLine("%");
            }
        }