Search in sources :

Example 6 with NumericList

use of maspack.interpolation.NumericList in project artisynth_core by artisynth.

the class NumericMonitorProbe method setVsize.

public void setVsize(int vsize, PlotTraceInfo[] traceInfos) {
    myVsize = vsize;
    myNumericList = new NumericList(myVsize);
    if (traceInfos != null) {
        myPlotTraceManager.rebuild(getPropsOrDimens(), traceInfos);
    } else {
        myPlotTraceManager.rebuild(getPropsOrDimens());
    }
    if (myLegend != null) {
        myLegend.rebuild();
    }
}
Also used : NumericList(maspack.interpolation.NumericList)

Example 7 with NumericList

use of maspack.interpolation.NumericList in project artisynth_core by artisynth.

the class NumericInputProbe method read.

/**
 * Reads the start and stop times, scale value, and data for this probe from
 * an ascii file. The following information should be provided in order,
 * separated by white space:
 * <ul>
 * <li>start time (either seconds or nanoseconds, as described below).
 * Ignored if <code>setTimes</code> is false.
 * <li>stop time (either seconds or nanoseconds, as described below)
 * Ignored if <code>setTimes</code> is false.
 * <li>scale value (floating point number; nominal value is 1)
 * Ignored if <code>setTimes</code> is false.
 * <li>interpolation order ("step", "linear", or "cubic")
 * <li>number of data values n at each knot point (an integer)
 * <li>either the knot point time step (floating point number, in seconds),
 * OR the keyword "explicit", indicating that knot time values are to be
 * given explicitly
 * <li>the knot point data, with each knot point specified by n numbers,
 * preceeded (if explicit time has been specified) by the corresponding time
 * value (in seconds).
 * </ul>
 * The start and stop times can be indicated in either seconds or
 * nanoseconds. The former is assumed if the value is a double with a
 * decimal point.
 *
 * For example, the following input
 *
 * <pre>
 * 2.0 10.0 1.2
 * linear 2 explicit
 * 0.0 2.0 2.0
 * 1.1 4.0 3.0
 * 3.0 0.0 1.0
 * </pre>
 *
 * specifies a probe with a start and stop time of 2 and 10 seconds,
 * respectively, a scale value of 1.2, linear interpolation, 2 values at each
 * knot point, and three knot points at times 0.0, 1.1, and 3.0.
 *
 * If knot time is given implicitly by a time setp, then time is assumed to
 * start at 0. The following input
 *
 * <pre>
 * 2000000000 3000000000 2.5
 * step 2 2.0
 * 2.0 2.0
 * 4.0 3.0
 * 0.0 1.0
 * </pre>
 *
 * specifies a probe with a start and stop time of 2 and 3 seconds,
 * respectively, a scale value of 2.5, step interpolation, 2 values at each
 * knot point, and three knot points with times of 0, 2.0, and 4.0 (given
 * implicity by a step size of 2.0).
 *
 * <p>
 * The character '#' is a comment character, causing all subsequent input up
 * to the next new line to be ignored.
 *
 * @param file
 * File from which to read the probe information
 * @param setTimes if <code>true</code>, sets the start time, stop time,
 * and scale values to those indicated at the head of the file. If
 * <code>false</code>, these values are ignored.
 * @throws IOException
 * if an I/O or format error occurred.
 */
