Search in sources :

Example 6 with PointAttachment

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());
    }
}
Also used : FemNode(artisynth.core.femmodels.FemNode) PointFem3dAttachment(artisynth.core.femmodels.PointFem3dAttachment) PointAttachment(artisynth.core.mechmodels.PointAttachment) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point)

Example 7 with PointAttachment

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;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) PointAttachment(artisynth.core.mechmodels.PointAttachment) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point)

Example 8 with PointAttachment

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

Example 9 with PointAttachment

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);
}
Also used : FemNode(artisynth.core.femmodels.FemNode) PointFem3dAttachment(artisynth.core.femmodels.PointFem3dAttachment) PointAttachment(artisynth.core.mechmodels.PointAttachment) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment)

Example 10 with PointAttachment

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));
    }
}
Also used : PointAttachment(artisynth.core.mechmodels.PointAttachment) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point)

Aggregations

PointAttachment (artisynth.core.mechmodels.PointAttachment)21 ContactPoint (artisynth.core.mechmodels.ContactPoint)17 Point (artisynth.core.mechmodels.Point)17 PointParticleAttachment (artisynth.core.mechmodels.PointParticleAttachment)16 Vertex3d (maspack.geometry.Vertex3d)10 FemNode (artisynth.core.femmodels.FemNode)9 PointFem3dAttachment (artisynth.core.femmodels.PointFem3dAttachment)9 VectorNd (maspack.matrix.VectorNd)7 PolygonalMesh (maspack.geometry.PolygonalMesh)6 HashMap (java.util.HashMap)4 ArrayList (java.util.ArrayList)3 Face (maspack.geometry.Face)3 Point3d (maspack.matrix.Point3d)3 FemNode3d (artisynth.core.femmodels.FemNode3d)2 ContactMaster (artisynth.core.mechmodels.ContactMaster)2 DynamicComponent (artisynth.core.mechmodels.DynamicComponent)2 IOException (java.io.IOException)2 BVFeatureQuery (maspack.geometry.BVFeatureQuery)2 MeshBase (maspack.geometry.MeshBase)2 Vector2d (maspack.matrix.Vector2d)2