From f89c773746983806a48be94b9b0dfa4d9f491778 Mon Sep 17 00:00:00 2001 From: "SND\\wo80_cp" Date: Sun, 1 Jun 2014 20:10:02 +0000 Subject: [PATCH] Code/comments cleanup git-svn-id: https://triangle.svn.codeplex.com/svn@75046 0e2699bc-83d4-4a8f-98e7-55e24ab8c7a5 --- Triangle.NET/TestApp/Views/StatisticView.cs | 6 +- Triangle.NET/Triangle/Data/BadTriQueue.cs | 16 ++--- Triangle.NET/Triangle/Data/BadTriangle.cs | 2 +- Triangle.NET/Triangle/Data/Osub.cs | 7 +- Triangle.NET/Triangle/Data/Otri.cs | 7 +- Triangle.NET/Triangle/Data/Segment.cs | 5 -- Triangle.NET/Triangle/Data/Triangle.cs | 6 -- Triangle.NET/Triangle/Geometry/IPolygon.cs | 43 ++++++++++- Triangle.NET/Triangle/Geometry/Polygon.cs | 23 ++++++ Triangle.NET/Triangle/Mesh.cs | 1 + .../Triangle/Meshing/ConstraintOptions.cs | 22 +++--- Triangle.NET/Triangle/Meshing/Converter.cs | 41 ++++------- .../Triangle/Meshing/GenericMesher.cs | 39 +++------- .../Triangle/Meshing/IConstraintMesher.cs | 15 ++++ Triangle.NET/Triangle/Meshing/IMesh.cs | 32 +++++++++ .../Triangle/Meshing/IQualityMesher.cs | 17 +++++ .../Triangle/Meshing/ITriangulator.cs | 7 +- .../Triangle/Meshing/QualityOptions.cs | 26 ++++--- Triangle.NET/Triangle/RobustPredicates.cs | 66 ++++++++--------- Triangle.NET/Triangle/Sampler.cs | 3 +- Triangle.NET/Triangle/Tools/BoundedVoronoi.cs | 16 ++--- Triangle.NET/Triangle/Tools/QuadTree.cs | 7 +- Triangle.NET/Triangle/Tools/Statistic.cs | 72 ------------------- Triangle.NET/Triangle/Tools/Voronoi.cs | 17 +++-- Triangle.NET/Triangle/TriangleLocator.cs | 6 +- 25 files changed, 261 insertions(+), 241 deletions(-) diff --git a/Triangle.NET/TestApp/Views/StatisticView.cs b/Triangle.NET/TestApp/Views/StatisticView.cs index a938867..f48c9fc 100644 --- a/Triangle.NET/TestApp/Views/StatisticView.cs +++ b/Triangle.NET/TestApp/Views/StatisticView.cs @@ -75,9 +75,9 @@ namespace MeshExplorer.Views public void HandleMeshChange(Mesh mesh) { // New mesh stats - lbNumVert.Text = statistic.Vertices.ToString(); - lbNumSeg.Text = statistic.ConstrainedEdges.ToString(); - lbNumTri.Text = statistic.Triangles.ToString(); + lbNumVert.Text = mesh.Vertices.Count.ToString(); + lbNumSeg.Text = mesh.Segments.Count.ToString(); + lbNumTri.Text = mesh.Triangles.Count.ToString(); // Update statistics tab angleHistogram1.SetData(statistic.MinAngleHistogram, statistic.MaxAngleHistogram); diff --git a/Triangle.NET/Triangle/Data/BadTriQueue.cs b/Triangle.NET/Triangle/Data/BadTriQueue.cs index 91ce69e..2670870 100644 --- a/Triangle.NET/Triangle/Data/BadTriQueue.cs +++ b/Triangle.NET/Triangle/Data/BadTriQueue.cs @@ -34,8 +34,6 @@ namespace TriangleNet.Data public BadTriQueue() { - //badtriangles = new List(); - queuefront = new BadTriangle[4096]; queuetail = new BadTriangle[4096]; nextnonemptyq = new int[4096]; @@ -147,19 +145,19 @@ namespace TriangleNet.Data /// /// /// - /// - /// - /// - public void Enqueue(ref Otri enqtri, double minedge, Vertex enqapex, Vertex enqorg, Vertex enqdest) + /// + /// + /// + public void Enqueue(ref Otri enqtri, double minedge, Vertex apex, Vertex org, Vertex dest) { // Allocate space for the bad triangle. BadTriangle newbad = new BadTriangle(); newbad.poortri = enqtri; newbad.key = minedge; - newbad.apex = enqapex; - newbad.org = enqorg; - newbad.dest = enqdest; + newbad.apex = apex; + newbad.org = org; + newbad.dest = dest; Enqueue(newbad); } diff --git a/Triangle.NET/Triangle/Data/BadTriangle.cs b/Triangle.NET/Triangle/Data/BadTriangle.cs index 39e0ea8..cd48829 100644 --- a/Triangle.NET/Triangle/Data/BadTriangle.cs +++ b/Triangle.NET/Triangle/Data/BadTriangle.cs @@ -21,7 +21,7 @@ namespace TriangleNet.Data class BadTriangle { public Otri poortri; // A skinny or too-large triangle. - public double key; // cos^2 of smallest (apical) angle. + public double key; // cos^2 of smallest (apical) angle. public Vertex org, dest, apex; // Its three vertices. public BadTriangle next; // Pointer to next bad triangle. diff --git a/Triangle.NET/Triangle/Data/Osub.cs b/Triangle.NET/Triangle/Data/Osub.cs index 84f951f..e66720d 100644 --- a/Triangle.NET/Triangle/Data/Osub.cs +++ b/Triangle.NET/Triangle/Data/Osub.cs @@ -14,10 +14,9 @@ namespace TriangleNet.Data /// An oriented subsegment. /// /// - /// Iincludes a pointer to a subsegment and an orientation. The orientation - /// denotes a side of the edge. Hence, there are two possible orientations. - /// By convention, the edge is always directed so that the "side" denoted - /// is the right side of the edge. + /// Includes a pointer to a subsegment and an orientation. The orientation denotes a + /// side of the edge. Hence, there are two possible orientations. By convention, the + /// edge is always directed so that the "side" denoted is the right side of the edge. /// struct Osub { diff --git a/Triangle.NET/Triangle/Data/Otri.cs b/Triangle.NET/Triangle/Data/Otri.cs index eead6a1..e4d9515 100644 --- a/Triangle.NET/Triangle/Data/Otri.cs +++ b/Triangle.NET/Triangle/Data/Otri.cs @@ -14,10 +14,9 @@ namespace TriangleNet.Data /// An oriented triangle. /// /// - /// Includes a pointer to a triangle and orientation. - /// The orientation denotes an edge of the triangle. Hence, there are - /// three possible orientations. By convention, each edge always points - /// counterclockwise about the corresponding triangle. + /// Includes a pointer to a triangle and orientation. The orientation denotes an edge + /// of the triangle. Hence, there are three possible orientations. By convention, each + /// edge always points counterclockwise about the corresponding triangle. /// struct Otri { diff --git a/Triangle.NET/Triangle/Data/Segment.cs b/Triangle.NET/Triangle/Data/Segment.cs index 67de461..80b3e77 100644 --- a/Triangle.NET/Triangle/Data/Segment.cs +++ b/Triangle.NET/Triangle/Data/Segment.cs @@ -13,11 +13,6 @@ namespace TriangleNet.Data /// /// The subsegment data structure. /// - /// - /// Each subsegment contains two pointers to adjoining subsegments, plus - /// four pointers to vertices, plus two pointers to adjoining triangles, - /// plus one boundary marker. - /// public class Segment : ISegment { // Hash for dictionary. Will be set by mesh instance. diff --git a/Triangle.NET/Triangle/Data/Triangle.cs b/Triangle.NET/Triangle/Data/Triangle.cs index ca1447c..272a6e5 100644 --- a/Triangle.NET/Triangle/Data/Triangle.cs +++ b/Triangle.NET/Triangle/Data/Triangle.cs @@ -13,12 +13,6 @@ namespace TriangleNet.Data /// /// The triangle data structure. /// - /// - /// Each triangle contains three pointers to adjoining triangles, plus three - /// pointers to vertices, plus three pointers to subsegments (declared below; - /// these pointers are usually 'dummysub'). It may or may not also contain - /// user-defined attributes and/or a floating-point "area constraint". - /// public class Triangle : ITriangle { // Hash for dictionary. Will be set by mesh instance. diff --git a/Triangle.NET/Triangle/Geometry/IPolygon.cs b/Triangle.NET/Triangle/Geometry/IPolygon.cs index 358798f..dc078fb 100644 --- a/Triangle.NET/Triangle/Geometry/IPolygon.cs +++ b/Triangle.NET/Triangle/Geometry/IPolygon.cs @@ -4,21 +4,62 @@ namespace TriangleNet.Geometry using System.Collections.Generic; using TriangleNet.Data; + /// + /// Polygon interface. + /// public interface IPolygon { + /// + /// Gets the vertices of the polygon. + /// List Points { get; } + + /// + /// Gets the segments of the polygon. + /// List Segments { get; } + /// + /// Gets a list of points defining the holes of the polygon. + /// List Holes { get; } - //List Regions { get; } + + /// + /// Gets a list of pointers defining the regions of the polygon. + /// List Regions { get; } + /// + /// Gets or sets value indicating wether the vertices have marks or not. + /// bool HasPointMarkers { get; set; } + + /// + /// Gets or sets value indicating wether the segments have marks or not. + /// bool HasSegmentMarkers { get; set; } + /// + /// Adds a contour to the polygon. + /// + /// Points making up the contour. + /// Contour marker. + /// Treat contour as a hole (interior boundary). + /// The hole is convex. void AddContour(IEnumerable points, int marker, bool hole, bool convex); + + /// + /// Adds a contour to the polygon. + /// + /// Points making up the contour. + /// Contour marker. + /// Point inside the contour, making it a hole. void AddContour(IEnumerable points, int marker, Point hole); + /// + /// Compute the bounds of the polygon. + /// + /// Rectangle defining an axis-aligned bounding box. Rectangle Bounds(); } } diff --git a/Triangle.NET/Triangle/Geometry/Polygon.cs b/Triangle.NET/Triangle/Geometry/Polygon.cs index b177801..6e045da 100644 --- a/Triangle.NET/Triangle/Geometry/Polygon.cs +++ b/Triangle.NET/Triangle/Geometry/Polygon.cs @@ -5,6 +5,9 @@ namespace TriangleNet.Geometry using System.Collections.Generic; using TriangleNet.Data; + /// + /// A polygon represented as a planar straight line graph. + /// public class Polygon : IPolygon { List points; @@ -13,30 +16,37 @@ namespace TriangleNet.Geometry List segments; + /// public List Points { get { return points; } } + /// public List Holes { get { return holes; } } + /// public List Regions { get { return regions; } } + /// public List Segments { get { return segments; } } + /// public bool HasPointMarkers { get; set; } + /// public bool HasSegmentMarkers { get; set; } + /// public int Count { get { return points.Count; } @@ -59,6 +69,7 @@ namespace TriangleNet.Geometry HasSegmentMarkers = false; } + /// public void AddContour(IEnumerable points, int marker = 0, bool hole = false, bool convex = false) { @@ -106,6 +117,7 @@ namespace TriangleNet.Geometry } } + /// public void AddContour(IEnumerable points, int marker, Point hole) { // Copy input to list. @@ -130,9 +142,11 @@ namespace TriangleNet.Geometry this.segments.Add(new Edge(offset + i, offset + ((i + 1) % count), marker)); } + // TODO: check if hole is actually inside contour? this.holes.Add(hole); } + /// public Rectangle Bounds() { var bounds = new Rectangle(); @@ -141,11 +155,17 @@ namespace TriangleNet.Geometry return bounds; } + /// + /// Add a vertex to the polygon. + /// public void Add(Vertex vertex) { this.points.Add(vertex); } + /// + /// Add a vertex to the polygon. + /// public void Add(Vertex vertex, double[] attributes) { // TODO: check attibutes @@ -155,6 +175,9 @@ namespace TriangleNet.Geometry this.points.Add(vertex); } + /// + /// Add a segment to the polygon. + /// public void Add(Edge edge) { this.segments.Add(edge); diff --git a/Triangle.NET/Triangle/Mesh.cs b/Triangle.NET/Triangle/Mesh.cs index b03ff1a..6b6c689 100644 --- a/Triangle.NET/Triangle/Mesh.cs +++ b/Triangle.NET/Triangle/Mesh.cs @@ -199,6 +199,7 @@ namespace TriangleNet behavior.MaxAngle = quality.MaximumAngle; behavior.MaxArea = quality.MaximumArea; + // TODO: behavior.VarArea = quality.VariableArea; this.Refine(); } diff --git a/Triangle.NET/Triangle/Meshing/ConstraintOptions.cs b/Triangle.NET/Triangle/Meshing/ConstraintOptions.cs index 1180409..d78c920 100644 --- a/Triangle.NET/Triangle/Meshing/ConstraintOptions.cs +++ b/Triangle.NET/Triangle/Meshing/ConstraintOptions.cs @@ -1,33 +1,31 @@  namespace TriangleNet.Meshing { + /// + /// Mesh constraint options for polygon triangulation. + /// public class ConstraintOptions { - public static ConstraintOptions Empty - { - get { return new ConstraintOptions(); } - } - - #region Public properties - /// - /// Gets or sets a value indicating wether to use regions. + /// Gets or sets a value indicating whether to use regions. /// public bool UseRegions { get; set; } /// - /// Gets or sets a value indicating wether to create a Conforming + /// Gets or sets a value indicating whether to create a Conforming /// Delaunay triangulation. /// public bool ConformingDelaunay { get; set; } /// - /// Enclose the convex hull with segments. + /// Gets or sets a value indicating whether to enclose the convex + /// hull with segments. /// public bool Convex { get; set; } /// - /// Suppresses boundary segment splitting. + /// Gets or sets a flag indicating whether to suppress boundary + /// segment splitting. /// /// /// 0 = split segments (default) @@ -35,7 +33,5 @@ namespace TriangleNet.Meshing /// 2 = prevent all segment splitting, including internal boundaries /// public int SegmentSplitting { get; set; } - - #endregion } } diff --git a/Triangle.NET/Triangle/Meshing/Converter.cs b/Triangle.NET/Triangle/Meshing/Converter.cs index 452b9f4..ca2154f 100644 --- a/Triangle.NET/Triangle/Meshing/Converter.cs +++ b/Triangle.NET/Triangle/Meshing/Converter.cs @@ -14,10 +14,13 @@ namespace TriangleNet.Meshing using TriangleNet.Geometry; /// - /// The DataReader class provides methods for mesh reconstruction. + /// The Converter class provides methods for mesh reconstruction. /// public class Converter { + /// + /// Reconstruct a triangulation from its raw data representation. + /// public Mesh ToMesh(Polygon polygon, IList triangles) { return ToMesh(polygon, triangles.ToArray()); @@ -26,25 +29,6 @@ namespace TriangleNet.Meshing /// /// Reconstruct a triangulation from its raw data representation. /// - /// - /// Reads an .ele file and reconstructs the original mesh. If the -p switch - /// is used, this procedure will also read a .poly file and reconstruct the - /// subsegments of the original mesh. If the -a switch is used, this - /// procedure will also read an .area file and set a maximum area constraint - /// on each triangle. - /// - /// Vertices that are not corners of triangles, such as nodes on edges of - /// subparametric elements, are discarded. - /// - /// This routine finds the adjacencies between triangles (and subsegments) - /// by forming one stack of triangles for each vertex. Each triangle is on - /// three different stacks simultaneously. Each triangle's subsegment - /// pointers are used to link the items in each stack. This memory-saving - /// feature makes the code harder to read. The most important thing to keep - /// in mind is that each triangle is removed from a stack precisely when - /// the corresponding pointer is adjusted to refer to a subsegment rather - /// than the next triangle of the stack. - /// public Mesh ToMesh(Polygon polygon, ITriangle[] triangles) { Otri tri = default(Otri); @@ -93,8 +77,8 @@ namespace TriangleNet.Meshing } /// - /// Finds the adjacencies between triangles by forming a stack of triangles - /// for each vertex. + /// Finds the adjacencies between triangles by forming a stack of triangles for + /// each vertex. Each triangle is on three different stacks simultaneously. /// private static List[] SetNeighbors(Mesh mesh, ITriangle[] triangles) { @@ -102,15 +86,14 @@ namespace TriangleNet.Meshing Otri triangleleft = default(Otri); Otri checktri = default(Otri); Otri checkleft = default(Otri); - Otri nexttri; // Triangle + Otri nexttri; Vertex tdest, tapex; Vertex checkdest, checkapex; int[] corner = new int[3]; int aroundvertex; int i; - // Allocate a temporary array that maps each vertex to some adjacent - // triangle. + // Allocate a temporary array that maps each vertex to some adjacent triangle. var vertexarray = new List[mesh.vertices.Count]; // Each vertex is initially unrepresented. @@ -164,11 +147,12 @@ namespace TriangleNet.Meshing { // Take the number for the origin of triangleloop. aroundvertex = corner[tri.orient]; + int index = vertexarray[aroundvertex].Count - 1; + // Look for other triangles having this vertex. nexttri = vertexarray[aroundvertex][index]; - // Link the current triangle to the next one in the stack. - //tri.triangle.neighbors[tri.orient] = nexttri; + // Push the current triangle onto the stack. vertexarray[aroundvertex].Add(tri); @@ -212,6 +196,9 @@ namespace TriangleNet.Meshing return vertexarray; } + /// + /// Finds the adjacencies between triangles and subsegments. + /// private static void SetSegments(Mesh mesh, Polygon polygon, List[] vertexarray) { Otri checktri = default(Otri); diff --git a/Triangle.NET/Triangle/Meshing/GenericMesher.cs b/Triangle.NET/Triangle/Meshing/GenericMesher.cs index 88dfaf4..759b851 100644 --- a/Triangle.NET/Triangle/Meshing/GenericMesher.cs +++ b/Triangle.NET/Triangle/Meshing/GenericMesher.cs @@ -7,6 +7,9 @@ namespace TriangleNet.Meshing using TriangleNet.IO; using TriangleNet.Meshing.Algorithm; + /// + /// Create meshes of point sets or polygons. + /// public class GenericMesher : ITriangulator, IConstraintMesher, IQualityMesher { ITriangulator triangulator; @@ -21,55 +24,31 @@ namespace TriangleNet.Meshing this.triangulator = triangulator; } - /// - /// Triangulates a point set. - /// - /// Collection of points. - /// Mesh + /// public IMesh Triangulate(ICollection points) { return triangulator.Triangulate(points); } - /// - /// Triangulates a polygon. - /// - /// The polygon. - /// Mesh + /// public IMesh Triangulate(IPolygon polygon) { return Triangulate(polygon, null, null); } - /// - /// Triangulates a polygon, applying constraint options. - /// - /// The polygon. - /// Constraint options. - /// Mesh + /// public IMesh Triangulate(IPolygon polygon, ConstraintOptions options) { return Triangulate(polygon, options, null); } - /// - /// Triangulates a polygon, applying quality options. - /// - /// The polygon. - /// Quality options. - /// Mesh + /// public IMesh Triangulate(IPolygon polygon, QualityOptions quality) { return Triangulate(polygon, null, quality); } - /// - /// Triangulates a polygon, applying quality and constraint options. - /// - /// The polygon. - /// Constraint options. - /// Quality options. - /// Mesh + /// public IMesh Triangulate(IPolygon polygon, ConstraintOptions options, QualityOptions quality) { var mesh = (Mesh)triangulator.Triangulate(polygon.Points); @@ -80,7 +59,7 @@ namespace TriangleNet.Meshing } /// - /// Generates a structured mesh with bounds (0, 0, width, height). + /// Generates a structured mesh with bounds [0, 0, width, height]. /// /// Width of the mesh (must be > 0). /// Height of the mesh (must be > 0). diff --git a/Triangle.NET/Triangle/Meshing/IConstraintMesher.cs b/Triangle.NET/Triangle/Meshing/IConstraintMesher.cs index c5fabde..1336417 100644 --- a/Triangle.NET/Triangle/Meshing/IConstraintMesher.cs +++ b/Triangle.NET/Triangle/Meshing/IConstraintMesher.cs @@ -3,9 +3,24 @@ namespace TriangleNet.Meshing { using TriangleNet.Geometry; + /// + /// Interface for polygon triangulation. + /// public interface IConstraintMesher { + /// + /// Triangulates a polygon. + /// + /// The polygon. + /// Mesh IMesh Triangulate(IPolygon polygon); + + /// + /// Triangulates a polygon, applying constraint options. + /// + /// The polygon. + /// Constraint options. + /// Mesh IMesh Triangulate(IPolygon polygon, ConstraintOptions options); } } diff --git a/Triangle.NET/Triangle/Meshing/IMesh.cs b/Triangle.NET/Triangle/Meshing/IMesh.cs index 33bb608..4db2e5e 100644 --- a/Triangle.NET/Triangle/Meshing/IMesh.cs +++ b/Triangle.NET/Triangle/Meshing/IMesh.cs @@ -5,17 +5,49 @@ namespace TriangleNet.Meshing using TriangleNet.Data; using TriangleNet.Geometry; + /// + /// Mesh interface. + /// public interface IMesh { + /// + /// Gets the vertices of the mesh. + /// ICollection Vertices { get; } + + /// + /// Gets the edges of the mesh. + /// IEnumerable Edges { get; } + + /// + /// Gets the segments (constraint edges) of the mesh. + /// ICollection Segments { get; } + + /// + /// Gets the triangles of the mesh. + /// ICollection Triangles { get; } + + /// + /// Gets the holes of the mesh. + /// IList Holes { get; } + /// + /// Gets the bounds of the mesh. + /// Rectangle Bounds { get; } + /// + /// Renumber mesh vertices and triangles. + /// void Renumber(); + + /// + /// Refine the mesh. + /// void Refine(QualityOptions quality); } } diff --git a/Triangle.NET/Triangle/Meshing/IQualityMesher.cs b/Triangle.NET/Triangle/Meshing/IQualityMesher.cs index d5f1075..8d8a1ff 100644 --- a/Triangle.NET/Triangle/Meshing/IQualityMesher.cs +++ b/Triangle.NET/Triangle/Meshing/IQualityMesher.cs @@ -3,9 +3,26 @@ namespace TriangleNet.Meshing { using TriangleNet.Geometry; + /// + /// Interface for polygon triangulation with quality constraints. + /// public interface IQualityMesher { + /// + /// Triangulates a polygon, applying quality options. + /// + /// The polygon. + /// Quality options. + /// Mesh IMesh Triangulate(IPolygon polygon, QualityOptions quality); + + /// + /// Triangulates a polygon, applying quality and constraint options. + /// + /// The polygon. + /// Constraint options. + /// Quality options. + /// Mesh IMesh Triangulate(IPolygon polygon, ConstraintOptions options, QualityOptions quality); } } diff --git a/Triangle.NET/Triangle/Meshing/ITriangulator.cs b/Triangle.NET/Triangle/Meshing/ITriangulator.cs index 8b55018..ea631c8 100644 --- a/Triangle.NET/Triangle/Meshing/ITriangulator.cs +++ b/Triangle.NET/Triangle/Meshing/ITriangulator.cs @@ -10,10 +10,15 @@ namespace TriangleNet.Meshing using TriangleNet.Geometry; /// - /// TODO: Update summary. + /// Interface for point set triangulation. /// public interface ITriangulator { + /// + /// Triangulates a point set. + /// + /// Collection of points. + /// Mesh IMesh Triangulate(ICollection points); } } diff --git a/Triangle.NET/Triangle/Meshing/QualityOptions.cs b/Triangle.NET/Triangle/Meshing/QualityOptions.cs index 516c002..588b0b4 100644 --- a/Triangle.NET/Triangle/Meshing/QualityOptions.cs +++ b/Triangle.NET/Triangle/Meshing/QualityOptions.cs @@ -4,15 +4,11 @@ namespace TriangleNet.Meshing using System; using TriangleNet.Geometry; + /// + /// Mesh constraint options for quality triangulation. + /// public class QualityOptions { - public static QualityOptions Empty - { - get { return new QualityOptions(); } - } - - #region Public properties - /// /// Gets or sets a maximum angle constraint. /// @@ -29,10 +25,22 @@ namespace TriangleNet.Meshing public double MaximumArea { get; set; } /// - /// Apply a user-defined triangle constraint. + /// Gets or sets a user-defined triangle constraint. /// + /// + /// The test function will be called for each triangle in the mesh. The + /// second argument is the area of the triangle tested. If the function + /// returns true, the triangle is considered bad and will be refined. + /// public Func UserTest { get; set; } - #endregion + /// + /// Gets or sets a area constraint per triangle. + /// + /// + /// If this flag is set to true, the value will + /// be used to check if a triangle needs refinement. + /// + public bool VariableArea { get; set; } } } diff --git a/Triangle.NET/Triangle/RobustPredicates.cs b/Triangle.NET/Triangle/RobustPredicates.cs index 66ba46b..2f36347 100644 --- a/Triangle.NET/Triangle/RobustPredicates.cs +++ b/Triangle.NET/Triangle/RobustPredicates.cs @@ -13,12 +13,14 @@ namespace TriangleNet using TriangleNet.Tools; /// + /// Adaptive exact arithmetic geometric predicates. + /// + /// /// The adaptive exact arithmetic geometric predicates implemented herein are described in /// detail in the paper "Adaptive Precision Floating-Point Arithmetic and Fast Robust /// Geometric Predicates." by Jonathan Richard Shewchuk, see /// http://www.cs.cmu.edu/~quake/robust.html - /// - /// + /// /// The macros of the original C code were automatically expanded using the Visual Studio /// command prompt with the command "CL /P /C EXACT.C", see /// http://msdn.microsoft.com/en-us/library/8z9z0bx6.aspx @@ -28,7 +30,7 @@ namespace TriangleNet private static double epsilon, splitter, resulterrbound; private static double ccwerrboundA, ccwerrboundB, ccwerrboundC; private static double iccerrboundA, iccerrboundB, iccerrboundC; - private static double o3derrboundA, o3derrboundB, o3derrboundC; + //private static double o3derrboundA, o3derrboundB, o3derrboundC; /// /// Initialize the variables used for exact arithmetic. @@ -82,9 +84,9 @@ namespace TriangleNet iccerrboundA = (10.0 + 96.0 * epsilon) * epsilon; iccerrboundB = (4.0 + 48.0 * epsilon) * epsilon; iccerrboundC = (44.0 + 576.0 * epsilon) * epsilon * epsilon; - o3derrboundA = (7.0 + 56.0 * epsilon) * epsilon; - o3derrboundB = (3.0 + 28.0 * epsilon) * epsilon; - o3derrboundC = (26.0 + 288.0 * epsilon) * epsilon * epsilon; + //o3derrboundA = (7.0 + 56.0 * epsilon) * epsilon; + //o3derrboundB = (3.0 + 28.0 * epsilon) * epsilon; + //o3derrboundC = (26.0 + 288.0 * epsilon) * epsilon * epsilon; } /// @@ -237,15 +239,15 @@ namespace TriangleNet /// /// Find the circumcenter of a triangle. /// - /// Triangle point. - /// Triangle point. - /// Triangle point. + /// Triangle point. + /// Triangle point. + /// Triangle point. /// Relative coordinate of new location. /// Relative coordinate of new location. /// Off-center constant. /// Coordinates of the circumcenter (or off-center) - public static Point FindCircumcenter(Point torg, Point tdest, Point tapex, - ref double xi, ref double eta, double offconstant) + public static Point FindCircumcenter(Point org, Point dest, Point apex, + ref double xi, ref double eta, double offconstant) { double xdo, ydo, xao, yao; double dodist, aodist, dadist; @@ -255,14 +257,14 @@ namespace TriangleNet Statistic.CircumcenterCount++; // Compute the circumcenter of the triangle. - xdo = tdest.x - torg.x; - ydo = tdest.y - torg.y; - xao = tapex.x - torg.x; - yao = tapex.y - torg.y; + xdo = dest.x - org.x; + ydo = dest.y - org.y; + xao = apex.x - org.x; + yao = apex.y - org.y; dodist = xdo * xdo + ydo * ydo; aodist = xao * xao + yao * yao; - dadist = (tdest.x - tapex.x) * (tdest.x - tapex.x) + - (tdest.y - tapex.y) * (tdest.y - tapex.y); + dadist = (dest.x - apex.x) * (dest.x - apex.x) + + (dest.y - apex.y) * (dest.y - apex.y); if (Behavior.NoExact) { @@ -273,7 +275,7 @@ namespace TriangleNet // Use the counterclockwise() routine to ensure a positive (and // reasonably accurate) result, avoiding any possibility of // division by zero. - denominator = 0.5 / CounterClockwise(tdest, tapex, torg); + denominator = 0.5 / CounterClockwise(dest, apex, org); // Don't count the above as an orientation test. Statistic.CounterClockwiseCount--; } @@ -321,8 +323,8 @@ namespace TriangleNet { if (offconstant > 0.0) { - dxoff = 0.5 * (tapex.x - tdest.x) - offconstant * (tapex.y - tdest.y); - dyoff = 0.5 * (tapex.y - tdest.y) + offconstant * (tapex.x - tdest.x); + dxoff = 0.5 * (apex.x - dest.x) - offconstant * (apex.y - dest.y); + dyoff = 0.5 * (apex.y - dest.y) + offconstant * (apex.x - dest.x); // If the off-center is closer to the destination than the // circumcenter, use the off-center instead. if (dxoff * dxoff + dyoff * dyoff < @@ -342,15 +344,15 @@ namespace TriangleNet xi = (yao * dx - xao * dy) * (2.0 * denominator); eta = (xdo * dy - ydo * dx) * (2.0 * denominator); - return new Point(torg.x + dx, torg.y + dy); + return new Point(org.x + dx, org.y + dy); } /// /// Find the circumcenter of a triangle. /// - /// Triangle point. - /// Triangle point. - /// Triangle point. + /// Triangle point. + /// Triangle point. + /// Triangle point. /// Relative coordinate of new location. /// Relative coordinate of new location. /// Coordinates of the circumcenter @@ -363,8 +365,8 @@ namespace TriangleNet /// This procedure also returns the square of the length of the triangle's /// shortest edge. /// - public static Point FindCircumcenter(Point torg, Point tdest, Point tapex, - ref double xi, ref double eta) + public static Point FindCircumcenter(Point org, Point dest, Point apex, + ref double xi, ref double eta) { double xdo, ydo, xao, yao; double dodist, aodist; @@ -374,10 +376,10 @@ namespace TriangleNet Statistic.CircumcenterCount++; // Compute the circumcenter of the triangle. - xdo = tdest.x - torg.x; - ydo = tdest.y - torg.y; - xao = tapex.x - torg.x; - yao = tapex.y - torg.y; + xdo = dest.x - org.x; + ydo = dest.y - org.y; + xao = apex.x - org.x; + yao = apex.y - org.y; dodist = xdo * xdo + ydo * ydo; aodist = xao * xao + yao * yao; @@ -390,7 +392,7 @@ namespace TriangleNet // Use the counterclockwise() routine to ensure a positive (and // reasonably accurate) result, avoiding any possibility of // division by zero. - denominator = 0.5 / CounterClockwise(tdest, tapex, torg); + denominator = 0.5 / CounterClockwise(dest, apex, org); // Don't count the above as an orientation test. Statistic.CounterClockwiseCount--; } @@ -406,7 +408,7 @@ namespace TriangleNet xi = (yao * dx - xao * dy) * (2.0 * denominator); eta = (xdo * dy - ydo * dx) * (2.0 * denominator); - return new Point(torg.x + dx, torg.y + dy); + return new Point(org.x + dx, org.y + dy); } #region Exact arithmetics diff --git a/Triangle.NET/Triangle/Sampler.cs b/Triangle.NET/Triangle/Sampler.cs index b128c78..aaa4de3 100644 --- a/Triangle.NET/Triangle/Sampler.cs +++ b/Triangle.NET/Triangle/Sampler.cs @@ -1,5 +1,6 @@ // ----------------------------------------------------------------------- // +// Original Triangle code by Jonathan Richard Shewchuk, http://www.cs.cmu.edu/~quake/triangle.html // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/ // // ----------------------------------------------------------------------- @@ -11,7 +12,7 @@ namespace TriangleNet using System.Linq; /// - /// Used for triangle sampling in the Mesh.Locate method. + /// Used for triangle sampling in the class. /// class Sampler { diff --git a/Triangle.NET/Triangle/Tools/BoundedVoronoi.cs b/Triangle.NET/Triangle/Tools/BoundedVoronoi.cs index fa07383..3d5eb76 100644 --- a/Triangle.NET/Triangle/Tools/BoundedVoronoi.cs +++ b/Triangle.NET/Triangle/Tools/BoundedVoronoi.cs @@ -315,7 +315,7 @@ namespace TriangleNet.Tools sfn.seg = subsegMap[f_next.triangle.hash]; // Insert point Lf,f_next /\ Sf_next into P - if (SegmentsIntersect(sfn.SegOrg(), sfn.SegDest(), cc_f, cc_f_next, out p, true)) + if (SegmentsIntersect(sfn.Org(), sfn.Dest(), cc_f, cc_f_next, out p, true)) { p.id = n + segIndex++; segPoints.Add(p); @@ -332,7 +332,7 @@ namespace TriangleNet.Tools if (!f_next.triangle.infected) { // Insert point Lf,f_next /\ Sf into P - if (SegmentsIntersect(sf.SegOrg(), sf.SegDest(), cc_f, cc_f_next, out p, true)) + if (SegmentsIntersect(sf.Org(), sf.Dest(), cc_f, cc_f_next, out p, true)) { p.id = n + segIndex++; segPoints.Add(p); @@ -348,14 +348,14 @@ namespace TriangleNet.Tools if (!sf.Equal(sfn)) { // Insert Lf,fnext /\ Sf and Lf,fnext /\ Sfnext into P - if (SegmentsIntersect(sf.SegOrg(), sf.SegDest(), cc_f, cc_f_next, out p, true)) + if (SegmentsIntersect(sf.Org(), sf.Dest(), cc_f, cc_f_next, out p, true)) { p.id = n + segIndex++; segPoints.Add(p); vpoints.Add(p); } - if (SegmentsIntersect(sfn.SegOrg(), sfn.SegDest(), cc_f, cc_f_next, out p, true)) + if (SegmentsIntersect(sfn.Org(), sfn.Dest(), cc_f, cc_f_next, out p, true)) { p.id = n + segIndex++; segPoints.Add(p); @@ -486,7 +486,7 @@ namespace TriangleNet.Tools sfn.seg = subsegMap[f_next.triangle.hash]; // Insert point Lf,f_next /\ Sf_next into P - if (SegmentsIntersect(sfn.SegOrg(), sfn.SegDest(), cc_f, cc_f_next, out p, true)) + if (SegmentsIntersect(sfn.Org(), sfn.Dest(), cc_f, cc_f_next, out p, true)) { p.id = n + segIndex++; segPoints.Add(p); @@ -499,8 +499,8 @@ namespace TriangleNet.Tools // Call Sf the constrained edge blinding f sf.seg = subsegMap[f.triangle.hash]; - sorg = sf.SegOrg(); - sdest = sf.SegDest(); + sorg = sf.Org(); + sdest = sf.Dest(); // if f_next is tagged non-blind then if (!f_next.triangle.infected) @@ -546,7 +546,7 @@ namespace TriangleNet.Tools vpoints.Add(p); } - if (SegmentsIntersect(sfn.SegOrg(), sfn.SegDest(), cc_f, cc_f_next, out p, true)) + if (SegmentsIntersect(sfn.Org(), sfn.Dest(), cc_f, cc_f_next, out p, true)) { p.id = n + segIndex++; segPoints.Add(p); diff --git a/Triangle.NET/Triangle/Tools/QuadTree.cs b/Triangle.NET/Triangle/Tools/QuadTree.cs index 3e1c7f6..da29482 100644 --- a/Triangle.NET/Triangle/Tools/QuadTree.cs +++ b/Triangle.NET/Triangle/Tools/QuadTree.cs @@ -55,20 +55,17 @@ namespace TriangleNet.Tools var point = new Point(x, y); var indices = root.FindTriangles(point); - var result = new List(); - foreach (var i in indices) { var tri = this.triangles[i]; if (IsPointInTriangle(point, tri.GetVertex(0), tri.GetVertex(1), tri.GetVertex(2))) { - result.Add(tri); - break; + return tri; } } - return result.FirstOrDefault(); + return null; } /// diff --git a/Triangle.NET/Triangle/Tools/Statistic.cs b/Triangle.NET/Triangle/Tools/Statistic.cs index a22b17b..20c3f65 100644 --- a/Triangle.NET/Triangle/Tools/Statistic.cs +++ b/Triangle.NET/Triangle/Tools/Statistic.cs @@ -8,7 +8,6 @@ namespace TriangleNet.Tools { using System; - using System.Text; using TriangleNet.Data; using TriangleNet.Geometry; @@ -109,66 +108,6 @@ namespace TriangleNet.Tools /// public double LargestAngle { get { return maxAngle; } } - int inVetrices = 0; - /// - /// Gets the number of input vertices. - /// - public int InputVertices { get { return inVetrices; } } - - int inTriangles = 0; - /// - /// Gets the number of input triangles. - /// - public int InputTriangles { get { return inTriangles; } } - - int inSegments = 0; - /// - /// Gets the number of input segments. - /// - public int InputSegments { get { return inSegments; } } - - int inHoles = 0; - /// - /// Gets the number of input holes. - /// - public int InputHoles { get { return inHoles; } } - - int outVertices = 0; - /// - /// Gets the number of mesh vertices. - /// - public int Vertices { get { return outVertices; } } - - int outTriangles = 0; - /// - /// Gets the number of mesh triangles. - /// - public int Triangles { get { return outTriangles; } } - - int outEdges = 0; - /// - /// Gets the number of mesh edges. - /// - public int Edges { get { return outEdges; } } - - int boundaryEdges = 0; - /// - /// Gets the number of exterior boundary edges. - /// - public int BoundaryEdges { get { return boundaryEdges; } } - - int intBoundaryEdges = 0; - /// - /// Gets the number of interior boundary edges. - /// - public int InteriorBoundaryEdges { get { return intBoundaryEdges; } } - - int constrainedEdges = 0; - /// - /// Gets the number of constrained edges. - /// - public int ConstrainedEdges { get { return constrainedEdges; } } - int[] angleTable; /// /// Gets the angle histogram. @@ -264,17 +203,6 @@ namespace TriangleNet.Tools /// public void Update(Mesh mesh, int sampleDegrees) { - inVetrices = mesh.invertices; - inTriangles = mesh.inelements; - inSegments = mesh.insegments; - inHoles = mesh.holes.Count; - outVertices = mesh.vertices.Count - mesh.undeads; - outTriangles = mesh.triangles.Count; - outEdges = (int)mesh.edges; - boundaryEdges = (int)mesh.hullsize; - intBoundaryEdges = mesh.subsegs.Count - (int)mesh.hullsize; - constrainedEdges = mesh.subsegs.Count; - Point[] p = new Point[3]; int k1, k2; diff --git a/Triangle.NET/Triangle/Tools/Voronoi.cs b/Triangle.NET/Triangle/Tools/Voronoi.cs index 23b7ebe..8ae83e2 100644 --- a/Triangle.NET/Triangle/Tools/Voronoi.cs +++ b/Triangle.NET/Triangle/Tools/Voronoi.cs @@ -5,13 +5,13 @@ // // ----------------------------------------------------------------------- -using System; -using System.Collections.Generic; -using TriangleNet.Data; -using TriangleNet.Geometry; - namespace TriangleNet.Tools { + using System; + using System.Collections.Generic; + using TriangleNet.Data; + using TriangleNet.Geometry; + /// /// The Voronoi Diagram is the dual of a pointset triangulation. /// @@ -103,7 +103,7 @@ namespace TriangleNet.Tools { //if (item.Boundary == 0) { - ConstructVoronoiRegion(region); + ConstructCell(region); } } } @@ -134,9 +134,8 @@ namespace TriangleNet.Tools /// /// Construct Voronoi region for given vertex. /// - /// - /// The circumcenter indices which make up the cell. - private void ConstructVoronoiRegion(VoronoiRegion region) + /// + private void ConstructCell(VoronoiRegion region) { var vertex = region.Generator as Vertex; diff --git a/Triangle.NET/Triangle/TriangleLocator.cs b/Triangle.NET/Triangle/TriangleLocator.cs index 5d578bb..429ffea 100644 --- a/Triangle.NET/Triangle/TriangleLocator.cs +++ b/Triangle.NET/Triangle/TriangleLocator.cs @@ -11,8 +11,12 @@ namespace TriangleNet using TriangleNet.Geometry; /// - /// TODO: Update summary. + /// Locate triangles in a mesh. /// + /// + /// WARNING: This routine is designed for convex triangulations, and will + /// not generally work after the holes and concavities have been carved. + /// class TriangleLocator { Sampler sampler;