Fixed issue #9771,

Added option to set triangulation algorithm, 
Added GeometryWriter to test app

git-svn-id: https://triangle.svn.codeplex.com/svn@71218 0e2699bc-83d4-4a8f-98e7-55e24ab8c7a5
This commit is contained in:
SND\wo80_cp
2012-12-07 13:03:09 +00:00
parent 40e15be85c
commit 2b8de82d97
5 changed files with 118 additions and 8 deletions
+89
View File
@@ -0,0 +1,89 @@
// -----------------------------------------------------------------------
// <copyright file="GeometryWriter.cs" company="">
// Christian Woltering, Triangle.NET, http://triangle.codeplex.com/
// </copyright>
// -----------------------------------------------------------------------
namespace MeshExplorer.IO
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using TriangleNet.Geometry;
/// <summary>
/// Writes an InputGeometry to standard Triangle format.
/// </summary>
public static class GeometryWriter
{
public static void Write(InputGeometry geometry, string filename)
{
using (StreamWriter writer = new StreamWriter(filename))
{
WritePoints(writer, geometry.Points, geometry.Count);
WriteSegments(writer, geometry.Segments);
WriteHoles(writer, geometry.Holes);
}
}
private static void WritePoints(StreamWriter writer, IEnumerable<Point> points, int count)
{
int attributes = 0, index = 0;
var first = points.FirstOrDefault();
if (first.Attributes != null)
{
attributes = first.Attributes.Length;
}
writer.WriteLine("{0} {1} {2} {3}", count, 2, attributes, 1);
foreach (var item in points)
{
// Vertex number, x and y coordinates.
writer.Write("{0} {1} {2}", index, item.X.ToString(Util.Nfi), item.Y.ToString(Util.Nfi));
// Write attributes.
for (int j = 0; j < attributes; j++)
{
writer.Write(" {0}", item.Attributes[j].ToString(Util.Nfi));
}
// Write the boundary marker.
writer.WriteLine(" {0}", item.Boundary);
index++;
}
}
private static void WriteSegments(StreamWriter writer, IEnumerable<Edge> edges)
{
int index = 0;
writer.WriteLine("{0} {1}", edges.Count(), 1);
foreach (var item in edges)
{
writer.WriteLine("{0} {1} {2} {3}", index, item.P0, item.P1, item.Boundary);
index++;
}
}
private static void WriteHoles(StreamWriter writer, IEnumerable<Point> holes)
{
int index = 0;
writer.WriteLine("{0}", holes.Count());
foreach (var item in holes)
{
writer.WriteLine("{0} {1} {2}", index, item.X.ToString(Util.Nfi), item.Y.ToString(Util.Nfi));
index++;
}
}
}
}
@@ -106,6 +106,7 @@
<Compile Include="IO\FileProcessor.cs" />
<Compile Include="IO\Formats\JsonFile.cs" />
<Compile Include="IO\Formats\TriangleFile.cs" />
<Compile Include="IO\GeometryWriter.cs" />
<Compile Include="IO\IMeshFile.cs" />
<Compile Include="IO\JsonParser.cs" />
<Compile Include="IO\RasterImage.cs" />
+5 -1
View File
@@ -47,7 +47,11 @@ namespace TriangleNet
/// <summary>
/// Create segments on the convex hull (boolean).
/// </summary>
Convex
Convex,
/// <summary>
/// Algorithm used for triangulation (TriangulationAlgorithm).
/// </summary>
TriangulationAlgorithm
};
/// <summary>
+17 -1
View File
@@ -566,7 +566,7 @@ namespace TriangleNet
if (value)
{
behavior.MinAngle = 20.0;
behavior.MaxAngle = 140.0;
behavior.MaxAngle = 0.0;
UpdateOptions();
}
@@ -656,6 +656,22 @@ namespace TriangleNet
logger.Warning("Invalid option value.", "Mesh.SetOption(int)");
}
/// <summary>
/// Set options for mesh generation.
/// </summary>
/// <param name="option">Mesh gerneration option.</param>
/// <param name="value">New option value.</param>
public void SetOption(Options option, TriangulationAlgorithm value)
{
if (option == Options.TriangulationAlgorithm)
{
behavior.Algorithm = value;
return;
}
logger.Warning("Invalid option value.", "Mesh.SetOption(TriangulationAlgorithm)");
}
/// <summary>
/// Keeps options synchronized.
/// </summary>
+6 -6
View File
@@ -2500,9 +2500,9 @@ namespace TriangleNet
//double p[5];
double[] petalx = new double[24];
double[] petaly = new double[24];
double[] petalr = new double[24];
double[] petalx = new double[2 * numpoints];
double[] petaly = new double[2 * numpoints];
double[] petalr = new double[2 * numpoints];
double[] wedges = new double[2000];
double xmid, ymid, dist, x3, y3;
@@ -2758,9 +2758,9 @@ namespace TriangleNet
//double p[5];
double[] petalx = new double[100];
double[] petaly = new double[100];
double[] petalr = new double[100];
double[] petalx = new double[2 * numpoints];
double[] petaly = new double[2 * numpoints];
double[] petalr = new double[2 * numpoints];
double[] wedges = new double[2000];
double xmid, ymid, dist, x3, y3;