Search in sources :

Example 11 with PointAttachment

use of artisynth.core.mechmodels.PointAttachment in project artisynth_core by artisynth.

the class FemMeshComp method buildNodeVertexMap.

protected void buildNodeVertexMap() {
    myNodeVertexMap = new HashMap<FemNode3d, Vertex3d>();
    myNumSingleAttachments = 0;
    for (int i = 0; i < myVertexAttachments.size(); i++) {
        PointAttachment pa = myVertexAttachments.get(i);
        if (pa instanceof PointParticleAttachment) {
            FemNode3d node = (FemNode3d) ((PointParticleAttachment) pa).getParticle();
            myNodeVertexMap.put(node, getMesh().getVertex(i));
            myNumSingleAttachments++;
        } else if (pa instanceof PointFem3dAttachment) {
            PointFem3dAttachment pfa = (PointFem3dAttachment) pa;
            for (FemNode node : pfa.getNodes()) {
                if (myNodeVertexMap.get(node) == null) {
                    myNodeVertexMap.put((FemNode3d) node, NO_SINGLE_VERTEX);
                }
            }
        }
    }
}
Also used : Vertex3d(maspack.geometry.Vertex3d) PointAttachment(artisynth.core.mechmodels.PointAttachment) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point)

Example 12 with PointAttachment

use of artisynth.core.mechmodels.PointAttachment in project artisynth_core by artisynth.

the class FemMeshComp method scanMeshUsingVertexInfo.

/**
 * New scan method where the vertex attachments are also scanned
 */
private void scanMeshUsingVertexInfo(ReaderTokenizer rtok) throws IOException {
    PolygonalMesh mesh = (PolygonalMesh) getMesh();
    ArrayList<Vertex3d> vtxList = new ArrayList<Vertex3d>();
    ArrayList<FemNode> nodes = new ArrayList<FemNode>();
    VectorNd weights = new VectorNd();
    rtok.nextToken();
    while (rtok.tokenIsWord()) {
        if (rtok.sval.equals("v")) {
            int nnum = rtok.scanInteger();
            if (nnum == -1) {
                double x = rtok.scanNumber();
                double y = rtok.scanNumber();
                double z = rtok.scanNumber();
                mesh.addVertex(new Vertex3d(x, y, z));
                myVertexAttachments.add(null);
                rtok.nextToken();
            } else {
                PointAttachment ax;
                double w = rtok.scanNumber();
                rtok.nextToken();
                Vertex3d vtx = new Vertex3d();
                if (rtok.tokenIsInteger()) {
                    nodes.clear();
                    weights.setSize(0);
                    nodes.add(getNodeFromNumber(rtok, nnum));
                    weights.append(w);
                    while (rtok.tokenIsInteger()) {
                        nodes.add(getNodeFromNumber(rtok, (int) rtok.lval));
                        weights.append(rtok.scanNumber());
                        rtok.nextToken();
                    }
                    PointFem3dAttachment attacher = new PointFem3dAttachment();
                    attacher.setFromNodes(nodes, weights);
                    ax = attacher;
                } else {
                    FemNode3d node = getNodeFromNumber(rtok, nnum);
                    ax = new PointParticleAttachment(node, null);
                }
                mesh.addVertex(vtx);
                myVertexAttachments.add(ax);
            }
        } else if (rtok.sval.equals("f")) {
            vtxList.clear();
            rtok.nextToken();
            while (rtok.tokenIsInteger()) {
                int vnum = (int) rtok.lval;
                if (vnum > mesh.numVertices()) {
                    throw new IOException("Vertex number " + vnum + " not found, " + rtok);
                }
                vtxList.add(mesh.getVertex(vnum - 1));
                rtok.nextToken();
            }
            mesh.addFace(vtxList.toArray(new Vertex3d[0]));
        } else {
            throw new IOException("Unexpected token: " + rtok);
        }
    }
    rtok.pushBack();
}
Also used : Vertex3d(maspack.geometry.Vertex3d) ArrayList(java.util.ArrayList) PointAttachment(artisynth.core.mechmodels.PointAttachment) IOException(java.io.IOException) PolygonalMesh(maspack.geometry.PolygonalMesh) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point) VectorNd(maspack.matrix.VectorNd) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment)

Example 13 with PointAttachment

use of artisynth.core.mechmodels.PointAttachment in project artisynth_core by artisynth.

the class FemMeshComp 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((FemNode3d) ppa.getParticle(), 1));
    }
}
Also used : ContactMaster(artisynth.core.mechmodels.ContactMaster) PointAttachment(artisynth.core.mechmodels.PointAttachment) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point)

Example 14 with PointAttachment

use of artisynth.core.mechmodels.PointAttachment 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 15 with PointAttachment

