Search in sources :

Example 16 with MuscleBundle

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

the class SpongeModel method addMuscleGroup.

protected void addMuscleGroup(String name, int origin) {
    MuscleBundle b = new MuscleBundle(name);
    for (int i = 0; i < numX; i++) {
        addMuscle(b, origin + i, origin + i + 1);
    }
    b.setFibresActive(true);
    addMuscleBundle(b);
    b.setRenderProps(getNewMuscleProps());
}
Also used : MuscleBundle(artisynth.core.femmodels.MuscleBundle)

Example 17 with MuscleBundle

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

the class SpongeModel method addSingleMuscle.

protected void addSingleMuscle() {
    Muscle m = new Muscle();
    m.setConstantMuscleMaterial(1, 1);
    m.setFirstPoint(getNode(r.nextInt(numNodes())));
    m.setSecondPoint(getNode(r.nextInt(numNodes())));
    MuscleBundle b = new MuscleBundle();
    b.addFibre(m);
    b.setFibresActive(true);
    addMuscleBundle(b);
    RenderProps props = createRenderProps();
    props.setLineColor(NumericProbePanel.colorList[getMuscleBundles().size()]);
    props.setLineRadius(len / 20);
    props.setLineStyle(LineStyle.SPINDLE);
    m.setRenderProps(props);
}
Also used : MuscleBundle(artisynth.core.femmodels.MuscleBundle) RenderProps(maspack.render.RenderProps) Muscle(artisynth.core.mechmodels.Muscle)

Example 18 with MuscleBundle

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

the class FemMuscleHeart method build.

// Model builder
@Override
public void build(String[] args) throws IOException {
    super.build(args);
    setMaxStepSize(0.005);
    // Root mechanical model
    MechModel mech = new MechModel("mech");
    mech.setGravity(0, 0, -9.8);
    addModel(mech);
    // -------------------------------------------------------------
    // HEART LOAD / ADD GEOMETRY
    // -------------------------------------------------------------
    // Heart surface mesh, with texture
    String heartFile = ArtisynthPath.getSrcRelativePath(this, "data/HumanHeart.obj");
    WavefrontReader wfr = new WavefrontReader(new File(heartFile));
    PolygonalMesh heartMesh = new PolygonalMesh();
    wfr.readMesh(heartMesh);
    // triangulate for interaction
    heartMesh.triangulate();
    // FEM heart:
    // - FEM mesh of heart convex hull
    // - embedded heart surface geometry
    FemMuscleModel heart = new FemMuscleModel("heart");
    TetGenReader.read(heart, ArtisynthPath.getSrcRelativePath(this, "data/HumanHeartHull.node"), ArtisynthPath.getSrcRelativePath(this, "data/HumanHeartHull.ele"));
    // add real-looking mesh
    FemMeshComp embeddedHeart = heart.addMesh(heartMesh);
    embeddedHeart.setName("embedded");
    // Allow inverted elements (poor quality mesh)
    heart.setWarnOnInvertedElements(false);
    heart.setAbortOnInvertedElements(false);
    // Convert unites to metres (original was cm)
    heart.scaleDistance(0.01);
    heart.setGravity(0, 0, -9.8);
    heart.setStiffnessDamping(0.02);
    // Set material properties
    heart.setDensity(1000);
    FemMaterial femMat = new LinearMaterial(2500, 0.33, true);
    // simple muscle
    MuscleMaterial muscleMat = new SimpleForceMuscle(500.0);
    heart.setMaterial(femMat);
    // Add heart to model
    mech.addModel(heart);
    // -------------------------------------------------------------
    // MUSCLE BUNDLES
    // -------------------------------------------------------------
    // One "long" direction muscle bundle
    // One "radial" muscle bundle
    // LONG BUNDLE
    // Compute the "long" direction of the heart
    PolygonalMesh hull = heart.getSurfaceMesh();
    RigidTransform3d trans = hull.computePrincipalAxes();
    Vector3d longAxis = new Vector3d();
    // first column of rotation
    trans.R.getColumn(0, longAxis);
    // Create the long axis muscle bundle
    MuscleBundle longBundle = new MuscleBundle("long");
    for (FemElement3d elem : heart.getElements()) {
        longBundle.addElement(elem, longAxis);
    }
    longBundle.setMuscleMaterial(muscleMat);
    heart.addMuscleBundle(longBundle);
    // RADIAL BUNDLE
    // Compute a plane through centre of heart
    Plane plane = new Plane(longAxis, new Point3d(trans.p));
    Point3d centroid = new Point3d();
    Vector3d radialDir = new Vector3d();
    // Create the radial muscle bundle
    MuscleBundle radialBundle = new MuscleBundle("radial");
    for (FemElement3d elem : heart.getElements()) {
        elem.computeCentroid(centroid);
        // project to plane and compute radial direction
        plane.project(centroid, centroid);
        radialDir.sub(centroid, trans.p);
        radialDir.normalize();
        radialBundle.addElement(elem, radialDir);
    }
    radialBundle.setMuscleMaterial(muscleMat);
    heart.addMuscleBundle(radialBundle);
    // -------------------------------------------------------------
    // RIGID TABLE AND COLLISION
    // -------------------------------------------------------------
    // Create a rigid box for the heart to fall on
    RigidBody box = RigidBody.createBox("box", 0.2, 0.2, 0.02, 0, /*addnormals*/
    true);
    box.setPose(new RigidTransform3d(new Vector3d(0, 0, -0.2), AxisAngle.IDENTITY));
    box.setDynamic(false);
    mech.addRigidBody(box);
    // Enable collisions between the heart and table
    mech.setCollisionBehavior(heart, box, true);
    // -------------------------------------------------------------
    // RENDER PROPERTIES
    // -------------------------------------------------------------
    // Hide elements and nodes
    RenderProps.setVisible(heart.getElements(), false);
    RenderProps.setVisible(heart.getNodes(), false);
    RenderProps.setLineColor(radialBundle, Color.BLUE);
    RenderProps.setLineColor(longBundle, Color.RED);
    radialBundle.setDirectionRenderLen(0.1);
    longBundle.setDirectionRenderLen(0.1);
    RenderProps.setVisible(radialBundle, false);
    RenderProps.setVisible(longBundle, false);
    RenderProps.setVisible(heart.getSurfaceMeshComp(), false);
    // adjust table render properties
    RenderProps.setShading(box, Shading.METAL);
    RenderProps.setSpecular(box, new Color(0.8f, 0.8f, 0.8f));
    // adjust heart mesh render properties
    RenderProps rprops = embeddedHeart.getRenderProps();
    rprops.getBumpMap().setScaling(0.01f);
    // don't modify specular
    rprops.getColorMap().setSpecularColoring(false);
    rprops.setShading(Shading.SMOOTH);
    rprops.setFaceColor(new Color(0.8f, 0.8f, 0.8f));
    rprops.getColorMap().setColorMixing(ColorMixing.MODULATE);
    rprops.setSpecular(new Color(0.4f, 0.4f, 0.4f));
    rprops.setShininess(128);
    // -------------------------------------------------------------
    // INPUT PROBES
    // -------------------------------------------------------------
    // Add heart probe
    addHeartProbe(longBundle, radialBundle);
}
Also used : WavefrontReader(maspack.geometry.io.WavefrontReader) SimpleForceMuscle(artisynth.core.materials.SimpleForceMuscle) RigidTransform3d(maspack.matrix.RigidTransform3d) FemElement3d(artisynth.core.femmodels.FemElement3d) Plane(maspack.matrix.Plane) FemMeshComp(artisynth.core.femmodels.FemMeshComp) FemMaterial(artisynth.core.materials.FemMaterial) MuscleMaterial(artisynth.core.materials.MuscleMaterial) Color(java.awt.Color) RenderProps(maspack.render.RenderProps) LinearMaterial(artisynth.core.materials.LinearMaterial) PolygonalMesh(maspack.geometry.PolygonalMesh) MechModel(artisynth.core.mechmodels.MechModel) MuscleBundle(artisynth.core.femmodels.MuscleBundle) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) FemMuscleModel(artisynth.core.femmodels.FemMuscleModel) RigidBody(artisynth.core.mechmodels.RigidBody) File(java.io.File)

