Rename MeshExplorer to Triangle.Viewer (keeping old namespace for now).

This commit is contained in:
wo80
2022-03-05 01:07:05 +01:00
parent 23c2682c6e
commit 4484c6c31a
60 changed files with 3 additions and 2 deletions
@@ -0,0 +1,158 @@
// -----------------------------------------------------------------------
// <copyright file="BaseGenerator.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------
namespace MeshExplorer.Generators
{
using System;
using System.Collections.Generic;
using TriangleNet.Geometry;
/// <summary>
/// TODO: Update summary.
/// </summary>
public abstract class BaseGenerator : IGenerator
{
private static int MAX_PARAMS = 3;
protected string name = "Name";
protected string description = "Description";
protected int parameter = 0;
protected string[] descriptions = new string[MAX_PARAMS];
protected int[][] ranges = new int[MAX_PARAMS][];
public virtual string Name { get { return name; } }
public virtual string Description { get { return description; } }
public virtual int ParameterCount { get { return parameter; } }
public virtual string ParameterDescription(int paramIndex)
{
if (descriptions[paramIndex] == null)
{
return String.Empty;
}
return descriptions[paramIndex];
}
public virtual string ParameterDescription(int paramIndex, double paramValue)
{
int[] range = ranges[paramIndex];
if (range == null)
{
return String.Empty;
}
int num = GetParamValueInt(paramIndex, paramValue);
return num.ToString();
}
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];
if (range == null)
{
return 0;
}
return (int)((range[1] - range[0]) / 100.0 * paramOffset + range[0]);
}
protected double GetParamValueDouble(int paramIndex, double paramOffset)
{
int[] range = ranges[paramIndex];
if (range == null)
{
return 0;
}
return ((range[1] - range[0]) / 100.0 * paramOffset + range[0]);
}
public override string ToString()
{
return this.Name;
}
}
}
@@ -0,0 +1,51 @@
// -----------------------------------------------------------------------
// <copyright file="StarInBox.cs" company="">
// Christian Woltering, Triangle.NET, http://triangle.codeplex.com/
// </copyright>
// -----------------------------------------------------------------------
namespace MeshExplorer.Generators
{
using System;
using TriangleNet.Geometry;
/// <summary>
/// Generates a star contained in a box.
/// </summary>
public class BoxWithHole : BaseGenerator
{
public BoxWithHole()
{
name = "Box with Hole";
description = "";
parameter = 3;
descriptions[0] = "Points on box sides:";
descriptions[1] = "Points on hole:";
descriptions[2] = "Radius:";
ranges[0] = new int[] { 5, 50 };
ranges[1] = new int[] { 10, 200 };
ranges[2] = new int[] { 5, 20 };
}
public override IPolygon Generate(double param0, double param1, double param2)
{
int n = GetParamValueInt(1, param1);
var input = new Polygon(n + 4);
double r = GetParamValueInt(2, param2);
// Generate circle (hole)
input.Add(new Contour(CreateCircle(r, n, 1), 1), new Point(0, 0));
n = GetParamValueInt(0, param0);
// Generate box
input.Add(new Contour(CreateRectangle(new Rectangle(-50, -50, 100, 100), n, 2), 2));
return input;
}
}
}
@@ -0,0 +1,64 @@
// -----------------------------------------------------------------------
// <copyright file="RingPolygon.cs" company="">
// Christian Woltering, Triangle.NET, http://triangle.codeplex.com/
// </copyright>
// -----------------------------------------------------------------------
namespace MeshExplorer.Generators
{
using TriangleNet.Geometry;
/// <summary>
/// Generates a ring polygon.
/// </summary>
public class CircleWithHole : BaseGenerator
{
public CircleWithHole()
{
name = "Circle with Hole";
description = "";
parameter = 2;
descriptions[0] = "Number of points:";
descriptions[1] = "Outer radius:";
ranges[0] = new int[] { 100, 250 };
ranges[1] = new int[] { 2, 15 };
}
public override IPolygon Generate(double param0, double param1, double param2)
{
// Number of points on the outer circle
int n = GetParamValueInt(0, param0);
double radius = GetParamValueInt(1, param1);
// Current radius and step size
double r, h = radius / n;
var input = new Polygon(n + 1);
// Inner cirlce (radius = 1) (hole)
r = 1;
input.Add(new Contour(CreateCircle(r, (int)(r / h), 1), 1), new Point(0, 0));
// Center cirlce
r = (radius + 1.0) / 2.0;
input.Add(new Contour(CreateCircle(r, (int)(r / h), 2), 2));
//count = input.Count;
// Outer cirlce
r = radius;
input.Add(new Contour(CreateCircle(r, (int)(r / h), 3), 3));
// Regions: |++++++|++++++|---|
// r 1 0
input.Regions.Add(new RegionPointer((r + 3.0) / 4.0, 0, 1));
input.Regions.Add(new RegionPointer((3 * r + 1.0) / 4.0, 0, 2));
return input;
}
}
}
@@ -0,0 +1,23 @@
// -----------------------------------------------------------------------
// <copyright file="IGenerator.cs" company="">
// Christian Woltering, Triangle.NET, http://triangle.codeplex.com/
// </copyright>
// -----------------------------------------------------------------------
namespace MeshExplorer.Generators
{
using TriangleNet.Geometry;
/// <summary>
/// Interface for generating input geometries.
/// </summary>
public interface IGenerator
{
string Name { get; }
string Description { get; }
int ParameterCount { get; }
string ParameterDescription(int paramIndex);
string ParameterDescription(int paramIndex, double paramValue);
IPolygon Generate(double param1, double param2, double param3);
}
}
@@ -0,0 +1,55 @@
// -----------------------------------------------------------------------
// <copyright file="RandomPoints.cs" company="">
// Christian Woltering, Triangle.NET, http://triangle.codeplex.com/
// </copyright>
// -----------------------------------------------------------------------
namespace MeshExplorer.Generators
{
using TriangleNet.Geometry;
/// <summary>
/// Simple random points generator.
/// </summary>
public class RandomPoints : BaseGenerator
{
public RandomPoints()
{
name = "Random Points";
description = "";
parameter = 3;
descriptions[0] = "Number of points:";
descriptions[1] = "Width:";
descriptions[2] = "Height:";
ranges[0] = new int[] { 10, 5000 };
ranges[1] = new int[] { 10, 200 };
ranges[2] = new int[] { 10, 200 };
}
public override IPolygon Generate(double param0, double param1, double param2)
{
int numPoints = GetParamValueInt(0, param0);
numPoints = (numPoints / 10) * 10;
if (numPoints < ranges[0][0])
{
numPoints = ranges[0][0];
}
var input = new Polygon(numPoints);
int width = GetParamValueInt(1, param1);
int height = GetParamValueInt(2, param2);
for (int i = 0; i < numPoints; i++)
{
input.Add(new Vertex(Util.Random.NextDouble() * width,
Util.Random.NextDouble() * height));
}
return input;
}
}
}
@@ -0,0 +1,100 @@
// -----------------------------------------------------------------------
// <copyright file="RandomPointsCircle.cs" company="">
// Christian Woltering, Triangle.NET, http://triangle.codeplex.com/
// </copyright>
// -----------------------------------------------------------------------
namespace MeshExplorer.Generators
{
using System;
using TriangleNet.Geometry;
/// <summary>
/// Simple random points generator (points distributed in a circle).
/// </summary>
public class RandomPointsCircle : BaseGenerator
{
public RandomPointsCircle()
{
name = "Random Points (Circle)";
description = "";
parameter = 2;
descriptions[0] = "Number of points:";
descriptions[1] = "Distribution:";
ranges[0] = new int[] { 5, 5000 };
ranges[1] = new int[] { 0, 1 };
}
public override string ParameterDescription(int paramIndex, double paramValue)
{
if (paramIndex == 0)
{
int numPoints = GetParamValueInt(paramIndex, paramValue);
numPoints = (numPoints / 10) * 10;
if (numPoints < 5)
{
numPoints = 5;
}
return numPoints.ToString();
}
if (paramIndex == 1)
{
double exp = (paramValue + 10) / 100;
if (exp > 1.092)
{
exp = 1.1;
}
return exp.ToString("0.00", Util.Nfi);
}
return "";
}
public override IPolygon Generate(double param0, double param1, double param2)
{
int numPoints = GetParamValueInt(0, param0);
numPoints = (numPoints / 10) * 10;
if (numPoints < 5)
{
numPoints = 5;
}
double exp = (param1 + 10) / 100;
var input = new Polygon(numPoints);
int i = 0, cNum = 2 * (int)Math.Floor(Math.Sqrt(numPoints));
double r, phi, radius = 100, step = 2 * Math.PI / cNum;
// Distrubute points equally on circle border
for (; i < cNum; i++)
{
// Add a little error
r = Util.Random.NextDouble();
input.Add(new Vertex((radius + r) * Math.Cos(i * step),
(radius + r) * Math.Sin(i * step)));
}
for (; i < numPoints; i++)
{
// Use sqrt(rand) to get normal distribution right.
r = Math.Pow(Util.Random.NextDouble(), exp) * radius;
phi = Util.Random.NextDouble() * Math.PI * 2;
input.Add(new Vertex(r * Math.Cos(phi), r * Math.Sin(phi)));
}
return input;
}
}
}
@@ -0,0 +1,100 @@
// -----------------------------------------------------------------------
// <copyright file="RingPolygon.cs" company="">
// Christian Woltering, Triangle.NET, http://triangle.codeplex.com/
// </copyright>
// -----------------------------------------------------------------------
namespace MeshExplorer.Generators
{
using System;
using System.Collections.Generic;
using TriangleNet.Geometry;
/// <summary>
/// Generates a ring polygon.
/// </summary>
public class RingPolygon : BaseGenerator
{
public RingPolygon()
{
name = "Ring";
description = "";
parameter = 2;
descriptions[0] = "Number of points:";
descriptions[1] = "Variation:";
ranges[0] = new int[] { 50, 250 };
ranges[1] = new int[] { 0, 1 };
}
public override string ParameterDescription(int paramIndex, double paramValue)
{
if (paramIndex == 0)
{
int numRays = GetParamValueInt(paramIndex, paramValue);
return numRays.ToString();
}
if (paramIndex == 1)
{
double variation = GetParamValueDouble(paramIndex, paramValue);
return variation.ToString("0.0", Util.Nfi);
}
return "";
}
public override IPolygon Generate(double param0, double param1, double param2)
{
int n = GetParamValueInt(0, param0);
int m = n / 2;
var input = new Polygon(n + 1);
double ro, r = 10;
double step = 2 * Math.PI / m;
var inner = new List<Vertex>(m);
// Inner ring
for (int i = 0; i < m; i++)
{
inner.Add(new Vertex(r * Math.Cos(i * step), r * Math.Sin(i * step)));
}
input.Add(new Contour(inner, 1));
r = 1.5 * r;
var outer = new List<Vertex>(n);
step = 2 * Math.PI / n;
double offset = step / 2;
// Outer ring
for (int i = 0; i < n; i++)
{
ro = r;
if (i % 2 == 0)
{
ro = r + r * Util.Random.NextDouble() * (param1 / 100);
}
outer.Add(new Vertex(ro * Math.Cos(i * step + offset), ro * Math.Sin(i * step + offset)));
}
input.Add(new Contour(outer, 2));
input.Holes.Add(new Point(0, 0));
return input;
}
public override string ToString()
{
return this.Name;
}
}
}
@@ -0,0 +1,63 @@
// -----------------------------------------------------------------------
// <copyright file="StarInBox.cs" company="">
// Christian Woltering, Triangle.NET, http://triangle.codeplex.com/
// </copyright>
// -----------------------------------------------------------------------
namespace MeshExplorer.Generators
{
using System;
using TriangleNet.Geometry;
/// <summary>
/// Generates a star contained in a box.
/// </summary>
public class StarInBox : BaseGenerator
{
public StarInBox()
{
name = "Star in Box";
description = "";
parameter = 1;
descriptions[0] = "Number of rays:";
ranges[0] = new int[] { 3, 61 };
}
public override IPolygon Generate(double param0, double param1, double param2)
{
int numRays = GetParamValueInt(0, param0);
var g = new Polygon(numRays + 4);
g.Add(new Vertex(0, 0)); // Center
double x, y, r, e, step = 2 * Math.PI / numRays;
for (int i = 0; i < numRays; i++)
{
e = Util.Random.NextDouble() * step * 0.7;
r = (Util.Random.NextDouble() + 0.7) * 0.5;
x = r * Math.Cos(i * step + e);
y = r * Math.Sin(i * step + e);
g.Add(new Vertex(x, y, 2));
g.Add(new Segment(g.Points[0], g.Points[i + 1], 2));
}
g.Add(new Vertex(-1, -1, 1)); // Box
g.Add(new Vertex(1, -1, 1));
g.Add(new Vertex(1, 1, 1));
g.Add(new Vertex(-1, 1, 1));
numRays = g.Count;
g.Add(new Segment(g.Points[numRays - 1], g.Points[numRays - 2], 1));
g.Add(new Segment(g.Points[numRays - 2], g.Points[numRays - 3], 1));
g.Add(new Segment(g.Points[numRays - 3], g.Points[numRays - 4], 1));
g.Add(new Segment(g.Points[numRays - 4], g.Points[numRays - 1], 1));
return g;
}
}
}