Search in sources :

Example 1 with DirectedEdge

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++;
    }
}
Also used : DirectedEdge(maspack.graph.DirectedEdge) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) ArrayList(java.util.ArrayList)

Example 2 with DirectedEdge

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;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) HashMap(java.util.HashMap) PolygonalMesh(maspack.geometry.PolygonalMesh) LinkedList(java.util.LinkedList) DirectedEdge(maspack.graph.DirectedEdge) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d)

Aggregations

DirectedEdge (maspack.graph.DirectedEdge)2 Point3d (maspack.matrix.Point3d)2 Vector3d (maspack.matrix.Vector3d)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 PolygonalMesh (maspack.geometry.PolygonalMesh)1 Vertex3d (maspack.geometry.Vertex3d)1