From 5c81656ca9479382aa9813076982725b4bc6d2e4 Mon Sep 17 00:00:00 2001 From: Hellblazer Date: Sat, 26 Aug 2023 00:01:24 -0700 Subject: [PATCH] eagle eye. firm up api. 12ms grid construct time tracking 1000 moving points ;) --- .../luciferase/sentinel/Sentinel.java | 44 +++---------------- .../luciferase/sentinel/Tetrahedron.java | 6 +++ .../luciferase/sentinel/Vertex.java | 18 ++++---- .../luciferase/sentinel/SentinelTest.java | 6 +-- .../sentinel/TetrahedralizationTest.java | 6 +-- 5 files changed, 27 insertions(+), 53 deletions(-) diff --git a/sentinel/src/main/java/com/hellblazer/luciferase/sentinel/Sentinel.java b/sentinel/src/main/java/com/hellblazer/luciferase/sentinel/Sentinel.java index 2214ed3..e05fa44 100644 --- a/sentinel/src/main/java/com/hellblazer/luciferase/sentinel/Sentinel.java +++ b/sentinel/src/main/java/com/hellblazer/luciferase/sentinel/Sentinel.java @@ -27,7 +27,6 @@ import java.util.ArrayList; import java.util.Deque; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.NoSuchElementException; import java.util.Random; @@ -154,42 +153,6 @@ public void clear() { } } - /** - * Delete the vertex from the tetrahedralization. This algorithm is the - * deleteInSphere algorithm from Ledoux. See "Flipping to Robustly Delete a - * Vertex in a Delaunay Tetrahedralization", H. Ledoux, C.M. Gold and G. Baciu, - * 2005 - *

- * - * @param v - the vertex to be deleted - */ - public void delete(Vertex v) { - assert v != null; - - LinkedList ears = v.getEars(); - class OC implements StarVisitor { - int order = 0; - - @Override - public void visit(V vertex, Tetrahedron t, Vertex x, Vertex y, Vertex z) { - order++; - } - } - var oc = new OC(); - v.getAdjacent().visitStar(v, oc); - while (oc.order > 4) { - for (int i = 0; i < ears.size();) { - if (ears.get(i).flip(i, ears, v)) { - ears.remove(i); - } else { - i++; - } - } - } - last = flip4to1(v); - size--; - } - /** * Answer the four corners of the universe * @@ -296,6 +259,13 @@ public Vertex track(Point3f p, Vertex near) { return v; } + public void untrack(Vertex v) { + if (head != null) { + head.detach(v); + v.clear(); + } + } + /** * Answer the iteration of all vertices in this tetrahedralization * diff --git a/sentinel/src/main/java/com/hellblazer/luciferase/sentinel/Tetrahedron.java b/sentinel/src/main/java/com/hellblazer/luciferase/sentinel/Tetrahedron.java index 3d2f221..8bc1ac8 100644 --- a/sentinel/src/main/java/com/hellblazer/luciferase/sentinel/Tetrahedron.java +++ b/sentinel/src/main/java/com/hellblazer/luciferase/sentinel/Tetrahedron.java @@ -692,6 +692,12 @@ public void addFaces(List faces) { faces.add(new Vertex[] { d, a, c }); } + public Point3f center() { + float[] center = new float[3]; + centerSphere(a.x, a.y, a.z, b.x, b.y, b.z, c.x, c.y, c.z, d.x, d.y, d.z, center); + return new Point3f(center[0], center[1], center[2]); + } + /** * * Perform the 1 -> 4 bistellar flip. This produces 4 new tetrahedron from the diff --git a/sentinel/src/main/java/com/hellblazer/luciferase/sentinel/Vertex.java b/sentinel/src/main/java/com/hellblazer/luciferase/sentinel/Vertex.java index 8bc1b7b..69e4a6e 100644 --- a/sentinel/src/main/java/com/hellblazer/luciferase/sentinel/Vertex.java +++ b/sentinel/src/main/java/com/hellblazer/luciferase/sentinel/Vertex.java @@ -142,7 +142,7 @@ public final Tetrahedron getAdjacent() { return adjacent; } - public LinkedList getEars() { + public final LinkedList getEars() { assert adjacent != null; EarSet aggregator = new EarSet(); adjacent.visitStar(this, aggregator); @@ -155,7 +155,7 @@ public LinkedList getEars() { * @param v - the vertex determining the neighborhood * @return the collection of neighboring vertices */ - public Collection getNeighbors() { + public final Collection getNeighbors() { assert adjacent != null; final Set neighbors = new IdentitySet<>(); @@ -167,7 +167,7 @@ public Collection getNeighbors() { return neighbors; } - public Deque getStar() { + public final Deque getStar() { assert adjacent != null; final Deque star = new ArrayDeque<>(); @@ -179,11 +179,10 @@ public Deque getStar() { /** * Answer the faces of the voronoi region around the receiver - * - * @param v - the vertex of interest + * * @return the list of faces defining the voronoi region defined by the receiver */ - public List getVoronoiRegion() { + public final List getVoronoiRegion() { assert adjacent != null; final List faces = new ArrayList<>(); @@ -215,9 +214,8 @@ public List getVoronoiRegion() { * and d; -1 if it lies outside; and 0 if the five points are * cospherical */ - public final int inSphere(Tuple3f a, Tuple3f b, Tuple3f c, Tuple3f d) { - double result = Geometry.inSphere(a.x, a.y, a.z, b.x, b.y, b.z, c.x, c.y, c.z, d.x, d.y, d.z, x, y, z); + double result = Geometry.inSphereFast(a.x, a.y, a.z, b.x, b.y, b.z, c.x, c.y, c.z, d.x, d.y, d.z, x, y, z); if (result > 0.0) { return 1; } else if (result < 0.0) { @@ -227,7 +225,7 @@ public final int inSphere(Tuple3f a, Tuple3f b, Tuple3f c, Tuple3f d) { } @Override - public Iterator iterator() { + public final Iterator iterator() { return new Iterator() { private Vertex next = Vertex.this; @@ -248,7 +246,7 @@ public Vertex next() { }; } - public Tetrahedron locate(Tuple3f query, Random entropy) { + public final Tetrahedron locate(Tuple3f query, Random entropy) { assert adjacent != null; return adjacent.locate(query, entropy); } diff --git a/sentinel/src/test/java/com/hellblazer/luciferase/sentinel/SentinelTest.java b/sentinel/src/test/java/com/hellblazer/luciferase/sentinel/SentinelTest.java index 74b9bca..31ccd29 100644 --- a/sentinel/src/test/java/com/hellblazer/luciferase/sentinel/SentinelTest.java +++ b/sentinel/src/test/java/com/hellblazer/luciferase/sentinel/SentinelTest.java @@ -68,7 +68,7 @@ public void smokin() throws Exception { var sentinel = new Sentinel(); var sites = new ArrayList(); var entropy = new Random(0x666); - for (var p : getRandomPoints(entropy, 500, 1000, true)) { + for (var p : getRandomPoints(entropy, 1000, 100, true)) { sites.add(sentinel.track(p)); } int iterations = 1000; @@ -78,13 +78,13 @@ public void smokin() throws Exception { site.moveBy(randomPoint(entropy, 10f, 10f)); } sentinel.rebuild(); - assertEquals(17, sites.get(75).getNeighbors().size()); + assertEquals(15, sites.get(75).getNeighbors().size()); } final var total = System.currentTimeMillis() - now; System.out.println("sites: %s total time: %s ms iterations: %s avg time: %s ms".formatted(sites.size(), total, iterations, total / iterations)); - assertEquals(11, sites.get(50).getNeighbors().size()); + assertEquals(12, sites.get(50).getNeighbors().size()); } } diff --git a/sentinel/src/test/java/com/hellblazer/luciferase/sentinel/TetrahedralizationTest.java b/sentinel/src/test/java/com/hellblazer/luciferase/sentinel/TetrahedralizationTest.java index 7a31b3d..16b8300 100644 --- a/sentinel/src/test/java/com/hellblazer/luciferase/sentinel/TetrahedralizationTest.java +++ b/sentinel/src/test/java/com/hellblazer/luciferase/sentinel/TetrahedralizationTest.java @@ -45,7 +45,7 @@ public void testCubic() { } Set L = T.tetrahedrons(); - assertEquals(189, L.size()); + assertEquals(190, L.size()); } @Test @@ -80,7 +80,7 @@ public void testLargeRandom() { } Set L = T.tetrahedrons(); - assertEquals(402835, L.size()); + assertEquals(402890, L.size()); } @Test @@ -91,6 +91,6 @@ public void testWorstCase() { } Set L = T.tetrahedrons(); - assertEquals(609, L.size()); + assertEquals(620, L.size()); } }