use of artisynth.core.mechmodels.PointAttachment in project artisynth_core by artisynth.
the class SkinMeshBody method getMass.
@Override
public double getMass() {
// XXX how to estimate mass?
// mass of all dependencies?
double m = 0;
for (PointAttachment pa : myVertexAttachments) {
for (DynamicComponent dmc : pa.getMasters()) {
if (dmc != null && !dmc.isMarked()) {
m += dmc.getMass(0);
dmc.setMarked(true);
}
}
}
// unmark
for (PointAttachment pa : myVertexAttachments) {
for (DynamicComponent dmc : pa.getMasters()) {
if (dmc != null && dmc.isMarked()) {
dmc.setMarked(false);
}
}
}
return m;
}
use of artisynth.core.mechmodels.PointAttachment in project artisynth_core by artisynth.
the class MFreeMeshComp method getVertexMasters.
public void getVertexMasters(List<ContactMaster> mlist, Vertex3d vtx) {
PointAttachment pa = getAttachment(vtx.getIndex());
if (pa instanceof PointFem3dAttachment) {
PointFem3dAttachment pfa = (PointFem3dAttachment) pa;
FemNode[] masters = pfa.getNodes();
for (int j = 0; j < masters.length; j++) {
mlist.add(new ContactMaster(masters[j], pfa.getCoordinate(j)));
}
} else {
PointParticleAttachment ppa = (PointParticleAttachment) pa;
mlist.add(new ContactMaster((MFreeNode3d) ppa.getParticle(), 1));
}
}
use of artisynth.core.mechmodels.PointAttachment in project artisynth_core by artisynth.
the class MFreeMeshComp method createPointAttachment.
public PointFem3dAttachment createPointAttachment(Point pnt) {
if (!(getMesh() instanceof PolygonalMesh)) {
return null;
}
PolygonalMesh mesh = (PolygonalMesh) getMesh();
if (!mesh.isTriangular()) {
return null;
}
// Find nearest face to the point. The vertices of this face will be used
// to find the nodes and weight for the attachment.
BVFeatureQuery query = new BVFeatureQuery();
Point3d near = new Point3d();
Vector2d uv = new Vector2d();
Face face = query.nearestFaceToPoint(near, uv, mesh, pnt.getPosition());
Vertex3d[] vtxs = face.getTriVertices();
double[] wgts = new double[] { 1 - uv.x - uv.y, uv.x, uv.y };
HashMap<FemNode, Double> nodeWeights = new HashMap<FemNode, Double>();
for (int i = 0; i < vtxs.length; i++) {
PointAttachment va = myVertexAttachments.get(vtxs[i].getIndex());
if (va instanceof PointParticleAttachment) {
PointParticleAttachment ppa = (PointParticleAttachment) va;
FemNode node = (FemNode) ppa.getParticle();
accumulateNodeWeights(node, wgts[i], nodeWeights);
} else if (va instanceof PointFem3dAttachment) {
PointFem3dAttachment pfa = (PointFem3dAttachment) va;
for (int k = 0; k < pfa.numMasters(); k++) {
FemNode node = pfa.getNodes()[k];
double w = pfa.getCoordinate(k);
accumulateNodeWeights(node, w * wgts[i], nodeWeights);
}
}
}
// Create a new PointFem3dAttachment
PointFem3dAttachment ax = new PointFem3dAttachment(pnt);
VectorNd weightVec = new VectorNd();
for (Double d : nodeWeights.values()) {
weightVec.append(d);
}
ax.setFromNodes(nodeWeights.keySet(), weightVec);
return ax;
}
use of artisynth.core.mechmodels.PointAttachment 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.mechmodels.PointAttachment 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