Search in sources :

Example 51 with Vertex3d

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

the class PolygonalMeshTest method compareMeshes.

private void compareMeshes(PolygonalMesh mesh, PolygonalMesh comp) {
    if (mesh.numVertices() != mesh.numVertices()) {
        throw new TestException("mesh has " + mesh.numVertices() + " vertices, expecting " + comp.numVertices());
    }
    for (int i = 0; i < mesh.numVertices(); i++) {
        Vertex3d vr = mesh.getVertices().get(i);
        Vertex3d vc = comp.getVertices().get(i);
        if (!vr.pnt.epsilonEquals(vc.pnt, 1e-10)) {
            throw new TestException("mesh vertex " + i + " is " + vr.pnt + ", expecting " + vc.pnt);
        }
    }
    if (mesh.numFaces() != mesh.numFaces()) {
        throw new TestException("mesh has " + mesh.numFaces() + " faces, expecting " + comp.numFaces());
    }
    for (int i = 0; i < mesh.numFaces(); i++) {
        Face fr = mesh.getFaces().get(i);
        Face fc = comp.getFaces().get(i);
        int[] ridxs = fr.getVertexIndices();
        int[] cidxs = fc.getVertexIndices();
        if (!compareIdxs(ridxs, cidxs)) {
            throw new TestException("mesh face " + i + " has indices " + idxsToStr(ridxs) + ", expecting " + idxsToStr(cidxs));
        }
    }
}
Also used : Vertex3d(maspack.geometry.Vertex3d)

Example 52 with Vertex3d

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

the class MayaAsciiReader method recursiveAddPolylines.

private void recursiveAddPolylines(Node<MayaNode> root, PolylineMesh mesh, AffineTransform3d trans, UnitInfo units, Pattern pregex) {
    // make copy so can traverse
    trans = new AffineTransform3d(trans);
    // children independently
    MayaNode data = root.getData();
    if (data instanceof MayaTransform) {
        MayaTransform dtrans = (MayaTransform) data;
        AffineTransform3d tu = new AffineTransform3d();
        dtrans.getTransform(tu);
        // convert units
        tu.p.scale(dtrans.units.length.getSI() / units.length.getSI());
        if (dtrans.inheritsTransform()) {
            trans.mul(tu);
        } else {
            trans.set(tu);
        }
    } else if (data instanceof MayaNurbsCurve) {
        MayaNurbsCurve mnc = (MayaNurbsCurve) data;
        if (pregex == null || pregex.matcher(mnc.getName()).matches()) {
            Polyline line = new Polyline(mnc.curve);
            if (line != null) {
                // transform line
                for (Vertex3d vtx : line.getVertices()) {
                    vtx.pnt.scale(mnc.units.length.getSI() / units.length.getSI());
                    vtx.pnt.transform(trans);
                }
                mesh.addLine(line);
            }
        }
    }
    for (Node<MayaNode> child : root.getChildren()) {
        recursiveAddPolylines(child, mesh, trans, units, pregex);
    }
}
Also used : Vertex3d(maspack.geometry.Vertex3d) Polyline(maspack.geometry.Polyline) AffineTransform3d(maspack.matrix.AffineTransform3d)

Example 53 with Vertex3d

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

the class OffWriter method writeMesh.

public void writeMesh(PolygonalMesh mesh) throws IOException {
    PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(myOstream)));
    pw.println("OFF");
    pw.printf("%d %d %d\n", mesh.numVertices(), mesh.numFaces(), 0);
    pw.flush();
    int[] oldIdxs = new int[mesh.numVertices()];
    int idx = 0;
    for (Vertex3d vtx : mesh.getVertices()) {
        Point3d pnt = vtx.getPosition();
        pw.println(myFmt.format(pnt.x) + " " + myFmt.format(pnt.y) + " " + myFmt.format(pnt.z));
        // protect vertex indices numbers
        oldIdxs[idx] = vtx.getIndex();
        vtx.setIndex(idx);
        idx++;
    }
    for (Face face : mesh.getFaces()) {
        int nf = face.numVertices();
        pw.print(nf);
        for (int j = 0; j < face.numVertices(); j++) {
            pw.print(" " + face.getVertex(j).getIndex());
        }
        pw.println();
    }
    pw.flush();
    // restore vertex indices
    idx = 0;
    for (Vertex3d vtx : mesh.getVertices()) {
        vtx.setIndex(oldIdxs[idx]);
        idx++;
    }
}
Also used : Vertex3d(maspack.geometry.Vertex3d) Point3d(maspack.matrix.Point3d) OutputStreamWriter(java.io.OutputStreamWriter) Face(maspack.geometry.Face) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter)

Example 54 with Vertex3d

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

the class AmiraMeshWriter method writeMesh.

