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();
}
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));
}
}
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);
}
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();
}
Aggregations