use of net.imagej.ops.geom.geom3d.mesh.TriangularFacet in project imagej-ops by imagej.
the class CentroidMesh method calculate.
@Override
public RealLocalizable calculate(final Mesh input) {
double c_x = 0;
double c_y = 0;
double c_z = 0;
for (int i = 0; i < input.getFacets().size(); i++) {
TriangularFacet f = (TriangularFacet) input.getFacets().get(i);
Vector3D normal = f.getNormal();
Vector3D a = f.getP0();
Vector3D b = f.getP1();
Vector3D c = f.getP2();
c_x += (1 / 24d) * normal.getX() * (Math.pow((a.getX() + b.getX()), 2) + Math.pow((b.getX() + c.getX()), 2) + Math.pow((c.getX() + a.getX()), 2));
c_y += (1 / 24d) * normal.getY() * (Math.pow((a.getY() + b.getY()), 2) + Math.pow((b.getY() + c.getY()), 2) + Math.pow((c.getY() + a.getY()), 2));
c_z += (1 / 24d) * normal.getZ() * (Math.pow((a.getZ() + b.getZ()), 2) + Math.pow((b.getZ() + c.getZ()), 2) + Math.pow((c.getZ() + a.getZ()), 2));
}
double d = 1 / (2 * sizeFunc.calculate(input).get());
c_x *= d;
c_y *= d;
c_z *= d;
return new RealPoint(-c_x, -c_y, -c_z);
}
use of net.imagej.ops.geom.geom3d.mesh.TriangularFacet 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);
}
}
}
use of net.imagej.ops.geom.geom3d.mesh.TriangularFacet in project imagej-ops by imagej.
the class AbstractFeatureTest method getMesh.
protected static Mesh getMesh() {
final List<Vertex> vertices = new ArrayList<>();
try {
Files.lines(Paths.get(AbstractFeatureTest.class.getResource("3d_geometric_features_mesh.txt").toURI())).forEach(l -> {
String[] coord = l.split(" ");
Vertex v = new Vertex(Double.parseDouble(coord[0]), Double.parseDouble(coord[1]), Double.parseDouble(coord[2]));
vertices.add(v);
});
} catch (IOException | URISyntaxException exc) {
exc.printStackTrace();
}
final DefaultMesh m = new DefaultMesh();
for (int i = 0; i < vertices.size(); i += 3) {
final TriangularFacet f = new TriangularFacet(vertices.get(i), vertices.get(i + 1), vertices.get(i + 2));
m.addFace(f);
}
return m;
}
Aggregations