use of artisynth.core.mechmodels.PointAttachment in project artisynth_core by artisynth.
the class MFreeMeshComp method addVertexNodes.
private void addVertexNodes(HashSet<MFreeNode3d> nodes, 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++) {
nodes.add((MFreeNode3d) masters[j]);
}
} else {
PointParticleAttachment ppa = (PointParticleAttachment) pa;
nodes.add((MFreeNode3d) ppa.getParticle());
}
}
use of artisynth.core.mechmodels.PointAttachment in project artisynth_core by artisynth.
the class MFreeMeshComp method copy.
@Override
public MFreeMeshComp copy(int flags, Map<ModelComponent, ModelComponent> copyMap) {
MFreeMeshComp fm = (MFreeMeshComp) super.copy(flags, copyMap);
MFreeModel3d newFem = (MFreeModel3d) copyMap.get(myModel);
if (newFem != null) {
fm.myModel = newFem;
} else {
fm.myModel = myModel;
}
HashMap<Vertex3d, Vertex3d> vertMap = null;
if (getMesh() != fm.getMesh()) {
vertMap = new HashMap<Vertex3d, Vertex3d>(myMeshInfo.numVertices());
for (int i = 0; i < myMeshInfo.numVertices(); i++) {
vertMap.put(getVertex(i), fm.getVertex(i));
}
}
fm.myVertexAttachments = new ArrayList<PointAttachment>(myVertexAttachments.size());
for (PointAttachment pa : myVertexAttachments) {
PointAttachment newPa = pa.copy(flags, copyMap);
fm.myVertexAttachments.add(newPa);
}
fm.buildNodeVertexMap();
// fm.myEdgeVtxs = new HashMap<EdgeDesc,Vertex3d[]>(myEdgeVtxs.size());
// for (Entry<EdgeDesc,Vertex3d[]> het : myEdgeVtxs.entrySet()) {
// het.getKey();
// Vertex3d[] oldVerts = het.getValue();
// EdgeDesc newEdge = het.getKey().copy(vertMap);
// Vertex3d[] newVerts = new Vertex3d[oldVerts.length];
//
// if (vertMap != null) {
// for (int i=0; i<newVerts.length; i++) {
// newVerts[i] = vertMap.get(oldVerts[i]);
// }
// } else {
// for (int i=0; i<newVerts.length; i++) {
// newVerts[i] = oldVerts[i];
// }
// }
// fm.myEdgeVtxs.put(newEdge, newVerts);
// }
fm.isSurfaceMesh = isSurfaceMesh();
return fm;
}
use of artisynth.core.mechmodels.PointAttachment 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.mechmodels.PointAttachment 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.mechmodels.PointAttachment in project artisynth_core by artisynth.
the class FemMeshComp 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;
FemNode3d n = (FemNode3d) ppa.getParticle();
pw.println("v " + n.getNumber() + " 1.0");
} else {
pw.println("v -1 " + vtx.getPosition().toString(fmt));
}
}
Aggregations