Search in sources :

Example 31 with MeshBase

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;
}
Also used : MeshBase(maspack.geometry.MeshBase)

Example 32 with MeshBase

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;
}
Also used : MeshBase(maspack.geometry.MeshBase) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 33 with MeshBase

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);
    }
}
Also used : RenderProps(maspack.render.RenderProps) MeshBase(maspack.geometry.MeshBase) VectorNd(maspack.matrix.VectorNd) PointAttachment(artisynth.core.mechmodels.PointAttachment) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point)

Example 34 with MeshBase

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();
                }
            }
        }
    }
}
Also used : MeshBase(maspack.geometry.MeshBase) FemMeshBase(artisynth.core.femmodels.FemMeshBase) SurfaceRender(artisynth.core.femmodels.FemModel.SurfaceRender)

Example 35 with MeshBase

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;
}
Also used : MeshBase(maspack.geometry.MeshBase)

Aggregations

MeshBase (maspack.geometry.MeshBase)39 PolygonalMesh (maspack.geometry.PolygonalMesh)10 ContactPoint (artisynth.core.mechmodels.ContactPoint)5 Point (artisynth.core.mechmodels.Point)5 SkinMeshBase (artisynth.core.mechmodels.SkinMeshBase)5 FemMeshBase (artisynth.core.femmodels.FemMeshBase)3 Point (java.awt.Point)3 SurfaceRender (artisynth.core.femmodels.FemModel.SurfaceRender)2 PointAttachment (artisynth.core.mechmodels.PointAttachment)2 PointParticleAttachment (artisynth.core.mechmodels.PointParticleAttachment)2 Color (java.awt.Color)2 File (java.io.File)2 PointMesh (maspack.geometry.PointMesh)2 Vertex3d (maspack.geometry.Vertex3d)2 XyzbReader (maspack.geometry.io.XyzbReader)2 VectorNd (maspack.matrix.VectorNd)2 RenderProps (maspack.render.RenderProps)2 ArgParser (argparser.ArgParser)1 FemNode (artisynth.core.femmodels.FemNode)1 PointFem3dAttachment (artisynth.core.femmodels.PointFem3dAttachment)1