Search in sources :

Example 26 with PointParticleAttachment

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

the class MFreeMeshComp method writeAttachment.

protected void writeAttachment(PointAttachment attacher, PrintWriter pw, NumberFormat fmt, CompositeComponent ancestor) throws IOException {
    pw.print("[ ");
    if (attacher instanceof PointParticleAttachment) {
        PointParticleAttachment ppa = (PointParticleAttachment) attacher;
        FemNode node = (FemNode) ppa.getParticle();
        pw.print(ComponentUtils.getWritePathName(ancestor, node) + " 1 ");
    } else if (attacher instanceof PointFem3dAttachment) {
        PointFem3dAttachment pfa = (PointFem3dAttachment) attacher;
        FemNode[] nodes = pfa.getNodes();
        VectorNd weights = pfa.getCoordinates();
        for (int i = 0; i < nodes.length; i++) {
            pw.print(ComponentUtils.getWritePathName(ancestor, nodes[i]) + " " + fmt.format(weights.get(i)) + " ");
        }
    }
    pw.println("]");
}
Also used : FemNode(artisynth.core.femmodels.FemNode) VectorNd(maspack.matrix.VectorNd) PointFem3dAttachment(artisynth.core.femmodels.PointFem3dAttachment) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment)

Example 27 with PointParticleAttachment

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

the class MFreeMeshComp method createPointAttachment.

public PointFem3dAttachment createPointAttachment(Point pnt) {
    if (!(getMesh() instanceof PolygonalMesh)) {
        return null;
    }
    PolygonalMesh mesh = (PolygonalMesh) getMesh();
    if (!mesh.isTriangular()) {
        return null;
    }
    // Find nearest face to the point. The vertices of this face will be used
    // to find the nodes and weight for the attachment.
    BVFeatureQuery query = new BVFeatureQuery();
    Point3d near = new Point3d();
    Vector2d uv = new Vector2d();
    Face face = query.nearestFaceToPoint(near, uv, mesh, pnt.getPosition());
    Vertex3d[] vtxs = face.getTriVertices();
    double[] wgts = new double[] { 1 - uv.x - uv.y, uv.x, uv.y };
    HashMap<FemNode, Double> nodeWeights = new HashMap<FemNode, Double>();
    for (int i = 0; i < vtxs.length; i++) {
        PointAttachment va = myVertexAttachments.get(vtxs[i].getIndex());
        if (va instanceof PointParticleAttachment) {
            PointParticleAttachment ppa = (PointParticleAttachment) va;
            FemNode node = (FemNode) ppa.getParticle();
            accumulateNodeWeights(node, wgts[i], nodeWeights);
        } else if (va instanceof PointFem3dAttachment) {
            PointFem3dAttachment pfa = (PointFem3dAttachment) va;
            for (int k = 0; k < pfa.numMasters(); k++) {
                FemNode node = pfa.getNodes()[k];
                double w = pfa.getCoordinate(k);
                accumulateNodeWeights(node, w * wgts[i], nodeWeights);
            }
        }
    }
    // Create a new PointFem3dAttachment
    PointFem3dAttachment ax = new PointFem3dAttachment(pnt);
    VectorNd weightVec = new VectorNd();
    for (Double d : nodeWeights.values()) {
        weightVec.append(d);
    }
    ax.setFromNodes(nodeWeights.keySet(), weightVec);
    return ax;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) FemNode(artisynth.core.femmodels.FemNode) HashMap(java.util.HashMap) PointAttachment(artisynth.core.mechmodels.PointAttachment) PolygonalMesh(maspack.geometry.PolygonalMesh) BVFeatureQuery(maspack.geometry.BVFeatureQuery) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point) Vector2d(maspack.matrix.Vector2d) Point3d(maspack.matrix.Point3d) VectorNd(maspack.matrix.VectorNd) PointFem3dAttachment(artisynth.core.femmodels.PointFem3dAttachment) Face(maspack.geometry.Face) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment)

