|
28 | 28 | */
|
29 | 29 | package net.imglib2.mesh;
|
30 | 30 |
|
31 |
| -import static org.junit.Assert.assertEquals; |
32 |
| -import static org.junit.Assert.assertTrue; |
33 |
| - |
34 | 31 | import javax.imageio.ImageIO;
|
35 | 32 | import javax.imageio.ImageReader;
|
36 | 33 | import java.awt.image.BufferedImage;
|
|
39 | 36 | import java.net.URISyntaxException;
|
40 | 37 | import java.nio.file.Files;
|
41 | 38 | import java.nio.file.Paths;
|
42 |
| -import java.util.ArrayList; |
43 |
| -import java.util.HashMap; |
44 |
| -import java.util.Iterator; |
45 |
| -import java.util.List; |
46 |
| -import java.util.Map; |
| 39 | +import java.util.*; |
47 | 40 |
|
48 | 41 | import gnu.trove.list.array.TLongArrayList;
|
49 | 42 | import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
|
|
67 | 60 | import net.imglib2.util.Fraction;
|
68 | 61 | import net.imglib2.view.RandomAccessibleIntervalCursor;
|
69 | 62 |
|
| 63 | +import static org.junit.Assert.*; |
| 64 | + |
70 | 65 | public class MeshesTest
|
71 | 66 | {
|
72 | 67 |
|
@@ -161,6 +156,34 @@ public void testMarchingCubesRealType()
|
161 | 156 | assertTrue( !expectedFacets.hasNext() && !actualFacets.hasNext() );
|
162 | 157 | }
|
163 | 158 |
|
| 159 | + @Test |
| 160 | + public void testBoundingBoxMesh() { |
| 161 | + final Mesh mesh = new NaiveDoubleMesh(); |
| 162 | + // Create a pyramid between the points |
| 163 | + long bbl = mesh.vertices().add(0, 0, 0); |
| 164 | + long bbr = mesh.vertices().add(1, 0, 0); |
| 165 | + long bfl = mesh.vertices().add(0, 1, 0); |
| 166 | + long t = mesh.vertices().add(0, 0, 1); |
| 167 | + mesh.triangles().add(bbl, bfl, bbr); |
| 168 | + mesh.triangles().add(t, bbr, bfl); |
| 169 | + mesh.triangles().add(t, bbl, bbr); |
| 170 | + mesh.triangles().add(t, bfl, bbl); |
| 171 | + |
| 172 | + // Get the bounding box |
| 173 | + final Mesh bounding = Meshes.boundingBoxMesh(mesh); |
| 174 | + // Assert expected points and number of vertices |
| 175 | + Iterator<Vertex> itr = bounding.vertices().iterator(); |
| 176 | + assertArrayEquals(new double[] {0, 0, 0}, itr.next().positionAsDoubleArray(), 0); |
| 177 | + assertArrayEquals(new double[] {1, 0, 0}, itr.next().positionAsDoubleArray(), 0); |
| 178 | + assertArrayEquals(new double[] {0, 1, 0}, itr.next().positionAsDoubleArray(), 0); |
| 179 | + assertArrayEquals(new double[] {1, 1, 0}, itr.next().positionAsDoubleArray(), 0); |
| 180 | + assertArrayEquals(new double[] {0, 0, 1}, itr.next().positionAsDoubleArray(), 0); |
| 181 | + assertArrayEquals(new double[] {1, 0, 1}, itr.next().positionAsDoubleArray(), 0); |
| 182 | + assertArrayEquals(new double[] {0, 1, 1}, itr.next().positionAsDoubleArray(), 0); |
| 183 | + assertArrayEquals(new double[] {1, 1, 1}, itr.next().positionAsDoubleArray(), 0); |
| 184 | + assertFalse(itr.hasNext()); |
| 185 | + } |
| 186 | + |
164 | 187 | private static Mesh createMeshWithNoise()
|
165 | 188 | {
|
166 | 189 | final Mesh mesh = new NaiveDoubleMesh();
|
|
0 commit comments