use of net.imglib2.type.logic.BoolType in project imagej-ops by imagej.
the class ConditionalTest method testDefault.
@Test
public void testDefault() {
final ByteType out = new ByteType((byte) 10);
final ByteType defaultVal = new ByteType((byte) 100);
assertEquals(10, ((ByteType) ops.run(Default.class, out, new BoolType(true), defaultVal)).get());
assertEquals(100, ((ByteType) ops.run(Default.class, out, new BoolType(false), defaultVal)).get());
}
use of net.imglib2.type.logic.BoolType in project imagej-ops by imagej.
the class ConditionalTest method testIf.
@Test
public void testIf() {
final ByteType ifTrueVal = new ByteType((byte) 10);
final ByteType ifFalseVal = new ByteType((byte) 100);
assertEquals(10, ((ByteType) ops.run(If.class, new BoolType(true), ifTrueVal, ifFalseVal)).get());
assertEquals(100, ((ByteType) ops.run(If.class, new BoolType(false), ifTrueVal, ifFalseVal)).get());
}
use of net.imglib2.type.logic.BoolType in project imagej-ops by imagej.
the class DefaultMarchingCubes method calculate.
@SuppressWarnings({ "unchecked" })
@Override
public DefaultMesh calculate(final RandomAccessibleInterval<T> input) {
DefaultMesh output = new DefaultMesh();
ExtendedRandomAccessibleInterval<T, RandomAccessibleInterval<T>> extended = Views.extendValue(input, (T) new BoolType(false));
Cursor<T> c = Views.interval(extended, new FinalInterval(new long[] { input.min(0) - 1, input.min(1) - 1, input.min(2) - 1 }, new long[] { input.max(0) + 1, input.max(1) + 1, input.max(2) + 1 })).localizingCursor();
while (c.hasNext()) {
c.next();
int cursorX = c.getIntPosition(0);
int cursorY = c.getIntPosition(1);
int cursorZ = c.getIntPosition(2);
Cursor<T> cu = getCube(extended, cursorX, cursorY, cursorZ);
int i = 0;
double[] vertex_values = new double[8];
while (cu.hasNext()) {
vertex_values[i++] = (cu.next().get()) ? 1 : 0;
}
// 6------7
// /| /|
// 2-----3 |
// | 4---|-5
// |/ |/
// 0-----1
vertex_values = mapFlatIterableToLookUpCube(vertex_values);
// 4------5
// /| /|
// 7-----6 |
// | 0---|-1
// |/ |/
// 3-----2
int cubeindex = getCubeIndex(vertex_values);
if (EDGE_TABLE[cubeindex] != 0) {
int[] p0 = new int[] { 0 + cursorX, 0 + cursorY, 1 + cursorZ };
int[] p1 = new int[] { 1 + cursorX, 0 + cursorY, 1 + cursorZ };
int[] p2 = new int[] { 1 + cursorX, 0 + cursorY, 0 + cursorZ };
int[] p3 = new int[] { 0 + cursorX, 0 + cursorY, 0 + cursorZ };
int[] p4 = new int[] { 0 + cursorX, 1 + cursorY, 1 + cursorZ };
int[] p5 = new int[] { 1 + cursorX, 1 + cursorY, 1 + cursorZ };
int[] p6 = new int[] { 1 + cursorX, 1 + cursorY, 0 + cursorZ };
int[] p7 = new int[] { 0 + cursorX, 1 + cursorY, 0 + cursorZ };
double[][] vertlist = new double[12][];
/* Find the vertices where the surface intersects the cube */
if (0 != (EDGE_TABLE[cubeindex] & 1)) {
vertlist[0] = interpolatePoint(p0, p1, vertex_values[0], vertex_values[1]);
}
if (0 != (EDGE_TABLE[cubeindex] & 2)) {
vertlist[1] = interpolatePoint(p1, p2, vertex_values[1], vertex_values[2]);
}
if (0 != (EDGE_TABLE[cubeindex] & 4)) {
vertlist[2] = interpolatePoint(p2, p3, vertex_values[2], vertex_values[3]);
}
if (0 != (EDGE_TABLE[cubeindex] & 8)) {
vertlist[3] = interpolatePoint(p3, p0, vertex_values[3], vertex_values[0]);
}
if (0 != (EDGE_TABLE[cubeindex] & 16)) {
vertlist[4] = interpolatePoint(p4, p5, vertex_values[4], vertex_values[5]);
}
if (0 != (EDGE_TABLE[cubeindex] & 32)) {
vertlist[5] = interpolatePoint(p5, p6, vertex_values[5], vertex_values[6]);
}
if (0 != (EDGE_TABLE[cubeindex] & 64)) {
vertlist[6] = interpolatePoint(p6, p7, vertex_values[6], vertex_values[7]);
}
if (0 != (EDGE_TABLE[cubeindex] & 128)) {
vertlist[7] = interpolatePoint(p7, p4, vertex_values[7], vertex_values[4]);
}
if (0 != (EDGE_TABLE[cubeindex] & 256)) {
vertlist[8] = interpolatePoint(p0, p4, vertex_values[0], vertex_values[4]);
}
if (0 != (EDGE_TABLE[cubeindex] & 512)) {
vertlist[9] = interpolatePoint(p1, p5, vertex_values[1], vertex_values[5]);
}
if (0 != (EDGE_TABLE[cubeindex] & 1024)) {
vertlist[10] = interpolatePoint(p2, p6, vertex_values[2], vertex_values[6]);
}
if (0 != (EDGE_TABLE[cubeindex] & 2048)) {
vertlist[11] = interpolatePoint(p3, p7, vertex_values[3], vertex_values[7]);
}
/* Create the triangle */
for (i = 0; TRIANGLE_TABLE[cubeindex][i] != -1; i += 3) {
TriangularFacet face = new TriangularFacet(new Vertex(vertlist[TRIANGLE_TABLE[cubeindex][i + 2]][0], vertlist[TRIANGLE_TABLE[cubeindex][i + 2]][1], vertlist[TRIANGLE_TABLE[cubeindex][i + 2]][2]), new Vertex(vertlist[TRIANGLE_TABLE[cubeindex][i + 1]][0], vertlist[TRIANGLE_TABLE[cubeindex][i + 1]][1], vertlist[TRIANGLE_TABLE[cubeindex][i + 1]][2]), new Vertex(vertlist[TRIANGLE_TABLE[cubeindex][i]][0], vertlist[TRIANGLE_TABLE[cubeindex][i]][1], vertlist[TRIANGLE_TABLE[cubeindex][i]][2]));
face.getArea();
output.addFace(face);
}
}
}
return output;
}
Aggregations