Search in sources :

Example 31 with Face

use of maspack.geometry.Face in project artisynth_core by artisynth.

the class IntersectionTester method computePenetratingFaceArea.

double computePenetratingFaceArea(ArrayList<PenetratingPoint> points) {
    double area = 0;
    HashSet<Vertex3d> vertices = new HashSet<Vertex3d>();
    for (PenetratingPoint p : points) {
        vertices.add(p.vertex);
    }
    HashSet<Face> faces = new HashSet<Face>();
    for (PenetratingPoint p : points) {
        Vertex3d vtx = p.vertex;
        Iterator<HalfEdge> it = vtx.getIncidentHalfEdges();
        while (it.hasNext()) {
            HalfEdge he = it.next();
            Face face = he.getFace();
            if (!faces.contains(face) && faceIsPenetrating(face, vertices)) {
                area += face.computeArea();
                System.out.println(" adding face " + face.getIndex() + " " + area);
                faces.add(face);
            }
        }
    }
    return area;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) HalfEdge(maspack.geometry.HalfEdge) Face(maspack.geometry.Face)

Example 32 with Face

use of maspack.geometry.Face in project artisynth_core by artisynth.

the class OffWriter method writeMesh.

public void writeMesh(PolygonalMesh mesh) throws IOException {
    PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(myOstream)));
    pw.println("OFF");
    pw.printf("%d %d %d\n", mesh.numVertices(), mesh.numFaces(), 0);
    pw.flush();
    int[] oldIdxs = new int[mesh.numVertices()];
    int idx = 0;
    for (Vertex3d vtx : mesh.getVertices()) {
        Point3d pnt = vtx.getPosition();
        pw.println(myFmt.format(pnt.x) + " " + myFmt.format(pnt.y) + " " + myFmt.format(pnt.z));
        // protect vertex indices numbers
        oldIdxs[idx] = vtx.getIndex();
        vtx.setIndex(idx);
        idx++;
    }
    for (Face face : mesh.getFaces()) {
        int nf = face.numVertices();
        pw.print(nf);
        for (int j = 0; j < face.numVertices(); j++) {
            pw.print(" " + face.getVertex(j).getIndex());
        }
        pw.println();
    }
    pw.flush();
    // restore vertex indices
    idx = 0;
    for (Vertex3d vtx : mesh.getVertices()) {
        vtx.setIndex(oldIdxs[idx]);
        idx++;
    }
}
Also used : Vertex3d(maspack.geometry.Vertex3d) Point3d(maspack.matrix.Point3d) OutputStreamWriter(java.io.OutputStreamWriter) Face(maspack.geometry.Face) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter)

Example 33 with Face

use of maspack.geometry.Face in project artisynth_core by artisynth.

the class GtsWriter method writeMesh.

public void writeMesh(PolygonalMesh mesh) throws IOException {
    PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(myOstream)));
    int[] oldIdxs = new int[mesh.numVertices()];
    int vidx = 0;
    for (Vertex3d vtx : mesh.getVertices()) {
        // protect vertex indices numbers
        oldIdxs[vidx] = vtx.getIndex();
        vtx.setIndex(vidx);
        vidx++;
    }
    LinkedHashMap<Edge, Integer> edgeList = new LinkedHashMap<Edge, Integer>();
    for (Face f : mesh.getFaces()) {
        HalfEdge he0 = f.firstHalfEdge();
        HalfEdge he = he0;
        do {
            HalfEdge next = he.getNext();
            Edge edge = new Edge(he.head, next.head);
            if (edgeList.get(edge) == null) {
                edgeList.put(edge, edgeList.size());
            }
            he = next;
        } while (he != he0);
    }
    pw.println(mesh.numVertices() + " " + edgeList.size() + " " + mesh.numFaces());
    for (Vertex3d vtx : mesh.getVertices()) {
        vtx.pnt.write(pw, myFmt);
        pw.println("");
    }
    for (Edge edge : edgeList.keySet()) {
        pw.println((edge.myVtx1.getIndex() + 1) + " " + (edge.myVtx2.getIndex() + 1));
    }
    for (Face f : mesh.getFaces()) {
        HalfEdge he0 = f.firstHalfEdge();
        HalfEdge he = he0;
        do {
            HalfEdge next = he.getNext();
            Edge edge = new Edge(he.head, next.head);
            Integer idx = edgeList.get(edge);
            pw.print((idx + 1) + " ");
            he = next;
        } while (he != he0);
        pw.println("");
    }
    // restore vertex indices
    vidx = 0;
    for (Vertex3d vtx : mesh.getVertices()) {
        vtx.setIndex(oldIdxs[vidx]);
        vidx++;
    }
}
Also used : Vertex3d(maspack.geometry.Vertex3d) OutputStreamWriter(java.io.OutputStreamWriter) HalfEdge(maspack.geometry.HalfEdge) Face(maspack.geometry.Face) Edge(maspack.geometry.io.GtsReader.Edge) HalfEdge(maspack.geometry.HalfEdge) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter) LinkedHashMap(java.util.LinkedHashMap)

Example 34 with Face

use of maspack.geometry.Face in project artisynth_core by artisynth.

the class MeshIntersectingProbe method findFaces.