use of artisynth.core.mechmodels.PointAttachment in project artisynth_core by artisynth.

the class FemMeshComp method createFineSurface.

protected void createFineSurface(int resolution, ElementFilter efilter) {
    // build from nodes/element filter
    createSurface(efilter);
    if (resolution < 2) {
        // if resolution < 2, just return regular surface
        return;
    }
    // Note: can no longer rely on the surface mesh consisting of only
    // FemMeshVertex
    // PolygonalMesh baseMesh = myFem.getSurfaceMesh();
    // since previously built
    PolygonalMesh baseMesh = (PolygonalMesh) getMesh();
    ArrayList<Face> baseFaces = baseMesh.getFaces();
    ArrayList<Vertex3d> baseVertices = baseMesh.getVertices();
    ArrayList<PointAttachment> baseAttachments = myVertexAttachments;
    // num vertices along the edge of each sub face
    int numv = resolution + 1;
    initializeSurfaceBuild();
    HashMap<EdgeDesc, Vertex3d[]> edgeVtxMap = new HashMap<EdgeDesc, Vertex3d[]>();
    // get newly empty mesh
    PolygonalMesh surfMesh = (PolygonalMesh) getMesh();
    for (Vertex3d vtx : baseVertices) {
        FemNode3d node = getNodeForVertex(baseAttachments.get(vtx.getIndex()));
        createVertex(node, vtx);
    // myNodeVertexMap.put (node, newVtx);
    }
    System.out.println("num base faces: " + baseFaces.size());
    for (int k = 0; k < baseFaces.size(); k++) {
        Face face = baseFaces.get(k);
        // store sub vertices for the face in the upper triangular half of
        // subv.
        MeshFactory.VertexSet subv = new MeshFactory.VertexSet(numv);
        FemElement3d elem = getFaceElement(face);
        if (elem == null) {
            continue;
        }
        HalfEdge he = face.firstHalfEdge();
        Vertex3d v0 = (Vertex3d) he.getHead();
        FemNode3d n0 = getNodeForVertex(baseAttachments.get(v0.getIndex()));
        he = he.getNext();
        Vertex3d v1 = (Vertex3d) he.getHead();
        FemNode3d n1 = getNodeForVertex(baseAttachments.get(v1.getIndex()));
        he = he.getNext();
        Vertex3d v2 = (Vertex3d) he.getHead();
        FemNode3d n2 = getNodeForVertex(baseAttachments.get(v2.getIndex()));
        subv.set(0, 0, getVertex(v0.getIndex()));
        subv.set(0, numv - 1, getVertex(v2.getIndex()));
        subv.set(numv - 1, numv - 1, getVertex(v1.getIndex()));
        Vertex3d[] vtxs01 = collectEdgeVertices(edgeVtxMap, v0, v1, n0, n1, elem, resolution);
        for (int i = 1; i < numv - 1; i++) {
            subv.set(i, i, vtxs01[i]);
        }
        Vertex3d[] vtxs02 = collectEdgeVertices(edgeVtxMap, v0, v2, n0, n2, elem, resolution);
        for (int j = 1; j < numv - 1; j++) {
            subv.set(0, j, vtxs02[j]);
        }
        Vertex3d[] vtxs21 = collectEdgeVertices(edgeVtxMap, v2, v1, n2, n1, elem, resolution);
        for (int i = 1; i < numv - 1; i++) {
            subv.set(i, numv - 1, vtxs21[i]);
        }
        for (int i = 1; i < numv - 1; i++) {
            for (int j = i + 1; j < numv - 1; j++) {
                double s1 = i / (double) resolution;
                double s0 = 1 - j / (double) resolution;
                Vertex3d vtx = createVertex(s0, s1, 1 - s0 - s1, elem, n0, n1, n2);
                subv.set(i, j, vtx);
            }
        }
        subv.check();
        for (int i = 0; i < resolution; i++) {
            for (int j = i; j < resolution; j++) {
                surfMesh.addFace(subv.get(i, j), subv.get(i + 1, j + 1), subv.get(i, j + 1));
                if (i != j) {
                    surfMesh.addFace(subv.get(i, j), subv.get(i + 1, j), subv.get(i + 1, j + 1));
                }
            }
        }
    }
    finalizeSurfaceBuild();
}
Also used : Vertex3d(maspack.geometry.Vertex3d) MeshFactory(maspack.geometry.MeshFactory) HashMap(java.util.HashMap) HalfEdge(maspack.geometry.HalfEdge) PointAttachment(artisynth.core.mechmodels.PointAttachment) PolygonalMesh(maspack.geometry.PolygonalMesh) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point) Face(maspack.geometry.Face)

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