public void writeMesh(PolylineMesh mesh) {
    PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(myOstream)));
    int nLineSize = 0;
    for (Polyline line : mesh.getLines()) {
        int nlineVerts = line.numVertices();
        if (nlineVerts > 0) {
            nLineSize += nlineVerts + 1;
        }
    }
    int nVerts = mesh.numVertices();
    pw.println(FILE_HEADER);
    // mesh name
    if (mesh.getName() != null) {
        pw.println("# " + mesh.getName());
    }
    pw.println();
    pw.println("define Lines " + nLineSize);
    pw.println("define Vertices " + nVerts);
    pw.println();
    pw.println("Parameters {");
    pw.println("    ContentType \"HxLineSet\"");
    pw.println("}");
    pw.println();
    pw.println("Vertices { float[3] Coordinates } = @1");
    pw.println("Lines { int LineIdx } = @2");
    pw.println();
    pw.println("@1 # xyz vertex coordinates");
    int idx = 0;
    for (Vertex3d vtx : mesh.getVertices()) {
        vtx.setIndex(idx++);
        pw.println(vtx.getPosition().toString(myFmt));
    }
    pw.println();
    pw.println("@2 # line indices, terminating with -1");
    for (Polyline line : mesh.getLines()) {
        idx = 0;
        Vertex3d[] vtxs = line.getVertices();
        if (vtxs.length > 0) {
            pw.print(vtxs[0].getIndex());
            for (int i = 1; i < vtxs.length; i++) {
                if ((i % maxLineIndexSize) == 0) {
                    pw.println();
                } else {
                    pw.print(" ");
                }
                pw.print(vtxs[i].getIndex());
            }
            if ((vtxs.length % maxLineIndexSize) == 0) {
                pw.println();
            } else {
                pw.print(" ");
            }
            pw.println(-1);
        }
    // end if non-null line
    }
    // end loop through lines
    pw.flush();
}
Also used : Vertex3d(maspack.geometry.Vertex3d) Polyline(maspack.geometry.Polyline) OutputStreamWriter(java.io.OutputStreamWriter) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter)

Example 55 with Vertex3d

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

the class GtsReader method readMesh.

public PolygonalMesh readMesh(PolygonalMesh mesh) throws IOException {
    if (mesh == null) {
        mesh = new PolygonalMesh();
    } else {
        mesh.clear();
    }
    ReaderTokenizer rtok = new ReaderTokenizer(new BufferedReader(new InputStreamReader(myIstream)));
    rtok.commentChar('!');
    rtok.commentChar('#');
    rtok.eolIsSignificant(true);
    int numVerts = rtok.scanInteger();
    int numEdges = rtok.scanInteger();
    int numFaces = rtok.scanInteger();
    while (rtok.nextToken() != ReaderTokenizer.TT_EOL) ;
    ArrayList<Edge> edgeList = new ArrayList<Edge>();
    for (int i = 0; i < numVerts; i++) {
        double x = rtok.scanNumber();
        double y = rtok.scanNumber();
        double z = rtok.scanNumber();
        mesh.addVertex(new Point3d(x, y, z));
        while (rtok.nextToken() != ReaderTokenizer.TT_EOL) ;
    }
    ArrayList<Vertex3d> verts = mesh.getVertices();
    for (int i = 0; i < numEdges; i++) {
        int idx1 = rtok.scanInteger() - 1;
        int idx2 = rtok.scanInteger() - 1;
        if (idx1 < 0 || idx1 >= numVerts) {
            System.out.println("Error: vertex " + idx1 + " out of range, " + rtok);
            System.exit(1);
        }
        if (idx2 < 0 || idx2 >= numVerts) {
            System.out.println("Error: vertex " + idx2 + " out of range, " + rtok);
            System.exit(1);
        }
        edgeList.add(new Edge(verts.get(idx1), verts.get(idx2)));
        while (rtok.nextToken() != ReaderTokenizer.TT_EOL) ;
    }
    for (int i = 0; i < numFaces; i++) {
        ArrayList<Edge> edges = new ArrayList<Edge>();
        while (rtok.nextToken() == ReaderTokenizer.TT_NUMBER) {
            if (!rtok.tokenIsInteger()) {
                System.out.println("Error: edge index expected, " + rtok);
                System.exit(1);
            }
            int idx = (int) rtok.lval - 1;
            if (idx < 0 || idx >= edgeList.size()) {
                System.out.println("Error: edge index " + idx + " out of range, " + rtok);
                System.exit(1);
            }
            edges.add(edgeList.get(idx));
        }
        int[] idxs = getFaceIndices(edges);
        if (idxs == null) {
            System.out.println("Error: face edges are not adjacent, " + rtok);
        }
        mesh.addFace(idxs);
        rtok.pushBack();
        while (rtok.nextToken() != ReaderTokenizer.TT_EOL) ;
    }
    return mesh;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) PolygonalMesh(maspack.geometry.PolygonalMesh) Point3d(maspack.matrix.Point3d) ReaderTokenizer(maspack.util.ReaderTokenizer) BufferedReader(java.io.BufferedReader)

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