Search in sources :

Example 16 with FemNode3d

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

the class FemCollision method positionBall.

void positionBall(FemModel3d ball, Vector3d startPos) {
    if (ball == null)
        return;
    Vector3d avg = new Vector3d();
    for (FemNode3d n : ball.getNodes()) avg.add(n.getPosition());
    avg.scale(1 / (double) ball.getNodes().size());
    Vector3d pos = new Vector3d(startPos);
    pos.sub(avg);
    ball.transformGeometry(new RigidTransform3d(pos, new AxisAngle()));
    for (FemNode3d n : ball.getNodes()) {
        n.setVelocity(0, 0, 0);
    }
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) AxisAngle(maspack.matrix.AxisAngle) Vector3d(maspack.matrix.Vector3d) FemNode3d(artisynth.core.femmodels.FemNode3d)

Example 17 with FemNode3d

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

the class FemMuscleDemo method initializeModel.

protected void initializeModel(int xn) throws IOException {
    double widthX = 0.09;
    double widthY = 0.03;
    double widthZ = 0.03;
    int numX = xn * 9;
    int numY = xn * 3;
    int numZ = xn * 3;
    tissue = new FemMuscleModel("fem");
    FemFactory.createHexGrid(tissue, widthX, widthY, widthZ, numX, numY, numZ);
    tissue.setBounds(new Point3d(-widthX, 0, 0), new Point3d(widthX, 0, 0));
    // XXX fix the leftmost nodes
    double EPS = 1e-9;
    double xmin = Double.POSITIVE_INFINITY;
    for (FemNode3d n : tissue.getNodes()) {
        if (n.getPosition().x < xmin) {
            xmin = n.getPosition().x;
        }
    }
    for (FemNode3d n : tissue.getNodes()) {
        if (Math.abs(n.getPosition().x - xmin) < 1e-10) {
            n.setDynamic(false);
        }
    }
    LinkedList<FemElement3d> topElems = new LinkedList<FemElement3d>();
    LinkedList<FemElement3d> midElems = new LinkedList<FemElement3d>();
    LinkedList<FemElement3d> botElems = new LinkedList<FemElement3d>();
    for (FemElement3d e : tissue.getElements()) {
        if (defaultMidElements == ALL) {
            midElems.add(e);
        }
        for (FemNode3d n : e.getNodes()) {
            if (Math.abs(n.getPosition().z - widthZ / 2) < EPS) {
                topElems.add(e);
                break;
            } else if (Math.abs(n.getPosition().z + widthZ / 2) < EPS) {
                botElems.add(e);
                break;
            } else if (defaultMidElements == MIDDLE && Math.abs(n.getPosition().z - widthZ / (2 * numZ)) < EPS) {
                midElems.add(e);
                break;
            }
        }
    }
    RenderProps.setLineWidth(tissue, 2);
    RenderProps.setLineColor(tissue, Color.PINK);
    RenderProps.setPointStyle(tissue, Renderer.PointStyle.SPHERE);
    RenderProps.setPointRadius(tissue, 0.03);
    RenderProps.setPointColor(tissue, Color.PINK);
    RenderProps.setFaceColor(tissue, Color.PINK.darker());
    GenericMuscle mm = new GenericMuscle();
    mm.setMaxStress(5000);
    BlemkerMuscle bm = new BlemkerMuscle();
    // bm.setMaxStress (5000);
    tissue.setMuscleMaterial(bm);
    MuscleBundle top, mid, bot;
    top = createBundle("top", topElems);
    mid = createBundle("mid", midElems);
    bot = createBundle("bot", botElems);
    int k = 0;
    setBundleRenderProps(top, getMuscleColor(k++));
    if (addMidMuscle) {
        setBundleRenderProps(mid, getMuscleColor(k++));
    }
    setBundleRenderProps(bot, getMuscleColor(k));
    tissue.addMuscleBundle(top);
    if (addMidMuscle) {
        tissue.addMuscleBundle(mid);
    }
    tissue.addMuscleBundle(bot);
    double qt = midQuadTerm;
    addStrand(top, -0.035, -0.005, 0.015, 0.035, -0.005, 0.015, 0, 8);
    addStrand(top, -0.035, 0.005, 0.015, 0.035, 0.005, 0.015, 0, 8);
    if (addMidMuscle) {
        addStrand(mid, -0.035, -0.005, 0.000, 0.035, -0.005, 0.000, qt, 8);
        addStrand(mid, -0.035, 0.005, 0.000, 0.035, 0.005, 0.000, qt, 8);
    }
    addStrand(bot, -0.035, -0.005, -0.015, 0.035, -0.005, -0.015, 0, 8);
    addStrand(bot, -0.035, 0.005, -0.015, 0.035, 0.005, -0.015, 0, 8);
    if (addMidMuscle) {
        if (addMidElementsWithin > 0) {
            mid.addElementsNearFibres(addMidElementsWithin);
        }
        if (autoComputeMidDirections) {
            mid.computeElementDirections();
        }
    }
    tissue.setDirectionRenderLen(0.5);
    RenderProps.setPointRadius(tissue, 0.001);
    tissue.setGravity(0, 0, 0);
    tissue.setDensity(1000);
    tissue.setMaterial(new MooneyRivlinMaterial(1037, 0, 0, 486, 0, 10000));
    // tissue.setPoissonsRatio (0.499);
    // tissue.setYoungsModulus (6912);
    tissue.setParticleDamping(6.22);
    // more stable with 0 stiffness damping ...
    tissue.setStiffnessDamping(0.01);
    // tissue.setMaxStepSize(100*TimeBase.USEC);
    tissue.setMaxStepSize(0.01);
    tissue.setIntegrator(Integrator.ConstrainedBackwardEuler);
    myModel.addModel(tissue);
    addModel(myModel);
    for (MuscleBundle b : tissue.getMuscleBundles()) {
        RenderProps.setVisible(b.getFibres(), false);
    }
    for (FemMarker m : tissue.markers()) {
        RenderProps.setVisible(m, false);
    }
    addProbes(tissue);
    createMusclePanel();
// int numWays = 20;
// double res = 0.1;
// for (int i = 0; i < numWays; i++) {
// addWayPoint (new WayPoint (TimeBase.secondsToTicks ((i + 1) * res)));
// }
}
Also used : FemElement3d(artisynth.core.femmodels.FemElement3d) MooneyRivlinMaterial(artisynth.core.materials.MooneyRivlinMaterial) BlemkerMuscle(artisynth.core.materials.BlemkerMuscle) FemMarker(artisynth.core.femmodels.FemMarker) Point(artisynth.core.mechmodels.Point) LinkedList(java.util.LinkedList) MuscleBundle(artisynth.core.femmodels.MuscleBundle) Point3d(maspack.matrix.Point3d) FemMuscleModel(artisynth.core.femmodels.FemMuscleModel) FemNode3d(artisynth.core.femmodels.FemNode3d) GenericMuscle(artisynth.core.materials.GenericMuscle)

