Search in sources :

Example 41 with NumberFormat

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

the class MeshSeparator method main.

public static void main(String[] args) {
    ArgParser parser = new ArgParser("[options] <infileName>");
    // parser.addOption ("-inFile %s #input file name", inFileName);
    parser.addOption("-out %s #base name for output file", outFileName);
    parser.addOption("-format %s #printf-syle format string for vertex output", formatStr);
    int idx = 0;
    while (idx < args.length) {
        try {
            idx = parser.matchArg(args, idx);
            if (parser.getUnmatchedArgument() != null) {
                String fileName = parser.getUnmatchedArgument();
                if (inFileName.value == null) {
                    inFileName.value = fileName;
                } else {
                    System.out.println("Ignoring extra input file " + fileName);
                }
            }
        } catch (Exception e) {
            // malformed or erroneous argument
            parser.printErrorAndExit(e.getMessage());
        }
    }
    if (inFileName.value == null) {
        parser.printErrorAndExit("input file name missing");
    }
    if (outFileName.value == null) {
        int dotIdx = inFileName.value.lastIndexOf('.');
        if (dotIdx == -1) {
            outFileName.value = inFileName.value;
        } else {
            outFileName.value = inFileName.value.substring(0, dotIdx);
        }
    }
    try {
        File meshFile = new File(inFileName.value);
        if (!meshFile.exists()) {
            System.out.println("Error: mesh file " + meshFile.getName() + " not found");
            meshFile = null;
            System.exit(1);
        }
        PolygonalMesh mesh = new PolygonalMesh(meshFile);
        PolygonalMesh[] meshes = mesh.partitionIntoConnectedMeshes();
        if (meshes == null) {
            System.out.println("Mesh " + meshFile + " has no separate components");
            System.exit(0);
        }
        double[] numv = new double[meshes.length];
        int[] idxs = new int[meshes.length];
        for (int i = 0; i < meshes.length; i++) {
            numv[i] = meshes[i].numVertices();
            idxs[i] = i;
        }
        ArraySort.quickSort(numv, idxs);
        for (int i = 0; i < meshes.length; i++) {
            NumberFormat fmt = new NumberFormat("%03d");
            File outFile = new File(outFileName.value + "_" + fmt.format(meshes.length - 1 - i) + ".obj");
            meshes[idxs[i]].write(outFile, formatStr.value);
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}
Also used : ArgParser(argparser.ArgParser) PolygonalMesh(maspack.geometry.PolygonalMesh) NumberFormat(maspack.util.NumberFormat)

Example 42 with NumberFormat

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

the class WavefrontToMaya method main.

public static void main(String[] args) {
    String outfile = null;
    String fmt = "%g";
    if (args.length < 1) {
        System.out.println("arguments: input_file [output_file] [number_format]");
        return;
    }
    if (args.length > 1) {
        outfile = args[1];
    }
    if (args.length > 2) {
        fmt = args[2];
    }
    doFiberExport(args[0], outfile, new NumberFormat(fmt));
}
Also used : NumberFormat(maspack.util.NumberFormat)

Example 43 with NumberFormat

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

the class FemModel3d method printANSYSNodes.

/**
 * Prints the nodes of this FEM in a format which is compatible with ANSYS.
 *
 * @param pw
 * PrintWriter to which nodes are written
 */
public void printANSYSNodes(PrintWriter pw) {
    NumberFormat ifmt = new NumberFormat("%8d");
    int nodeIdx = 1;
    for (FemNode3d n : myNodes) {
        pw.println(ifmt.format(nodeIdx) + " " + n.myRest.toString("%16.9e    "));
        nodeIdx++;
    }
    pw.flush();
}
Also used : Point(artisynth.core.mechmodels.Point) NumberFormat(maspack.util.NumberFormat)

Example 44 with NumberFormat

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

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

the class TetGenWriter method writeElemFile.

public static void writeElemFile(FemModel3d fem, String fileName) {
    try {
        PrintWriter pw = new PrintWriter(new File(fileName));
        NumberFormat dfmt = new NumberFormat("%6d");
        ComponentList<FemElement3d> elemList = fem.getElements();
        pw.println(elemList.size() + " 4 0");
        for (FemElement3d e : elemList) {
            FemNode3d[] nodes = e.getNodes();
            int[] firstRow = new int[4];
            if (e instanceof TetElement) {
                firstRow[0] = nodes[0].getNumber();
                firstRow[1] = nodes[1].getNumber();
                firstRow[2] = nodes[2].getNumber();
                firstRow[3] = nodes[3].getNumber();
            } else {
                System.out.println("Unknown element type: " + e.getClass().getName());
                continue;
            }
            pw.print(e.getNumber() + " ");
            for (int i = 0; i < firstRow.length; i++) {
                pw.print(dfmt.format(firstRow[i]));
            }
            pw.println();
        }
        pw.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) 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