Basic support for region area constraints.

git-svn-id: https://triangle.svn.codeplex.com/svn@79346 0e2699bc-83d4-4a8f-98e7-55e24ab8c7a5
This commit is contained in:
SND\wo80_cp
2016-07-15 22:48:07 +00:00
parent 507ef402ce
commit f7dba8af41
4 changed files with 60 additions and 3 deletions
@@ -17,6 +17,23 @@ namespace TriangleNet.Geometry
{
internal Point point;
internal int id;
internal double area;
/// <summary>
/// Gets or sets a region area constraint.
/// </summary>
public double Area
{
get { return area; }
set
{
if (value < 0.0)
{
throw new ArgumentException("Area constraints must not be negative.");
}
area = value;
}
}
/// <summary>
/// Initializes a new instance of the <see cref="RegionPointer" /> class.
@@ -25,9 +42,22 @@ namespace TriangleNet.Geometry
/// <param name="y">Y coordinate of the region.</param>
/// <param name="id">Region id.</param>
public RegionPointer(double x, double y, int id)
: this(x, y, id, 0.0)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="RegionPointer" /> class.
/// </summary>
/// <param name="x">X coordinate of the region.</param>
/// <param name="y">Y coordinate of the region.</param>
/// <param name="id">Region id.</param>
/// <param name="area">Area constraint.</param>
public RegionPointer(double x, double y, int id, double area)
{
this.point = new Point(x, y);
this.id = id;
this.area = area;
}
}
}
+24 -2
View File
@@ -446,7 +446,7 @@ namespace TriangleNet.IO
// Read area constraints (optional).
if (TryReadLine(reader, out line))
{
int regions = int.Parse(line[0]);
int id, regions = int.Parse(line[0]);
if (regions > 0)
{
@@ -462,10 +462,32 @@ namespace TriangleNet.IO
throw new Exception("Invalid region attributes.");
}
if (!int.TryParse(line[3], out id))
{
id = i;
}
double area = 0.0;
if (line.Length > 4)
{
double.TryParse(line[4], NumberStyles.Number, nfi, out area);
}
// Triangle's .poly file format allows region definitions with
// either 4 or 5 parameters, and different interpretations for
// them depending on the number of parameters.
//
// See http://www.cs.cmu.edu/~quake/triangle.poly.html
//
// The .NET version will interpret the fourth parameter always
// as an integer region id and the optional fifth parameter as
// an area constraint.
data.Regions.Add(new RegionPointer(
double.Parse(line[1], nfi), // Region x
double.Parse(line[2], nfi), // Region y
int.Parse(line[3]))); // Region id
id, area));
}
}
}
@@ -186,6 +186,7 @@ namespace TriangleNet.Meshing
// holes have been carved.
regionTris[i] = searchtri.tri;
regionTris[i].label = region.id;
regionTris[i].area = region.area;
}
}
}
@@ -92,7 +92,11 @@ namespace TriangleNet.Meshing.Iterators
public void Process(Triangle triangle)
{
// Default action is to just set the region id for all trianlges.
this.Process(triangle, (tri) => { tri.label = triangle.label; });
this.Process(triangle, (tri) =>
{
tri.label = triangle.label;
tri.area = triangle.area;
});
}
/// <summary>