Example 19 with MuscleBundle

use of artisynth.core.femmodels.MuscleBundle 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 20 with MuscleBundle

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

the class FemSurfaceTargetDemo method addMuscle.

public void addMuscle(String name, Color color, Vector3d dir) {
    MuscleBundle b = new MuscleBundle(name);
    for (FemElement3d e : fem.getElements()) {
        b.addElement(e, dir);
    }
    b.setMuscleMaterial(new SimpleForceMuscle(muscleMaxStress));
    b.setDirectionRenderLen(w / 4);
    RenderProps.setLineColor(b, color);
    RenderProps.setLineWidth(b, 4);
    fem.addMuscleBundle(b);
}
Also used : MuscleBundle(artisynth.core.femmodels.MuscleBundle) SimpleForceMuscle(artisynth.core.materials.SimpleForceMuscle) FemElement3d(artisynth.core.femmodels.FemElement3d)

Aggregations

MuscleBundle (artisynth.core.femmodels.MuscleBundle)25 Muscle (artisynth.core.mechmodels.Muscle)6 FemElement3d (artisynth.core.femmodels.FemElement3d)4 ConstantAxialMuscle (artisynth.core.materials.ConstantAxialMuscle)4 Point3d (maspack.matrix.Point3d)4 FemMuscleModel (artisynth.core.femmodels.FemMuscleModel)3 Point (artisynth.core.mechmodels.Point)3 Color (java.awt.Color)3 DoubleFieldSlider (maspack.widgets.DoubleFieldSlider)3 TrackingController (artisynth.core.inverse.TrackingController)2 SimpleForceMuscle (artisynth.core.materials.SimpleForceMuscle)2 MuscleExciter (artisynth.core.mechmodels.MuscleExciter)2 Point (java.awt.Point)2 LinkedList (java.util.LinkedList)2 RenderProps (maspack.render.RenderProps)2 FemMarker (artisynth.core.femmodels.FemMarker)1 FemMeshComp (artisynth.core.femmodels.FemMeshComp)1 FemNode (artisynth.core.femmodels.FemNode)1 FemNode3d (artisynth.core.femmodels.FemNode3d)1 MuscleElementDesc (artisynth.core.femmodels.MuscleElementDesc)1