use of net.imagej.ops.geom.geom3d.mesh.Vertex in project imagej-ops by imagej.
the class DefaultConvexHull3D method calculate.
@Override
public Mesh calculate(final Mesh input) {
DefaultMesh output = new DefaultMesh();
Set<Vertex> vertices = new LinkedHashSet<>();
for (final RealLocalizable v : input.getVertices()) {
vertices.add(new Vertex(v.getDoublePosition(0), v.getDoublePosition(1), v.getDoublePosition(2)));
}
List<TriangularFacet> facets = new ArrayList<>();
List<TriangularFacet> facetsWithPointInFront = new ArrayList<>();
final double epsilon = computeHull(vertices, facets, facetsWithPointInFront);
for (TriangularFacet f : facets) {
output.addFace(f);
}
output.setEpsilon(epsilon);
return output;
}
use of net.imagej.ops.geom.geom3d.mesh.Vertex in project imagej-ops by imagej.
the class DefaultConvexHull3D method getV3.
/**
* Finds the point with the largest distance to the plane described by v0, v1,
* v2.
*
* @param v0 Vertex of the plane.
* @param v1 Vertex of the plane.
* @param v2 Vertex of the plane.
* @return Vertex with the largest distance.
*/
private Vertex getV3(final double epsilon, final Set<Vertex> vertices, final Vertex v0, final Vertex v1, final Vertex v2) {
double distPlanePoint = epsilon;
Vertex v3 = null;
Vector3D d0 = v1.subtract(v0);
Vector3D d1 = v2.subtract(v0);
Vector3D normal = d0.crossProduct(d1).normalize();
for (final Vertex v : vertices) {
double d = Math.abs(normal.dotProduct(v.subtract(v0)));
if (d > distPlanePoint) {
distPlanePoint = d;
v3 = v;
}
}
return v3;
}
use of net.imagej.ops.geom.geom3d.mesh.Vertex in project imagej-ops by imagej.
the class DefaultConvexHull3D method replaceFacet.
/**
* Replaces a facet with at least three new facets.
*
* @param facet the facet to replace. At least one point must be in front of
* next.
*/
private void replaceFacet(final double epsilon, final Set<Vertex> vertices, final List<TriangularFacet> facets, final List<TriangularFacet> facetsPointInFront, final TriangularFacet facet) {
final Vertex v = facet.getMaximumDistanceVertex();
final Horizon horizon = computeHorizon(epsilon, vertices, facets, facetsPointInFront, facet, v);
assignPointsToFacets(epsilon, vertices, createFacets(horizon, v), facets, facetsPointInFront);
}
use of net.imagej.ops.geom.geom3d.mesh.Vertex in project imagej-ops by imagej.
the class DefaultConvexHull3D method nextFacetToMerge.
/**
* Returns a facet which is in front of vTop and neighbor of front.
*
* @param frontFacet facet in front of vTop
* @param vTop point which is added to the convex hull
* @return neighboring facet of front or null if no facet is in front
*/
private TriangularFacet nextFacetToMerge(final double epsilon, final Horizon frontFacet, final Vertex vTop) {
Iterator<TriangularFacet> it = frontFacet.getNeighbors().iterator();
while (it.hasNext()) {
TriangularFacet f = it.next();
if (f.distanceToPlane(vTop) > epsilon) {
// with two edges or one edge
if (frontFacet.containsAll(f.getVertices())) {
Vertex v0 = f.getVertex(0);
Vertex v1 = f.getVertex(1);
Vertex v2 = f.getVertex(2);
int numEdges = 0;
if (frontFacet.hasEdge(v0, v2)) {
numEdges++;
}
if (frontFacet.hasEdge(v2, v1)) {
numEdges++;
}
if (frontFacet.hasEdge(v1, v0)) {
numEdges++;
}
if (numEdges == 1) {
// and will be merged.
continue;
}
}
// not part of frontFacet.
return f;
}
}
return null;
}
use of net.imagej.ops.geom.geom3d.mesh.Vertex in project imagej-ops by imagej.
the class DefaultConvexHull3D method getV2.
/**
* Finds the vertex with the largest distance to the line described by v0, v1.
*
* @param v0 Vertex of the line.
* @param v1 Vertex of the line.
* @return Vertex with the largest distance.
*/
private Vertex getV2(final double epsilon, final Set<Vertex> vertices, final Vertex v0, final Vertex v1) {
Iterator<Vertex> it = vertices.iterator();
// v0 -------------------------------------v1
// |
// | d
// |
// * v
//
// d = |(v - v0) x (v - v1)| / |(v1 - v0)|
// We can omit the common denominator because it does not change over
// all computations.
double distLinePoint = epsilon;
Vertex v2 = null;
while (it.hasNext()) {
Vertex v = it.next();
Vector3D d0 = v.subtract(v1);
Vector3D d1 = v.subtract(v0);
double lengthSq = d0.crossProduct(d1).getNormSq();
if (lengthSq > distLinePoint) {
distLinePoint = lengthSq;
v2 = v;
}
}
return v2;
}
Aggregations