Search in sources :

Example 11 with HalfEdge

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

the class CutPlaneProbe method extractBoundaries.

/**
 * Gets the boundaries of the supplied display mesh
 */
protected static ArrayList<Vertex3d[]> extractBoundaries(PolygonalMesh surface) {
    ArrayList<Vertex3d[]> boundaries = new ArrayList<Vertex3d[]>(1);
    ArrayList<Vertex3d> vtxList = null;
    LinkedList<HalfEdge> borderEdges = new LinkedList<HalfEdge>(surface.findBorderEdges());
    while (borderEdges.size() > 0) {
        vtxList = new ArrayList<Vertex3d>();
        HalfEdge borderEdge = borderEdges.get(0);
        borderEdges.remove(0);
        vtxList.add(borderEdge.head);
        vtxList.add(borderEdge.tail);
        Vertex3d lastVtx = borderEdge.tail;
        while (lastVtx != vtxList.get(0)) {
            Iterator<HalfEdge> eit = borderEdge.tail.getIncidentHalfEdges();
            HalfEdge he;
            while (eit.hasNext()) {
                he = eit.next();
                if (he != borderEdge && he.opposite == null) {
                    borderEdge = he;
                    break;
                }
            }
            if (borderEdges.contains(borderEdge)) {
                borderEdges.remove(borderEdge);
            }
            lastVtx = borderEdge.tail;
            if (!vtxList.contains(lastVtx) || lastVtx == vtxList.get(0)) {
                vtxList.add(lastVtx);
            } else {
                System.out.println("boundary not closed");
                break;
            }
        }
        boundaries.add(vtxList.toArray(new Vertex3d[vtxList.size()]));
    }
    return boundaries;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) ArrayList(java.util.ArrayList) HalfEdge(maspack.geometry.HalfEdge) LinkedList(java.util.LinkedList)

Example 12 with HalfEdge

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

the class FaceComponent method drawFaces.

void drawFaces(Renderer renderer, Shading shading, RenderProps props) {
    boolean useVertexColors = useVertexColouring;
    if (renderer.isSelecting()) {
        useVertexColors = false;
    }
    Face face = myFace;
    boolean useVertexNormals = false;
    ArrayList<Vector3d> normals = null;
    int[] normalIndices = null;
    int normalFaceOff = -1;
    if ((shading == Shading.SMOOTH || shading == Shading.METAL) && myMesh.hasNormals()) {
        useVertexNormals = true;
        normals = myMesh.getNormals();
        normalIndices = myMesh.getNormalIndices();
        normalFaceOff = myMesh.getFeatureIndexOffsets()[face.getIndex()];
    }
    Vector3d faceNrm = face.getNormal();
    ArrayList<float[]> colors = null;
    int[] colorIndices = null;
    int colorFaceOff = -1;
    if (useVertexColouring) {
        colors = myMesh.getColors();
        colorIndices = myMesh.getColorIndices();
        colorFaceOff = myMesh.getFeatureIndexOffsets()[face.getIndex()];
    }
    renderer.beginDraw(DrawMode.TRIANGLE_FAN);
    HalfEdge he = face.firstHalfEdge();
    int k = 0;
    do {
        Vertex3d vtx = he.head;
        Point3d pnt = vtx.myRenderPnt;
        if (useVertexColors) {
            int cidx = colorIndices[colorFaceOff + k];
            if (cidx != -1) {
                float[] color = colors.get(cidx);
                renderer.setColor(color);
            }
        }
        if (useVertexNormals) {
            int nidx = normalIndices[normalFaceOff + k];
            if (nidx != -1) {
                Vector3d normal = normals.get(nidx);
                renderer.setNormal(normal);
            }
        } else {
            renderer.setNormal(faceNrm);
        }
        renderer.addVertex(pnt.x, pnt.y, pnt.z);
        he = he.getNext();
        k++;
    } while (he != face.firstHalfEdge());
    renderer.endDraw();
}
Also used : Vertex3d(maspack.geometry.Vertex3d) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) HalfEdge(maspack.geometry.HalfEdge) Face(maspack.geometry.Face)

Example 13 with HalfEdge

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

the class FaceComponent method drawEdges.

private void drawEdges(Renderer renderer, RenderProps props) {
    Face face = myFace;
    HalfEdge he = face.firstHalfEdge();
    ArrayList<float[]> colors;
    int[] colorIndices;
    int faceOff;
    if (useVertexColouring) {
        colors = myMesh.getColors();
        colorIndices = myMesh.getColorIndices();
        faceOff = myMesh.getFeatureIndexOffsets()[face.getIndex()];
    } else {
        colors = null;
        colorIndices = null;
        faceOff = -1;
    }
    int k = 0;
    renderer.beginDraw(DrawMode.LINE_LOOP);
    do {
        if (useVertexColouring) {
            int cidx = colorIndices[faceOff + k];
            if (cidx != -1) {
                float[] color = colors.get(cidx);
                renderer.setColor(color);
            }
        }
        Point3d pnt = he.head.myRenderPnt;
        renderer.addVertex(pnt);
        he = he.getNext();
        k++;
    } while (he != face.firstHalfEdge());
    renderer.endDraw();
}
Also used : Point3d(maspack.matrix.Point3d) HalfEdge(maspack.geometry.HalfEdge) Face(maspack.geometry.Face)

Example 14 with HalfEdge

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

the class FaceComponent method prerender.

@Override
public void prerender(RenderList list) {
    HalfEdge he0 = myFace.firstHalfEdge();
    HalfEdge he = he0;
    do {
        he.getHead().saveRenderInfo();
        he = he.getNext();
    } while (he != he0);
    myFace.computeRenderNormal();
}
Also used : HalfEdge(maspack.geometry.HalfEdge)

Example 15 with HalfEdge

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

the class IntersectionTester method findPenetratingFaces.

private Face[] findPenetratingFaces(ArrayList<PenetratingPoint> points) {
    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)) {
                faces.add(face);
            }
        }
    }
    return faces.toArray(new Face[0]);
}
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