Search in sources :

Example 56 with Vertex3d

use of maspack.geometry.Vertex3d 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 57 with Vertex3d

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

the class FemDisplayProbe method updatePosState.

/**
 * Move vertices of clipped mesh along with FEM, like an embedded mesh
 */
protected synchronized void updatePosState() {
    if (clipped && !useRestCoordinates) {
        for (Vertex3d vtx : myPlaneSurface.getVertices()) {
            VtxInfo vi = clippedVtxMap.get(vtx);
            vtx.pnt.setZero();
            for (int i = 0; i < vi.nodes.length; i++) {
                vtx.pnt.scaledAdd(vi.coords[i], vi.nodes[i].getPosition());
            }
        }
    }
}
Also used : Vertex3d(maspack.geometry.Vertex3d)

Example 58 with Vertex3d

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

the class FemDisplayProbe method computeClippedVertexColors.

// if we are clipped to the FEM, then the shape function values are fixed
private void computeClippedVertexColors() {
    RenderProps rprops = getRenderProps();
    float alpha = (float) rprops.getAlpha();
    Color faceColor = rprops.getFaceColor();
    Color femFaceColor = null;
    double stressVal = 0;
    if (mySurfaceRendering == SurfaceRender.Stress || mySurfaceRendering == SurfaceRender.Strain) {
        if (myStressPlotRanging == Ranging.Auto) {
            myStressPlotRange.merge(myFem.getNodalPlotRange(mySurfaceRendering));
        }
    } else {
        femFaceColor = myFem.getRenderProps().getFaceColor();
    }
    float[] carray = new float[3];
    // use our stored map of values
    for (Vertex3d vtx : myPlaneSurface.getVertices()) {
        switch(mySurfaceRendering) {
            case None:
                setColor(vtx, faceColor, alpha);
                break;
            case Strain:
                stressVal = getStrainValue(clippedVtxMap.get(vtx));
                myColorMap.getRGB(stressVal / myStressPlotRange.getRange(), carray);
                setColor(vtx, carray[0], carray[1], carray[2], alpha);
                break;
            case Stress:
                stressVal = getStressValue(clippedVtxMap.get(vtx));
                myColorMap.getRGB(stressVal / myStressPlotRange.getRange(), carray);
                setColor(vtx, carray[0], carray[1], carray[2], alpha);
                break;
            default:
                setColor(vtx, femFaceColor, alpha);
        }
    }
}
Also used : Vertex3d(maspack.geometry.Vertex3d) Color(java.awt.Color) RenderProps(maspack.render.RenderProps)

Example 59 with Vertex3d

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

the class FemDisplayProbe method updateVertexIndicators.

/**
 *  determines which vertices are inside the supplied mesh
 */
protected void updateVertexIndicators() {
    vtxIndicatorMap = new HashMap<Vertex3d, Boolean>(myPlaneSurface.numVertices());
    TriangleIntersector ti = new TriangleIntersector();
    BVFeatureQuery query = new BVFeatureQuery();
    ti.setEpsilon(myIntersectionTolerance);
    if (myFem != null) {
        PolygonalMesh mesh = myFem.getSurfaceMesh();
        for (Vertex3d vtx : myPlaneSurface.getVertices()) {
            Point3d pnt = vtx.getWorldPoint();
            if (query.isInsideOrientedMesh(mesh, pnt, myIntersectionTolerance)) {
                vtxIndicatorMap.put(vtx, true);
            } else {
                vtxIndicatorMap.put(vtx, false);
            }
        }
    }
}
Also used : Vertex3d(maspack.geometry.Vertex3d) Point3d(maspack.matrix.Point3d) TriangleIntersector(maspack.geometry.TriangleIntersector) BVFeatureQuery(maspack.geometry.BVFeatureQuery) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 60 with Vertex3d

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

the class FemDisplayProbe method createVtxMap.

// map of vertices to coordinates inside FEM
private void createVtxMap() {
    clippedVtxMap = new HashMap<Vertex3d, VtxInfo>(myPlaneSurface.numVertices());
    Point3d loc = new Point3d();
    Vector3d ncoords = new Vector3d();
    for (Vertex3d vtx : myPlaneSurface.getVertices()) {
        FemElement3d elem = myFem.findNearestElement(loc, vtx.getWorldPoint());
        elem.getNaturalCoordinates(ncoords, vtx.getWorldPoint());
        VtxInfo info = new VtxInfo();
        info.nodes = elem.getNodes();
        info.coords = new double[info.nodes.length];
        for (int i = 0; i < info.coords.length; i++) {
            info.coords[i] = elem.getN(i, ncoords);
        }
        clippedVtxMap.put(vtx, info);
    }
}
Also used : Vertex3d(maspack.geometry.Vertex3d) FemElement3d(artisynth.core.femmodels.FemElement3d) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d)

Aggregations

Vertex3d (maspack.geometry.Vertex3d)81 Point3d (maspack.matrix.Point3d)35 Face (maspack.geometry.Face)30 PolygonalMesh (maspack.geometry.PolygonalMesh)24 Vector3d (maspack.matrix.Vector3d)23 ContactPoint (artisynth.core.mechmodels.ContactPoint)22 Point (artisynth.core.mechmodels.Point)22 ArrayList (java.util.ArrayList)19 PointParticleAttachment (artisynth.core.mechmodels.PointParticleAttachment)15 HalfEdge (maspack.geometry.HalfEdge)13 PointAttachment (artisynth.core.mechmodels.PointAttachment)10 HashMap (java.util.HashMap)10 Vector2d (maspack.matrix.Vector2d)8 VectorNd (maspack.matrix.VectorNd)8 BVFeatureQuery (maspack.geometry.BVFeatureQuery)7 RenderProps (maspack.render.RenderProps)6 PointFem3dAttachment (artisynth.core.femmodels.PointFem3dAttachment)5 Color (java.awt.Color)5 FemNode (artisynth.core.femmodels.FemNode)4 BufferedWriter (java.io.BufferedWriter)4