use of artisynth.core.femmodels.PointFem3dAttachment in project artisynth_core by artisynth.
the class MFreeMeshComp method updateVertexColors.
protected void updateVertexColors() {
if (mySurfaceRendering != SurfaceRender.Stress && mySurfaceRendering != SurfaceRender.Strain) {
return;
}
if (myStressPlotRanging == Ranging.Auto) {
myStressPlotRange.merge(myModel.getNodalPlotRange(mySurfaceRendering));
}
RenderProps rprops = getRenderProps();
float alpha = (float) rprops.getAlpha();
MeshBase mesh = getMesh();
double sval = 0;
for (int i = 0; i < myVertexAttachments.size(); i++) {
PointAttachment attacher = myVertexAttachments.get(i);
sval = 0;
if (attacher instanceof PointFem3dAttachment) {
PointFem3dAttachment pfa = (PointFem3dAttachment) attacher;
FemNode[] nodes = pfa.getNodes();
VectorNd weights = pfa.getCoordinates();
for (int j = 0; j < nodes.length; j++) {
if (nodes[j] instanceof MFreeNode3d) {
// paranoid!
MFreeNode3d node = (MFreeNode3d) nodes[j];
double w = weights.get(j);
if (mySurfaceRendering == SurfaceRender.Strain) {
sval += w * node.getVonMisesStrain();
} else if (mySurfaceRendering == SurfaceRender.Stress) {
sval += w * node.getVonMisesStress();
}
}
}
} else if (attacher instanceof PointParticleAttachment) {
PointParticleAttachment ppa = (PointParticleAttachment) attacher;
MFreeNode3d node = (MFreeNode3d) ppa.getParticle();
if (mySurfaceRendering == SurfaceRender.Strain) {
sval = node.getVonMisesStrain();
} else if (mySurfaceRendering == SurfaceRender.Stress) {
sval = node.getVonMisesStress();
}
}
double smin = myStressPlotRange.getLowerBound();
double srng = myStressPlotRange.getRange();
double c = (sval - smin) / srng;
c = Math.max(0, Math.min(c, 1.0));
myColorMap.getRGB(c, colorArray);
mesh.setColor(i, colorArray[0], colorArray[1], colorArray[2], alpha);
}
}
use of artisynth.core.femmodels.PointFem3dAttachment in project artisynth_core by artisynth.
the class MFreeMeshComp method postscanItem.
protected boolean postscanItem(Deque<ScanToken> tokens, CompositeComponent ancestor) throws IOException {
if (postscanAttributeName(tokens, "fem")) {
myModel = postscanReference(tokens, MFreeModel3d.class, ancestor);
return true;
} else if (postscanAttributeName(tokens, "attachments")) {
for (int i = 0; i < myVertexAttachments.size(); i++) {
PointAttachment va = myVertexAttachments.get(i);
FemNode[] nodes = ScanWriteUtils.postscanReferences(tokens, FemNode.class, ancestor);
if (va instanceof PointParticleAttachment) {
PointParticleAttachment ppa = (PointParticleAttachment) va;
ppa.setParticle(nodes[0]);
} else if (va instanceof PointFem3dAttachment) {
PointFem3dAttachment pfa = (PointFem3dAttachment) va;
double[] coords = (double[]) tokens.poll().value();
pfa.setFromNodes(nodes, coords);
}
}
buildNodeVertexMap();
return true;
}
return super.postscanItem(tokens, ancestor);
}
use of artisynth.core.femmodels.PointFem3dAttachment 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.femmodels.PointFem3dAttachment in project artisynth_core by artisynth.
the class MFreeMeshComp method writeAttachment.
protected void writeAttachment(PointAttachment attacher, PrintWriter pw, NumberFormat fmt, CompositeComponent ancestor) throws IOException {
pw.print("[ ");
if (attacher instanceof PointParticleAttachment) {
PointParticleAttachment ppa = (PointParticleAttachment) attacher;
FemNode node = (FemNode) ppa.getParticle();
pw.print(ComponentUtils.getWritePathName(ancestor, node) + " 1 ");
} else if (attacher instanceof PointFem3dAttachment) {
PointFem3dAttachment pfa = (PointFem3dAttachment) attacher;
FemNode[] nodes = pfa.getNodes();
VectorNd weights = pfa.getCoordinates();
for (int i = 0; i < nodes.length; i++) {
pw.print(ComponentUtils.getWritePathName(ancestor, nodes[i]) + " " + fmt.format(weights.get(i)) + " ");
}
}
pw.println("]");
}
use of artisynth.core.femmodels.PointFem3dAttachment 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;
}
Aggregations