Example 18 with FemNode3d

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

the class FemSkinDemo method getRightNodes.

LinkedList<FemNode3d> getRightNodes(FemModel3d femMod) {
    LinkedList<FemNode3d> nodes = new LinkedList<FemNode3d>();
    double maxx = Double.NEGATIVE_INFINITY;
    for (FemNode3d n : femMod.getNodes()) {
        if (n.getPosition().x > maxx) {
            maxx = n.getPosition().x;
        }
    }
    for (FemNode3d n : femMod.getNodes()) {
        if (n.getPosition().x > maxx - EPS) {
            nodes.add(n);
        }
    }
    return nodes;
}
Also used : FemNode3d(artisynth.core.femmodels.FemNode3d)

Example 19 with FemNode3d

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

the class FemSkinDemo method build.

public void build(String[] args) {
    myMech = new MechModel("mech");
    RenderProps.setPointStyle(myMech, Renderer.PointStyle.SPHERE);
    double midw = 0.6;
    FemModel3d femMod1 = createFem("fem1", midw, 0.2, 0.2);
    FemModel3d femMod2 = createFem("fem2", midw, 0.2, 0.2);
    // fix the leftmost nodes
    LinkedList<FemNode3d> leftNodes1 = getLeftNodes(femMod1);
    LinkedList<FemNode3d> rightNodes1 = getRightNodes(femMod1);
    LinkedList<FemNode3d> leftNodes2 = getLeftNodes(femMod2);
    LinkedList<FemNode3d> rightNodes2 = getRightNodes(femMod2);
    RigidTransform3d X = new RigidTransform3d();
    double wx = 0.1;
    double wy = 0.3;
    double wz = 0.3;
    double transx = wx / 2 + 1.5 * midw;
    RigidBody leftBody = createBlock("leftBlock", wx, wy, wz);
    leftBody.setPose(new RigidTransform3d(-transx, 0, 0));
    RigidTransform3d TCW = new RigidTransform3d();
    TCW.p.set(-transx - wx / 2, 0, wz / 2);
    TCW.R.mulAxisAngle(1, 0, 0, Math.PI / 2);
    RevoluteJoint joint = new RevoluteJoint(leftBody, TCW);
    RenderProps.setLineRadius(joint, 0.01);
    joint.setAxisLength(0.4);
    myMech.addBodyConnector(joint);
    RigidBody middleBody = createBlock("middleBlock", midw, 0.21, 0.21);
    RigidBody rightBody = createBlock("rightBlock", wx, wy, wz);
    rightBody.setPose(new RigidTransform3d(transx, 0, 0));
    TCW.p.set(transx + wx / 2, 0, wz / 2);
    TCW.R.setAxisAngle(1, 0, 0, Math.PI / 2);
    joint = new RevoluteJoint(rightBody, TCW);
    RenderProps.setLineRadius(joint, 0.01);
    joint.setAxisLength(0.4);
    myMech.addBodyConnector(joint);
    femMod1.transformGeometry(new RigidTransform3d(-midw, 0, 0));
    femMod2.transformGeometry(new RigidTransform3d(midw, 0, 0));
    for (FemNode3d n : leftNodes1) {
        myMech.attachPoint(n, leftBody);
    }
    for (FemNode3d n : rightNodes1) {
        myMech.attachPoint(n, middleBody);
    }
    for (FemNode3d n : leftNodes2) {
        myMech.attachPoint(n, middleBody);
    }
    for (FemNode3d n : rightNodes2) {
        myMech.attachPoint(n, rightBody);
    }
    PolygonalMesh mesh = MeshFactory.createRoundedCylinder(/*r=*/
    0.3, /*h=*/
    1.8, /*nsclices=*/
    12, /*nsegs=*/
    10, /*flatbotton=*/
    false);
    // flip aout y axis
    mesh.transform(new RigidTransform3d(0, 0, 0, 0, Math.PI / 2, 0));
    SkinMeshBody skinBody = new SkinMeshBody(mesh);
    skinBody.addFrame(rightBody);
    skinBody.addFrame(middleBody);
    skinBody.addFrame(leftBody);
    skinBody.addFemModel(femMod1);
    skinBody.addFemModel(femMod2);
    skinBody.computeWeights();
    skinBody.setName("skin");
    RenderProps.setDrawEdges(skinBody, true);
    RenderProps.setFaceStyle(skinBody, Renderer.FaceStyle.NONE);
    myMech.addMeshBody(skinBody);
    addModel(myMech);
}
Also used : SkinMeshBody(artisynth.core.femmodels.SkinMeshBody) FemModel3d(artisynth.core.femmodels.FemModel3d) FemNode3d(artisynth.core.femmodels.FemNode3d)

