Skip to content

Commit

Permalink
reduce large tet scale to match float domain +/- 32k
Browse files Browse the repository at this point in the history
  • Loading branch information
Hellblazer committed Aug 26, 2023
1 parent d7da336 commit f843807
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,32 @@
import javax.vecmath.Tuple3f;

/**
* A Delaunay tetrahedralization.
* A Delaunay tetrahedralization. This implementation is optimized for
* Luciferase, not for any other particular use. As such, it is based on floats,
* not doubles - although predicates are evaluated with doubles to ensure
* nothing horrible blows up. The extent of the "Big Tetrahedron" that defines
* the maximum extent of the universe for this tetrahedralization is thus {-32k,
* +32k}. This implementation also uses the "fast" version of the inSphere
* predicate, rather than the exact. The exact version is most expensive so made
* the call here. The result is that the generated mesh isn't precisely exact.
* As long as it doesn't blow up, for the purposes of kinetic point tracking,
* we're happy.
* <p>
* We are largely concerned with the topology of the tracked points, and their
* relative location, not the precise form of the mesh that encodes the
* topology. Because we throw the tetrahedra away on every rebuild, there's
* really little need for an index and so random walk is used. It is assumed
* that the vast majority, if not damn near entirety of operations concerning
* the Sentinel and its tracked components and topology will be operating with a
* vertex after the tetrahedralization has occurred. Consequently operations on
* Vertex and Tetrahedron are the defacto operation origination rather at the
* Sentinel level.
*
* @author <a href="mailto:hal.hildebrand@gmail.com">Hal Hildebrand</a>
*
*/

public class Sentinel {
public class Sentinel implements Iterable<Vertex> {
/**
* Cannonical enumeration of the vertex ordinals
*/
Expand All @@ -70,7 +89,7 @@ public class Sentinel {
/**
* Scale of the universe
*/
private static float SCALE = (float) Math.pow(2D, 30D);
private static float SCALE = (float) Math.pow(2, 16);

public static Vertex[] getFourCorners() {
Vertex[] fourCorners = new Vertex[4];
Expand Down Expand Up @@ -162,6 +181,21 @@ public Vertex[] extent() {
return fourCorners;
}

@Override
public Iterator<Vertex> iterator() {
return head != null ? head.iterator() : new Iterator<Vertex>() {
@Override
public boolean hasNext() {
return false;
}

@Override
public Vertex next() {
throw new NoSuchElementException();
}
};
}

/**
* Locate the tetrahedron which contains the query point via a stochastic walk
* through the delaunay triangulation. This location algorithm is a slight
Expand Down Expand Up @@ -207,7 +241,7 @@ public void rebuild() {
* @return
*/
public Stream<Vertex> stream() {
return StreamSupport.stream(vertices().spliterator(), false);
return StreamSupport.stream(spliterator(), false);
}

/**
Expand Down Expand Up @@ -266,32 +300,6 @@ public void untrack(Vertex v) {
}
}

/**
* Answer the iteration of all vertices in this tetrahedralization
*
* @return
*/
public Iterable<Vertex> vertices() {
return head != null ? head : new Iterable<Vertex>() {

@Override
public Iterator<Vertex> iterator() {
return new Iterator<Vertex>() {

@Override
public boolean hasNext() {
return false;
}

@Override
public Vertex next() {
throw new NoSuchElementException();
}
};
}
};
}

/**
* Perform the 4->1 bistellar flip. This flip is the inverse of the 1->4 flip.
*
Expand Down
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(190, L.size());
assertEquals(184, L.size());
}

@Test
Expand All @@ -65,7 +65,7 @@ public void testGrid() {
}

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

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

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

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

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

0 comments on commit f843807

Please sign in to comment.