public void read(File file, boolean setTimes) throws IOException {
    // myAttachedFile = null;
    ReaderTokenizer rtok = new ReaderTokenizer(new BufferedReader(new FileReader(file)));
    rtok.commentChar('#');
    rtok.ordinaryChar('/');
    double time = 0;
    time = scanTimeQuantity(rtok);
    if (setTimes) {
        setStartTime(time);
    }
    time = scanTimeQuantity(rtok);
    if (setTimes) {
        setStopTime(time);
    }
    if (rtok.nextToken() != ReaderTokenizer.TT_NUMBER) {
        throw new IOException("expecting scale value, line " + rtok.lineno());
    }
    if (setTimes) {
        setScale(rtok.nval);
    }
    int numValues = 0;
    Order interpolationOrder;
    double timeStep;
    if (rtok.nextToken() != ReaderTokenizer.TT_WORD) {
        throw new IOException("expecting interpolation method, line " + rtok.lineno());
    }
    interpolationOrder = Order.fromString(rtok.sval);
    if (interpolationOrder == null) {
        if (rtok.sval.equalsIgnoreCase("linear")) {
            interpolationOrder = Order.Linear;
        } else if (rtok.sval.equalsIgnoreCase("step")) {
            interpolationOrder = Order.Step;
        } else if (rtok.sval.equalsIgnoreCase("cubic")) {
            interpolationOrder = Order.Cubic;
        } else {
            throw new IOException("unknown interpolation order '" + rtok.sval + "', line " + rtok.lineno());
        }
    }
    if (rtok.nextToken() != ReaderTokenizer.TT_NUMBER || (numValues = (int) rtok.nval) != rtok.nval) {
        throw new IOException("expecting number of values, line " + rtok.lineno());
    }
    if (rtok.nextToken() == ReaderTokenizer.TT_NUMBER) {
        timeStep = rtok.nval;
    } else if (rtok.ttype == ReaderTokenizer.TT_WORD && rtok.sval.equals("explicit")) {
        timeStep = EXPLICIT_TIME;
    } else {
        throw new IOException("expecting either a time step or the keyword 'explicit', line " + rtok.lineno());
    }
    // myNumericList = new NumericList (numValues);
    myNumericList = new NumericList(myVsize);
    myInterpolation.setOrder(interpolationOrder);
    myNumericList.setInterpolation(myInterpolation);
    addData(rtok, timeStep);
}
Also used : Order(maspack.interpolation.Interpolation.Order) NumericList(maspack.interpolation.NumericList)

Example 8 with NumericList

use of maspack.interpolation.NumericList in project artisynth_core by artisynth.

the class NumericOutputProbe method set.

public void set(Property[] props, String[] driverExpressions, String[] variableNames, PlotTraceInfo[] traceInfos) {
    if (variableNames.length != props.length) {
        throw new IllegalArgumentException("Number of variable names does not equal the number of properties");
    }
    NumericConverter[] newConverters = createConverters(props);
    LinkedHashMap<String, NumericProbeVariable> newVariables = new LinkedHashMap<String, NumericProbeVariable>();
    for (int i = 0; i < props.length; i++) {
        String name = variableNames[i];
        if (name == null || newVariables.get(name) != null) {
            throw new IllegalArgumentException("null or repeated variable name '" + name + "'");
        }
        if (!isValidVariableName(name)) {
            throw new IllegalArgumentException("variable name '" + name + "' is not a valid variable name");
        }
        newVariables.put(name, new NumericProbeVariable(newConverters[i].getDimension()));
    }
    ArrayList<NumericProbeDriver> newDrivers = createDrivers(driverExpressions, newVariables);
    myVsize = 0;
    for (int i = 0; i < newDrivers.size(); i++) {
        myVsize += newDrivers.get(i).getOutputSize();
    }
    myDrivers = newDrivers;
    myPropList = createPropertyList(props);
    myVariables = newVariables;
    myConverters = newConverters;
    myNumericList = new NumericList(myVsize);
    if (traceInfos != null) {
        myPlotTraceManager.rebuild(getPropsOrDimens(), traceInfos);
    } else {
        myPlotTraceManager.rebuild(getPropsOrDimens());
    }
    if (myLegend != null) {
        myLegend.rebuild();
    }
}
Also used : NumericConverter(maspack.properties.NumericConverter) NumericList(maspack.interpolation.NumericList)

Example 9 with NumericList

use of maspack.interpolation.NumericList in project artisynth_core by artisynth.

the class NumericProbeBase method createNumericList.

public void createNumericList(int vsize) {
    myVsize = vsize;
    myNumericList = new NumericList(myVsize);
    myNumericList.setInterpolation(myInterpolation);
}
Also used : NumericList(maspack.interpolation.NumericList)

Aggregations

NumericList (maspack.interpolation.NumericList)9 PlotTraceInfo (artisynth.core.probes.PlotTraceInfo)2 Point (java.awt.Point)2 Order (maspack.interpolation.Interpolation.Order)2 NumericListKnot (maspack.interpolation.NumericListKnot)2 VectorNd (maspack.matrix.VectorNd)2 NumericConverter (maspack.properties.NumericConverter)2 BasicStroke (java.awt.BasicStroke)1 Graphics2D (java.awt.Graphics2D)1 Interpolation (maspack.interpolation.Interpolation)1