Search in sources :

Example 46 with NumberFormat

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

the class TetGenWriter method writeNodeFile.

public static void writeNodeFile(FemModel3d fem, String fileName) {
    try {
        PrintWriter pw = new PrintWriter(new File(fileName));
        NumberFormat fmt = new NumberFormat("%19g");
        ComponentList<FemNode3d> nodeList = fem.getNodes();
        pw.println(nodeList.size() + " 3 0 0");
        for (FemNode3d n : nodeList) {
            pw.print(n.getNumber());
            pw.println(" " + n.getPosition().toString(fmt));
        }
        pw.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : IOException(java.io.IOException) File(java.io.File) PrintWriter(java.io.PrintWriter) NumberFormat(maspack.util.NumberFormat)

Example 47 with NumberFormat

use of maspack.util.NumberFormat 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 48 with NumberFormat

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

the class SparseBlockMatrix method toString.

public String toString(String fmtStr, int nrows, int ncols) {
    int numValues = numNonZeroVals();
    double[] values = new double[numValues];
    int[] colIdxs = new int[numValues];
    int[] rowOffs = new int[rowSize() + 1];
    getCRSIndices(colIdxs, rowOffs, Partition.Full);
    getCRSValues(values, Partition.Full);
    StringBuffer buf = new StringBuffer(20 * numValues);
    NumberFormat fmt = new NumberFormat(fmtStr);
    int rowIdx = 0;
    for (int i = 0; i < numValues; i++) {
        while ((rowIdx + 1) < rowSize() && i >= rowOffs[rowIdx + 1] - 1) {
            rowIdx++;
        }
        buf.append("(" + rowIdx + " " + (colIdxs[i] - 1) + " " + fmt.format(values[i]) + ")\n");
    }
    return buf.toString();
}
Also used : NumberFormat(maspack.util.NumberFormat)

Example 49 with NumberFormat

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

the class MatrixBase method setDefaultFormat.

/**
 * Sets the default format string used in {@link #toString() toString}. For
 * a description of the format string syntax, see {@link
 * maspack.util.NumberFormat NumberFormat}.
 *
 * @param fmtStr
 * new format string
 * @throws IllegalArgumentException
 * if the format string is invalid
 * @see #getDefaultFormat
 */
public static void setDefaultFormat(String fmtStr) {
    NumberFormat fmt = new NumberFormat(fmtStr);
    myDefaultFmt = fmt;
}
Also used : NumberFormat(maspack.util.NumberFormat)

Example 50 with NumberFormat

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

the class MatrixBase method writeToFile.

public void writeToFile(String fileName, String fmtStr) {
    NumberFormat fmt = new NumberFormat(fmtStr);
    try {
        PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(fileName)));
        write(pw, fmt);
        pw.close();
    } catch (Exception e) {
        System.out.println("Error writing matrix to file " + fileName + ":");
        System.out.println(e);
    }
}
Also used : FileWriter(java.io.FileWriter) InternalErrorException(maspack.util.InternalErrorException) IOException(java.io.IOException) NumberFormat(maspack.util.NumberFormat) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter)

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