use of maspack.graph.DirectedEdge in project artisynth_core by artisynth.
the class FemIntersector method fixOverlaps.
// fix graph so that there are no overlapping edges
private void fixOverlaps(DirectedGraph<Point3d, Vector3d> graph, double tol) {
ArrayList<DirectedEdge<Point3d, Vector3d>> edges = new ArrayList<DirectedEdge<Point3d, Vector3d>>(graph.getEdges());
int idx = 0;
while (idx < edges.size()) {
DirectedEdge<Point3d, Vector3d> edge = edges.get(idx);
Vertex<Point3d, Vector3d> vtx1 = edge.getVertex(0);
Vertex<Point3d, Vector3d> vtx2 = edge.getVertex(1);
Point3d a = vtx1.getData();
Point3d b = vtx2.getData();
for (Vertex<Point3d, Vector3d> vtx : graph.getVertices()) {
if (vtx != vtx1 && vtx != vtx2) {
double d = lineSegmentDistance(a, b, vtx.getData());
if (d < tol) {
graph.removeEdge(edge);
DirectedEdge<Point3d, Vector3d> newEdge = connectIfUnique(graph, vtx1, vtx, edge.getData(), edge.getCost());
if (!edges.contains(newEdge)) {
edges.add(newEdge);
}
newEdge = connectIfUnique(graph, vtx, vtx2, edge.getData(), edge.getCost());
if (!edges.contains(newEdge)) {
edges.add(newEdge);
}
break;
}
}
}
idx++;
}
}
use of maspack.graph.DirectedEdge in project artisynth_core by artisynth.
the class FemIntersector method buildMesh.
private PolygonalMesh buildMesh(DirectedGraph<Point3d, Vector3d> graph, Vector3d normal) {
PolygonalMesh mesh = new PolygonalMesh();
LinkedList<DirectedEdge<Point3d, Vector3d>> remainingEdges = new LinkedList<DirectedEdge<Point3d, Vector3d>>(graph.getEdges());
HashMap<Point3d, Vertex3d> vtxMap = new HashMap<Point3d, Vertex3d>(graph.numVertices());
for (Vertex<Point3d, Vector3d> v : graph.getVertices()) {
Vertex3d vtx = mesh.addVertex(v.getData());
vtxMap.put(v.getData(), vtx);
}
while (remainingEdges.size() > 0) {
DirectedEdge<Point3d, Vector3d> e = remainingEdges.get(0);
ArrayList<DirectedEdge<Point3d, Vector3d>> face = findFace(e, graph, normal);
if (face == null) {
remainingEdges.remove(0);
} else {
Vertex3d[] vtxs = new Vertex3d[face.size()];
int idx = 0;
for (DirectedEdge<Point3d, Vector3d> edge : face) {
vtxs[idx++] = vtxMap.get(edge.getVertex(0).getData());
remainingEdges.remove(edge);
}
mesh.addFace(vtxs);
}
}
return mesh;
}
Aggregations