Skip to content

Commit

Permalink
[API] ImPlot Performance Improvement (#115)
Browse files Browse the repository at this point in the history
* Make native array method public to enable use of primitive arrays.

* Make public methods for the performance methods that are separate from the native ones.

* Finish adding performance methods.

* Add finals.

* Add final finals.
  • Loading branch information
calvertdw committed Mar 1, 2022
1 parent 57cb0c9 commit bfbe56c
Showing 1 changed file with 136 additions and 1 deletion.
137 changes: 136 additions & 1 deletion imgui-binding/src/main/java/imgui/extension/implot/ImPlot.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,13 @@ public static <T extends Number> void plotLine(final String labelID, final T[] x
nPlotLine(labelID, x, y, x.length, offset);
}

/**
* Plots a standard 2D line plot.
*/
public static void plotLine(final String labelID, final double[] xs, final double[] ys, final int size, final int offset) {
nPlotLine(labelID, xs, ys, size, offset);
}

private static native void nPlotLine(String labelID, double[] xs, double[] ys, int size, int offset); /*
ImPlot::PlotLine(labelID, xs, ys, size, offset);
*/
Expand All @@ -325,6 +332,10 @@ public static <T extends Number> void plotScatter(final String labelID, final T[
nPlotScatter(labelID, x, y, x.length, offset);
}

public static void plotScatter(final String labelID, final double[] xs, final double[] ys, final int size, final int offset) {
nPlotScatter(labelID, xs, ys, size, offset);
}

private static native void nPlotScatter(String labelID, double[] xs, double[] ys, int size, int offset); /*
ImPlot::PlotScatter(labelID, xs, ys, size, offset);
*/
Expand All @@ -349,6 +360,13 @@ public static <T extends Number> void plotStairs(final String labelID, final T[]
nPlotStairs(labelID, x, y, x.length, offset);
}

/**
* Plots a a stairstep graph. The y value is continued constantly from every x position, i.e. the interval [x[i], x[i+1]) has the value y[i].
*/
public static void plotStairs(final String labelID, final double[] xs, final double[] ys, final int size, final int offset) {
nPlotStairs(labelID, xs, ys, size, offset);
}

private static native void nPlotStairs(String labelID, double[] xs, double[] ys, int size, int offset); /*
ImPlot::PlotStairs(labelID, xs, ys, size, offset);
*/
Expand Down Expand Up @@ -394,10 +412,24 @@ public static <T extends Number> void plotShaded(final String labelID, final T[]
nPlotShaded(labelID, x, y1, y2, x.length, offset);
}

/**
* Plots a shaded (filled) region between two lines, or a line and a horizontal reference. Set yRef (default 0) to +/-INFINITY for infinite fill extents.
*/
public static void plotShaded(final String labelID, final double[] xs, final double[] ys, final int size, final int yRef, final int offset) {
nPlotShaded(labelID, xs, ys, size, yRef, offset);
}

private static native void nPlotShaded(String labelID, double[] xs, double[] ys, int size, int yRef, int offset); /*
ImPlot::PlotShaded(labelID, xs, ys, size, yRef, offset);
*/

/**
* Plots a shaded (filled) region between two lines, or a line and a horizontal reference.
*/
public static void plotShaded(final String labelID, final double[] xs, final double[] ys1, final double[] ys2, final int size, final int offset) {
nPlotShaded(labelID, xs, ys1, ys2, size, offset);
}

private static native void nPlotShaded(String labelID, double[] xs, double[] ys1, double[] ys2, int size, int offset); /*
ImPlot::PlotShaded(labelID, xs, ys1, ys2, size, offset);
*/
Expand Down Expand Up @@ -432,6 +464,14 @@ public static <T extends Number> void plotBars(final String labelID, final T[] x
nPlotBars(labelID, x, y, x.length, width, offset);
}

/**
* Plots a vertical bar graph.
* @param width is in X units
*/
public static void plotBars(final String labelID, final double[] xs, final double[] ys, final int size, final float width, final int offset) {
nPlotBars(labelID, xs, ys, size, width, offset);
}

private static native void nPlotBars(String labelID, double[] xs, double[] ys, int size, float width, int offset); /*
ImPlot::PlotBars(labelID, xs, ys, size, width, offset);
*/
Expand Down Expand Up @@ -466,6 +506,14 @@ public static <T extends Number> void plotBarsH(final String labelID, final T[]
nPlotBarsH(labelID, x, y, x.length, height, offset);
}

/**
* Plots a horizontal bar graph.
* @param height is in Y units
*/
public static void plotBarsH(final String labelID, final double[] xs, final double[] ys, final int size, final float height, final int offset) {
nPlotBarsH(labelID, xs, ys, size, height, offset);
}

private static native void nPlotBarsH(String labelID, double[] xs, double[] ys, int size, float height, int offset); /*
ImPlot::PlotBarsH(labelID, xs, ys, size, height, offset);
*/
Expand All @@ -492,6 +540,13 @@ public static <T extends Number> void plotErrorBars(final String labelID, final
nPlotErrorBars(labelID, x, y, errOut, x.length, offset);
}

/**
* Plots vertical error bar. The labelID should be the same as the labelID of the associated line or bar plot.
*/
public static void plotErrorBars(final String labelID, final double[] xs, final double[] ys, final double[] err, final int size, final int offset) {
nPlotErrorBars(labelID, xs, ys, err, size, offset);
}

private static native void nPlotErrorBars(String labelID, double[] xs, double[] ys, double[] err, int size, int offset); /*
ImPlot::PlotErrorBars(labelID, xs, ys, err, size, offset);
*/
Expand All @@ -518,6 +573,13 @@ public static <T extends Number> void plotErrorBarsH(final String labelID, final
nPlotErrorBarsH(labelID, x, y, errOut, x.length, offset);
}

/**
* Plots horizontal error bar. The labelID should be the same as the labelID of the associated line or bar plot.
*/
public static void plotErrorBarsH(final String labelID, final double[] xs, final double[] ys, final double[] err, final int size, final int offset) {
nPlotErrorBarsH(labelID, xs, ys, err, size, offset);
}

private static native void nPlotErrorBarsH(String labelID, double[] xs, double[] ys, double[] err, int size, int offset); /*
ImPlot::PlotErrorBarsH(labelID, xs, ys, err, size, offset);
*/
Expand All @@ -543,6 +605,13 @@ public static <T extends Number> void plotStems(final String labelID, final T[]
nPlotStems(labelID, v, v.length, yRef, offset);
}

/**
* Plots vertical stems.
*/
public static void plotStems(final String labelID, final double[] values, final int size, final int yRef, final int offset) {
nPlotStems(labelID, values, size, yRef, offset);
}

private static native void nPlotStems(String labelID, double[] values, int size, int yRef, int offset); /*
ImPlot::PlotStems(labelID, values, size, yRef, offset);
*/
Expand All @@ -568,6 +637,13 @@ public static <T extends Number> void plotVLines(final String labelID, final T[]
nPlotVLines(labelID, v, v.length, offset);
}

/**
* Plots infinite vertical lines (e.g. for references or asymptotes).
*/
public static void plotVLines(final String labelID, final double[] values, final int size, final int offset) {
nPlotVLines(labelID, values, size, offset);
}

private static native void nPlotVLines(String labelID, double[] values, int size, int offset); /*
ImPlot::PlotVLines(labelID, values, size, offset);
*/
Expand All @@ -593,6 +669,13 @@ public static <T extends Number> void plotHLines(final String labelID, final T[]
nPlotHLines(labelID, v, v.length, offset);
}

/**
* Plots infinite horizontal lines (e.g. for references or asymptotes).
*/
public static void plotHLines(final String labelID, final double[] values, final int size, final int offset) {
nPlotHLines(labelID, values, size, offset);
}

private static native void nPlotHLines(String labelID, double[] values, int size, int offset); /*
ImPlot::PlotHLines(labelID, values, size, offset);
*/
Expand Down Expand Up @@ -627,6 +710,13 @@ public static <T extends Number> void plotPieChart(final String[] labelIDs, fina
nPlotPieChart(labelIDsSs, maxSize, v, v.length, x, y, radius);
}

/**
* Plots a pie chart. If the sum of values {@code >} 1, each value will be normalized. Center and radius are in plot units. #label_fmt can be set to NULL for no labels.
*/
public static void plotPieChart(final String labelIDsSs, final int strLen, final double[] values, final int size, final double x, final double y, final double radius) {
nPlotPieChart(labelIDsSs, strLen, values, size, x, y, radius);
}

//JNI function splits up passed string labelIDsSs to array for use in C++, as String[] is not converted by JNI
private static native void nPlotPieChart(String labelIDsSs, int strLen, double[] values, int size, double x, double y, double radius); /*
char** labelIDs = new char*[size];
Expand Down Expand Up @@ -670,6 +760,14 @@ public static <T extends Number> void plotHeatmap(final String labelID, final T[
nPlotHeatmap(labelID, v, values[0].length, values.length);
}

/**
* Plots a 2D heatmap chart.
* @param values must have fixed dimensions (all arrays are same length)
*/
public static void plotHeatmap(final String labelID, final double[] values, final int rows, final int cols) {
nPlotHeatmap(labelID, values, rows, cols);
}

private static native void nPlotHeatmap(String labelID, double[] values, int rows, int cols); /*
ImPlot::PlotHeatmap(labelID, values, rows, cols);
*/
Expand All @@ -693,6 +791,13 @@ public static <T extends Number> double plotHistogram(final String labelID, fina
return nPlotHistogram(labelID, v, v.length);
}

/**
* Plots a horizontal histogram.
*/
public static double plotHistogram(final String labelID, final double[] values, final int size) {
return nPlotHistogram(labelID, values, size);
}

private static native double nPlotHistogram(String labelID, double[] values, int size); /*
return ImPlot::PlotHistogram(labelID, values, size);
*/
Expand All @@ -709,6 +814,13 @@ public static <T extends Number> double plotHistogram2D(final String labelID, fi
return nPlotHistogram2D(labelID, x, y, x.length);
}

/**
* Plots two dimensional, bivariate histogram as a heatmap.
*/
public static double plotHistogram2D(final String labelID, final double[] xs, final double[] ys, final int size) {
return nPlotHistogram2D(labelID, xs, ys, size);
}

private static native double nPlotHistogram2D(String labelID, double[] xs, double[] ys, int size); /*
return ImPlot::PlotHistogram2D(labelID, xs, ys, size);
*/
Expand All @@ -730,6 +842,13 @@ public static <T extends Number> void plotDigital(final String labelID, final T[
nPlotDigital(labelID, x, y, x.length);
}

/**
* Plots digital data. Digital plots do not respond to y drag or zoom, and are always referenced to the bottom of the plot.
*/
public static void plotDigital(final String labelID, final double[] xs, final double[] ys, final int size) {
nPlotDigital(labelID, xs, ys, size);
}

private static native void nPlotDigital(String labelID, double[] xs, double[] ys, int size); /*
ImPlot::PlotDigital(labelID, xs, ys, size);
*/
Expand Down Expand Up @@ -865,6 +984,14 @@ public static void setNextPlotTicksX(final double xMin, final double xMax, final
nSetNextPlotTicksX(xMin, xMax, nTicks, labelStrings[0], labelStrings[1], labelStrings[2], labelStrings[3], keepDefault);
}

/**
* This function MUST be called BEFORE beginPlot!
* Set the X axis ticks and optionally the labels for the next plot. To keep the default ticks, set #keepDefault=true.
*/
public static void setNextPlotTicksX(final double xMin, final double xMax, final int nTicks, final String s1, final String s2, final String s3, final String s4, final boolean keepDefault) {
nSetNextPlotTicksX(xMin, xMax, nTicks, s1, s2, s3, s4, keepDefault);
}

private static native void nSetNextPlotTicksX(double xMin, double xMax, int nTicks, String s1, String s2, String s3, String s4, boolean keepDefault); /*
char* strings[] = {s1, s2, s3, s4};
ImPlot::SetNextPlotTicksX(xMin, xMax, nTicks, strings, keepDefault);
Expand Down Expand Up @@ -903,7 +1030,15 @@ public static void setNextPlotTicksY(final double xMin, final double xMax, final
nSetNextPlotTicksY(xMin, xMax, nTicks, labelStrings[0], labelStrings[1], labelStrings[2], labelStrings[3], keepDefault, yAxis);
}

public static native void nSetNextPlotTicksY(double xMin, double xMax, int nTicks, String s1, String s2, String s3, String s4, boolean keepDefault, int yAxis); /*
/**
* This function MUST be called BEFORE beginPlot!
* Set the Y axis ticks and optionally the labels for the next plot. To keep the default ticks, set #keepDefault=true.
*/
public static void setNextPlotTicksY(final double xMin, final double xMax, final int nTicks, final String s1, final String s2, final String s3, final String s4, final boolean keepDefault, final int yAxis) {
nSetNextPlotTicksY(xMin, xMax, nTicks, s1, s2, s3, s4, keepDefault, yAxis);
}

private static native void nSetNextPlotTicksY(double xMin, double xMax, int nTicks, String s1, String s2, String s3, String s4, boolean keepDefault, int yAxis); /*
char* strings[] = {s1, s2, s3, s4};
ImPlot::SetNextPlotTicksY(xMin, xMax, nTicks, strings, keepDefault, yAxis);
*/
Expand Down

0 comments on commit bfbe56c

Please sign in to comment.