Search in sources :

Example 36 with NumberFormat

use of maspack.util.NumberFormat in project artisynth_core by artisynth.

the class PolygonalMesh method write.

/**
 * Writes this mesh to a File, using an Alias Wavefront "obj" file
 * format. Behaves the same as {@link
 * #write(java.io.PrintWriter,maspack.util.NumberFormat,boolean,boolean)}
 * with <code>zeroIndexed</code> and <code>facesClockwise</code> set to
 * false.
 *
 * @param file
 * File to write this mesh to
 * @param fmtStr
 * format string for writing the vertex coordinates. If <code>null</code>,
 * a format of <code>"%.8g"</code> is assumed.
 */
public void write(File file, String fmtStr) throws IOException {
    if (fmtStr == null) {
        fmtStr = "%.8g";
    }
    NumberFormat fmt = new NumberFormat(fmtStr);
    PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file)));
    write(pw, fmt, /*zeroIndexed=*/
    false, /*facesClockwise=*/
    false);
}
Also used : FileWriter(java.io.FileWriter) NumberFormat(maspack.util.NumberFormat) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter)

Example 37 with NumberFormat

use of maspack.util.NumberFormat in project artisynth_core by artisynth.

the class NURBSSurface method write.

/**
 * {@inheritDoc}
 */
public void write(PrintWriter pw, String fmtStr, boolean relative) throws IOException {
    double[] minmax = new double[2];
    int numc = numControlPoints();
    NumberFormat fmt = new NumberFormat(fmtStr);
    for (int i = 0; i < myCtrlPnts.size(); i++) {
        pw.println("v " + myCtrlPnts.get(i).toString(fmt));
    }
    pw.println("deg " + ucurve.getDegree() + " " + vcurve.getDegree());
    resetLine(pw);
    addToLine(pw, "surf");
    ucurve.getRange(minmax);
    addToLine(pw, " " + fmt.format(minmax[0]) + " " + fmt.format(minmax[1]));
    vcurve.getRange(minmax);
    addToLine(pw, " " + fmt.format(minmax[0]) + " " + fmt.format(minmax[1]));
    for (int i = 0; i < numc; i++) {
        addToLine(pw, relative ? " " + (-numc + i) : " " + (i + 1));
    }
    resetLine(pw);
    addToLine(pw, "parm u");
    if (ucurve.isClosed()) {
        addToLine(pw, " closed");
    }
    double[] knotsu = ucurve.getKnots();
    for (int i = 0; i < knotsu.length; i++) {
        addToLine(pw, " " + fmt.format(knotsu[i]));
    }
    resetLine(pw);
    addToLine(pw, "parm v");
    if (vcurve.isClosed()) {
        addToLine(pw, " closed");
    }
    double[] knotsv = vcurve.getKnots();
    for (int i = 0; i < knotsv.length; i++) {
        addToLine(pw, " " + fmt.format(knotsv[i]));
    }
    resetLine(pw);
    pw.println("end");
    pw.flush();
}
Also used : NumberFormat(maspack.util.NumberFormat)

Example 38 with NumberFormat

use of maspack.util.NumberFormat in project artisynth_core by artisynth.

the class PolylineMesh method write.

/**
 * Writes this mesh 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. 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 vertex coordinates is specified by a
 * {@link maspack.util.NumberFormat NumberFormat}.
 *
 * @param pw
 * PrintWriter to write this mesh to
 * @param fmt
 * format for writing the vertex coordinates. If <code>null</code>,
 * a format of <code>"%.8g"</code> is assumed.
 * @param zeroIndexed
 * if true, index numbering for mesh vertices starts at 0. Otherwise,
 * numbering starts at 1.
 */
