Search in sources :

Example 11 with PointFem3dAttachment

use of artisynth.core.femmodels.PointFem3dAttachment in project artisynth_core by artisynth.

the class MFreeMeshComp method setVertexAttachment.

public void setVertexAttachment(int vidx, double[] weights, MFreeNode3d[] nodes) {
    if (weights.length > 1) {
        PointFem3dAttachment pattacher = new PointFem3dAttachment();
        pattacher.setFromNodes(nodes, weights);
        setVertexAttachment(vidx, pattacher);
    } else if (weights.length == 1) {
        PointParticleAttachment attacher = new PointParticleAttachment(nodes[0], null);
        setVertexAttachment(vidx, attacher);
    }
}
Also used : PointFem3dAttachment(artisynth.core.femmodels.PointFem3dAttachment) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment)

Example 12 with PointFem3dAttachment

use of artisynth.core.femmodels.PointFem3dAttachment in project artisynth_core by artisynth.

the class MFreeMeshComp method scanMeshUsingVertexInfo.

/**
 * New scan method where the vertex attachments are also scanned
 */
private void scanMeshUsingVertexInfo(ReaderTokenizer rtok) throws IOException {
    PolygonalMesh mesh = (PolygonalMesh) getMesh();
    ArrayList<Vertex3d> vtxList = new ArrayList<Vertex3d>();
    ArrayList<FemNode> nodes = new ArrayList<FemNode>();
    VectorNd weights = new VectorNd();
    rtok.nextToken();
    while (rtok.tokenIsWord()) {
        if (rtok.sval.equals("v")) {
            int nnum = rtok.scanInteger();
            if (nnum == -1) {
                double x = rtok.scanNumber();
                double y = rtok.scanNumber();
                double z = rtok.scanNumber();
                mesh.addVertex(new Vertex3d(x, y, z));
                myVertexAttachments.add(null);
                rtok.nextToken();
            } else {
                PointAttachment ax;
                double w = rtok.scanNumber();
                rtok.nextToken();
                Vertex3d vtx = new Vertex3d();
                if (rtok.tokenIsInteger()) {
                    nodes.clear();
                    weights.setSize(0);
                    nodes.add(getNodeFromNumber(rtok, nnum));
                    weights.append(w);
                    while (rtok.tokenIsInteger()) {
                        nodes.add(getNodeFromNumber(rtok, (int) rtok.lval));
                        weights.append(rtok.scanNumber());
                        rtok.nextToken();
                    }
                    PointFem3dAttachment attacher = new PointFem3dAttachment();
                    attacher.setFromNodes(nodes, weights);
                    ax = attacher;
                } else {
                    MFreeNode3d node = (MFreeNode3d) getNodeFromNumber(rtok, nnum);
                    ax = new PointParticleAttachment(node, null);
                }
                mesh.addVertex(vtx);
                myVertexAttachments.add(ax);
            }
        } else if (rtok.sval.equals("f")) {
            vtxList.clear();
            rtok.nextToken();
            while (rtok.tokenIsInteger()) {
                int vnum = (int) rtok.lval;
                if (vnum > mesh.numVertices()) {
                    throw new IOException("Vertex number " + vnum + " not found, " + rtok);
                }
                vtxList.add(mesh.getVertex(vnum - 1));
                rtok.nextToken();
            }
            mesh.addFace(vtxList.toArray(new Vertex3d[0]));
        } else {
            throw new IOException("Unexpected token: " + rtok);
        }
    }
    rtok.pushBack();
}
Also used : Vertex3d(maspack.geometry.Vertex3d) FemNode(artisynth.core.femmodels.FemNode) ArrayList(java.util.ArrayList) PointAttachment(artisynth.core.mechmodels.PointAttachment) IOException(java.io.IOException) PolygonalMesh(maspack.geometry.PolygonalMesh) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point) VectorNd(maspack.matrix.VectorNd) PointFem3dAttachment(artisynth.core.femmodels.PointFem3dAttachment) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment)

Example 13 with PointFem3dAttachment

use of artisynth.core.femmodels.PointFem3dAttachment in project artisynth_core by artisynth.

the class MFreeMeshComp method writeVertexInfo.

private void writeVertexInfo(PrintWriter pw, Vertex3d vtx, NumberFormat fmt) {
    PointAttachment pa = null;
    if (vtx.getIndex() < myVertexAttachments.size()) {
        pa = getAttachment(vtx.getIndex());
    }
    if (pa instanceof PointFem3dAttachment) {
        PointFem3dAttachment pfa = (PointFem3dAttachment) pa;
        FemNode[] masters = pfa.getNodes();
        pw.print("v");
        for (int j = 0; j < masters.length; j++) {
            pw.print(" " + masters[j].getNumber() + " " + fmt.format(pfa.getCoordinate(j)));
        }
        pw.println("");
    } else if (pa instanceof PointParticleAttachment) {
        PointParticleAttachment ppa = (PointParticleAttachment) pa;
        MFreeNode3d n = (MFreeNode3d) ppa.getParticle();
        pw.println("v " + n.getNumber() + " 1.0");
    } else {
        pw.println("v -1 " + vtx.getPosition().toString(fmt));
    }
}
Also used : FemNode(artisynth.core.femmodels.FemNode) PointFem3dAttachment(artisynth.core.femmodels.PointFem3dAttachment) PointAttachment(artisynth.core.mechmodels.PointAttachment) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point)

Aggregations

PointFem3dAttachment (artisynth.core.femmodels.PointFem3dAttachment)13 PointParticleAttachment (artisynth.core.mechmodels.PointParticleAttachment)13 FemNode (artisynth.core.femmodels.FemNode)10 PointAttachment (artisynth.core.mechmodels.PointAttachment)9 ContactPoint (artisynth.core.mechmodels.ContactPoint)8 Point (artisynth.core.mechmodels.Point)8 VectorNd (maspack.matrix.VectorNd)6 Vertex3d (maspack.geometry.Vertex3d)5 ArrayList (java.util.ArrayList)4 PolygonalMesh (maspack.geometry.PolygonalMesh)3 Point3d (maspack.matrix.Point3d)3 FemNode3d (artisynth.core.femmodels.FemNode3d)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 FemElement3d (artisynth.core.femmodels.FemElement3d)1 FemMeshBase (artisynth.core.femmodels.FemMeshBase)1 FemMeshComp (artisynth.core.femmodels.FemMeshComp)1 IntegrationData3d (artisynth.core.femmodels.IntegrationData3d)1 IntegrationPoint3d (artisynth.core.femmodels.IntegrationPoint3d)1 ContactMaster (artisynth.core.mechmodels.ContactMaster)1