Search in sources :

Example 96 with Point3d

use of maspack.matrix.Point3d in project artisynth_core by artisynth.

the class RobustPreds method getWorldPoint.

private static Point3d getWorldPoint(Vertex3d v) {
    Point3d wpnt = new Point3d();
    v.getWorldPoint(wpnt);
    return wpnt;
}
Also used : Point3d(maspack.matrix.Point3d)

Example 97 with Point3d

use of maspack.matrix.Point3d in project artisynth_core by artisynth.

the class WavefrontWriter method writeMesh.

/**
 * Writes a PolylineMesh to a PrintWriter, using an Alias Wavefront "obj"
 * file format. Vertices are printed first, each starting with the letter
 * "v" and followed by x, y, and z coordinates. Lines are printed next,
 * starting with the letter "f" and followed by a list of integers which
 * gives the indices of that line's vertices. Unless {@link
 * #getZeroIndexed()} returns <code>true</code>, these indices are
 * 1-based. An example of a simple three point line is:
 *
 * <pre>
 *    v 1.0 0.0 0.0
 *    v 0.0 1.0 0.0
 *    v 0.0 0.0 1.0
 *    l 0 1 2
 * </pre>
 *
 * <p>
 * The format used to print the vertex coordinates can be
 * controlled by
 * {@link #setFormat(String)} or {@link #setFormat(NumberFormat)}.
 * The default format has eight decimal places and is specified
 * by the string <code>"%.8g"</code>.
 *
 * @param pw
 * PrintWriter to write the mesh to
 * @param mesh
 * PolylineMesh to be written
 */
public void writeMesh(PrintWriter pw, PolylineMesh mesh) throws IOException {
    ArrayList<Vertex3d> vertices = mesh.getVertices();
    ArrayList<Polyline> lines = mesh.getLines();
    for (Vertex3d vertex : vertices) {
        Point3d pnt = vertex.pnt;
        pw.println("v " + myFmt.format(pnt.x) + " " + myFmt.format(pnt.y) + " " + myFmt.format(pnt.z));
    }
    // int lineCnt = 0;
    for (Polyline line : lines) {
        // int idxCnt = 0;
        pw.print("l");
        int[] idxs = line.getVertexIndices();
        for (int i = 0; i < idxs.length; i++) {
            if (myZeroIndexed) {
                pw.print(" " + (idxs[i] + vOffset));
            } else {
                pw.print(" " + (idxs[i] + 1 + vOffset));
            }
        }
        pw.println("");
    }
    pw.flush();
    vOffset += vertices.size();
}
Also used : Point3d(maspack.matrix.Point3d)

Example 98 with Point3d

use of maspack.matrix.Point3d in project artisynth_core by artisynth.

the class XyzReader method read.

public PointMesh read(PointMesh mesh, InputStream in) throws IOException {
    ReaderTokenizer rtok = new ReaderTokenizer(new BufferedReader(new InputStreamReader(in)));
    if (mesh == null) {
        mesh = new PointMesh();
    }
    mesh.clear();
    ArrayList<Point3d> vtxs = new ArrayList<Point3d>();
    ArrayList<Vector3d> nrms = new ArrayList<Vector3d>();
    boolean done = false;
    while (!done) {
        try {
            double vx = rtok.scanNumber();
            double vy = rtok.scanNumber();
            double vz = rtok.scanNumber();
            double nx = rtok.scanNumber();
            double ny = rtok.scanNumber();
            double nz = rtok.scanNumber();
            vtxs.add(new Point3d(vx, vy, vz));
            nrms.add(new Vector3d(nx, ny, nz));
        } catch (EOFException e) {
            done = true;
        }
    }
    mesh.set(vtxs.toArray(new Point3d[0]), nrms.toArray(new Vector3d[0]));
    return mesh;
}
Also used : PointMesh(maspack.geometry.PointMesh) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) ReaderTokenizer(maspack.util.ReaderTokenizer) ArrayList(java.util.ArrayList)

Example 99 with Point3d

use of maspack.matrix.Point3d in project artisynth_core by artisynth.

the class XyzbWriter method writeMesh.