Example 20 with FemNode3d

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

the class ArticulatedFem method build.

public void build(String[] args) {
    int nlinks = 3;
    int nelemsx = 6;
    int nelemsz = 2;
    double femLength = 0.6;
    double femHeight = 0.2;
    double boxLength = 0.1;
    double boxHeight = 0.3;
    double linkLength = femLength + 2 * boxLength;
    myMechMod = new MechModel("mech");
    RigidTransform3d X = new RigidTransform3d();
    RigidBody lastBox = null;
    double linkCenter;
    RigidBody leftAnchorBox = makeBox();
    linkCenter = linkLength * (-nlinks / 2.0 + 0.5);
    X.p.set(linkCenter - (boxLength + femLength) / 2, 0, boxHeight);
    leftAnchorBox.setPose(X);
    leftAnchorBox.setDynamic(false);
    // myMechMod.addRigidBody (leftAnchorBox);
    RigidBody rightAnchorBox = makeBox();
    linkCenter = linkLength * (-nlinks / 2.0 + (nlinks - 1) + 0.5);
    X.p.set(linkCenter + (boxLength + femLength) / 2, 0, boxHeight);
    rightAnchorBox.setPose(X);
    rightAnchorBox.setDynamic(false);
    for (int i = 0; i < nlinks; i++) {
        linkCenter = linkLength * (-nlinks / 2.0 + i + 0.5);
        LinkedList<FemNode3d> leftNodes = new LinkedList<FemNode3d>();
        LinkedList<FemNode3d> rightNodes = new LinkedList<FemNode3d>();
        FemModel3d femMod = FemFactory.createTetGrid(null, femLength, femHeight, femHeight, nelemsx, nelemsz, nelemsz);
        femMod.setDensity(myDensity);
        femMod.setLinearMaterial(200000, 0.4, true);
        femMod.setGravity(0, 0, -9.8);
        double eps = 0.000001;
        for (FemNode3d n : femMod.getNodes()) {
            double x = n.getPosition().x;
            if (x <= -femLength / 2 + eps) {
                leftNodes.add(n);
            } else if (x >= femLength / 2 - eps) {
                rightNodes.add(n);
            }
        }
        femMod.setStiffnessDamping(0.002);
        RenderProps.setLineWidth(femMod.getElements(), 2);
        RenderProps.setLineColor(femMod.getElements(), Color.BLUE);
        RenderProps.setPointStyle(femMod.getNodes(), Renderer.PointStyle.SPHERE);
        RenderProps.setPointRadius(femMod.getNodes(), 0.005);
        femMod.setSurfaceRendering(SurfaceRender.Shaded);
        RenderProps.setFaceColor(femMod, new Color(0f, 0.7f, 0.7f));
        RenderProps.setLineColor(femMod.getElements(), new Color(0f, 0.2f, 0.2f));
        RenderProps.setLineWidth(femMod.getElements(), 3);
        X.p.set(linkCenter, 0, 0);
        femMod.transformGeometry(X);
        myMechMod.addModel(femMod);
        RigidBody leftBox = makeBox();
        X.p.set(linkCenter - (boxLength + femLength) / 2, 0, 0);
        leftBox.setPose(X);
        myMechMod.addRigidBody(leftBox);
        RigidBody rightBox = makeBox();
        X.p.set(linkCenter + (boxLength + femLength) / 2, 0, 0);
        rightBox.setPose(X);
        myMechMod.addRigidBody(rightBox);
        for (FemNode3d n : leftNodes) {
            myMechMod.attachPoint(n, leftBox);
        }
        for (FemNode3d n : rightNodes) {
            myMechMod.attachPoint(n, rightBox);
        }
        RigidTransform3d TCA = new RigidTransform3d();
        RigidTransform3d TCB = new RigidTransform3d();
        RevoluteJoint joint;
        TCA.p.set(-boxLength / 2, 0, boxHeight / 2);
        TCA.R.mulAxisAngle(1, 0, 0, Math.PI / 2);
        if (lastBox == null) {
            TCB.mul(leftBox.getPose(), TCA);
            // TCB.mulInverseLeft (leftAnchorBox.getPose(), TCB);
            joint = new RevoluteJoint(leftBox, TCA, TCB);
        } else {
            TCB.p.set(boxLength / 2, 0, boxHeight / 2);
            TCB.R.mulAxisAngle(1, 0, 0, Math.PI / 2);
            joint = new RevoluteJoint(leftBox, TCA, lastBox, TCB);
        }
        RenderProps.setLineRadius(joint, 0.01);
        RenderProps.setLineColor(joint, new Color(0.15f, 0.15f, 1f));
        joint.setAxisLength(0.5);
        myMechMod.addBodyConnector(joint);
        if (addLastJoint && i == nlinks - 1) {
            TCA.p.set(boxLength / 2, 0, boxHeight / 2);
            TCB.mul(rightBox.getPose(), TCA);
            // TCB.mulInverseLeft (rightAnchorBox.getPose(), TCB);
            joint = new RevoluteJoint(rightBox, TCA, TCB);
            RenderProps.setLineRadius(joint, 0.01);
            RenderProps.setLineColor(joint, new Color(0.15f, 0.15f, 1f));
            joint.setAxisLength(0.5);
            myMechMod.addBodyConnector(joint);
        }
        lastBox = rightBox;
    }
    if (!addLastJoint) {
        lastBox.setDynamic(false);
    }
    myMechMod.setIntegrator(Integrator.BackwardEuler);
    addModel(myMechMod);
    addControlPanel(myMechMod);
}
Also used : MechModel(artisynth.core.mechmodels.MechModel) RigidTransform3d(maspack.matrix.RigidTransform3d) FemModel3d(artisynth.core.femmodels.FemModel3d) Color(java.awt.Color) FemNode3d(artisynth.core.femmodels.FemNode3d) RevoluteJoint(artisynth.core.mechmodels.RevoluteJoint) RigidBody(artisynth.core.mechmodels.RigidBody) RevoluteJoint(artisynth.core.mechmodels.RevoluteJoint) LinkedList(java.util.LinkedList)

