use of maspack.interpolation.NumericListKnot 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);
}
}
}
}
}
use of maspack.interpolation.NumericListKnot 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();
}
use of maspack.interpolation.NumericListKnot in project artisynth_core by artisynth.
the class NumericControlProbe method loadEmpty.
public void loadEmpty() {
NumericListKnot knotStart = new NumericListKnot(myVsize);
NumericListKnot knotEnd = new NumericListKnot(myVsize);
knotStart.t = getStartTime();
knotEnd.t = getStopTime();
myNumericList.add(knotStart);
myNumericList.add(knotEnd);
}
use of maspack.interpolation.NumericListKnot in project artisynth_core by artisynth.
the class NumericControlProbe method addData.
/**
* Adds data to internal data list.
*
* @param t
* time in seconds
* @param v
* vector of values
*
* @throws IllegalArgumentException
* if size of vector is not equal to {@link #getVsize()}
*/
public void addData(double t, VectorNd v) {
if (v.size() != myVsize) {
throw new IllegalArgumentException("input vector has size " + v.size() + " vs. " + myVsize);
}
NumericListKnot knot = new NumericListKnot(myVsize);
knot.t = t;
knot.v.set(v);
myNumericList.add(knot);
// extendStopTimeIfNecessary();
}
use of maspack.interpolation.NumericListKnot in project artisynth_core by artisynth.
the class NumericControlProbe method write.
/**
* Writes the start and stop times, scale value, and data for this probe to a
* PrintWriter, using the format described for {@link #read(File,boolean)
* read(File)}. The format used for producing floating point numbers can be
* controlled using a printf-style format string, details of which are
* described in {@link maspack.util.NumberFormat NumberFormat}.
*
* @param pw
* writer which accepts the output
* @param fmtStr
* printf-style format string (if set to null then "%g" will be assumed,
* which will produce full precision output).
* @throws IOException
* if an I/O error occurs.
*/
public void write(PrintWriter pw, String fmtStr) throws IOException {
pw.println(getStartTime() + " " + getStopTime() + " " + myScale);
pw.print(myInterpolation.getOrder() + " " + myNumericList.getVectorSize());
pw.println(" explicit");
if (fmtStr == null) {
fmtStr = "%g";
}
NumberFormat fmt = new NumberFormat(fmtStr);
Iterator<NumericListKnot> it = myNumericList.iterator();
while (it.hasNext()) {
NumericListKnot knot = it.next();
pw.println(fmt.format(knot.t) + " " + knot.v.toString(fmt));
}
}
Aggregations