use of net.imagej.ops.geom.geom3d.mesh.Facet in project imagej-ops by imagej.
the class DefaultInertiaTensor3DMesh method calculate.
@Override
public RealMatrix calculate(final Mesh input) {
final RealLocalizable o = centroid.calculate(input);
BlockRealMatrix tensor = new BlockRealMatrix(3, 3);
final Iterator<Facet> c = input.getFacets().iterator();
while (c.hasNext()) {
final TriangularFacet tf = (TriangularFacet) c.next();
tensor = tensor.add(tetrahedronInertiaTensor(tf.getVertex(0), tf.getVertex(1), tf.getVertex(2), o));
}
return tensor;
}
use of net.imagej.ops.geom.geom3d.mesh.Facet in project imagej-ops by imagej.
the class DefaultVoxelization3D method calculate.
@Override
public RandomAccessibleInterval<BitType> calculate(Mesh input) {
Img<BitType> outImg = ops.create().img(new FinalInterval(width, height, depth), new BitType());
DefaultMesh dMesh = (DefaultMesh) input;
Set<RealLocalizable> verts = dMesh.getVertices();
RealPoint minPoint = new RealPoint(verts.iterator().next());
RealPoint maxPoint = new RealPoint(verts.iterator().next());
for (RealLocalizable v : verts) {
if (v.getDoublePosition(0) < minPoint.getDoublePosition(0))
minPoint.setPosition(v.getDoublePosition(0), 0);
if (v.getDoublePosition(1) < minPoint.getDoublePosition(1))
minPoint.setPosition(v.getDoublePosition(1), 1);
if (v.getDoublePosition(2) < minPoint.getDoublePosition(2))
minPoint.setPosition(v.getDoublePosition(2), 2);
if (v.getDoublePosition(0) > maxPoint.getDoublePosition(0))
maxPoint.setPosition(v.getDoublePosition(0), 0);
if (v.getDoublePosition(1) > maxPoint.getDoublePosition(1))
maxPoint.setPosition(v.getDoublePosition(1), 1);
if (v.getDoublePosition(2) > maxPoint.getDoublePosition(2))
maxPoint.setPosition(v.getDoublePosition(2), 2);
}
RealPoint dimPoint = new RealPoint((maxPoint.getDoublePosition(0) - minPoint.getDoublePosition(0)), (maxPoint.getDoublePosition(1) - minPoint.getDoublePosition(1)), (maxPoint.getDoublePosition(2) - minPoint.getDoublePosition(2)));
double[] stepSizes = new double[3];
stepSizes[0] = dimPoint.getDoublePosition(0) / width;
stepSizes[1] = dimPoint.getDoublePosition(1) / height;
stepSizes[2] = dimPoint.getDoublePosition(2) / depth;
double[] voxelHalfsize = new double[3];
for (int k = 0; k < stepSizes.length; k++) voxelHalfsize[k] = stepSizes[k] / 2.0;
for (Facet f : dMesh.getFacets()) {
TriangularFacet tri = (TriangularFacet) f;
Vector3D v1 = tri.getP0();
Vector3D v2 = tri.getP1();
Vector3D v3 = tri.getP2();
double[] minSubBoundary = new double[] { Math.min(Math.min(v1.getX(), v2.getX()), v3.getX()) - minPoint.getDoublePosition(0), Math.min(Math.min(v1.getY(), v2.getY()), v3.getY()) - minPoint.getDoublePosition(1), Math.min(Math.min(v1.getZ(), v2.getZ()), v3.getZ()) - minPoint.getDoublePosition(2) };
double[] maxSubBoundary = new double[] { Math.max(Math.max(v1.getX(), v2.getX()), v3.getX()) - minPoint.getDoublePosition(0), Math.max(Math.max(v1.getY(), v2.getY()), v3.getY()) - minPoint.getDoublePosition(1), Math.max(Math.max(v1.getZ(), v2.getZ()), v3.getZ()) - minPoint.getDoublePosition(2) };
// Should use the
RandomAccess<BitType> ra = outImg.randomAccess();
// interval
// implementation
// for speed
long[] indices = new long[3];
for (indices[0] = (long) Math.floor(minSubBoundary[0] / stepSizes[0]); indices[0] < Math.floor(maxSubBoundary[0] / stepSizes[0]); indices[0]++) {
for (indices[1] = (long) Math.floor(minSubBoundary[1] / stepSizes[1]); indices[1] < Math.floor(maxSubBoundary[1] / stepSizes[1]); indices[1]++) {
for (indices[2] = (long) Math.floor(minSubBoundary[2] / stepSizes[2]); indices[2] < Math.floor(maxSubBoundary[2] / stepSizes[2]); indices[2]++) {
ra.setPosition(indices);
if (// Don't check if voxel is already
!ra.get().get()) // filled
{
double[] voxelCenter = new double[3];
for (int k = 0; k < 3; k++) voxelCenter[k] = indices[k] * stepSizes[k] + voxelHalfsize[k];
if (triBoxOverlap(voxelCenter, voxelHalfsize, v1, v2, v3) == 1) {
ra.get().set(true);
}
}
}
}
}
}
return outImg;
}
use of net.imagej.ops.geom.geom3d.mesh.Facet in project imagej-ops by imagej.
the class DefaultVolumeMesh method calculate.
@Override
public DoubleType calculate(final Mesh input) {
double volume = 0;
for (Facet f : input.getFacets()) {
TriangularFacet tf = (TriangularFacet) f;
volume += signedVolumeOfTriangle(tf.getP0(), tf.getP1(), tf.getP2());
}
return new DoubleType(Math.abs(volume));
}
use of net.imagej.ops.geom.geom3d.mesh.Facet in project imagej-ops by imagej.
the class MeshFeatureTests method marchingCubes.
@Test
public void marchingCubes() {
final DefaultMesh result = (DefaultMesh) ops.run(DefaultMarchingCubes.class, ROI);
final List<Facet> expectedFacets = mesh.getFacets();
final List<Facet> resultFacets = result.getFacets();
for (int i = 0; i < expectedFacets.size(); i++) {
final TriangularFacet tmpR = (TriangularFacet) resultFacets.get(i);
final TriangularFacet tmpE = (TriangularFacet) expectedFacets.get(i);
for (int j = 0; j < 3; j++) {
final Vertex resultVertex = tmpR.getVertex(j);
final Vertex expectedVertex = tmpE.getVertex(j);
assertEquals("Triangular Facet point " + j + " differes in x- coordinate:", expectedVertex.getDoublePosition(0), resultVertex.getDoublePosition(0), EPSILON);
assertEquals("Triangular Facet point " + j + " differes in y- coordinate:", expectedVertex.getDoublePosition(1), resultVertex.getDoublePosition(1), EPSILON);
assertEquals("Triangular Facet point " + j + " differes in z- coordinate:", expectedVertex.getDoublePosition(2), resultVertex.getDoublePosition(2), EPSILON);
}
}
}
Aggregations