use of artisynth.core.femmodels.FemMarker in project artisynth_core by artisynth.
the class FemBeamMech method build.
public void build(String[] args) {
femPath = "models/mech/models/fem/";
modPath = "models/mech/";
int nn = 2;
myFemMod = FemFactory.createTetGrid(null, 0.6, 0.2, 0.2, nn * 3, nn * 1, nn * 1);
myFemMod.setName("fem");
myFemMod.setDensity(myDensity);
myFemMod.setBounds(new Point3d(-0.6, 0, 0), new Point3d(0.6, 0, 0));
myFemMod.setLinearMaterial(60000, 0.33, true);
myFemMod.setStiffnessDamping(0.002);
myFemMod.setImplicitIterations(100);
myFemMod.setImplicitPrecision(0.001);
myFemMod.setSurfaceRendering(SurfaceRender.Shaded);
Renderable elems = myFemMod.getElements();
RenderProps.setLineWidth(elems, 2);
RenderProps.setLineColor(elems, Color.BLUE);
Renderable nodes = myFemMod.getNodes();
RenderProps.setPointStyle(nodes, Renderer.PointStyle.SPHERE);
RenderProps.setPointRadius(nodes, 0.005);
RenderProps.setPointColor(nodes, Color.GREEN);
// fix the leftmost nodes
double EPS = 1e-9;
for (FemNode3d n : myFemMod.getNodes()) {
if (n.getPosition().x < -0.3 + EPS) {
myLeftNodes.add(n);
}
}
System.out.println("fixed nodes:");
for (FemNode3d n : myLeftNodes) {
n.setDynamic(false);
}
RenderProps.setFaceColor(myFemMod, new Color(0.4f, 0.4f, 1.0f));
myFemMod.setProfiling(true);
RigidBody anchorBox = new RigidBody("anchorBox");
PolygonalMesh mesh = MeshFactory.createBox(0.1, 0.3, 0.3);
anchorBox.setMesh(mesh, /* fileName= */
null);
RigidTransform3d X = new RigidTransform3d();
X.p.set(-0.35, 0, 0);
anchorBox.setPose(X);
anchorBox.setDynamic(false);
myMechMod = new MechModel("mech");
myMechMod.addModel(myFemMod);
myMechMod.addRigidBody(anchorBox);
System.out.println("models: " + myMechMod.findComponent("models"));
System.out.println("models/fem: " + myMechMod.findComponent("models/fem"));
myMechMod.setIntegrator(Integrator.BackwardEuler);
addModel(myMechMod);
myMechMod.setProfiling(true);
// add marker to lower right corner element
Point3d corner = new Point3d(0.3, -0.1, -0.1);
FemElement cornerElem = null;
for (FemElement e : myFemMod.getElements()) {
FemNode[] nodeList = e.getNodes();
for (int i = 0; i < nodeList.length; i++) {
if (nodeList[i].getPosition().epsilonEquals(corner, 1e-8)) {
cornerElem = e;
break;
}
}
}
if (cornerElem != null) {
FemMarker mkr = new FemMarker(0.3, -0.07, -0.03);
myFemMod.addMarker(mkr, cornerElem);
RenderProps.setPointStyle(mkr, Renderer.PointStyle.SPHERE);
RenderProps.setPointRadius(mkr, 0.01);
RenderProps.setPointColor(mkr, Color.WHITE);
Particle part = new Particle(1, 0.5, -0.07, -0.03);
RenderProps.setPointStyle(part, Renderer.PointStyle.SPHERE);
RenderProps.setPointRadius(part, 0.01);
part.setDynamic(false);
myMechMod.addParticle(part);
AxialSpring spr = new AxialSpring(1000, 0, 0);
myMechMod.attachAxialSpring(part, mkr, spr);
RenderProps.setLineStyle(spr, Renderer.LineStyle.SPINDLE);
RenderProps.setLineRadius(spr, 0.01);
RenderProps.setLineColor(spr, Color.GREEN);
}
int numWays = 0;
double res = 0.2;
for (int i = 0; i < numWays; i++) {
addWayPoint(new WayPoint((i + 1) * res, true));
}
addControlPanel(myMechMod, myFemMod);
}
use of artisynth.core.femmodels.FemMarker 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)));
// }
}
use of artisynth.core.femmodels.FemMarker in project artisynth_core by artisynth.
the class FemMuscleDemo method addStrand.
/**
* Adds a strand of muscles interpolated between two points, using FemNodes
* if they are close enough, or otherwise inserting markers.
*/
protected void addStrand(MuscleBundle bundle, double p0x, double p0y, double p0z, double p1x, double p1y, double p1z, double quadTerm, int numPnts) {
Point pnt;
Point prevPnt = null;
Point3d pos0 = new Point3d(p0x, p0y, p0z);
Point3d pos1 = new Point3d(p1x, p1y, p1z);
Point3d pos = new Point3d();
for (int i = 0; i < numPnts; i++) {
double s = i / (numPnts - 1.0);
pos.combine(1 - s, pos0, s, pos1);
double r = Math.sqrt(pos.x * pos.x + pos.y * pos.y);
pos.z += quadTerm * r * r;
pnt = findNearestNode(pos);
if (pnt.distance(pos) > 0.0001) {
FemMarker mkr = new FemMarker(pos);
tissue.addMarker(mkr);
pnt = mkr;
}
if (prevPnt != null) {
Muscle muscle = new Muscle();
muscle.setConstantMuscleMaterial(1, 1);
muscle.setFirstPoint(prevPnt);
muscle.setSecondPoint(pnt);
bundle.addFibre(muscle);
}
prevPnt = pnt;
}
}
use of artisynth.core.femmodels.FemMarker in project artisynth_core by artisynth.
the class FemBeamWithMuscle method build.
public void build(String[] args) throws IOException {
// Create simple FEM beam
super.build(args);
// Add a particle fixed in space
Particle p1 = new Particle(/*mass=*/
0, -length / 2, 0, 2 * width);
mech.addParticle(p1);
p1.setDynamic(false);
RenderProps.setSphericalPoints(p1, 0.02, Color.BLUE);
// Add a marker at the end of the model
FemMarker mkr = createMarker(fem, length / 2 - 0.1, 0, width / 2);
// Create a muscle between the point an marker
Muscle muscle = createMuscle();
muscle.setPoints(p1, mkr);
mech.addAxialSpring(muscle);
}
use of artisynth.core.femmodels.FemMarker in project artisynth_core by artisynth.
the class FemBeamWithMuscle method createMarker.
// Creates a FEM Marker
protected FemMarker createMarker(FemModel3d fem, double x, double y, double z) {
FemMarker mkr = new FemMarker(/*name=*/
null, x, y, z);
RenderProps.setSphericalPoints(mkr, 0.02, Color.BLUE);
fem.addMarker(mkr);
return mkr;
}
Aggregations