Search in sources :

Example 16 with HalfEdge

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

the class IntersectionTester method getPointEdge.

/**
 * Return the edge of a face that contains an intersection point.
 */
private HalfEdge getPointEdge(IntersectionPoint pa, Face face) {
    PolygonalMesh mesh = (PolygonalMesh) face.getMesh();
    if (edgeOnMesh(pa.edge, mesh)) {
        if (pa.edge.getFace() == face) {
            return pa.edge;
        } else if (getOppositeFace(pa.edge) == face) {
            return pa.edge.opposite;
        } else {
            throw new InternalErrorException("Face edge not found for point " + pa);
        }
    } else {
        // convert pa to mesh local coordinates
        Point3d paLoc = new Point3d(pa);
        paLoc.inverseTransform(mesh.getMeshToWorld());
        HalfEdge he0 = face.firstHalfEdge();
        HalfEdge he = he0;
        HalfEdge heMin = null;
        double dmin = Double.POSITIVE_INFINITY;
        do {
            double d = LineSegment.distance(he.getHead().pnt, he.getTail().pnt, paLoc);
            if (d < dmin) {
                heMin = he;
                dmin = d;
            }
            he = he.getNext();
        } while (he != he0);
        return heMin;
    }
}
Also used : Point3d(maspack.matrix.Point3d) HalfEdge(maspack.geometry.HalfEdge) InternalErrorException(maspack.util.InternalErrorException) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 17 with HalfEdge

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

the class CollisionRenderer method buildFaceSegments.

protected void buildFaceSegments(RenderObject ro, CollisionHandler handler, ArrayList<TriTriIntersection> intersections) {
    BVFeatureQuery query = new BVFeatureQuery();
    PolygonalMesh mesh0 = handler.getCollidable(0).getCollisionMesh();
    PolygonalMesh mesh1 = handler.getCollidable(1).getCollisionMesh();
    ArrayList<Face> faces = new ArrayList<Face>();
    // mark faces as visited and add segments
    for (TriTriIntersection isect : intersections) {
        isect.face0.setVisited();
        isect.face1.setVisited();
    // add partials?
    }
    // mark interior faces and add segments
    for (TriTriIntersection isect : intersections) {
        if (isect.face0.getMesh() != mesh0) {
            findInsideFaces(isect.face0, query, mesh0, faces);
            findInsideFaces(isect.face1, query, mesh1, faces);
        } else {
            findInsideFaces(isect.face0, query, mesh1, faces);
            findInsideFaces(isect.face1, query, mesh0, faces);
        }
    }
    for (TriTriIntersection isect : intersections) {
        isect.face0.clearVisited();
        isect.face1.clearVisited();
    }
    // add faces to render object and clear visited flag
    Vector3d nrm = new Vector3d();
    Point3d p0 = new Point3d();
    Point3d p1 = new Point3d();
    Point3d p2 = new Point3d();
    for (Face face : faces) {
        face.clearVisited();
        face.getWorldNormal(nrm);
        ro.addNormal((float) nrm.x, (float) nrm.y, (float) nrm.z);
        HalfEdge he = face.firstHalfEdge();
        he.head.getWorldPoint(p0);
        he = he.getNext();
        he.head.getWorldPoint(p1);
        he = he.getNext();
        he.head.getWorldPoint(p2);
        int v0idx = ro.vertex((float) p0.x, (float) p0.y, (float) p0.z);
        int v1idx = ro.vertex((float) p1.x, (float) p1.y, (float) p1.z);
        int v2idx = ro.vertex((float) p2.x, (float) p2.y, (float) p2.z);
        ro.addTriangle(v0idx, v1idx, v2idx);
    }
}
Also used : Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) ArrayList(java.util.ArrayList) TriTriIntersection(maspack.geometry.TriTriIntersection) HalfEdge(maspack.geometry.HalfEdge) Face(maspack.geometry.Face) BVFeatureQuery(maspack.geometry.BVFeatureQuery) PolygonalMesh(maspack.geometry.PolygonalMesh) IntersectionPoint(maspack.collision.IntersectionPoint) PenetratingPoint(maspack.collision.PenetratingPoint)

Example 18 with HalfEdge

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

the class CollisionRenderer method findInsideFaces.

protected void findInsideFaces(Face face, BVFeatureQuery query, PolygonalMesh mesh, ArrayList<Face> faces) {
    face.setVisited();
    Point3d pnt = new Point3d();
    HalfEdge he = face.firstHalfEdge();
    for (int i = 0; i < 3; i++) {
        if (he.opposite != null) {
            Face oFace = he.opposite.getFace();
            if (!oFace.isVisited()) {
                // check if inside
                oFace.computeWorldCentroid(pnt);
                boolean inside = query.isInsideOrientedMesh(mesh, pnt, -1);
                if (inside) {
                    faces.add(oFace);
                    findInsideFaces(oFace, query, mesh, faces);
                }
            }
        }
        he = he.getNext();
    }
}
Also used : Point3d(maspack.matrix.Point3d) HalfEdge(maspack.geometry.HalfEdge) Face(maspack.geometry.Face) IntersectionPoint(maspack.collision.IntersectionPoint) PenetratingPoint(maspack.collision.PenetratingPoint)

Example 19 with HalfEdge

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

the class IntersectionTester method faceIsPenetrating.

private boolean faceIsPenetrating(Face face, HashSet<Vertex3d> vertices) {
    HalfEdge he0 = face.firstHalfEdge();
    HalfEdge he = he0;
    do {
        if (!vertices.contains(he.getHead())) {
            return false;
        }
        he = he.getNext();
    } while (he != he0);
    return true;
}
Also used : HalfEdge(maspack.geometry.HalfEdge)

Example 20 with HalfEdge

use of maspack.geometry.HalfEdge 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)

Aggregations

HalfEdge (maspack.geometry.HalfEdge)33 Face (maspack.geometry.Face)16 Vertex3d (maspack.geometry.Vertex3d)13 Point3d (maspack.matrix.Point3d)8 ArrayList (java.util.ArrayList)7 ContactPoint (artisynth.core.mechmodels.ContactPoint)6 Point (artisynth.core.mechmodels.Point)6 IntersectionPoint (maspack.collision.IntersectionPoint)6 Vector3d (maspack.matrix.Vector3d)6 PolygonalMesh (maspack.geometry.PolygonalMesh)5 HashSet (java.util.HashSet)4 HashMap (java.util.HashMap)3 PenetratingPoint (maspack.collision.PenetratingPoint)3 PointParticleAttachment (artisynth.core.mechmodels.PointParticleAttachment)2 BufferedWriter (java.io.BufferedWriter)2 OutputStreamWriter (java.io.OutputStreamWriter)2 PrintWriter (java.io.PrintWriter)2 NumberFormat (maspack.util.NumberFormat)2 FemElement3d (artisynth.core.femmodels.FemElement3d)1 PointAttachment (artisynth.core.mechmodels.PointAttachment)1