Skip to content

Commit

Permalink
eagle eye. firm up api.
Browse files Browse the repository at this point in the history
12ms grid construct time tracking 1000 moving points ;)
  • Loading branch information
Hellblazer committed Aug 26, 2023
1 parent 7b6bb5a commit 5c81656
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
* <p>
*
* @param v - the vertex to be deleted
*/
public void delete(Vertex v) {
assert v != null;

LinkedList<OrientedFace> 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
*
Expand Down Expand Up @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,12 @@ public void addFaces(List<Vertex[]> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public final Tetrahedron getAdjacent() {
return adjacent;
}

public LinkedList<OrientedFace> getEars() {
public final LinkedList<OrientedFace> getEars() {
assert adjacent != null;
EarSet aggregator = new EarSet();
adjacent.visitStar(this, aggregator);
Expand All @@ -155,7 +155,7 @@ public LinkedList<OrientedFace> getEars() {
* @param v - the vertex determining the neighborhood
* @return the collection of neighboring vertices
*/
public Collection<Vertex> getNeighbors() {
public final Collection<Vertex> getNeighbors() {
assert adjacent != null;

final Set<Vertex> neighbors = new IdentitySet<>();
Expand All @@ -167,7 +167,7 @@ public Collection<Vertex> getNeighbors() {
return neighbors;
}

public Deque<OrientedFace> getStar() {
public final Deque<OrientedFace> getStar() {
assert adjacent != null;

final Deque<OrientedFace> star = new ArrayDeque<>();
Expand All @@ -179,11 +179,10 @@ public Deque<OrientedFace> 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<Tuple3f[]> getVoronoiRegion() {
public final List<Tuple3f[]> getVoronoiRegion() {
assert adjacent != null;

final List<Tuple3f[]> faces = new ArrayList<>();
Expand Down Expand Up @@ -215,9 +214,8 @@ public List<Tuple3f[]> 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) {
Expand All @@ -227,7 +225,7 @@ public final int inSphere(Tuple3f a, Tuple3f b, Tuple3f c, Tuple3f d) {
}

@Override
public Iterator<Vertex> iterator() {
public final Iterator<Vertex> iterator() {
return new Iterator<Vertex>() {
private Vertex next = Vertex.this;

Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void smokin() throws Exception {
var sentinel = new Sentinel();
var sites = new ArrayList<Vertex>();
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;
Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void testCubic() {
}

Set<Tetrahedron> L = T.tetrahedrons();
assertEquals(189, L.size());
assertEquals(190, L.size());
}

@Test
Expand Down Expand Up @@ -80,7 +80,7 @@ public void testLargeRandom() {
}

Set<Tetrahedron> L = T.tetrahedrons();
assertEquals(402835, L.size());
assertEquals(402890, L.size());
}

@Test
Expand All @@ -91,6 +91,6 @@ public void testWorstCase() {
}

Set<Tetrahedron> L = T.tetrahedrons();
assertEquals(609, L.size());
assertEquals(620, L.size());
}
}

0 comments on commit 5c81656

Please sign in to comment.