Example 28 with PointParticleAttachment

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

the class MFreeMeshComp method setVertexAttachment.

public void setVertexAttachment(int vidx, double[] weights, MFreeNode3d[] nodes) {
    if (weights.length > 1) {
        PointFem3dAttachment pattacher = new PointFem3dAttachment();
        pattacher.setFromNodes(nodes, weights);
        setVertexAttachment(vidx, pattacher);
    } else if (weights.length == 1) {
        PointParticleAttachment attacher = new PointParticleAttachment(nodes[0], null);
        setVertexAttachment(vidx, attacher);
    }
}
Also used : PointFem3dAttachment(artisynth.core.femmodels.PointFem3dAttachment) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment)

Example 29 with PointParticleAttachment

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

the class MFreeMeshComp method writeMesh.

public boolean writeMesh(PrintWriter pw, boolean nodeFormat) {
    PolygonalMesh mesh = null;
    if (!(getMesh() instanceof PolygonalMesh)) {
        return false;
    }
    mesh = (PolygonalMesh) getMesh();
    pw.print("[ ");
    NumberFormat fmt = new NumberFormat("%.8g");
    IndentingPrintWriter.addIndentation(pw, 2);
    if (!nodeFormat) {
        for (Vertex3d vtx : mesh.getVertices()) {
            writeVertexInfo(pw, vtx, fmt);
        }
    }
    ArrayList<Integer> nodeNums = new ArrayList<Integer>();
    for (Face face : mesh.getFaces()) {
        HalfEdge he0 = face.firstHalfEdge();
        HalfEdge he = he0;
        pw.print("f");
        do {
            int vidx = he.head.getIndex();
            if (nodeFormat) {
                PointParticleAttachment ppa = (PointParticleAttachment) getAttachment(vidx);
                MFreeNode3d node = (MFreeNode3d) ppa.getParticle();
                pw.print(" " + node.getNumber());
            } else {
                pw.print(" " + (vidx + 1));
            }
            he = he.getNext();
        } while (he != he0);
        pw.println("");
    }
    IndentingPrintWriter.addIndentation(pw, -2);
    pw.println("]");
    return true;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) ArrayList(java.util.ArrayList) HalfEdge(maspack.geometry.HalfEdge) Face(maspack.geometry.Face) PolygonalMesh(maspack.geometry.PolygonalMesh) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point) NumberFormat(maspack.util.NumberFormat)

Example 30 with PointParticleAttachment

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

the class MFreeMeshComp 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 {
                    MFreeNode3d node = (MFreeNode3d) 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) FemNode(artisynth.core.femmodels.FemNode) 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) PointFem3dAttachment(artisynth.core.femmodels.PointFem3dAttachment) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment)

Aggregations

PointParticleAttachment (artisynth.core.mechmodels.PointParticleAttachment)31 ContactPoint (artisynth.core.mechmodels.ContactPoint)21 Point (artisynth.core.mechmodels.Point)21 PointAttachment (artisynth.core.mechmodels.PointAttachment)16 Vertex3d (maspack.geometry.Vertex3d)15 PointFem3dAttachment (artisynth.core.femmodels.PointFem3dAttachment)13 ArrayList (java.util.ArrayList)12 VectorNd (maspack.matrix.VectorNd)11 FemNode (artisynth.core.femmodels.FemNode)10 PolygonalMesh (maspack.geometry.PolygonalMesh)10 Point3d (maspack.matrix.Point3d)9 Face (maspack.geometry.Face)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)3 FemNode3d (artisynth.core.femmodels.FemNode3d)2 ContactMaster (artisynth.core.mechmodels.ContactMaster)2 ObjectToken (artisynth.core.util.ObjectToken)2 BVFeatureQuery (maspack.geometry.BVFeatureQuery)2 HalfEdge (maspack.geometry.HalfEdge)2 MeshBase (maspack.geometry.MeshBase)2