Search in sources :

Example 6 with HalfEdge

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

the class SurfaceMeshContourIxer method doFaceFaceCollision.

/**
 * Collide one triangular face with the second, but not the other way around.
 *
 * @param allMips new MIPs are appended to this list
 * @param f0 The face which has its edges checked
 * @param f1 The face which has its face checked
 *
 * @return the number of edge/face collisions detected in this call.
 */
protected int doFaceFaceCollision(ArrayList<IntersectionPoint> allMips, Face f0, Face f1, boolean edgeOnMesh0) {
    int numFound = 0;
    // Faces assumed to be triangular here!
    for (int eidx = 0; eidx < 3; eidx++) {
        HalfEdge e = f0.getEdge(eidx).getPrimary();
        EdgeFacePair pair = new EdgeFacePair(e, f1);
        // First check if we've already tested this edge/face pair
        if (mySavedEdgeFaceResults.containsKey(pair)) {
            if (mySavedEdgeFaceResults.get(pair) != null) {
                numFound++;
            }
            continue;
        }
        IntersectionPoint mip = new IntersectionPoint();
        boolean collided = robustIntersectionWithFace(e, f1, mip, edgeOnMesh0);
        if (collided) {
            mySavedEdgeFaceResults.put(pair, mip);
            allMips.add(mip);
            numFound++;
        } else {
            mySavedEdgeFaceResults.put(pair, null);
        }
    }
    return numFound;
}
Also used : IntersectionPoint(maspack.collision.IntersectionPoint) HalfEdge(maspack.geometry.HalfEdge) IntersectionPoint(maspack.collision.IntersectionPoint)

Example 7 with HalfEdge

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

the class AmiraMeshWriter method writeMesh.

public void writeMesh(PolygonalMesh mesh) {
    PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(myOstream)));
    if (!mesh.isTriangular()) {
        throw new IllegalArgumentException("Mesh must be triangular");
    }
    int nVerts = mesh.numVertices();
    int nFaces = mesh.numFaces();
    pw.println(FILE_HEADER);
    // mesh name
    if (mesh.getName() != null) {
        pw.println("# " + mesh.getName());
    }
    pw.println();
    pw.println("define Nodes " + nVerts);
    pw.println("define Triangles " + nFaces);
    pw.println();
    pw.println("Parameters {");
    // pw.println("    ContentType \"HxLineSet\"");
    // XXX confirm with amira about valid parameter set
    pw.println("}");
    pw.println();
    pw.println("Nodes { float[3] Coordinates } = @1");
    pw.println("Triangles { int[3] Nodes } = @2");
    pw.println();
    pw.println("@1 # xyz vertex coordinates");
    int idx = 0;
    for (Vertex3d vtx : mesh.getVertices()) {
        vtx.setIndex(idx++);
        pw.println(vtx.getPosition().toString(myFmt));
    }
    pw.println();
    pw.println("@2 # triangular face indices");
    for (Face face : mesh.getFaces()) {
        HalfEdge he = face.firstHalfEdge();
        Vertex3d vtx = he.getHead();
        pw.print(vtx.getIndex());
        he = he.getNext();
        vtx = he.getHead();
        pw.print(" " + vtx.getIndex());
        he = he.getNext();
        vtx = he.getHead();
        pw.println(" " + vtx.getIndex());
    }
    // end loop through faces
    pw.flush();
}
Also used : Vertex3d(maspack.geometry.Vertex3d) OutputStreamWriter(java.io.OutputStreamWriter) HalfEdge(maspack.geometry.HalfEdge) Face(maspack.geometry.Face) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter)

Example 8 with HalfEdge

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

the class SkinMeshBody method collectVertices.

private void collectVertices(Vertex3d vtx, int networkDist, ArrayList<Vertex3d> list) {
    if (list.contains(vtx)) {
        return;
    }
    list.add(vtx);
    if (networkDist > 0) {
        Iterator<HalfEdge> it = vtx.getIncidentHalfEdges();
        while (it.hasNext()) {
            HalfEdge he = it.next();
            Vertex3d vtxTail = he.tail;
            collectVertices(vtxTail, networkDist - 1, list);
        }
    }
}
Also used : Vertex3d(maspack.geometry.Vertex3d) HalfEdge(maspack.geometry.HalfEdge)

Example 9 with HalfEdge

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

the class CollisionRenderer method createPenetrationRenderObject.

RenderObject createPenetrationRenderObject(CollisionHandler handler, ArrayList<PenetratingPoint> points, ArrayList<PenetrationRegion> regions) {
    RenderObject rd = new RenderObject();
    HashMap<Vertex3d, Double> depthMap = new HashMap<Vertex3d, Double>();
    double maxd = 0;
    for (PenetratingPoint pp : points) {
        depthMap.put(pp.vertex, pp.distance);
        if (pp.distance > maxd) {
            maxd = pp.distance;
        }
    }
    ScalarRange range = handler.myBehavior.myPenetrationDepthRange;
    range.updateInterval(0, maxd);
    float[] rgb = new float[3];
    for (int i = 0; i < 256; i++) {
        handler.myManager.myColorMap.getRGB(i / 255.0, rgb);
        rd.addColor(rgb);
    }
    Point3d wpnt = new Point3d();
    Vector3d wnrm = new Vector3d();
    for (PenetrationRegion region : regions) {
        for (Face face : region.getFaces()) {
            HalfEdge he = face.firstHalfEdge();
            Vertex3d v0 = he.getHead();
            Vertex3d v1 = he.getNext().getHead();
            Vertex3d v2 = he.getTail();
            v0.getWorldPoint(wpnt);
            int pi0 = rd.addPosition(wpnt);
            v1.getWorldPoint(wpnt);
            int pi1 = rd.addPosition(wpnt);
            v2.getWorldPoint(wpnt);
            int pi2 = rd.addPosition(wpnt);
            int ci0 = getColorIndex(range, v0, depthMap);
            int ci1 = getColorIndex(range, v1, depthMap);
            int ci2 = getColorIndex(range, v2, depthMap);
            face.getWorldNormal(wnrm);
            int ni = rd.addNormal(wnrm);
            int v0idx = rd.addVertex(pi0, ni, ci0, -1);
            int v1idx = rd.addVertex(pi1, ni, ci1, -1);
            int v2idx = rd.addVertex(pi2, ni, ci2, -1);
            rd.addTriangle(v0idx, v1idx, v2idx);
        }
    }
    return rd;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) HashMap(java.util.HashMap) HalfEdge(maspack.geometry.HalfEdge) IntersectionPoint(maspack.collision.IntersectionPoint) PenetratingPoint(maspack.collision.PenetratingPoint) PenetratingPoint(maspack.collision.PenetratingPoint) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) RenderObject(maspack.render.RenderObject) Face(maspack.geometry.Face) PenetrationRegion(maspack.collision.PenetrationRegion) ScalarRange(artisynth.core.util.ScalarRange)

Example 10 with HalfEdge

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

the class MeshIntersectingProbe method getFaces.

/**
 * Returns a list of all faces that use this vertex
 */
public ArrayList<Face> getFaces(Vertex3d vtx) {
    Iterator<HalfEdge> hit = vtx.getIncidentHalfEdges();
    ArrayList<Face> faces = new ArrayList<Face>();
    while (hit.hasNext()) {
        HalfEdge he = hit.next();
        faces.add(he.getFace());
    }
    return faces;
}
Also used : ArrayList(java.util.ArrayList) 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