Skip to content

Commit bfbe56c

Browse files
authored
[API] ImPlot Performance Improvement (#115)
* 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.
1 parent 57cb0c9 commit bfbe56c

File tree

1 file changed

+136
-1
lines changed
  • imgui-binding/src/main/java/imgui/extension/implot

1 file changed

+136
-1
lines changed

imgui-binding/src/main/java/imgui/extension/implot/ImPlot.java

Lines changed: 136 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,13 @@ public static <T extends Number> void plotLine(final String labelID, final T[] x
301301
nPlotLine(labelID, x, y, x.length, offset);
302302
}
303303

304+
/**
305+
* Plots a standard 2D line plot.
306+
*/
307+
public static void plotLine(final String labelID, final double[] xs, final double[] ys, final int size, final int offset) {
308+
nPlotLine(labelID, xs, ys, size, offset);
309+
}
310+
304311
private static native void nPlotLine(String labelID, double[] xs, double[] ys, int size, int offset); /*
305312
ImPlot::PlotLine(labelID, xs, ys, size, offset);
306313
*/
@@ -325,6 +332,10 @@ public static <T extends Number> void plotScatter(final String labelID, final T[
325332
nPlotScatter(labelID, x, y, x.length, offset);
326333
}
327334

335+
public static void plotScatter(final String labelID, final double[] xs, final double[] ys, final int size, final int offset) {
336+
nPlotScatter(labelID, xs, ys, size, offset);
337+
}
338+
328339
private static native void nPlotScatter(String labelID, double[] xs, double[] ys, int size, int offset); /*
329340
ImPlot::PlotScatter(labelID, xs, ys, size, offset);
330341
*/
@@ -349,6 +360,13 @@ public static <T extends Number> void plotStairs(final String labelID, final T[]
349360
nPlotStairs(labelID, x, y, x.length, offset);
350361
}
351362

363+
/**
364+
* 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].
365+
*/
366+
public static void plotStairs(final String labelID, final double[] xs, final double[] ys, final int size, final int offset) {
367+
nPlotStairs(labelID, xs, ys, size, offset);
368+
}
369+
352370
private static native void nPlotStairs(String labelID, double[] xs, double[] ys, int size, int offset); /*
353371
ImPlot::PlotStairs(labelID, xs, ys, size, offset);
354372
*/
@@ -394,10 +412,24 @@ public static <T extends Number> void plotShaded(final String labelID, final T[]
394412
nPlotShaded(labelID, x, y1, y2, x.length, offset);
395413
}
396414

415+
/**
416+
* 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.
417+
*/
418+
public static void plotShaded(final String labelID, final double[] xs, final double[] ys, final int size, final int yRef, final int offset) {
419+
nPlotShaded(labelID, xs, ys, size, yRef, offset);
420+
}
421+
397422
private static native void nPlotShaded(String labelID, double[] xs, double[] ys, int size, int yRef, int offset); /*
398423
ImPlot::PlotShaded(labelID, xs, ys, size, yRef, offset);
399424
*/
400425

426+
/**
427+
* Plots a shaded (filled) region between two lines, or a line and a horizontal reference.
428+
*/
429+
public static void plotShaded(final String labelID, final double[] xs, final double[] ys1, final double[] ys2, final int size, final int offset) {
430+
nPlotShaded(labelID, xs, ys1, ys2, size, offset);
431+
}
432+
401433
private static native void nPlotShaded(String labelID, double[] xs, double[] ys1, double[] ys2, int size, int offset); /*
402434
ImPlot::PlotShaded(labelID, xs, ys1, ys2, size, offset);
403435
*/
@@ -432,6 +464,14 @@ public static <T extends Number> void plotBars(final String labelID, final T[] x
432464
nPlotBars(labelID, x, y, x.length, width, offset);
433465
}
434466

467+
/**
468+
* Plots a vertical bar graph.
469+
* @param width is in X units
470+
*/
471+
public static void plotBars(final String labelID, final double[] xs, final double[] ys, final int size, final float width, final int offset) {
472+
nPlotBars(labelID, xs, ys, size, width, offset);
473+
}
474+
435475
private static native void nPlotBars(String labelID, double[] xs, double[] ys, int size, float width, int offset); /*
436476
ImPlot::PlotBars(labelID, xs, ys, size, width, offset);
437477
*/
@@ -466,6 +506,14 @@ public static <T extends Number> void plotBarsH(final String labelID, final T[]
466506
nPlotBarsH(labelID, x, y, x.length, height, offset);
467507
}
468508

509+
/**
510+
* Plots a horizontal bar graph.
511+
* @param height is in Y units
512+
*/
513+
public static void plotBarsH(final String labelID, final double[] xs, final double[] ys, final int size, final float height, final int offset) {
514+
nPlotBarsH(labelID, xs, ys, size, height, offset);
515+
}
516+
469517
private static native void nPlotBarsH(String labelID, double[] xs, double[] ys, int size, float height, int offset); /*
470518
ImPlot::PlotBarsH(labelID, xs, ys, size, height, offset);
471519
*/
@@ -492,6 +540,13 @@ public static <T extends Number> void plotErrorBars(final String labelID, final
492540
nPlotErrorBars(labelID, x, y, errOut, x.length, offset);
493541
}
494542

543+
/**
544+
* Plots vertical error bar. The labelID should be the same as the labelID of the associated line or bar plot.
545+
*/
546+
public static void plotErrorBars(final String labelID, final double[] xs, final double[] ys, final double[] err, final int size, final int offset) {
547+
nPlotErrorBars(labelID, xs, ys, err, size, offset);
548+
}
549+
495550
private static native void nPlotErrorBars(String labelID, double[] xs, double[] ys, double[] err, int size, int offset); /*
496551
ImPlot::PlotErrorBars(labelID, xs, ys, err, size, offset);
497552
*/
@@ -518,6 +573,13 @@ public static <T extends Number> void plotErrorBarsH(final String labelID, final
518573
nPlotErrorBarsH(labelID, x, y, errOut, x.length, offset);
519574
}
520575

576+
/**
577+
* Plots horizontal error bar. The labelID should be the same as the labelID of the associated line or bar plot.
578+
*/
579+
public static void plotErrorBarsH(final String labelID, final double[] xs, final double[] ys, final double[] err, final int size, final int offset) {
580+
nPlotErrorBarsH(labelID, xs, ys, err, size, offset);
581+
}
582+
521583
private static native void nPlotErrorBarsH(String labelID, double[] xs, double[] ys, double[] err, int size, int offset); /*
522584
ImPlot::PlotErrorBarsH(labelID, xs, ys, err, size, offset);
523585
*/
@@ -543,6 +605,13 @@ public static <T extends Number> void plotStems(final String labelID, final T[]
543605
nPlotStems(labelID, v, v.length, yRef, offset);
544606
}
545607

608+
/**
609+
* Plots vertical stems.
610+
*/
611+
public static void plotStems(final String labelID, final double[] values, final int size, final int yRef, final int offset) {
612+
nPlotStems(labelID, values, size, yRef, offset);
613+
}
614+
546615
private static native void nPlotStems(String labelID, double[] values, int size, int yRef, int offset); /*
547616
ImPlot::PlotStems(labelID, values, size, yRef, offset);
548617
*/
@@ -568,6 +637,13 @@ public static <T extends Number> void plotVLines(final String labelID, final T[]
568637
nPlotVLines(labelID, v, v.length, offset);
569638
}
570639

640+
/**
641+
* Plots infinite vertical lines (e.g. for references or asymptotes).
642+
*/
643+
public static void plotVLines(final String labelID, final double[] values, final int size, final int offset) {
644+
nPlotVLines(labelID, values, size, offset);
645+
}
646+
571647
private static native void nPlotVLines(String labelID, double[] values, int size, int offset); /*
572648
ImPlot::PlotVLines(labelID, values, size, offset);
573649
*/
@@ -593,6 +669,13 @@ public static <T extends Number> void plotHLines(final String labelID, final T[]
593669
nPlotHLines(labelID, v, v.length, offset);
594670
}
595671

672+
/**
673+
* Plots infinite horizontal lines (e.g. for references or asymptotes).
674+
*/
675+
public static void plotHLines(final String labelID, final double[] values, final int size, final int offset) {
676+
nPlotHLines(labelID, values, size, offset);
677+
}
678+
596679
private static native void nPlotHLines(String labelID, double[] values, int size, int offset); /*
597680
ImPlot::PlotHLines(labelID, values, size, offset);
598681
*/
@@ -627,6 +710,13 @@ public static <T extends Number> void plotPieChart(final String[] labelIDs, fina
627710
nPlotPieChart(labelIDsSs, maxSize, v, v.length, x, y, radius);
628711
}
629712

713+
/**
714+
* 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.
715+
*/
716+
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) {
717+
nPlotPieChart(labelIDsSs, strLen, values, size, x, y, radius);
718+
}
719+
630720
//JNI function splits up passed string labelIDsSs to array for use in C++, as String[] is not converted by JNI
631721
private static native void nPlotPieChart(String labelIDsSs, int strLen, double[] values, int size, double x, double y, double radius); /*
632722
char** labelIDs = new char*[size];
@@ -670,6 +760,14 @@ public static <T extends Number> void plotHeatmap(final String labelID, final T[
670760
nPlotHeatmap(labelID, v, values[0].length, values.length);
671761
}
672762

763+
/**
764+
* Plots a 2D heatmap chart.
765+
* @param values must have fixed dimensions (all arrays are same length)
766+
*/
767+
public static void plotHeatmap(final String labelID, final double[] values, final int rows, final int cols) {
768+
nPlotHeatmap(labelID, values, rows, cols);
769+
}
770+
673771
private static native void nPlotHeatmap(String labelID, double[] values, int rows, int cols); /*
674772
ImPlot::PlotHeatmap(labelID, values, rows, cols);
675773
*/
@@ -693,6 +791,13 @@ public static <T extends Number> double plotHistogram(final String labelID, fina
693791
return nPlotHistogram(labelID, v, v.length);
694792
}
695793

794+
/**
795+
* Plots a horizontal histogram.
796+
*/
797+
public static double plotHistogram(final String labelID, final double[] values, final int size) {
798+
return nPlotHistogram(labelID, values, size);
799+
}
800+
696801
private static native double nPlotHistogram(String labelID, double[] values, int size); /*
697802
return ImPlot::PlotHistogram(labelID, values, size);
698803
*/
@@ -709,6 +814,13 @@ public static <T extends Number> double plotHistogram2D(final String labelID, fi
709814
return nPlotHistogram2D(labelID, x, y, x.length);
710815
}
711816

817+
/**
818+
* Plots two dimensional, bivariate histogram as a heatmap.
819+
*/
820+
public static double plotHistogram2D(final String labelID, final double[] xs, final double[] ys, final int size) {
821+
return nPlotHistogram2D(labelID, xs, ys, size);
822+
}
823+
712824
private static native double nPlotHistogram2D(String labelID, double[] xs, double[] ys, int size); /*
713825
return ImPlot::PlotHistogram2D(labelID, xs, ys, size);
714826
*/
@@ -730,6 +842,13 @@ public static <T extends Number> void plotDigital(final String labelID, final T[
730842
nPlotDigital(labelID, x, y, x.length);
731843
}
732844

845+
/**
846+
* Plots digital data. Digital plots do not respond to y drag or zoom, and are always referenced to the bottom of the plot.
847+
*/
848+
public static void plotDigital(final String labelID, final double[] xs, final double[] ys, final int size) {
849+
nPlotDigital(labelID, xs, ys, size);
850+
}
851+
733852
private static native void nPlotDigital(String labelID, double[] xs, double[] ys, int size); /*
734853
ImPlot::PlotDigital(labelID, xs, ys, size);
735854
*/
@@ -865,6 +984,14 @@ public static void setNextPlotTicksX(final double xMin, final double xMax, final
865984
nSetNextPlotTicksX(xMin, xMax, nTicks, labelStrings[0], labelStrings[1], labelStrings[2], labelStrings[3], keepDefault);
866985
}
867986

987+
/**
988+
* This function MUST be called BEFORE beginPlot!
989+
* Set the X axis ticks and optionally the labels for the next plot. To keep the default ticks, set #keepDefault=true.
990+
*/
991+
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) {
992+
nSetNextPlotTicksX(xMin, xMax, nTicks, s1, s2, s3, s4, keepDefault);
993+
}
994+
868995
private static native void nSetNextPlotTicksX(double xMin, double xMax, int nTicks, String s1, String s2, String s3, String s4, boolean keepDefault); /*
869996
char* strings[] = {s1, s2, s3, s4};
870997
ImPlot::SetNextPlotTicksX(xMin, xMax, nTicks, strings, keepDefault);
@@ -903,7 +1030,15 @@ public static void setNextPlotTicksY(final double xMin, final double xMax, final
9031030
nSetNextPlotTicksY(xMin, xMax, nTicks, labelStrings[0], labelStrings[1], labelStrings[2], labelStrings[3], keepDefault, yAxis);
9041031
}
9051032

906-
public static native void nSetNextPlotTicksY(double xMin, double xMax, int nTicks, String s1, String s2, String s3, String s4, boolean keepDefault, int yAxis); /*
1033+
/**
1034+
* This function MUST be called BEFORE beginPlot!
1035+
* Set the Y axis ticks and optionally the labels for the next plot. To keep the default ticks, set #keepDefault=true.
1036+
*/
1037+
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) {
1038+
nSetNextPlotTicksY(xMin, xMax, nTicks, s1, s2, s3, s4, keepDefault, yAxis);
1039+
}
1040+
1041+
private static native void nSetNextPlotTicksY(double xMin, double xMax, int nTicks, String s1, String s2, String s3, String s4, boolean keepDefault, int yAxis); /*
9071042
char* strings[] = {s1, s2, s3, s4};
9081043
ImPlot::SetNextPlotTicksY(xMin, xMax, nTicks, strings, keepDefault, yAxis);
9091044
*/

0 commit comments

Comments
 (0)