Search in sources :

Example 71 with Vertex3d

use of maspack.geometry.Vertex3d 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 72 with Vertex3d

use of maspack.geometry.Vertex3d in project artisynth_core by artisynth.

the class FemMeshComp method scanMeshUsingNodeNumbers.

/**
 * Old method of scanning mesh usign node numbers only.
 */
private void scanMeshUsingNodeNumbers(ReaderTokenizer rtok) throws IOException {
    PolygonalMesh mesh = (PolygonalMesh) getMesh();
    // nodeVertexMap is used during the construction of the mesh,
    // so we build it during the construction rather then letting
    // it be built in finalizeSurfaceBuild()
    myNodeVertexMap = new HashMap<FemNode3d, Vertex3d>();
    myNumSingleAttachments = 0;
    ArrayList<Vertex3d> vtxList = new ArrayList<Vertex3d>();
    rtok.nextToken();
    while (rtok.tokenIsWord("f")) {
        vtxList.clear();
        rtok.nextToken();
        while (rtok.tokenIsInteger()) {
            int nnum = (int) rtok.lval;
            FemNode3d node = getNodeFromNumber(rtok, nnum);
            Vertex3d vtx = myNodeVertexMap.get(node);
            if (vtx == null) {
                vtx = new Vertex3d(new Point3d(node.getPosition()));
                myNodeVertexMap.put(node, vtx);
                myVertexAttachments.add(new PointParticleAttachment(node, null));
                myNumSingleAttachments++;
                mesh.addVertex(vtx);
            }
            vtxList.add(vtx);
            rtok.nextToken();
        }
        mesh.addFace(vtxList.toArray(new Vertex3d[0]));
    }
    rtok.pushBack();
}
Also used : Vertex3d(maspack.geometry.Vertex3d) Point3d(maspack.matrix.Point3d) ArrayList(java.util.ArrayList) PolygonalMesh(maspack.geometry.PolygonalMesh) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point)

Example 73 with Vertex3d

use of maspack.geometry.Vertex3d 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 74 with Vertex3d

use of maspack.geometry.Vertex3d in project artisynth_core by artisynth.

the class FemMeshComp 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);
                FemNode3d node = (FemNode3d) 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 75 with Vertex3d

use of maspack.geometry.Vertex3d in project artisynth_core by artisynth.

the class FemMeshComp method createEmbedded.

public static FemMeshComp createEmbedded(FemMeshComp surf, MeshBase mesh, FemModel3d fem) {
    double reduceTol = 1e-8;
    ArrayList<FemNode> nodes = new ArrayList<FemNode>();
    VectorNd weights = new VectorNd();
    if (surf == null) {
        surf = new FemMeshComp(fem);
    }
    surf.setMesh(mesh);
    ArrayList<Vertex3d> verts = mesh.getVertices();
    surf.myVertexAttachments.clear();
    for (int i = 0; i < verts.size(); i++) {
        // this could works very similarly to the code that adds
        // marker points into a mesh
        Vertex3d vtx = verts.get(i);
        // if (vtx instanceof FemMeshVertex) {
        // nodes.clear();
        // nodes.add(((FemMeshVertex)vtx).getPoint());
        // weights.clear();
        // weights.add(1.0);
        // }
        // else
        {
            FemElement3d elem = surf.myFem.findContainingElement(vtx.pnt);
            Point3d newLoc = new Point3d(vtx.pnt);
            if (elem == null) {
                // won't use newLoc since we're not projecting vertex onto FEM
                elem = surf.myFem.findNearestSurfaceElement(newLoc, vtx.pnt);
            }
            VectorNd coords = new VectorNd(elem.numNodes());
            // first see if there's a node within reduceTol of the point,
            // and if so just use that
            double maxDist = Double.NEGATIVE_INFINITY;
            double minDist = Double.POSITIVE_INFINITY;
            FemNode3d nearestNode = null;
            FemNode3d[] elemNodes = elem.getNodes();
            for (int k = 0; k < elemNodes.length; k++) {
                double d = vtx.pnt.distance(elemNodes[k].getPosition());
                if (d > maxDist) {
                    maxDist = d;
                }
                if (d < minDist) {
                    minDist = d;
                    nearestNode = elemNodes[k];
                }
            }
            if (minDist / maxDist <= reduceTol) {
                // weight everything to the nearest node
                nodes.clear();
                nodes.add(nearestNode);
                weights.setSize(0);
                weights.append(1.0);
            } else {
                Vector3d c3 = new Vector3d();
                boolean converged = elem.getNaturalCoordinates(c3, vtx.pnt, 1000) >= 0;
                if (!converged) {
                    System.err.println("Warning: getNaturalCoordinatesRobust() did not converge, " + "element=" + ComponentUtils.getPathName(elem) + ", point=" + vtx.pnt);
                // c3.setZero();
                // XXX debugging:
                // elem.getNaturalCoordinates(c3,  vtx.pnt, 1000); // try again once more
                }
                for (int j = 0; j < elem.numNodes(); j++) {
                    coords.set(j, elem.getN(j, c3));
                }
                nodes.clear();
                weights.setSize(0);
                for (int k = 0; k < coords.size(); k++) {
                    if (Math.abs(coords.get(k)) >= reduceTol) {
                        nodes.add(elem.getNodes()[k]);
                        weights.append(coords.get(k));
                    }
                }
            }
        }
        if (weights.size() > 1) {
            PointFem3dAttachment attacher = new PointFem3dAttachment();
            attacher.setFromNodes(nodes, weights);
            surf.myVertexAttachments.add(attacher);
        } else if (weights.size() == 1) {
            PointParticleAttachment attacher = new PointParticleAttachment(nodes.get(0), null);
            surf.myVertexAttachments.add(attacher);
        }
    }
    surf.buildNodeVertexMap();
    return surf;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) ArrayList(java.util.ArrayList) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) VectorNd(maspack.matrix.VectorNd) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment)

Aggregations

Vertex3d (maspack.geometry.Vertex3d)81 Point3d (maspack.matrix.Point3d)35 Face (maspack.geometry.Face)30 PolygonalMesh (maspack.geometry.PolygonalMesh)24 Vector3d (maspack.matrix.Vector3d)23 ContactPoint (artisynth.core.mechmodels.ContactPoint)22 Point (artisynth.core.mechmodels.Point)22 ArrayList (java.util.ArrayList)19 PointParticleAttachment (artisynth.core.mechmodels.PointParticleAttachment)15 HalfEdge (maspack.geometry.HalfEdge)13 PointAttachment (artisynth.core.mechmodels.PointAttachment)10 HashMap (java.util.HashMap)10 Vector2d (maspack.matrix.Vector2d)8 VectorNd (maspack.matrix.VectorNd)8 BVFeatureQuery (maspack.geometry.BVFeatureQuery)7 RenderProps (maspack.render.RenderProps)6 PointFem3dAttachment (artisynth.core.femmodels.PointFem3dAttachment)5 Color (java.awt.Color)5 FemNode (artisynth.core.femmodels.FemNode)4 BufferedWriter (java.io.BufferedWriter)4