Update test app input generators
git-svn-id: https://triangle.svn.codeplex.com/svn@75066 0e2699bc-83d4-4a8f-98e7-55e24ab8c7a5
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
namespace MeshExplorer.Generators
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TriangleNet.Geometry;
|
||||
|
||||
/// <summary>
|
||||
@@ -52,6 +53,79 @@ namespace MeshExplorer.Generators
|
||||
|
||||
public abstract IPolygon Generate(double param0, double param1, double param2);
|
||||
|
||||
#region Contour helpers
|
||||
|
||||
protected List<Vertex> CreateCircle(double r, int n, int boundary = 0)
|
||||
{
|
||||
return CreateCircle(0.0, 0.0, r, n, boundary);
|
||||
}
|
||||
|
||||
protected List<Vertex> CreateCircle(double x, double y, double r, int n, int boundary = 0)
|
||||
{
|
||||
return CreateEllipse(0.0, 0.0, r, 1.0, 1.0, n, boundary);
|
||||
}
|
||||
|
||||
protected List<Vertex> CreateEllipse(double r, double a, double b, int n, int boundary = 0)
|
||||
{
|
||||
return CreateEllipse(0.0, 0.0, r, a, b, n, boundary);
|
||||
}
|
||||
|
||||
protected List<Vertex> CreateEllipse(double x, double y, double r, double a, double b, int n, int boundary = 0)
|
||||
{
|
||||
var contour = new List<Vertex>(n);
|
||||
|
||||
double dphi = 2 * Math.PI / n;
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
contour.Add(new Vertex(x + a * r * Math.Cos(i * dphi), y + b * r * Math.Sin(i * dphi), boundary));
|
||||
}
|
||||
|
||||
return contour;
|
||||
}
|
||||
|
||||
protected List<Vertex> CreateRectangle(Rectangle rect, int n, int boundary = 0)
|
||||
{
|
||||
return CreateRectangle(rect, n, n, boundary);
|
||||
}
|
||||
|
||||
protected List<Vertex> CreateRectangle(Rectangle rect, int nH, int nV, int boundary = 0)
|
||||
{
|
||||
var contour = new List<Vertex>(2 * nH + 2 * nV);
|
||||
|
||||
// Horizontal and vertical step sizes.
|
||||
double stepH = rect.Width / nH;
|
||||
double stepV = rect.Height / nV;
|
||||
|
||||
// Left box boundary points
|
||||
for (int i = 0; i < nV; i++)
|
||||
{
|
||||
contour.Add(new Vertex(rect.Left, rect.Bottom + i * stepV, 1));
|
||||
}
|
||||
|
||||
// Top box boundary points
|
||||
for (int i = 0; i < nH; i++)
|
||||
{
|
||||
contour.Add(new Vertex(rect.Left + i * stepH, rect.Top, 1));
|
||||
}
|
||||
|
||||
// Right box boundary points
|
||||
for (int i = 0; i < nV; i++)
|
||||
{
|
||||
contour.Add(new Vertex(rect.Right, rect.Top - i * stepV, 1));
|
||||
}
|
||||
|
||||
// Bottom box boundary points
|
||||
for (int i = 0; i < nH; i++)
|
||||
{
|
||||
contour.Add(new Vertex(rect.Right - i * stepH, rect.Bottom, 1));
|
||||
}
|
||||
|
||||
return contour;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected int GetParamValueInt(int paramIndex, double paramOffset)
|
||||
{
|
||||
int[] range = ranges[paramIndex];
|
||||
|
||||
@@ -31,66 +31,19 @@ namespace MeshExplorer.Generators
|
||||
|
||||
public override IPolygon Generate(double param0, double param1, double param2)
|
||||
{
|
||||
int numPoints = GetParamValueInt(1, param1);
|
||||
int n = GetParamValueInt(1, param1);
|
||||
|
||||
var input = new Polygon(numPoints + 4);
|
||||
|
||||
double x, y, step = 2 * Math.PI / numPoints;
|
||||
var input = new Polygon(n + 4);
|
||||
|
||||
double r = GetParamValueInt(2, param2);
|
||||
|
||||
// Generate circle
|
||||
for (int i = 0; i < numPoints; i++)
|
||||
{
|
||||
x = r * Math.Cos(i * step);
|
||||
y = r * Math.Sin(i * step);
|
||||
// Generate circle (hole)
|
||||
input.AddContour(CreateCircle(r, n, 1), 1, new Point(0, 0));
|
||||
|
||||
input.Add(new Vertex(x, y, 2));
|
||||
input.Add(new Edge(i, (i + 1) % numPoints, 2));
|
||||
}
|
||||
n = GetParamValueInt(0, param0);
|
||||
|
||||
numPoints = input.Points.Count;
|
||||
|
||||
int numPointsB = GetParamValueInt(0, param0);
|
||||
|
||||
// Box sides are 100 units long
|
||||
step = 100.0 / numPointsB;
|
||||
|
||||
// Left box boundary points
|
||||
for (int i = 0; i < numPointsB; i++)
|
||||
{
|
||||
input.Add(new Vertex(-50, -50 + i * step, 1));
|
||||
}
|
||||
|
||||
// Top box boundary points
|
||||
for (int i = 0; i < numPointsB; i++)
|
||||
{
|
||||
input.Add(new Vertex(-50 + i * step, 50, 1));
|
||||
}
|
||||
|
||||
// Right box boundary points
|
||||
for (int i = 0; i < numPointsB; i++)
|
||||
{
|
||||
input.Add(new Vertex(50, 50 - i * step, 1));
|
||||
}
|
||||
|
||||
// Bottom box boundary points
|
||||
for (int i = 0; i < numPointsB; i++)
|
||||
{
|
||||
input.Add(new Vertex(50 - i * step, -50, 1));
|
||||
}
|
||||
|
||||
// Add box segments
|
||||
for (int i = numPoints; i < input.Count - 1; i++)
|
||||
{
|
||||
input.Add(new Edge(i, i + 1, 1));
|
||||
}
|
||||
|
||||
// Add last segments which closes the box
|
||||
input.Add(new Edge(input.Count - 1, numPoints, 1));
|
||||
|
||||
// Add hole
|
||||
input.Holes.Add(new Point(0, 0));
|
||||
// Generate box
|
||||
input.AddContour(CreateRectangle(new Rectangle(-50, -50, 100, 100), n, 2), 2);
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
@@ -6,10 +6,6 @@
|
||||
|
||||
namespace MeshExplorer.Generators
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using TriangleNet.Geometry;
|
||||
|
||||
/// <summary>
|
||||
@@ -34,53 +30,27 @@ namespace MeshExplorer.Generators
|
||||
{
|
||||
// Number of points on the outer circle
|
||||
int n = GetParamValueInt(0, param0);
|
||||
int count, npoints;
|
||||
|
||||
double radius = GetParamValueInt(1, param1);
|
||||
|
||||
// Step size on the outer circle
|
||||
double h = 2 * Math.PI * radius / n;
|
||||
|
||||
// Current radius and step size
|
||||
double r, dphi;
|
||||
double r, h = radius / n;
|
||||
|
||||
var input = new Polygon(n + 1);
|
||||
|
||||
// Inner cirlce (radius = 1)
|
||||
// Inner cirlce (radius = 1) (hole)
|
||||
r = 1;
|
||||
npoints = (int)(2 * Math.PI * r / h);
|
||||
dphi = 2 * Math.PI / npoints;
|
||||
for (int i = 0; i < npoints; i++)
|
||||
{
|
||||
input.Add(new Vertex(r * Math.Cos(i * dphi), r * Math.Sin(i * dphi), 1));
|
||||
input.Add(new Edge(i, (i + 1) % npoints, 1));
|
||||
}
|
||||
|
||||
count = input.Count;
|
||||
input.AddContour(CreateCircle(r, (int)(r / h), 1), 1, new Point(0, 0));
|
||||
|
||||
// Center cirlce
|
||||
r = (radius + 1) / 2.0;
|
||||
npoints = (int)(2 * Math.PI * r / h);
|
||||
dphi = 2 * Math.PI / npoints;
|
||||
for (int i = 0; i < npoints; i++)
|
||||
{
|
||||
input.Add(new Vertex(r * Math.Cos(i * dphi), r * Math.Sin(i * dphi), 2));
|
||||
input.Add(new Edge(count + i, count + (i + 1) % npoints, 2));
|
||||
}
|
||||
r = (radius + 1.0) / 2.0;
|
||||
input.AddContour(CreateCircle(r, (int)(r / h), 2), 2);
|
||||
|
||||
count = input.Count;
|
||||
//count = input.Count;
|
||||
|
||||
// Outer cirlce
|
||||
r = radius;
|
||||
npoints = (int)(2 * Math.PI * r / h);
|
||||
dphi = 2 * Math.PI / npoints;
|
||||
for (int i = 0; i < npoints; i++)
|
||||
{
|
||||
input.Add(new Vertex(r * Math.Cos(i * dphi), r * Math.Sin(i * dphi), 3));
|
||||
input.Add(new Edge(count + i, count + (i + 1) % npoints, 3));
|
||||
}
|
||||
|
||||
input.Holes.Add(new Point(0, 0));
|
||||
input.AddContour(CreateCircle(r, (int)(r / h), 3), 3);
|
||||
|
||||
// Regions: |++++++|++++++|---|
|
||||
// r 1 0
|
||||
|
||||
Reference in New Issue
Block a user