Update examples.
This commit is contained in:
@@ -25,7 +25,7 @@ namespace TriangleNet.Examples
|
||||
// Generate mesh.
|
||||
var mesh = mesher.Triangulate(points);
|
||||
|
||||
if (print) SvgImage.Save(mesh, "example-1.png", 500);
|
||||
if (print) SvgImage.Save(mesh, "example-1.svg", 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
|
||||
namespace TriangleNet.Examples
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using TriangleNet;
|
||||
using TriangleNet.IO;
|
||||
using TriangleNet.Meshing;
|
||||
|
||||
/// <summary>
|
||||
/// Processing meshes in parallel.
|
||||
/// </summary>
|
||||
public class Example10
|
||||
{
|
||||
/// <summary>
|
||||
/// Reads all .poly files from given directory and processes them in parallel.
|
||||
/// </summary>
|
||||
public static void Run(string dir)
|
||||
{
|
||||
var files = Directory.EnumerateFiles(dir, "*.poly", SearchOption.AllDirectories);
|
||||
|
||||
var queue = new ConcurrentQueue<string>(files);
|
||||
|
||||
int concurrencyLevel = Environment.ProcessorCount / 2;
|
||||
|
||||
var tasks = new Task<MeshResult>[concurrencyLevel];
|
||||
|
||||
for (int i = 0; i < concurrencyLevel; i++)
|
||||
{
|
||||
tasks[i] = Task.Run(() =>
|
||||
{
|
||||
// Each task has it's own triangle pool and predicates instance.
|
||||
var pool = new TrianglePool();
|
||||
var predicates = new RobustPredicates();
|
||||
|
||||
// The factory methods return the above instances.
|
||||
var config = new Configuration()
|
||||
{
|
||||
Predicates = () => predicates,
|
||||
TrianglePool = () => pool.Restart()
|
||||
};
|
||||
|
||||
var mesher = new GenericMesher(config);
|
||||
var result = new MeshResult();
|
||||
|
||||
while (queue.Count > 0)
|
||||
{
|
||||
if (queue.TryDequeue(out var file))
|
||||
{
|
||||
var poly = FileProcessor.Read(file);
|
||||
|
||||
var mesh = mesher.Triangulate(poly);
|
||||
|
||||
ProcessMesh(mesh, result);
|
||||
}
|
||||
}
|
||||
|
||||
pool.Clear();
|
||||
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
Task.WaitAll(tasks);
|
||||
|
||||
int numberOfTriangles = tasks.Sum(t => t.Result.NumberOfTriangles);
|
||||
int invalid = tasks.Sum(t => t.Result.Invalid);
|
||||
|
||||
Console.WriteLine("Total number of triangles processed: {0}", numberOfTriangles);
|
||||
|
||||
if (invalid > 0)
|
||||
{
|
||||
Console.WriteLine(" Number of invalid triangulations: {0}", invalid);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ProcessMesh(IMesh mesh, MeshResult result)
|
||||
{
|
||||
result.NumberOfTriangles += mesh.Triangles.Count;
|
||||
|
||||
if (!MeshValidator.IsConsistent((Mesh)mesh))
|
||||
{
|
||||
result.Invalid += 1;
|
||||
}
|
||||
}
|
||||
|
||||
class MeshResult
|
||||
{
|
||||
public int NumberOfTriangles;
|
||||
public int Invalid;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@
|
||||
// Generate mesh using the polygons Triangulate extension method.
|
||||
var mesh = poly.Triangulate(quality);
|
||||
|
||||
if (print) SvgImage.Save(mesh, "example-2.png", 500);
|
||||
if (print) SvgImage.Save(mesh, "example-2.svg", 500);
|
||||
}
|
||||
|
||||
public static IPolygon CreatePolygon(double h = 0.2)
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace TriangleNet.Examples
|
||||
// Generate mesh.
|
||||
var mesh = CreateMesh();
|
||||
|
||||
if (print) SvgImage.Save(mesh, "example-3.png", 500);
|
||||
if (print) SvgImage.Save(mesh, "example-3.svg", 500);
|
||||
}
|
||||
|
||||
public static IMesh CreateMesh()
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace TriangleNet.Examples
|
||||
|
||||
smoother.Smooth(mesh, 5);
|
||||
|
||||
if (print) SvgImage.Save(mesh, "example-4.png", 500);
|
||||
if (print) SvgImage.Save(mesh, "example-4.svg", 500);
|
||||
}
|
||||
|
||||
public static IPolygon CreatePolygon()
|
||||
|
||||
@@ -19,11 +19,11 @@ namespace TriangleNet.Examples
|
||||
|
||||
FindBoundary1(mesh);
|
||||
|
||||
if (print) SvgImage.Save(mesh, "example-5-1.png", 500, true, false);
|
||||
if (print) SvgImage.Save(mesh, "example-5-1.svg", 500, true, false);
|
||||
|
||||
FindBoundary2(mesh);
|
||||
|
||||
if (print) SvgImage.Save(mesh, "example-5-2.png", 500, true, false);
|
||||
if (print) SvgImage.Save(mesh, "example-5-2.svg", 500, true, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
using TriangleNet.Topology;
|
||||
|
||||
/// <summary>
|
||||
/// Boolean operation on mesh regions (intersection, difference, xor).
|
||||
/// Boolean operations on mesh regions (intersection, difference, xor).
|
||||
/// </summary>
|
||||
public static class Example6
|
||||
{
|
||||
public static void Run() //FindRegions()
|
||||
public static void Run()
|
||||
{
|
||||
// Generate the input geometry.
|
||||
var polygon = new Polygon(8, true);
|
||||
|
||||
@@ -72,8 +72,11 @@ namespace TriangleNet.Examples
|
||||
double x = p.X;
|
||||
double y = p.Y;
|
||||
|
||||
double xr = Math.Cos(radians) * x - Math.Sin(radians) * y;
|
||||
double yr = Math.Sin(radians) * x + Math.Cos(radians) * y;
|
||||
double s = Math.Sin(radians);
|
||||
double c = Math.Cos(radians);
|
||||
|
||||
double xr = c * x - s * y;
|
||||
double yr = s * x + c * y;
|
||||
|
||||
poly.Points.Add(new Vertex(xr, yr) { ID = id++ });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user