Rename Sampler to TriangleSampler;

Make TriangleLocator public;

git-svn-id: https://triangle.svn.codeplex.com/svn@79449 0e2699bc-83d4-4a8f-98e7-55e24ab8c7a5
This commit is contained in:
SND\wo80_cp
2016-08-23 20:29:52 +00:00
parent 4a4da6c5fb
commit e1c523299f
4 changed files with 41 additions and 19 deletions
+1 -1
View File
@@ -23,7 +23,7 @@ namespace TriangleNet
/// <remarks>The result of a search indicates that the point falls in the
/// interior of a triangle, on an edge, on a vertex, or outside the mesh.
/// </remarks>
enum LocateResult { InTriangle, OnEdge, OnVertex, Outside };
public enum LocateResult { InTriangle, OnEdge, OnVertex, Outside };
/// <summary>
/// Labels that signify the result of vertex insertion.
+1 -1
View File
@@ -123,7 +123,7 @@
<Compile Include="MeshValidator.cs" />
<Compile Include="NewLocation.cs" />
<Compile Include="RobustPredicates.cs" />
<Compile Include="Sampler.cs" />
<Compile Include="TriangleSampler.cs" />
<Compile Include="TriangleLocator.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
+22 -5
View File
@@ -7,8 +7,8 @@
namespace TriangleNet
{
using TriangleNet.Topology;
using TriangleNet.Geometry;
using TriangleNet.Topology;
/// <summary>
/// Locate triangles in a mesh.
@@ -16,10 +16,15 @@ namespace TriangleNet
/// <remarks>
/// WARNING: This routine is designed for convex triangulations, and will
/// not generally work after the holes and concavities have been carved.
///
/// Based on a paper by Ernst P. Mucke, Isaac Saias, and Binhai Zhu, "Fast
/// Randomized Point Location Without Preprocessing in Two- and Three-Dimensional
/// Delaunay Triangulations," Proceedings of the Twelfth Annual Symposium on
/// Computational Geometry, ACM, May 1996.
/// </remarks>
class TriangleLocator
public class TriangleLocator
{
Sampler sampler;
TriangleSampler sampler;
Mesh mesh;
IPredicates predicates;
@@ -28,14 +33,23 @@ namespace TriangleNet
// proximate vertices are inserted sequentially.
internal Otri recenttri;
public TriangleLocator(Mesh mesh)
: this(mesh, RobustPredicates.Default)
{
}
public TriangleLocator(Mesh mesh, IPredicates predicates)
{
this.mesh = mesh;
this.predicates = predicates;
sampler = new Sampler(mesh);
sampler = new TriangleSampler(mesh);
}
/// <summary>
/// Suggest the given triangle as a starting triangle for point location.
/// </summary>
/// <param name="otri"></param>
public void Update(ref Otri otri)
{
otri.Copy(ref recenttri);
@@ -114,7 +128,7 @@ namespace TriangleNet
/// However, it can still be used to find the circumcenter of a triangle, as
/// long as the search is begun from the triangle in question.</remarks>
public LocateResult PreciseLocate(Point searchpoint, ref Otri searchtri,
bool stopatsubsegment)
bool stopatsubsegment)
{
Otri backtracktri = default(Otri);
Osub checkedge = default(Osub);
@@ -313,6 +327,7 @@ namespace TriangleNet
// Where are we?
torg = searchtri.Org();
tdest = searchtri.Dest();
// Check the starting triangle's vertices.
if ((torg.x == searchpoint.x) && (torg.y == searchpoint.y))
{
@@ -323,6 +338,7 @@ namespace TriangleNet
searchtri.Lnext();
return LocateResult.OnVertex;
}
// Orient 'searchtri' to fit the preconditions of calling preciselocate().
ahead = predicates.CounterClockwise(torg, tdest, searchpoint);
if (ahead < 0.0)
@@ -340,6 +356,7 @@ namespace TriangleNet
return LocateResult.OnEdge;
}
}
return PreciseLocate(searchpoint, ref searchtri, false);
}
}
@@ -1,5 +1,5 @@
// -----------------------------------------------------------------------
// <copyright file="Sampler.cs">
// <copyright file="TriangleSampler.cs">
// 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/
// </copyright>
@@ -14,12 +14,14 @@ namespace TriangleNet
/// <summary>
/// Used for triangle sampling in the <see cref="TriangleLocator"/> class.
/// </summary>
class Sampler : IEnumerable<Triangle>
class TriangleSampler : IEnumerable<Triangle>
{
private const int RANDOM_SEED = 110503;
// Empirically chosen factor.
private const int samplefactor = 11;
private Random rand;
private Random random;
private Mesh mesh;
// Number of random samples for point location (at least 1).
@@ -28,10 +30,15 @@ namespace TriangleNet
// Number of triangles in mesh.
private int triangleCount = 0;
public Sampler(Mesh mesh)
public TriangleSampler(Mesh mesh)
: this(mesh, new Random(RANDOM_SEED))
{
}
public TriangleSampler(Mesh mesh, Random random)
{
this.mesh = mesh;
this.rand = new Random(110503);
this.random = random;
}
/// <summary>
@@ -46,18 +53,16 @@ namespace TriangleNet
/// <summary>
/// Update sampling parameters if mesh changed.
/// </summary>
/// <param name="mesh">Current mesh.</param>
public void Update(bool forceUpdate = false)
public void Update()
{
int count = mesh.triangles.Count;
// TODO: Is checking the triangle count a good way to monitor mesh changes?
if (triangleCount != count || forceUpdate)
if (triangleCount != count)
{
triangleCount = count;
// The number of random samples taken is proportional to the cube root of
// the number of triangles in the mesh. The next bit of code assumes
// The number of random samples taken is proportional to the cube root
// of the number of triangles in the mesh. The next bit of code assumes
// that the number of triangles increases monotonically (or at least
// doesn't decrease enough to matter).
while (samplefactor * samples * samples * samples < count)
@@ -69,7 +74,7 @@ namespace TriangleNet
public IEnumerator<Triangle> GetEnumerator()
{
return mesh.triangles.Sample(samples, rand).GetEnumerator();
return mesh.triangles.Sample(samples, random).GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()