Aggregations

FemNode3d (artisynth.core.femmodels.FemNode3d)38 FemModel3d (artisynth.core.femmodels.FemModel3d)12 Point3d (maspack.matrix.Point3d)12 RigidTransform3d (maspack.matrix.RigidTransform3d)9 FemElement3d (artisynth.core.femmodels.FemElement3d)8 MechModel (artisynth.core.mechmodels.MechModel)8 Point (artisynth.core.mechmodels.Point)7 RigidBody (artisynth.core.mechmodels.RigidBody)7 Vector3d (maspack.matrix.Vector3d)6 ArrayList (java.util.ArrayList)5 FemMarker (artisynth.core.femmodels.FemMarker)4 IntegrationPoint3d (artisynth.core.femmodels.IntegrationPoint3d)4 VectorNd (maspack.matrix.VectorNd)4 TetElement (artisynth.core.femmodels.TetElement)3 RevoluteJoint (artisynth.core.mechmodels.RevoluteJoint)3 LinkedList (java.util.LinkedList)3 FemNode (artisynth.core.femmodels.FemNode)2 HexElement (artisynth.core.femmodels.HexElement)2 PointFem3dAttachment (artisynth.core.femmodels.PointFem3dAttachment)2 PyramidElement (artisynth.core.femmodels.PyramidElement)2