use of maspack.geometry.MeshBase in project artisynth_core by artisynth.
the class MeshViewer method loadMesh.
private boolean loadMesh(File file) {
MeshBase mesh = null;
try {
mesh = GenericMeshReader.readMesh(file);
// if (file.getName().endsWith (".xyzb")) {
// XyzbReader reader = new XyzbReader (file);
// reader.setSkip (skipCount.value);
// mesh = reader.readMesh();
// ((PointMesh)mesh).setNormalRenderLen (myPointNormalLen);
// }
// else if (file.getName().endsWith (".obj")) {
// mesh = new PolygonalMesh (file);
// }
// else if (file.getName().endsWith (".ply")) {
// PlyReader reader = new PlyReader (file);
// mesh = reader.readMesh();
// }
// else {
// throw new IOException ("Unrecognized file type");
// }
} catch (Exception ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(this, "Can't open or read file: " + ex, "Error", JOptionPane.ERROR_MESSAGE);
mesh = null;
}
if (mesh != null) {
viewer.clearRenderables();
myMeshes.clear();
addMesh(file.getName(), mesh);
viewer.autoFitPerspective();
viewer.rerender();
}
return mesh != null;
}
use of maspack.geometry.MeshBase in project artisynth_core by artisynth.
the class FemMeshComp method markSurfaceMesh.
protected void markSurfaceMesh(boolean set) {
MeshBase mesh = getMesh();
if (mesh != null && !(mesh instanceof PolygonalMesh)) {
throw new IllegalArgumentException("Mesh must be a PolygonalMesh to be set as a surface");
}
isSurfaceMesh = set;
}
use of maspack.geometry.MeshBase in project artisynth_core by artisynth.
the class FemMeshComp method updateVertexColors.
protected void updateVertexColors() {
if (mySurfaceRendering != SurfaceRender.Stress && mySurfaceRendering != SurfaceRender.Strain) {
return;
}
if (myStressPlotRanging == Ranging.Auto) {
myStressPlotRange.merge(myFem.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 FemNode3d) {
// paranoid!
FemNode3d node = (FemNode3d) 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;
FemNode3d node = (FemNode3d) 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 maspack.geometry.MeshBase in project artisynth_core by artisynth.
the class MFreeMeshComp method setSurfaceRendering.
@Override
public void setSurfaceRendering(SurfaceRender mode) {
SurfaceRender oldMode = getSurfaceRendering();
super.setSurfaceRendering(mode);
if (oldMode != mode) {
if (myModel != null) {
// paranoid: myFem should always be non-null here
switch(mode) {
case Strain:
myModel.setComputeNodalStrain(true);
myModel.updateStressAndStiffness();
break;
case Stress:
myModel.setComputeNodalStress(true);
myModel.updateStressAndStiffness();
break;
default:
{
myModel.setComputeNodalStrain(false);
myModel.setComputeNodalStress(false);
break;
}
}
}
// save/restore original vertex colors
MeshBase mesh = getMesh();
if (mesh != null) {
boolean oldStressOrStrain = isStressOrStrainRendering(oldMode);
boolean newStressOrStrain = isStressOrStrainRendering(mode);
if (newStressOrStrain != oldStressOrStrain) {
if (newStressOrStrain) {
saveShading();
saveMeshColoring(mesh);
mesh.setVertexColoringEnabled();
mesh.setVertexColorMixing(ColorMixing.REPLACE);
myRenderProps.setShading(Shading.NONE);
// enable stress/strain rendering *after* vertex coloring set
// not sure we need this here
updateVertexColors();
} else {
// disable stress/strain rendering *before* restoring colors
restoreMeshColoring(mesh);
restoreShading();
}
}
}
}
}
use of maspack.geometry.MeshBase in project artisynth_core by artisynth.
the class RigidCompositeBody method doSetInertia.
private void doSetInertia(SpatialInertia M) {
mySpatialInertia.set(M);
double volume = 0;
for (RigidMeshComp mc : myMeshList) {
MeshBase mesh = mc.getMesh();
if (mesh != null && mc.isPhysical()) {
volume += getMeshVolume(mesh);
}
}
if (volume > 0) {
myDensity = M.getMass() / volume;
} else {
myDensity = 0;
}
myInertiaMethod = InertiaMethod.Explicit;
}
Aggregations