Cleanup EPS and SVG code;
Option to gzip compress EPS and SVG images git-svn-id: https://triangle.svn.codeplex.com/svn@79412 0e2699bc-83d4-4a8f-98e7-55e24ab8c7a5
This commit is contained in:
@@ -135,6 +135,11 @@ namespace MeshExplorer.Controls
|
||||
Rectangle newRect = new Rectangle(1, y, boxSize, boxSize);
|
||||
Color text_color = Color.White;
|
||||
|
||||
brushOuter = new LinearGradientBrush(newRect, ColorScheme.ColorGray107, ColorScheme.ColorGray110, mode);
|
||||
e.Graphics.FillRectangle(brushOuter, newRect);
|
||||
|
||||
newRect = new Rectangle(2, y + 1, boxSize - 3, boxSize - 3);
|
||||
|
||||
if (Enabled)
|
||||
{
|
||||
if (base.Focused)
|
||||
@@ -142,11 +147,6 @@ namespace MeshExplorer.Controls
|
||||
else
|
||||
brushBorder = new Pen(Color.FromArgb(38, 38, 38), 1f);
|
||||
|
||||
brushOuter = new LinearGradientBrush(newRect, ColorScheme.ColorGray107, ColorScheme.ColorGray110, mode);
|
||||
e.Graphics.FillRectangle(brushOuter, newRect);
|
||||
|
||||
newRect = new Rectangle(2, y + 1, boxSize - 3, boxSize - 3);
|
||||
|
||||
switch (m_State)
|
||||
{
|
||||
case eButtonState.Normal:
|
||||
@@ -170,15 +170,14 @@ namespace MeshExplorer.Controls
|
||||
}
|
||||
else
|
||||
{
|
||||
text_color = Color.FromArgb(110, 110, 110);
|
||||
brushBorder = new Pen(Color.FromArgb(48, 48, 48), 1f);
|
||||
brushOuter = new LinearGradientBrush(newRect, Color.FromArgb(82, 82, 82), Color.FromArgb(67, 67, 67), mode);
|
||||
brushInner = new LinearGradientBrush(newRect, Color.FromArgb(76, 76, 76), Color.FromArgb(65, 65, 65), mode);
|
||||
e.Graphics.FillRectangle(brushOuter, newRect);
|
||||
newRect.Inflate(-1, -1);
|
||||
e.Graphics.FillRectangle(brushInner, newRect);
|
||||
newRect.Inflate(1, 1);
|
||||
|
||||
brushBorder = new Pen(Color.FromArgb(48, 48, 48), 1f);
|
||||
e.Graphics.DrawRectangle(brushBorder, newRect);
|
||||
|
||||
text_color = Color.FromArgb(160, 160, 160);
|
||||
checkMark.Color = Color.FromArgb(180, 180, 180);
|
||||
}
|
||||
|
||||
e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
|
||||
|
||||
+21
-6
@@ -32,6 +32,7 @@
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.lbSize = new System.Windows.Forms.Label();
|
||||
this.cbUseCompression = new MeshExplorer.Controls.DarkCheckBox();
|
||||
this.darkSlider1 = new MeshExplorer.Controls.DarkSlider();
|
||||
this.darkTextBox1 = new MeshExplorer.Controls.DarkTextBox();
|
||||
this.darkListBox1 = new MeshExplorer.Controls.DarkListBox();
|
||||
@@ -53,7 +54,7 @@
|
||||
//
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.BackColor = System.Drawing.Color.Transparent;
|
||||
this.label3.Location = new System.Drawing.Point(12, 198);
|
||||
this.label3.Location = new System.Drawing.Point(12, 190);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(59, 13);
|
||||
this.label3.TabIndex = 2;
|
||||
@@ -63,7 +64,7 @@
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.BackColor = System.Drawing.Color.Transparent;
|
||||
this.label1.Location = new System.Drawing.Point(12, 156);
|
||||
this.label1.Location = new System.Drawing.Point(12, 148);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(74, 13);
|
||||
this.label1.TabIndex = 2;
|
||||
@@ -74,17 +75,29 @@
|
||||
this.lbSize.AutoSize = true;
|
||||
this.lbSize.BackColor = System.Drawing.Color.Transparent;
|
||||
this.lbSize.ForeColor = System.Drawing.Color.Gray;
|
||||
this.lbSize.Location = new System.Drawing.Point(272, 156);
|
||||
this.lbSize.Location = new System.Drawing.Point(272, 148);
|
||||
this.lbSize.Name = "lbSize";
|
||||
this.lbSize.Size = new System.Drawing.Size(40, 13);
|
||||
this.lbSize.TabIndex = 2;
|
||||
this.lbSize.Text = "800 px";
|
||||
//
|
||||
// cbUseCompression
|
||||
//
|
||||
this.cbUseCompression.BackColor = System.Drawing.Color.DimGray;
|
||||
this.cbUseCompression.Checked = false;
|
||||
this.cbUseCompression.Enabled = false;
|
||||
this.cbUseCompression.Location = new System.Drawing.Point(15, 231);
|
||||
this.cbUseCompression.Name = "cbUseCompression";
|
||||
this.cbUseCompression.Size = new System.Drawing.Size(297, 23);
|
||||
this.cbUseCompression.TabIndex = 6;
|
||||
this.cbUseCompression.Text = "Use GZip compression";
|
||||
this.cbUseCompression.UseVisualStyleBackColor = false;
|
||||
//
|
||||
// darkSlider1
|
||||
//
|
||||
this.darkSlider1.BackColor = System.Drawing.Color.Transparent;
|
||||
this.darkSlider1.CriticalPercent = ((uint)(0u));
|
||||
this.darkSlider1.Location = new System.Drawing.Point(15, 169);
|
||||
this.darkSlider1.Location = new System.Drawing.Point(15, 161);
|
||||
this.darkSlider1.Maximum = 100;
|
||||
this.darkSlider1.Minimum = 0;
|
||||
this.darkSlider1.Name = "darkSlider1";
|
||||
@@ -100,7 +113,7 @@
|
||||
this.darkTextBox1.Cursor = System.Windows.Forms.Cursors.IBeam;
|
||||
this.darkTextBox1.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.darkTextBox1.ForeColor = System.Drawing.Color.Black;
|
||||
this.darkTextBox1.Location = new System.Drawing.Point(12, 214);
|
||||
this.darkTextBox1.Location = new System.Drawing.Point(12, 206);
|
||||
this.darkTextBox1.Name = "darkTextBox1";
|
||||
this.darkTextBox1.Size = new System.Drawing.Size(300, 21);
|
||||
this.darkTextBox1.TabIndex = 4;
|
||||
@@ -119,7 +132,7 @@
|
||||
"Scalable Vector Graphics (*.svg)"});
|
||||
this.darkListBox1.Location = new System.Drawing.Point(12, 25);
|
||||
this.darkListBox1.Name = "darkListBox1";
|
||||
this.darkListBox1.Size = new System.Drawing.Size(302, 118);
|
||||
this.darkListBox1.Size = new System.Drawing.Size(302, 110);
|
||||
this.darkListBox1.TabIndex = 3;
|
||||
this.darkListBox1.SelectedIndexChanged += new System.EventHandler(this.darkListBox1_SelectedIndexChanged);
|
||||
//
|
||||
@@ -149,6 +162,7 @@
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(76)))), ((int)(((byte)(76)))), ((int)(((byte)(76)))));
|
||||
this.ClientSize = new System.Drawing.Size(324, 299);
|
||||
this.Controls.Add(this.cbUseCompression);
|
||||
this.Controls.Add(this.darkSlider1);
|
||||
this.Controls.Add(this.darkTextBox1);
|
||||
this.Controls.Add(this.darkListBox1);
|
||||
@@ -183,5 +197,6 @@
|
||||
private System.Windows.Forms.Label label1;
|
||||
private Controls.DarkSlider darkSlider1;
|
||||
private System.Windows.Forms.Label lbSize;
|
||||
private Controls.DarkCheckBox cbUseCompression;
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,8 @@ namespace MeshExplorer
|
||||
{
|
||||
get
|
||||
{
|
||||
int size = (int)darkSlider1.Value;
|
||||
return 18 * size + 200;
|
||||
int size = (int)((2000.0 - 200.0) / 100.0 * darkSlider1.Value + 200.0);
|
||||
return size - (size % 50);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,11 @@ namespace MeshExplorer
|
||||
set { darkTextBox1.Text = value; }
|
||||
}
|
||||
|
||||
public bool UseCompression
|
||||
{
|
||||
get { return cbUseCompression.Enabled && cbUseCompression.Checked; }
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
base.OnPaint(e);
|
||||
@@ -50,6 +55,8 @@ namespace MeshExplorer
|
||||
{
|
||||
string ext = ".png";
|
||||
|
||||
cbUseCompression.Enabled = darkListBox1.SelectedIndex > 0;
|
||||
|
||||
if (darkListBox1.SelectedIndex == 1)
|
||||
{
|
||||
ext = ".eps";
|
||||
|
||||
@@ -11,7 +11,6 @@ using TriangleNet.Meshing.Algorithm;
|
||||
using TriangleNet.Rendering;
|
||||
using TriangleNet.Smoothing;
|
||||
using TriangleNet.Voronoi;
|
||||
using TriangleNet.Rendering.Text;
|
||||
|
||||
namespace MeshExplorer
|
||||
{
|
||||
@@ -702,22 +701,11 @@ namespace MeshExplorer
|
||||
{
|
||||
int format = export.ImageFormat;
|
||||
int size = export.ImageSize;
|
||||
bool compress = export.UseCompression;
|
||||
|
||||
if (format == 1)
|
||||
{
|
||||
var eps = new EpsImage();
|
||||
eps.Export(this.mesh, export.ImageName, size);
|
||||
}
|
||||
else if (format == 2)
|
||||
{
|
||||
var svg = new SvgImage();
|
||||
svg.Export(this.mesh, export.ImageName, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
var img = new RasterImage();
|
||||
img.Export(this.mesh, export.ImageName, size);
|
||||
}
|
||||
var writer = new ImageWriter();
|
||||
|
||||
writer.Export(this.mesh, export.ImageName, format, size, compress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
// -----------------------------------------------------------------------
|
||||
// <copyright file="RasterImage.cs" company="">
|
||||
// Christian Woltering, Triangle.NET, http://triangle.codeplex.com/
|
||||
// </copyright>
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
namespace MeshExplorer.IO
|
||||
{
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using TriangleNet;
|
||||
using TriangleNet.Rendering.GDI;
|
||||
using TriangleNet.Rendering.Text;
|
||||
|
||||
/// <summary>
|
||||
/// Writes an image of the mesh to disk.
|
||||
/// </summary>
|
||||
public class ImageWriter
|
||||
{
|
||||
/// <summary>
|
||||
/// Export the mesh to PNG format.
|
||||
/// </summary>
|
||||
/// <param name="mesh">The current mesh.</param>
|
||||
/// <param name="filename">The PNG filename.</param>
|
||||
/// <param name="type">Image type (0 = png, 1 = eps, 2 = svg).</param>
|
||||
/// <param name="width">The desired width of the image.</param>
|
||||
/// <param name="compress">Use GZip compression (only eps or svg).</param>
|
||||
public void Export(Mesh mesh, string filename, int type, int width, bool compress)
|
||||
{
|
||||
if (type == 1)
|
||||
{
|
||||
ExportEps(mesh, filename, width, compress);
|
||||
}
|
||||
else if (type == 2)
|
||||
{
|
||||
ExportSvg(mesh, filename, width, compress);
|
||||
}
|
||||
else
|
||||
{
|
||||
ImageRenderer.Save(mesh, filename, width);
|
||||
}
|
||||
}
|
||||
|
||||
private void ExportEps(Mesh mesh, string filename, int width, bool compress)
|
||||
{
|
||||
var eps = new EpsImage();
|
||||
|
||||
eps.Export(mesh, filename, width);
|
||||
|
||||
if (compress)
|
||||
{
|
||||
CompressFile(filename, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void ExportSvg(Mesh mesh, string filename, int width, bool compress)
|
||||
{
|
||||
var svg = new SvgImage();
|
||||
|
||||
svg.Export(mesh, filename, width);
|
||||
|
||||
if (compress)
|
||||
{
|
||||
CompressFile(filename, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void CompressFile(string filename, bool cleanup)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
using (var input = File.OpenRead(filename))
|
||||
using (var output = File.Create(filename + ".gz"))
|
||||
using (var gzip = new GZipStream(output, CompressionMode.Compress))
|
||||
{
|
||||
input.CopyTo(gzip);
|
||||
}
|
||||
|
||||
if (cleanup)
|
||||
{
|
||||
File.Delete(filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
// -----------------------------------------------------------------------
|
||||
// <copyright file="RasterImage.cs" company="">
|
||||
// Christian Woltering, Triangle.NET, http://triangle.codeplex.com/
|
||||
// </copyright>
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
namespace MeshExplorer.IO
|
||||
{
|
||||
using System;
|
||||
using TriangleNet;
|
||||
using TriangleNet.Rendering.GDI;
|
||||
|
||||
/// <summary>
|
||||
/// Writes an image of the mesh to disk.
|
||||
/// </summary>
|
||||
public class RasterImage
|
||||
{
|
||||
/// <summary>
|
||||
/// Export the mesh to PNG format.
|
||||
/// </summary>
|
||||
/// <param name="mesh">The current mesh.</param>
|
||||
/// <param name="filename">The PNG filename.</param>
|
||||
/// <param name="width">The desired width (pixel) 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}.png", DateTime.Now.ToString("yyyy-M-d-hh-mm-ss"));
|
||||
}
|
||||
|
||||
ImageRenderer.Save(mesh, filename, width);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,9 +112,9 @@
|
||||
<Compile Include="IO\FileProcessor.cs" />
|
||||
<Compile Include="IO\Formats\JsonFile.cs" />
|
||||
<Compile Include="IO\Formats\TriangleFile.cs" />
|
||||
<Compile Include="IO\ImageWriter.cs" />
|
||||
<Compile Include="IO\IMeshFile.cs" />
|
||||
<Compile Include="IO\JsonParser.cs" />
|
||||
<Compile Include="IO\RasterImage.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Settings.cs" />
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
|
||||
namespace TriangleNet.Rendering.Text
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using TriangleNet.Geometry;
|
||||
|
||||
static class EdgeIterator
|
||||
{
|
||||
/// <summary>
|
||||
/// Enumerate the edges of the mesh.
|
||||
/// </summary>
|
||||
/// <param name="mesh"></param>
|
||||
/// <param name="skipSegments"></param>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// In contrast to the <see cref="TriangleNet.Meshing.Iterators.EdgeIterator"/> this
|
||||
/// method will return objects that include the vertex information (and not only the
|
||||
/// indices).
|
||||
/// </remarks>
|
||||
public static IEnumerable<ISegment> EnumerateEdges(Mesh mesh, bool skipSegments = true)
|
||||
{
|
||||
foreach (var t in mesh.Triangles)
|
||||
{
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
int nid = t.GetNeighborID(i);
|
||||
|
||||
if ((t.ID < nid) || (nid < 0))
|
||||
{
|
||||
var s = t.GetSegment(i);
|
||||
|
||||
if (skipSegments && s == null)
|
||||
{
|
||||
// Since segments will be processed separately, don't
|
||||
// include them in the enumeration.
|
||||
yield return new Segment(
|
||||
t.GetVertex((i + 1) % 3),
|
||||
t.GetVertex((i + 2) % 3));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s == null)
|
||||
{
|
||||
yield return new Segment(
|
||||
t.GetVertex((i + 1) % 3),
|
||||
t.GetVertex((i + 2) % 3));
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,10 +39,25 @@ namespace TriangleNet.Rendering.Text
|
||||
DefaultPointSize = 1;
|
||||
}
|
||||
|
||||
//public void Append(string ps)
|
||||
//{
|
||||
// _w.WriteLine(ps);
|
||||
//}
|
||||
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("%");
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawPoint(Point p)
|
||||
{
|
||||
@@ -114,13 +129,11 @@ namespace TriangleNet.Rendering.Text
|
||||
_w.WriteLine("%%Document-Fonts: Times-Roman");
|
||||
_w.WriteLine("%%LanguageLevel: 3");
|
||||
_w.WriteLine("%%EndComments");
|
||||
_w.WriteLine("%%BeginProlog");
|
||||
_w.WriteLine("/inch {72 mul} def");
|
||||
_w.WriteLine("%%EndProlog");
|
||||
_w.WriteLine("%%Page: 1 1");
|
||||
_w.WriteLine("save");
|
||||
|
||||
// Define points.
|
||||
_w.WriteLine("% Define points.");
|
||||
_w.WriteLine("/P {");
|
||||
_w.WriteLine("2 dict begin");
|
||||
_w.WriteLine("/y exch def");
|
||||
@@ -132,6 +145,7 @@ namespace TriangleNet.Rendering.Text
|
||||
_w.WriteLine("} def");
|
||||
|
||||
// Define lines.
|
||||
_w.WriteLine("% Define lines.");
|
||||
_w.WriteLine("/L {");
|
||||
_w.WriteLine("2 dict begin");
|
||||
_w.WriteLine("/y2 exch def");
|
||||
@@ -149,9 +163,6 @@ namespace TriangleNet.Rendering.Text
|
||||
{
|
||||
_w.WriteLine("%");
|
||||
_w.WriteLine("restore showpage");
|
||||
_w.WriteLine("%");
|
||||
_w.WriteLine("% End of page.");
|
||||
_w.WriteLine("%");
|
||||
_w.WriteLine("%%Trailer");
|
||||
_w.WriteLine("%%EOF");
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
namespace TriangleNet.Rendering.Text
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using TriangleNet;
|
||||
using TriangleNet.Geometry;
|
||||
@@ -23,14 +22,12 @@ namespace TriangleNet.Rendering.Text
|
||||
public class EpsImage
|
||||
{
|
||||
// EPS page metrics
|
||||
|
||||
PageSize ps = new PageSize(36, 126, 576, 666);
|
||||
PageSize clip = new PageSize(18, 108, 594, 684);
|
||||
|
||||
// Mesh metrics
|
||||
double x_max, x_min;
|
||||
double y_max, y_min;
|
||||
//double x_scale, y_scale;
|
||||
|
||||
// TODO: use color manager
|
||||
private static Color ColorPoints = Color.FromArgb(0, 100, 0);
|
||||
@@ -76,14 +73,16 @@ namespace TriangleNet.Rendering.Text
|
||||
eps.SetClip(GetRectangle(clip));
|
||||
|
||||
// Draw edges.
|
||||
eps.AddComment("Draw edges.");
|
||||
eps.SetStroke(0.4f, ColorLines);
|
||||
|
||||
foreach (var e in EnumerateEdges(mesh))
|
||||
foreach (var e in EdgeIterator.EnumerateEdges(mesh))
|
||||
{
|
||||
eps.DrawLine(Transform(e.GetVertex(0)), Transform(e.GetVertex(1)));
|
||||
}
|
||||
|
||||
// Draw Segments.
|
||||
eps.AddComment("Draw Segments.");
|
||||
eps.SetStroke(0.8f, ColorSegments);
|
||||
|
||||
foreach (var s in mesh.Segments)
|
||||
@@ -92,6 +91,7 @@ namespace TriangleNet.Rendering.Text
|
||||
}
|
||||
|
||||
// Draw points.
|
||||
eps.AddComment("Draw points.");
|
||||
eps.SetColor(ColorPoints);
|
||||
|
||||
foreach (var node in mesh.Vertices)
|
||||
@@ -101,125 +101,6 @@ namespace TriangleNet.Rendering.Text
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
private void DrawTitle(EpsDocument eps)
|
||||
{
|
||||
var buffer = new StringBuilder();
|
||||
|
||||
buffer.AppendLine("%");
|
||||
buffer.AppendLine("% Set the RGB color to black.");
|
||||
buffer.AppendLine("%");
|
||||
buffer.AppendLine("0.000 0.000 0.000 setrgbcolor");
|
||||
buffer.AppendLine("%");
|
||||
buffer.AppendLine("% Set the font and its size.");
|
||||
buffer.AppendLine("%");
|
||||
buffer.AppendLine("/Times-Roman findfont");
|
||||
buffer.AppendLine("0.50 inch scalefont");
|
||||
buffer.AppendLine("setfont");
|
||||
buffer.AppendLine("%");
|
||||
buffer.AppendLine("% Print a title.");
|
||||
buffer.AppendLine("%");
|
||||
buffer.AppendLine("%210 702 moveto");
|
||||
buffer.AppendLine("%(Triangulation) show");
|
||||
}
|
||||
|
||||
private void DrawPointLabels(StreamWriter eps, Mesh mesh)
|
||||
{
|
||||
int n = mesh.Vertices.Count;
|
||||
|
||||
IntPoint p;
|
||||
|
||||
StringBuilder labels = new StringBuilder();
|
||||
|
||||
foreach (var node in mesh.Vertices)
|
||||
{
|
||||
p = Transform(node);
|
||||
|
||||
labels.AppendFormat(" {0} {1} moveto ({2}) show", p.X, p.Y + 5, node.ID);
|
||||
labels.AppendLine();
|
||||
}
|
||||
|
||||
eps.WriteLine("%");
|
||||
eps.WriteLine("% Label the nodes.");
|
||||
eps.WriteLine("%");
|
||||
eps.WriteLine("% Set the RGB color to darker blue.");
|
||||
eps.WriteLine("%");
|
||||
eps.WriteLine("0.000 0.250 0.850 setrgbcolor");
|
||||
eps.WriteLine("/Times-Roman findfont");
|
||||
eps.WriteLine("0.20 inch scalefont");
|
||||
eps.WriteLine("setfont");
|
||||
eps.WriteLine("%");
|
||||
|
||||
eps.WriteLine(labels.ToString());
|
||||
}
|
||||
|
||||
private void DrawTriangles(StreamWriter eps, Mesh mesh, bool label)
|
||||
{
|
||||
eps.WriteLine("%");
|
||||
eps.WriteLine("% Set the triangle line color and width.");
|
||||
eps.WriteLine("%");
|
||||
eps.WriteLine("0.6 0.6 0.6 setrgbcolor");
|
||||
eps.WriteLine("0.5 setlinewidth");
|
||||
eps.WriteLine("%");
|
||||
eps.WriteLine("% Draw the triangles.");
|
||||
eps.WriteLine("%");
|
||||
|
||||
IntPoint a, b, c;
|
||||
|
||||
foreach (var t in mesh.Triangles)
|
||||
{
|
||||
a = Transform(t.GetVertex(0));
|
||||
b = Transform(t.GetVertex(1));
|
||||
c = Transform(t.GetVertex(2));
|
||||
|
||||
eps.WriteLine("newpath");
|
||||
|
||||
eps.WriteLine(" {0} {1} moveto", a.X, a.Y);
|
||||
eps.WriteLine(" {0} {1} lineto", b.X, b.Y);
|
||||
eps.WriteLine(" {0} {1} lineto", c.X, c.Y);
|
||||
eps.WriteLine(" {0} {1} lineto", a.X, a.Y);
|
||||
|
||||
eps.WriteLine("stroke");
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawTriangleLabels(StreamWriter eps, Mesh mesh)
|
||||
{
|
||||
var labels = new StringBuilder();
|
||||
|
||||
IntPoint a, b, c;
|
||||
|
||||
foreach (var t in mesh.Triangles)
|
||||
{
|
||||
a = Transform(t.GetVertex(0));
|
||||
b = Transform(t.GetVertex(1));
|
||||
c = Transform(t.GetVertex(2));
|
||||
|
||||
eps.WriteLine("newpath");
|
||||
|
||||
a = Transform((a.X + b.X + c.X) / 3.0, (a.Y + b.Y + c.Y) / 3.0);
|
||||
|
||||
labels.AppendFormat(" {0} {1} moveto ({2}) show", a.X, a.Y, t.ID);
|
||||
labels.AppendLine();
|
||||
|
||||
eps.WriteLine("stroke");
|
||||
}
|
||||
|
||||
eps.WriteLine("%");
|
||||
eps.WriteLine("% Label the triangles.");
|
||||
eps.WriteLine("%");
|
||||
eps.WriteLine("% Set the RGB color to darker red.");
|
||||
eps.WriteLine("%");
|
||||
eps.WriteLine("0.950 0.250 0.150 setrgbcolor");
|
||||
eps.WriteLine("/Times-Roman findfont");
|
||||
eps.WriteLine("0.20 inch scalefont");
|
||||
eps.WriteLine("setfont");
|
||||
eps.WriteLine("%");
|
||||
|
||||
eps.WriteLine(labels.ToString());
|
||||
}
|
||||
//*/
|
||||
|
||||
private IntRectangle GetRectangle(PageSize size)
|
||||
{
|
||||
return new IntRectangle((int)size.X, (int)size.Y, (int)size.Width, (int)size.Height);
|
||||
@@ -272,26 +153,5 @@ namespace TriangleNet.Rendering.Text
|
||||
clip.Expand(0, -delta);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<ISegment> EnumerateEdges(Mesh mesh, bool segments = false)
|
||||
{
|
||||
foreach (var t in mesh.Triangles)
|
||||
{
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
int nid = t.GetNeighborID(i);
|
||||
|
||||
if ((t.ID < nid) || (nid < 0))
|
||||
{
|
||||
if (segments || t.GetSegment(i) == null)
|
||||
{
|
||||
yield return new Segment(
|
||||
t.GetVertex((i + 1) % 3),
|
||||
t.GetVertex((i + 2) % 3));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,9 @@ namespace TriangleNet.Rendering.Text
|
||||
/// </summary>
|
||||
public class SvgImage
|
||||
{
|
||||
// Iterations to insert a linebreak in SVG path.
|
||||
private const int LINEBREAK_COUNT = 10;
|
||||
|
||||
float scale = 1f;
|
||||
|
||||
/// <summary>
|
||||
@@ -57,12 +60,13 @@ namespace TriangleNet.Rendering.Text
|
||||
using (var svg = new FormattingStreamWriter(filename))
|
||||
{
|
||||
svg.WriteLine("<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\"");
|
||||
svg.WriteLine(" width=\"{0}px\" height=\"{1}px\"", width, height);
|
||||
svg.WriteLine(" viewBox=\"0 0 {0} {1}\">", width, height);
|
||||
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);
|
||||
|
||||
@@ -76,13 +80,15 @@ namespace TriangleNet.Rendering.Text
|
||||
|
||||
private void DrawTriangles(StreamWriter svg, Mesh mesh, bool label)
|
||||
{
|
||||
svg.Write(" <path d=\"");
|
||||
svg.Write("\t<path d=\"");
|
||||
|
||||
StringBuilder labels = new StringBuilder();
|
||||
|
||||
Vertex v1, v2, v3;
|
||||
double x1, y1, x2, y2, x3, y3, xa, ya;
|
||||
|
||||
int i = 1;
|
||||
|
||||
foreach (var tri in mesh.Triangles)
|
||||
{
|
||||
v1 = tri.GetVertex(0);
|
||||
@@ -99,6 +105,14 @@ namespace TriangleNet.Rendering.Text
|
||||
svg.Write("M {0:0.#},{1:0.#} L {2:0.#},{3:0.#} {4:0.#},{5:0.#} Z ",
|
||||
x1, y1, x2, y2, x3, y3);
|
||||
|
||||
if (i % LINEBREAK_COUNT == 0)
|
||||
{
|
||||
svg.WriteLine();
|
||||
svg.Write("\t");
|
||||
}
|
||||
|
||||
i++;
|
||||
|
||||
if (label)
|
||||
{
|
||||
xa = (x1 + x2 + x3) / 3.0;
|
||||
@@ -108,28 +122,65 @@ namespace TriangleNet.Rendering.Text
|
||||
xa, ya, tri.ID);
|
||||
labels.AppendLine();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
svg.WriteLine("\" style=\"stroke:#969696; fill:none; stroke-linejoin:bevel;\"/>");
|
||||
svg.WriteLine("\" style=\"stroke:#c2c2c2; fill:none; stroke-linejoin:bevel;\"/>");
|
||||
|
||||
// Label the triangles.
|
||||
if (label)
|
||||
{
|
||||
svg.WriteLine(" <g font-family=\"Verdana\" font-size=\"11\" fill=\"black\">");
|
||||
svg.WriteLine("\t<g font-family=\"Verdana\" font-size=\"11\" fill=\"black\">");
|
||||
svg.Write(labels.ToString());
|
||||
svg.WriteLine(" <g/>");
|
||||
svg.WriteLine("\t<g/>");
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawEdges(StreamWriter svg, Mesh mesh)
|
||||
{
|
||||
svg.Write("\t<path d=\"");
|
||||
|
||||
StringBuilder labels = new StringBuilder();
|
||||
|
||||
Vertex v1, v2;
|
||||
double x1, y1, x2, y2;
|
||||
|
||||
int i = 1;
|
||||
|
||||
foreach (var e in EdgeIterator.EnumerateEdges(mesh))
|
||||
{
|
||||
v1 = e.GetVertex(0);
|
||||
v2 = e.GetVertex(1);
|
||||
|
||||
x1 = scale * v1.X;
|
||||
y1 = scale * v1.Y;
|
||||
x2 = scale * v2.X;
|
||||
y2 = scale * v2.Y;
|
||||
|
||||
svg.Write("M {0:0.#},{1:0.#} L {2:0.#},{3:0.#} ",
|
||||
x1, y1, x2, y2);
|
||||
|
||||
if (i % LINEBREAK_COUNT == 0)
|
||||
{
|
||||
svg.WriteLine();
|
||||
svg.Write("\t");
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
svg.WriteLine("\" style=\"stroke:#c2c2c2; fill:none; stroke-linejoin:bevel;\"/>");
|
||||
}
|
||||
|
||||
private void DrawSegments(StreamWriter svg, Mesh mesh)
|
||||
{
|
||||
svg.Write(" <path d=\"");
|
||||
svg.Write("\t<path d=\"");
|
||||
|
||||
StringBuilder labels = new StringBuilder();
|
||||
|
||||
double x1, y1, x2, y2;
|
||||
|
||||
int i = 1;
|
||||
|
||||
foreach (var seg in mesh.Segments)
|
||||
{
|
||||
x1 = scale * seg.GetVertex(0).X;
|
||||
@@ -139,6 +190,14 @@ namespace TriangleNet.Rendering.Text
|
||||
|
||||
svg.Write("M {0:0.#},{1:0.#} L {2:0.#},{3:0.#} ",
|
||||
x1, y1, x2, y2);
|
||||
|
||||
if (i % LINEBREAK_COUNT == 0)
|
||||
{
|
||||
svg.WriteLine();
|
||||
svg.Write("\t");
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
svg.WriteLine("\" style=\"stroke:#4682B4; fill:none; stroke-linejoin:bevel; stroke-width:2px;\"/>");
|
||||
@@ -148,22 +207,18 @@ namespace TriangleNet.Rendering.Text
|
||||
{
|
||||
int n = mesh.Vertices.Count;
|
||||
|
||||
int circle_size = 1;
|
||||
float circle_size = 1.5f;
|
||||
|
||||
if (n < 100)
|
||||
{
|
||||
circle_size = 4;
|
||||
}
|
||||
else if (n < 500)
|
||||
{
|
||||
circle_size = 3;
|
||||
}
|
||||
else if (n < 1000)
|
||||
else if (n < 500)
|
||||
{
|
||||
circle_size = 2;
|
||||
}
|
||||
|
||||
svg.WriteLine(" <g style=\"fill: #006400\">");
|
||||
svg.WriteLine("\t<g style=\"fill: #006400\">");
|
||||
|
||||
double x, y;
|
||||
|
||||
@@ -174,7 +229,7 @@ namespace TriangleNet.Rendering.Text
|
||||
x = scale * node.X;
|
||||
y = scale * node.Y;
|
||||
|
||||
svg.WriteLine(" <circle cx=\"{0:0.#}\" cy=\"{1:0.#}\" r=\"{2:0.#}\" />",
|
||||
svg.WriteLine("\t\t<circle cx=\"{0:0.#}\" cy=\"{1:0.#}\" r=\"{2:0.#}\" />",
|
||||
x, y, circle_size);
|
||||
|
||||
if (label)
|
||||
@@ -185,14 +240,14 @@ namespace TriangleNet.Rendering.Text
|
||||
}
|
||||
}
|
||||
|
||||
svg.WriteLine(" </g>");
|
||||
svg.WriteLine("\t</g>");
|
||||
|
||||
// Label the nodes.
|
||||
if (label)
|
||||
{
|
||||
svg.WriteLine(" <g font-family=\"Verdana\" font-size=\"11\" fill=\"black\">");
|
||||
svg.WriteLine("\t<g font-family=\"Verdana\" font-size=\"11\" fill=\"black\">");
|
||||
svg.Write(labels.ToString());
|
||||
svg.WriteLine(" <g/>");
|
||||
svg.WriteLine("\t<g/>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,7 @@
|
||||
<Compile Include="RenderContext.cs" />
|
||||
<Compile Include="RenderLayer.cs" />
|
||||
<Compile Include="RenderManager.cs" />
|
||||
<Compile Include="Text\EdgeIterator.cs" />
|
||||
<Compile Include="Text\EpsDocument.cs" />
|
||||
<Compile Include="Text\EpsImage.cs" />
|
||||
<Compile Include="Text\FormattingStreamWriter.cs" />
|
||||
|
||||
Reference in New Issue
Block a user