Search in sources :

Example 11 with FemNode

use of artisynth.core.femmodels.FemNode 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 12 with FemNode

use of artisynth.core.femmodels.FemNode 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)

Example 13 with FemNode

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

the class FemSurfaceTargetDemo method addTrackingController.

public void addTrackingController() {
    TrackingController tcon = new TrackingController(mech, "tcon");
    for (FemNode n : fem.getNodes()) {
        if (n.getPosition().x < -l / 2 + eps) {
            tcon.addMotionTarget(n);
            RenderProps.setAlpha(n, 0.5);
        }
    }
    for (MuscleBundle b : fem.getMuscleBundles()) {
        tcon.addExciter(b);
    }
    // project reference points to body
    addController(new SurfaceTargetController(body.getMesh(), tcon.getMotionSources(), tcon.getTargetPoints()));
    for (TargetPoint p : tcon.getTargetPoints()) {
        RenderProps.setPointRadius(p, l / 100);
    }
    tcon.addL2RegularizationTerm(0.1);
    tcon.setProbeDuration(10);
    tcon.createProbesAndPanel(this);
    addController(tcon);
}
Also used : FemNode(artisynth.core.femmodels.FemNode) MuscleBundle(artisynth.core.femmodels.MuscleBundle) TargetPoint(artisynth.core.inverse.TargetPoint) TrackingController(artisynth.core.inverse.TrackingController)

Example 14 with FemNode

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

the class FemSurfaceTargetDemo method build.

@Override
public void build(String[] args) throws IOException {
    super.build(args);
    mech = new MechModel("mech");
    mech.setGravity(Vector3d.ZERO);
    addModel(mech);
    fem = new FemMuscleModel("fem");
    fem.setStiffnessDamping(0.1);
    mech.addModel(fem);
    // boundary conditions
    FemFactory.createHexGrid(fem, l, w, w, nl, nw, nw);
    for (FemNode n : fem.getNodes()) {
        if (n.getPosition().x > l / 2 - eps) {
            n.setDynamic(false);
        }
    }
    // muscles
    addMuscle("vert", Color.RED, Vector3d.Z_UNIT);
    addMuscle("trans", Color.BLUE, Vector3d.Y_UNIT);
    body = new RigidBody("plate");
    body.setMesh(MeshFactory.createBox(l, l, l / 10));
    body.setPose(new RigidTransform3d(-1.2 * w - l / 20, 0, 0, 0, 1, 0, Math.PI / 2));
    body.setDynamic(false);
    mech.addRigidBody(body);
    mech.setCollisionBehavior(body, fem, true);
    addTrackingController();
    setupRenderProps();
}
Also used : MechModel(artisynth.core.mechmodels.MechModel) FemNode(artisynth.core.femmodels.FemNode) RigidTransform3d(maspack.matrix.RigidTransform3d) FemMuscleModel(artisynth.core.femmodels.FemMuscleModel) RigidBody(artisynth.core.mechmodels.RigidBody)

Aggregations

FemNode (artisynth.core.femmodels.FemNode)14 PointFem3dAttachment (artisynth.core.femmodels.PointFem3dAttachment)10 PointParticleAttachment (artisynth.core.mechmodels.PointParticleAttachment)10 PointAttachment (artisynth.core.mechmodels.PointAttachment)9 ContactPoint (artisynth.core.mechmodels.ContactPoint)7 Point (artisynth.core.mechmodels.Point)7 VectorNd (maspack.matrix.VectorNd)5 PolygonalMesh (maspack.geometry.PolygonalMesh)4 Vertex3d (maspack.geometry.Vertex3d)4 ArrayList (java.util.ArrayList)3 Point3d (maspack.matrix.Point3d)3 FemNode3d (artisynth.core.femmodels.FemNode3d)2 MechModel (artisynth.core.mechmodels.MechModel)2 RigidBody (artisynth.core.mechmodels.RigidBody)2 HashMap (java.util.HashMap)2 RigidTransform3d (maspack.matrix.RigidTransform3d)2 FemElement (artisynth.core.femmodels.FemElement)1 FemElement3d (artisynth.core.femmodels.FemElement3d)1 FemMarker (artisynth.core.femmodels.FemMarker)1 FemMeshBase (artisynth.core.femmodels.FemMeshBase)1