use of artisynth.core.femmodels.PointFem3dAttachment in project artisynth_core by artisynth.
the class MFreeMeshComp method setVertexAttachment.
public void setVertexAttachment(int vidx, double[] weights, MFreeNode3d[] nodes) {
if (weights.length > 1) {
PointFem3dAttachment pattacher = new PointFem3dAttachment();
pattacher.setFromNodes(nodes, weights);
setVertexAttachment(vidx, pattacher);
} else if (weights.length == 1) {
PointParticleAttachment attacher = new PointParticleAttachment(nodes[0], null);
setVertexAttachment(vidx, attacher);
}
}
use of artisynth.core.femmodels.PointFem3dAttachment 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.PointFem3dAttachment 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));
}
}
Aggregations