use of net.imagej.ops.geom.geom3d.mesh.TriangularFacet 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.TriangularFacet in project imagej-ops by imagej.
the class DefaultConvexHull3D method computeHorizon.
/**
* Computes the horizon of vTop. The horizon is the merged facet of all facets
* which are in front of the point vTop.
*
* @param frontFacet a face which is in front of vTop
* @param vTop a point outside of the convex hull
* @return facet containing all facets which are in front of vTop
*/
private Horizon computeHorizon(final double epsilon, final Set<Vertex> vertices, final List<TriangularFacet> facets, final List<TriangularFacet> facetsWithPointInFront, final TriangularFacet frontFacet, final Vertex vTop) {
// Points which are in front have to be reassigned after all new facets
// are constructed.
vertices.addAll(frontFacet.getVerticesInFront());
// frontFacet is not a result facet. Remove it from result list.
facets.remove(frontFacet);
Horizon h = new Horizon(frontFacet);
TriangularFacet merge = nextFacetToMerge(epsilon, h, vTop);
while (merge != null) {
// This points have to be reassigned as well.
vertices.addAll(merge.getVerticesInFront());
// This face has some points in front and therefore is not a result
// face.
facets.remove(merge);
// After this step this facet is merged with another facet.
facetsWithPointInFront.remove(merge);
if (h.containsAll(merge.getVertices())) {
updateNeighbors(frontFacet, merge);
h.complexMerge(merge);
} else {
updateNeighbors(frontFacet, merge);
h.simpleMerge(merge);
}
merge = nextFacetToMerge(epsilon, h, vTop);
}
return h;
}
use of net.imagej.ops.geom.geom3d.mesh.TriangularFacet 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.TriangularFacet in project imagej-ops by imagej.
the class DefaultConvexHull3D method createFacets.
/**
* Adds for each edge of the horizon and vTop a new facet.
*
* @param horizon facet of all facets seen from point vTop
* @param vTop point which is added to the convex hull
* @return new created facets
*/
private List<TriangularFacet> createFacets(final Horizon horizon, final Vertex vTop) {
List<TriangularFacet> newFacets = new ArrayList<>();
Vertex vLeft, vRight;
// triangles 1 to n
for (int i = 1; i < horizon.size(); i++) {
vLeft = horizon.getVertex(i - 1);
vRight = horizon.getVertex(i);
TriangularFacet f = new TriangularFacet(vRight, vTop, vLeft);
setNeighborZero(f, horizon.getNeighbor(i));
newFacets.add(f);
}
// triangle 0, this triangle connects the n-th triangle with
// triangle number 1
vRight = horizon.getVertex(0);
vLeft = horizon.getLastVertex();
TriangularFacet f = new TriangularFacet(vRight, vTop, vLeft);
setNeighborZero(f, horizon.getNeighbor(0));
newFacets.add(f);
// set neighbors 1 and 2 of each triangle
// triangle 0 has triangle n and 1 as neighbors.
connectTriangles(newFacets);
return newFacets;
}
use of net.imagej.ops.geom.geom3d.mesh.TriangularFacet 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;
}
Aggregations