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);
}
}
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);
}
}
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);
}
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));
}
}
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();
}
Aggregations