From 4963b68eefb9ffbf7206e629878458f42899ab8a Mon Sep 17 00:00:00 2001 From: "SND\\wo80_cp" Date: Thu, 24 Apr 2014 17:53:16 +0000 Subject: [PATCH] Fix QuadTree; ConformingDelaunay should imply quality meshing; git-svn-id: https://triangle.svn.codeplex.com/svn@74908 0e2699bc-83d4-4a8f-98e7-55e24ab8c7a5 --- Triangle.NET/Triangle/Mesh.cs | 6 +- .../Triangle/{Quality.cs => QualityMesher.cs} | 4 +- Triangle.NET/Triangle/Tools/QuadTree.cs | 77 ++++++++++--------- Triangle.NET/Triangle/Triangle.csproj | 2 +- 4 files changed, 46 insertions(+), 43 deletions(-) rename Triangle.NET/Triangle/{Quality.cs => QualityMesher.cs} (97%) diff --git a/Triangle.NET/Triangle/Mesh.cs b/Triangle.NET/Triangle/Mesh.cs index 2255a46..6cb4dbe 100644 --- a/Triangle.NET/Triangle/Mesh.cs +++ b/Triangle.NET/Triangle/Mesh.cs @@ -27,7 +27,7 @@ namespace TriangleNet ILog logger; - Quality quality; + QualityMesher quality; // Stack that maintains a list of recently flipped triangles. Stack flipstack; @@ -200,7 +200,7 @@ namespace TriangleNet holes = new List(); regions = new List(); - quality = new Quality(this); + quality = new QualityMesher(this); locator = new TriangleLocator(this); @@ -377,7 +377,7 @@ namespace TriangleNet regions.Clear(); } - if (behavior.Quality && (triangles.Count > 0)) + if ((behavior.Quality || behavior.ConformingDelaunay) && triangles.Count > 0) { quality.EnforceQuality(); // Enforce angle and area constraints. } diff --git a/Triangle.NET/Triangle/Quality.cs b/Triangle.NET/Triangle/QualityMesher.cs similarity index 97% rename from Triangle.NET/Triangle/Quality.cs rename to Triangle.NET/Triangle/QualityMesher.cs index 522192d..b60bcf0 100644 --- a/Triangle.NET/Triangle/Quality.cs +++ b/Triangle.NET/Triangle/QualityMesher.cs @@ -16,7 +16,7 @@ namespace TriangleNet /// /// Provides methods for mesh quality enforcement and testing. /// - class Quality + class QualityMesher { Queue badsubsegs; BadTriQueue queue; @@ -27,7 +27,7 @@ namespace TriangleNet ILog logger; - public Quality(Mesh mesh) + public QualityMesher(Mesh mesh) { logger = SimpleLog.Instance; diff --git a/Triangle.NET/Triangle/Tools/QuadTree.cs b/Triangle.NET/Triangle/Tools/QuadTree.cs index 252ff3d..57537b3 100644 --- a/Triangle.NET/Triangle/Tools/QuadTree.cs +++ b/Triangle.NET/Triangle/Tools/QuadTree.cs @@ -255,12 +255,14 @@ namespace TriangleNet.Tools void FindTriangleIntersections(Point[] triangle, int index) { - // PLEASE NOTE: Handling of component comparison is tightly associated with the implementation - // of the findRegion() function. That means when the point to be compared equals - // the pivot point the triangle must be put at least into region 2. + // PLEASE NOTE: + // Handling of component comparison is tightly associated with the implementation + // of the findRegion() function. That means when the point to be compared equals + // the pivot point the triangle must be put at least into region 2. + // // Linear equations are in parametric form. - // m_pivot.dx = triangle[0].dx + t * (triangle[1].dx - triangle[0].dx) - // m_pivot.dy = triangle[0].dy + t * (triangle[1].dy - triangle[0].dy) + // pivot.x = triangle[0].x + t * (triangle[1].x - triangle[0].x) + // pivot.y = triangle[0].y + t * (triangle[1].y - triangle[0].y) int k = 2; @@ -284,21 +286,19 @@ namespace TriangleNet.Tools void FindIntersectionsWithX(double dx, double dy, Point[] triangle, int index, int k) { - // find intersection with plane x = m_pivot.dX - double t = (pivot.X - triangle[k].X) / dx; + double t; + // find intersection with plane x = m_pivot.dX + t = (pivot.X - triangle[k].X) / dx; if (t < (1 + EPS) && t > -EPS) { // we have an intersection double yComponent = triangle[k].Y + t * dy; - if (yComponent < pivot.Y) + if (yComponent < pivot.Y && yComponent >= bounds.Ymin) { - if (yComponent >= bounds.Ymin) - { - AddToRegion(index, SW); - AddToRegion(index, SE); - } + AddToRegion(index, SW); + AddToRegion(index, SE); } else if (yComponent <= bounds.Ymax) { @@ -306,6 +306,7 @@ namespace TriangleNet.Tools AddToRegion(index, NE); } } + // find intersection with plane x = m_boundingBox[0].dX t = (bounds.Xmin - triangle[k].X) / dx; if (t < (1 + EPS) && t > -EPS) @@ -313,15 +314,16 @@ namespace TriangleNet.Tools // we have an intersection double yComponent = triangle[k].Y + t * dy; - if (yComponent <= pivot.Y && yComponent >= bounds.Ymin) + if (yComponent < pivot.Y && yComponent >= bounds.Ymin) { AddToRegion(index, SW); } - else if (yComponent >= pivot.Y && yComponent <= bounds.Ymax) + else if (yComponent <= bounds.Ymax) // TODO: check && yComponent >= pivot.Y { AddToRegion(index, NW); } } + // find intersection with plane x = m_boundingBox[1].dX t = (bounds.Xmax - triangle[k].X) / dx; if (t < (1 + EPS) && t > -EPS) @@ -329,11 +331,11 @@ namespace TriangleNet.Tools // we have an intersection double yComponent = triangle[k].Y + t * dy; - if (yComponent <= pivot.Y && yComponent >= bounds.Ymin) + if (yComponent < pivot.Y && yComponent >= bounds.Ymin) { AddToRegion(index, SE); } - else if (yComponent >= pivot.Y && yComponent <= bounds.Ymax) + else if (yComponent <= bounds.Ymax) { AddToRegion(index, NE); } @@ -342,20 +344,19 @@ namespace TriangleNet.Tools void FindIntersectionsWithY(double dx, double dy, Point[] triangle, int index, int k) { + double t, xComponent; + // find intersection with plane y = m_pivot.dY - double t = (pivot.Y - triangle[k].Y) / (dy); + t = (pivot.Y - triangle[k].Y) / dy; if (t < (1 + EPS) && t > -EPS) { // we have an intersection - double xComponent = triangle[k].X + t * (dy); + xComponent = triangle[k].X + t * dx; - if (xComponent > pivot.X) + if (xComponent > pivot.X && xComponent <= bounds.Xmax) { - if (xComponent <= bounds.Xmax) - { - AddToRegion(index, SE); - AddToRegion(index, NE); - } + AddToRegion(index, SE); + AddToRegion(index, NE); } else if (xComponent >= bounds.Xmin) { @@ -363,37 +364,39 @@ namespace TriangleNet.Tools AddToRegion(index, NW); } } + // find intersection with plane y = m_boundingBox[0].dY t = (bounds.Ymin - triangle[k].Y) / dy; if (t < (1 + EPS) && t > -EPS) { // we have an intersection - double xComponent = triangle[k].X + t * dx; + xComponent = triangle[k].X + t * dx; - if (xComponent <= pivot.X && xComponent >= bounds.Xmin) - { - AddToRegion(index, SW); - } - else if (xComponent >= pivot.X && xComponent <= bounds.Xmax) + if (xComponent > pivot.X && xComponent <= bounds.Xmax) { AddToRegion(index, SE); } + else if (xComponent >= bounds.Xmin) + { + AddToRegion(index, SW); + } } + // find intersection with plane y = m_boundingBox[1].dY t = (bounds.Ymax - triangle[k].Y) / dy; if (t < (1 + EPS) && t > -EPS) { // we have an intersection - double xComponent = triangle[k].X + t * dx; + xComponent = triangle[k].X + t * dx; - if (xComponent <= pivot.X && xComponent >= bounds.Xmin) - { - AddToRegion(index, NW); - } - else if (xComponent >= pivot.X && xComponent <= bounds.Xmax) + if (xComponent > pivot.X && xComponent <= bounds.Xmax) { AddToRegion(index, NE); } + else if (xComponent >= bounds.Xmin) + { + AddToRegion(index, NW); + } } } diff --git a/Triangle.NET/Triangle/Triangle.csproj b/Triangle.NET/Triangle/Triangle.csproj index 7fbd442..9bc56e7 100644 --- a/Triangle.NET/Triangle/Triangle.csproj +++ b/Triangle.NET/Triangle/Triangle.csproj @@ -75,7 +75,7 @@ - +