public void write(PrintWriter pw, NumberFormat fmt, boolean zeroIndexed) throws IOException {
    if (fmt == null) {
        fmt = new NumberFormat("%.8g");
    }
    for (Vertex3d vertex : myVertices) {
        Point3d pnt = vertex.pnt;
        pw.println("v " + fmt.format(pnt.x) + " " + fmt.format(pnt.y) + " " + fmt.format(pnt.z));
    }
    // int lineCnt = 0;
    for (Polyline line : myLines) {
        // int idxCnt = 0;
        pw.print("l");
        int[] idxs = line.getVertexIndices();
        for (int i = 0; i < idxs.length; i++) {
            if (zeroIndexed) {
                pw.print(" " + (idxs[i]));
            } else {
                pw.print(" " + (idxs[i] + 1));
            }
        }
        pw.println("");
    }
    pw.flush();
}
Also used : Point3d(maspack.matrix.Point3d) NumberFormat(maspack.util.NumberFormat)

Example 39 with NumberFormat

use of maspack.util.NumberFormat in project artisynth_core by artisynth.

the class ColorBar method setDefaults.

@Override
protected void setDefaults() {
    setFont(new Font(defaultFontName, 0, defaultFontSize));
    myRenderProps = createDefaultRenderProps();
    hAlignment = defaultHAlignment;
    vAlignment = defaultVAlignment;
    myTextSize = defaultTextSize;
    myFontSize = defaultFontSize;
    myLoc = new Rectangle2d(defaultLoc);
    myColorMap = defaultColorMap;
    myValueRange = new DoubleInterval(defaultInterval);
    nBarDivisions = defaultBarDivisions;
    myTickFractions = new Vector2d(defaultTickFraction);
    myLabelPos = new VectorNd(0);
    myLabelText = new ArrayList<String>();
    myTextOffset = new Vector2d(defaultTextOffset);
    myNumberFormat = new NumberFormat(defaultNumberFormat);
    myRenderObject = null;
    myRenderObjectRebuildRequest = true;
}
Also used : Vector2d(maspack.matrix.Vector2d) Rectangle2d(maspack.geometry.Rectangle2d) VectorNd(maspack.matrix.VectorNd) DoubleInterval(maspack.util.DoubleInterval) Font(java.awt.Font) NumberFormat(maspack.util.NumberFormat)

Example 40 with NumberFormat

use of maspack.util.NumberFormat in project artisynth_core by artisynth.

the class ObjToMdl method main.

public static void main(String[] args) {
    if (args.length != 2) {
        System.out.println("usage: java artisynth.models.badin.ObjToMdl inputObjMeshName outputMdlMeshName");
        return;
    }
    try {
        PolygonalMesh mesh = new PolygonalMesh(new File(args[0]));
        PrintWriter pw = new PrintWriter(new File(args[1]));
        MDLMeshIO.write(mesh, args[1], pw, new NumberFormat("%g"));
        pw.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : IOException(java.io.IOException) PolygonalMesh(maspack.geometry.PolygonalMesh) File(java.io.File) PrintWriter(java.io.PrintWriter) NumberFormat(maspack.util.NumberFormat)

Aggregations

NumberFormat (maspack.util.NumberFormat)55 PrintWriter (java.io.PrintWriter)15 IOException (java.io.IOException)8 Point3d (maspack.matrix.Point3d)6 BufferedWriter (java.io.BufferedWriter)5 File (java.io.File)5 PolygonalMesh (maspack.geometry.PolygonalMesh)5 Point (artisynth.core.mechmodels.Point)4 FileWriter (java.io.FileWriter)4 ArrayList (java.util.ArrayList)4 SparseBlockMatrix (maspack.matrix.SparseBlockMatrix)4 ReaderTokenizer (maspack.util.ReaderTokenizer)4 TestException (maspack.util.TestException)4 Face (maspack.geometry.Face)3 VectorNd (maspack.matrix.VectorNd)3 FunctionTimer (maspack.util.FunctionTimer)3 InternalErrorException (maspack.util.InternalErrorException)3 ContactPoint (artisynth.core.mechmodels.ContactPoint)2 PointParticleAttachment (artisynth.core.mechmodels.PointParticleAttachment)2 Font (java.awt.Font)2