// finds faces near a points
private ArrayList<Face> findFaces(Point3d p, OBBTree obbt, Vector3d vx, Vector3d vy, Point3d o, double tol) {
    ArrayList<Face> faces = new ArrayList<Face>();
    ArrayList<BVNode> nodes = new ArrayList<BVNode>();
    obbt.intersectPoint(nodes, p);
    Point2d p2d = Intersector2d.get2dCoordinate(p, vx, vy, o);
    Point3d uvw = new Point3d();
    for (BVNode obbn : nodes) {
        for (int i = 0; i < obbn.getNumElements(); i++) {
            Boundable ps = obbn.getElements()[i];
            if (ps instanceof Face) {
                Face f = (Face) ps;
                Vertex3d[] vtxs = f.getVertices();
                Point2d p0 = Intersector2d.get2dCoordinate(vtxs[0].getWorldPoint(), vx, vy, o);
                Point2d p1 = Intersector2d.get2dCoordinate(vtxs[1].getWorldPoint(), vx, vy, o);
                Point2d p2 = Intersector2d.get2dCoordinate(vtxs[2].getWorldPoint(), vx, vy, o);
                Intersector2d.getBarycentric(p2d, p0, p1, p2, uvw);
                if (uvw.x > -tol && uvw.y > -tol && uvw.z > -tol) {
                    faces.add(f);
                }
            }
        }
    }
    return faces;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) Point2d(maspack.matrix.Point2d) BVNode(maspack.geometry.BVNode) Point3d(maspack.matrix.Point3d) ArrayList(java.util.ArrayList) Boundable(maspack.geometry.Boundable) Face(maspack.geometry.Face)

Example 35 with Face

use of maspack.geometry.Face in project artisynth_core by artisynth.

the class MeshIntersectingProbe method findNextEdge.

// NOTE: only works for convex faces (so, triangular is okay)
// finds the next edge while clipping around in a circle
private static HalfEdge findNextEdge(LinkedList<Point3d> contour, ArrayList<Face> faceList, Intersector2d ti, SplitStorage info, Vector3d vx, Vector3d vy, Point3d o) {
    Vector3d dir = new Vector3d();
    Point3d vtxp = info.vtx.getWorldPoint();
    Point2d vtx2d = Intersector2d.get2dCoordinate(vtxp, vx, vy, o);
    dir.sub(contour.get(info.idx + 1), contour.get(info.idx));
    for (Face face : faceList) {
        HalfEdge he0 = face.getEdge(0);
        HalfEdge he = he0;
        do {
            if (info.vtx != he.head && info.vtx != he.tail) {
                Point2d p1 = Intersector2d.get2dCoordinate(he.head.getWorldPoint(), vx, vy, o);
                Point2d p2 = Intersector2d.get2dCoordinate(he.tail.getWorldPoint(), vx, vy, o);
                ArrayList<Point2d> pnts = new ArrayList<Point2d>();
                Vector2d lineDir = Intersector2d.get2dVector(dir, vx, vy);
                int npoints = ti.intersectLineLineSegment(vtx2d, lineDir, p1, p2, pnts);
                if (npoints == 1) {
                    Point3d p = Intersector2d.get3dCoordinate(pnts.get(0), vx, vy, o);
                    Vector3d ldir = new Vector3d(p.x - vtxp.x, p.y - vtxp.y, p.z - vtxp.z);
                    // check direction
                    if (ldir.dot(dir) > -ti.epsilon) {
                        // check if we passed the next point
                        Point3d pNext = contour.get(info.idx + 1);
                        if (ldir.norm() < pNext.distance(vtxp) + ti.epsilon) {
                            if (p.distance(pNext) < ti.epsilon) {
                                // move to next point
                                info.idx++;
                            }
                            info.vtx = createOrGetVertex(p, face.getVertices(), ti.epsilon);
                            return he;
                        } else {
                            // advance to next vertex
                            info.vtx = createOrGetVertex(pNext, face.getVertices(), ti.epsilon);
                            info.face = face;
                            // move to next point
                            info.idx++;
                            return null;
                        }
                    }
                }
            }
            he = he.getNext();
        } while (he != he0);
    }
    info.face = null;
    return null;
}
Also used : Vector2d(maspack.matrix.Vector2d) Vector3d(maspack.matrix.Vector3d) Point2d(maspack.matrix.Point2d) Point3d(maspack.matrix.Point3d) ArrayList(java.util.ArrayList) HalfEdge(maspack.geometry.HalfEdge) Face(maspack.geometry.Face)

Aggregations

Face (maspack.geometry.Face)49 Vertex3d (maspack.geometry.Vertex3d)30 Point3d (maspack.matrix.Point3d)25 Vector3d (maspack.matrix.Vector3d)20 HalfEdge (maspack.geometry.HalfEdge)16 PolygonalMesh (maspack.geometry.PolygonalMesh)14 ArrayList (java.util.ArrayList)11 Vector2d (maspack.matrix.Vector2d)9 ContactPoint (artisynth.core.mechmodels.ContactPoint)7 Point (artisynth.core.mechmodels.Point)7 HashMap (java.util.HashMap)7 BVFeatureQuery (maspack.geometry.BVFeatureQuery)6 PointParticleAttachment (artisynth.core.mechmodels.PointParticleAttachment)5 IntersectionPoint (maspack.collision.IntersectionPoint)5 BufferedWriter (java.io.BufferedWriter)4 OutputStreamWriter (java.io.OutputStreamWriter)4 PrintWriter (java.io.PrintWriter)4 DistanceGrid (maspack.geometry.DistanceGrid)4 PointAttachment (artisynth.core.mechmodels.PointAttachment)3 PenetratingPoint (maspack.collision.PenetratingPoint)3