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:
@@ -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" />
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user