Search in sources :

Example 26 with NumberFormat

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

the class MdlToObj method main.

public static void main(String[] args) {
    if (args.length != 2) {
        System.out.println("usage: java artisynth.models.badin.MdlToObj inputMdlMeshName outputObjMeshName");
        return;
    }
    try {
        PolygonalMesh mesh = MDLMeshIO.read(args[0], null);
        PrintWriter pw = new PrintWriter(new File(args[1]));
        mesh.write(pw, new NumberFormat("%g"), /*zeroindexed=*/
        false);
        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)

Example 27 with NumberFormat

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

the class DoubleFieldSlider method setLabels.

public void setLabels(String fmtStr, double inc) {
    Hashtable<Integer, JComponent> labels = new Hashtable<Integer, JComponent>();
    NumberFormat fmt = new NumberFormat(fmtStr);
    double x = mySliderRange.getLowerBound();
    int sliderVal;
    while ((sliderVal = toSliderValue(x)) <= mySlider.getMaximum()) {
        JLabel label = new JLabel(fmt.format(x).trim());
        label.setHorizontalTextPosition(SwingConstants.CENTER);
        labels.put(new Integer(sliderVal), label);
        x += inc;
    }
    mySlider.setLabelTable(labels);
    mySlider.setPaintLabels(true);
}
Also used : Hashtable(java.util.Hashtable) NumberFormat(maspack.util.NumberFormat)

Example 28 with NumberFormat

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

the class LemkeContactSolverTest method runsolver.

private int runsolver(int runcnt, int numd, Wrench wapplied, boolean randomInput) {
    Wrench wapp = null;
    Twist tw0 = null;
    if (wapplied == null && vel0 == null) {
        throw new IllegalArgumentException("vel0 or wext must be specified");
    }
    if (wapplied != null) {
        wapp = new Wrench();
        if (randomInput) {
            wapp.f.setRandom();
            wapp.m.setRandom();
            wapp.f.z -= 1;
        } else {
            wapp.set(wapplied);
        }
    } else {
        tw0 = new Twist();
        if (randomInput) {
            tw0.v.setRandom();
            tw0.w.setRandom();
            tw0.v.z -= 1;
        } else {
            tw0.set(vel0);
        }
    }
    solver.resetPivotCount();
    Twist vel = new Twist();
    timer.start();
    int status = 0;
    for (int k = 0; k < runcnt; k++) {
        // status = solver.solve (vel, pnts,
        // nrms, fcoefs, pnts.length,
        // bpos, wapp, numd);
        solver.setNumFrictionDirections(numd);
        // LemkeContactSolver.SHOW_COLS);
        if (wapp != null) {
            status = solver.solve(vel, contacts, contacts.length, myInertia, wapp, restitution);
        } else {
            status = solver.solve(vel, contacts, contacts.length, myInertia, tw0, restitution);
        }
    // System.out.println (solver.getConfigString());
    }
    timer.stop();
    if (randomInput && solver.getPivotCount() == 0) {
        return 0;
    } else if (status != LemkeContactSolver.SOLVED) {
        System.out.println("no solution");
        System.out.println("wapp=[" + wapp + "]");
        return 0;
    } else {
        if (verbose || doTiming) {
            System.out.print(pnts.length + ":" + numd + "(" + solver.getPivotCount() / runcnt + " pivots)");
            if (doTiming) {
                System.out.print("  " + timer.result(runcnt));
            }
            System.out.println("");
            System.out.print("vel = [");
            NumberFormat fmt = new NumberFormat("%8.3f");
            for (int i = 0; i < 6; i++) {
                String numStr = fmt.format(vel.get(i));
                if (numStr.equals("  -0.000")) {
                    numStr = "   0.000";
                }
                System.out.print(numStr + " ");
            }
            System.out.println("]");
        }
    }
    return (int) (timer.getTimeUsec() / runcnt);
}
Also used : NumberFormat(maspack.util.NumberFormat)

Example 29 with NumberFormat

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

the class LemkeSolverBase method printQv.

protected void printQv(String msg, double[] qv, int numv) {
    Variable[] basicVars = getBasicVars();
    int maxNameLength = getMaxNameLength(basicVars, numv);
    NumberFormat ffmt = new NumberFormat("%24g");
    StringBuffer sbuf = new StringBuffer(256);
    if (msg != null) {
        System.out.println(msg);
    }
    for (int i = 0; i < numv; i++) {
        sbuf.setLength(0);
        sbuf.append("  ");
        sbuf.append(basicVars[i].getName());
        while (sbuf.length() < maxNameLength + 2) {
            sbuf.insert(2, ' ');
        }
        sbuf.append("   ");
        sbuf.append(ffmt.format(qv[i]));
        System.out.println(sbuf.toString());
    }
}
Also used : NumberFormat(maspack.util.NumberFormat)

Example 30 with NumberFormat

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

the class LemkeSolverBase method printMinRatioInfo.

protected void printMinRatioInfo(double[] mv, double[] qv, int numv, int z_i, int blocking_i, int[] candidates, int numc, boolean[] displayRow) {
    Variable[] basicVars = getBasicVars();
    int[] idxs = getDisplayIndices(basicVars, numv, displayRow, z_i);
    boolean[] isCandidate = new boolean[numv];
    if (candidates != null) {
        for (int i = 0; i < numc; i++) {
            isCandidate[candidates[i]] = true;
        }
    }
    NumberFormat ifmt = new NumberFormat("%3d");
    NumberFormat ffmt = new NumberFormat("%24g");
    StringBuffer sbuf = new StringBuffer(256);
    if (blocking_i != -1) {
        System.out.println("blocking variable=" + basicVars[blocking_i].getName());
    }
    int maxNameLength = getMaxNameLength(basicVars, numv);
    for (int k = 0; k < idxs.length; k++) {
        int i = idxs[k];
        sbuf.setLength(0);
        sbuf.append(basicVars[i].isZ() ? "z " : "  ");
        sbuf.append(basicVars[i].getName());
        while (sbuf.length() < maxNameLength + 2) {
            sbuf.insert(2, ' ');
        }
        sbuf.append(' ');
        sbuf.append(isCandidate[i] ? '*' : ' ');
        sbuf.append(i == blocking_i ? "XX " : "   ");
        sbuf.append(ffmt.format(mv[i]));
        sbuf.append(ffmt.format(qv[i]));
        sbuf.append(ffmt.format(-qv[i] / mv[i]));
        System.out.println(sbuf.toString());
    }
}
Also used : 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