Search in sources :

Example 1 with NumericList

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

the class NumericProbePanel method drawKnots.

private void drawKnots(Graphics g) {
    if (drawKnotsP) {
        double timePerPixel = (maxXRange - minXRange) / getWidth();
        double yFactor = 1.0 / yValuePerPixel;
        NumericList list = myProbe.getNumericList();
        Iterator<NumericListKnot> it = list.iterator();
        // used only if we are not working in virtual time
        double probeScale = myProbe.getScale();
        double probeStartTime = myProbe.getStartTime();
        while (it.hasNext()) {
            NumericListKnot knot = it.next();
            double t = knot.t;
            if (!useVirtualTime) {
                // convert t to timeline time
                t = t * probeScale + probeStartTime;
            }
            int x = (int) ((t - minXRange) / timePerPixel);
            for (int v = knot.v.size() - 1; v >= 0; v--) {
                int idx = myProbe.getOrderedTraceIndex(v);
                PlotTraceInfo pti = myProbe.getPlotTraceInfo(idx);
                if (pti.isVisible()) {
                    g.setColor(pti.getColor());
                    double y = -(knot.v.get(idx) - maxYRange) * yFactor;
                    if (largeDisplay)
                        g.fillOval(x - 4, (int) y - 4, 8, 8);
                    else
                        g.fillRect(x - 2, (int) y - 2, 5, 5);
                }
            }
        }
    }
}
Also used : NumericListKnot(maspack.interpolation.NumericListKnot) NumericList(maspack.interpolation.NumericList) Point(java.awt.Point) PlotTraceInfo(artisynth.core.probes.PlotTraceInfo)

Example 2 with NumericList

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

the class NumericProbePanel method drawPlotLines.

private void drawPlotLines(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    NumericList list = myProbe.getNumericList();
    if (list != null) {
        int numXPixels = this.getWidth();
        NumericListKnot tempKnot;
        int yVectorSize = 0;
        int[] xInterpolationBuffer = null;
        int[][] yInterpolationBuffer = null;
        tempKnot = null;
        // Fix by Ian for interpolation before 1st knot point
        yVectorSize = list.getVectorSize();
        // VectorNd yVector = new VectorNd(yVectorSize);
        yVector.setSize(yVectorSize);
        xInterpolationBuffer = new int[numXPixels];
        yInterpolationBuffer = new int[yVectorSize][numXPixels + 1];
        double timePerPixel = (maxXRange - minXRange) / getWidth();
        tempKnot = null;
        double t;
        // used only if we are not working in virtual time
        double probeScale = myProbe.getScale();
        double probeStartTime = myProbe.getStartTime();
        // Create line plot
        for (int index = 0; index < numXPixels; index++) {
            t = minXRange + timePerPixel * index;
            if (!useVirtualTime) {
                // convert t back to virtual time
                t = (t - probeStartTime) / probeScale;
            }
            // we have to offset the time increment by the minimum x range
            // because we are not starting from zero
            tempKnot = list.interpolate(yVector, t, myProbe.getInterpolation(), tempKnot);
            xInterpolationBuffer[index] = index;
            for (int k = 0; k < yVectorSize; k++) {
                if (k < yVector.size()) {
                    yInterpolationBuffer[k][index] = (int) -((yVector.get(k) - maxYRange) / yValuePerPixel);
                }
            }
        }
        if (largeDisplay) {
            g2.setStroke(new BasicStroke(2));
        }
        // Draw line plot
        for (int k = yVectorSize - 1; k >= 0; k--) {
            int idx = myProbe.getOrderedTraceIndex(k);
            PlotTraceInfo pti = myProbe.getPlotTraceInfo(idx);
            if (pti.isVisible()) {
                g2.setColor(pti.getColor());
                g2.drawPolyline(xInterpolationBuffer, yInterpolationBuffer[idx], numXPixels);
            }
        }
    }
    myLastInterpolationOrder = myProbe.getInterpolationOrder();
}
Also used : BasicStroke(java.awt.BasicStroke) NumericListKnot(maspack.interpolation.NumericListKnot) NumericList(maspack.interpolation.NumericList) Point(java.awt.Point) Graphics2D(java.awt.Graphics2D) PlotTraceInfo(artisynth.core.probes.PlotTraceInfo)

Example 3 with NumericList

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

the class NumericControlProbe 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 4 with NumericList

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

the class NumericInputProbe method set.

public void set(Property[] props, String[] driverExpressions, String[] variableNames, int[] variableDimensions, PlotTraceInfo[] traceInfos) {
    if (props.length != driverExpressions.length) {
        throw new IllegalArgumentException("number of drivers must equal number of properties");
    }
    if (variableNames.length != variableDimensions.length) {
        throw new IllegalArgumentException("number of channels must equal number of variable names");
    }
    NumericConverter[] newConverters = createConverters(props);
    LinkedHashMap<String, NumericProbeVariable> newVariables = new LinkedHashMap<String, NumericProbeVariable>();
    int newVsize = 0;
    for (int i = 0; i < variableNames.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");
        }
        if (variableDimensions[i] <= 0) {
            throw new IllegalArgumentException("channel sizes must be greater than 0");
        }
        newVariables.put(name, new NumericProbeVariable(variableDimensions[i]));
        newVsize += variableDimensions[i];
    }
    ArrayList<NumericProbeDriver> newDrivers = createDrivers(driverExpressions, newVariables);
    myPropList = createPropertyList(props);
    myConverters = newConverters;
    // myPropValues = new double[props.length][];
    myVariables = newVariables;
    myDrivers = newDrivers;
    if (myNumericList == null || myVsize != newVsize) {
        myVsize = newVsize;
        myNumericList = new NumericList(myVsize);
        myNumericList.setInterpolation(myInterpolation);
        myTmpVec = new VectorNd(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) VectorNd(maspack.matrix.VectorNd)

Example 5 with NumericList

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

the class RigidTransformInputProbe method setRigid.

/**
 * Set the rigid body associated with this probe.
 *
 * This must only be called once in the lifetime of the probe. Reseting the
 * rigid body is not supported at the moment.  Create a new
 * RigidTransformInputProbe instead.
 *
 * @param rigid rigid body for this probe
 */
public void setRigid(RigidBody rigid) {
    if (rigid != null) {
        throw new UnsupportedOperationException("A rigid body has already been set! Aborting");
    }
    myRigid = rigid;
    /*
       * setup default interpolator
       */
    myTransAndQuaternParams = new NumericList(myVectorSize);
    myInterpolation = new Interpolation(Interpolation.Order.Linear, myExtendEnd);
    myTransAndQuaternParams.setInterpolation(myInterpolation);
    myTmpVec = new VectorNd(myVectorSize);
    setStartTime(0.);
    setStopTime(0.);
    setUpdateInterval(-1);
    setActive(true);
}
Also used : Interpolation(maspack.interpolation.Interpolation) NumericList(maspack.interpolation.NumericList) VectorNd(maspack.matrix.VectorNd)

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