Search in sources :

Example 6 with NumericListKnot

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

the class NumericInputProbe method addData.

public void addData(ReaderTokenizer rtok, double timeStep) throws IOException {
    double time = 0;
    // If zero vector size, don't bother adding data
    if (myVsize == 0) {
        return;
    }
    while (rtok.nextToken() != ReaderTokenizer.TT_EOF) {
        NumericListKnot knot = new NumericListKnot(myVsize);
        if (timeStep == EXPLICIT_TIME) {
            if (rtok.ttype != ReaderTokenizer.TT_NUMBER) {
                throw new IOException("Expected time value, line " + rtok.lineno());
            }
            knot.t = rtok.nval;
            time = knot.t;
        } else {
            knot.t = time;
            time += timeStep;
            rtok.pushBack();
        }
        if (rtok.scanNumbers(knot.v.getBuffer(), myVsize) != myVsize) {
            if (rtok.ttype == ReaderTokenizer.TT_EOF) {
                return;
            } else {
                throw new IOException("Unexpected token " + rtok.tokenName() + ", line " + rtok.lineno());
            }
        }
        myNumericList.add(knot);
    }
}
Also used : NumericListKnot(maspack.interpolation.NumericListKnot)

Example 7 with NumericListKnot

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

the class RigidTransformInputProbe method addTransform.

public void addTransform(double t, RigidTransform3d tx) {
    VectorNd posVector = new VectorNd();
    Vector3d offset = tx.getOffset();
    posVector.append(offset.x);
    posVector.append(offset.y);
    posVector.append(offset.z);
    RotationMatrix3d rot = new RotationMatrix3d();
    Vector3d scale = new Vector3d();
    Matrix3d shear = new Matrix3d();
    tx.getMatrixComponents(rot, scale, shear);
    Quaternion q = new Quaternion(rot.getAxisAngle());
    posVector.append(q.s);
    posVector.append(q.u.x);
    posVector.append(q.u.y);
    posVector.append(q.u.z);
    NumericListKnot knot = new NumericListKnot(myVectorSize);
    knot.t = t;
    knot.v.set(posVector);
    myTransAndQuaternParams.add(knot);
    if (t < getStartTime()) {
        setStartTime(t);
    }
    if (t > getStopTime()) {
        setStopTime(t);
    }
}
Also used : RotationMatrix3d(maspack.matrix.RotationMatrix3d) Matrix3d(maspack.matrix.Matrix3d) NumericListKnot(maspack.interpolation.NumericListKnot) Vector3d(maspack.matrix.Vector3d) Quaternion(maspack.matrix.Quaternion) VectorNd(maspack.matrix.VectorNd) RotationMatrix3d(maspack.matrix.RotationMatrix3d)

Example 8 with NumericListKnot

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

the class NumericOutputProbe method apply.

public void apply(double t) {
    if (myPropList == null) {
        throw new ImproperStateException("probe not initialized");
    }
    // XXX don't we want to apply scaling here too?
    double tloc = (t - getStartTime()) / myScale;
    NumericListKnot knot = new NumericListKnot(myVsize);
    int i = 0;
    for (NumericProbeVariable var : myVariables.values()) {
        Object obj = myPropList.get(i).get();
        var.setValues(myConverters[i].objectToArray(obj));
        i++;
    }
    updateJythonVariables(myVariables, tloc);
    int k = 0;
    double[] buf = knot.v.getBuffer();
    for (NumericProbeDriver driver : myDrivers) {
        double[] vals = driver.eval(myVariables, myJythonLocals);
        for (int j = 0; j < vals.length; j++) {
            buf[k++] = vals[j];
        }
    }
    knot.t = tloc;
    myNumericList.add(knot);
    myNumericList.clearAfter(knot);
}
Also used : NumericListKnot(maspack.interpolation.NumericListKnot) ImproperStateException(maspack.matrix.ImproperStateException)

Example 9 with NumericListKnot

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

the class NumericOutputProbe method writeData.

public void writeData(PrintWriter pw, String fmtStr, boolean showTime) {
    NumberFormat timeFmt = null;
    if (showTime) {
        if (getUpdateInterval() < 1e-5) {
            timeFmt = new NumberFormat("%12.9f");
        } else {
            timeFmt = new NumberFormat("%9.6f");
        }
    }
    NumberFormat fmt = new NumberFormat(fmtStr);
    Iterator<NumericListKnot> it = myNumericList.iterator();
    while (it.hasNext()) {
        NumericListKnot knot = it.next();
        if (showTime) {
            pw.print(timeFmt.format(knot.t) + " ");
        }
        pw.println(knot.v.toString(fmt));
    }
}
Also used : NumericListKnot(maspack.interpolation.NumericListKnot)

Example 10 with NumericListKnot

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

the class NumericProbeBase method scaleNumericList.

/**
 * Scales the values of a numberic probe. Method added by Chad. author: Chad
 * Scales the values of a numberic probe.
 *
 * @param scale
 * the parameter by which to scale the values.
 */
public void scaleNumericList(double scale) {
    Iterator numericListIterator = myNumericList.iterator();
    NumericListKnot datavalue = null;
    VectorNd yVector = null;
    double[] vectorArray = null;
    while (numericListIterator.hasNext()) {
        datavalue = (NumericListKnot) numericListIterator.next();
        yVector = datavalue.v;
        vectorArray = yVector.getBuffer();
        for (int i = 0; i < yVector.size(); i++) {
            // System.out.print(vectorArray[i]+ ",");
            vectorArray[i] *= scale;
        // System.out.println(vectorArray[i]);
        }
    }
    updateDisplays();
}
Also used : NumericListKnot(maspack.interpolation.NumericListKnot) VectorNd(maspack.matrix.VectorNd)

Aggregations

NumericListKnot (maspack.interpolation.NumericListKnot)24 VectorNd (maspack.matrix.VectorNd)3 PlotTraceInfo (artisynth.core.probes.PlotTraceInfo)2 Point (java.awt.Point)2 NumericList (maspack.interpolation.NumericList)2 BasicStroke (java.awt.BasicStroke)1 Graphics2D (java.awt.Graphics2D)1 ImproperStateException (maspack.matrix.ImproperStateException)1 Matrix3d (maspack.matrix.Matrix3d)1 Point3d (maspack.matrix.Point3d)1 Quaternion (maspack.matrix.Quaternion)1 RotationMatrix3d (maspack.matrix.RotationMatrix3d)1 Vector3d (maspack.matrix.Vector3d)1