/**
 * Writes a PointMesh to a PrintWriter, using the binary xyzb
 * format.
 *
 * @param bout
 * Binary output stream to write this mesh to
 * @param mesh
 * PointMesh to be written
 */
public void writeMesh(BinaryOutputStream bout, PointMesh mesh) throws IOException {
    ArrayList<Vertex3d> vertices = mesh.getVertices();
    ArrayList<Vector3d> normals = null;
    if (getWriteNormals(mesh)) {
        normals = mesh.getNormals();
    }
    for (int i = 0; i < vertices.size(); i++) {
        Point3d pnt = vertices.get(i).pnt;
        bout.writeFloat((float) pnt.x);
        bout.writeFloat((float) pnt.y);
        bout.writeFloat((float) pnt.z);
        if (normals != null) {
            Vector3d nrm = normals.get(i);
            bout.writeFloat((float) nrm.x);
            bout.writeFloat((float) nrm.y);
            bout.writeFloat((float) nrm.z);
        }
    }
    bout.flush();
}
Also used : Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d)

Example 100 with Point3d

use of maspack.matrix.Point3d in project artisynth_core by artisynth.

the class OffReader method read.

public static PolygonalMesh read(PolygonalMesh mesh, Reader reader) throws IOException {
    ReaderTokenizer rtok = new ReaderTokenizer(reader);
    ArrayList<Point3d> nodeList = new ArrayList<Point3d>();
    ArrayList<ArrayList<Integer>> faceList = new ArrayList<ArrayList<Integer>>();
    rtok.eolIsSignificant(false);
    int nVerts = 0;
    int nFaces = 0;
    int nEdges = 0;
    // read first info
    rtok.nextToken();
    if (rtok.ttype != ReaderTokenizer.TT_WORD || !rtok.sval.equalsIgnoreCase("OFF")) {
        throw new IOException("Expected 'OFF' at start of file");
    }
    nVerts = rtok.scanInteger();
    nFaces = rtok.scanInteger();
    nEdges = rtok.scanInteger();
    if (nEdges != 0) {
        System.err.println("Separate edges not supported\n");
    }
    double[] vals = new double[3];
    for (int i = 0; i < nVerts; i++) {
        int nread = rtok.scanNumbers(vals, 3);
        if (nread != 3) {
            throw new IOException("Failed to read vertices");
        }
        Point3d pnt = new Point3d(vals[0], vals[1], vals[2]);
        nodeList.add(pnt);
    }
    for (int i = 0; i < nFaces; i++) {
        int nv = rtok.scanInteger();
        ArrayList<Integer> vtxs = new ArrayList<Integer>(nv);
        for (int j = 0; j < nv; j++) {
            int vIdx = rtok.scanInteger();
            vtxs.add(vIdx);
        }
        faceList.add(vtxs);
    }
    return buildMesh(mesh, nodeList, faceList);
}
Also used : Point3d(maspack.matrix.Point3d) ReaderTokenizer(maspack.util.ReaderTokenizer) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Aggregations

Point3d (maspack.matrix.Point3d)464 Vector3d (maspack.matrix.Vector3d)128 ArrayList (java.util.ArrayList)59 RigidTransform3d (maspack.matrix.RigidTransform3d)48 Vertex3d (maspack.geometry.Vertex3d)35 Point (artisynth.core.mechmodels.Point)30 PolygonalMesh (maspack.geometry.PolygonalMesh)30 Face (maspack.geometry.Face)25 ReaderTokenizer (maspack.util.ReaderTokenizer)19 IOException (java.io.IOException)18 RotationMatrix3d (maspack.matrix.RotationMatrix3d)17 Vector2d (maspack.matrix.Vector2d)16 VectorNd (maspack.matrix.VectorNd)16 IntegrationPoint3d (artisynth.core.femmodels.IntegrationPoint3d)15 HashMap (java.util.HashMap)14 Muscle (artisynth.core.mechmodels.Muscle)13 FemNode3d (artisynth.core.femmodels.FemNode3d)12 Particle (artisynth.core.mechmodels.Particle)12 BufferedReader (java.io.BufferedReader)11 Plane (maspack.matrix.Plane)11