|
| 1 | +package com.arrayfire; |
| 2 | + |
| 3 | +import com.arrayfire.Graphics.ColorMap; |
| 4 | +import com.arrayfire.Graphics.MarkerType; |
| 5 | +import com.sun.tools.jdeps.Graph; |
| 6 | + |
| 7 | +import jdk.jfr.Unsigned; |
| 8 | + |
| 9 | +public class Window implements AutoCloseable { |
| 10 | + |
| 11 | + protected long ref; |
| 12 | + private int r; |
| 13 | + private int c; |
| 14 | + private ColorMap cmap; |
| 15 | + |
| 16 | + public Window() { |
| 17 | + ref = 0; |
| 18 | + r = c = -1; |
| 19 | + cmap = ColorMap.DEFAULT; |
| 20 | + initWindow(1280, 720, "ArrayFire"); |
| 21 | + } |
| 22 | + |
| 23 | + public Window(String title) { |
| 24 | + ref = 0; |
| 25 | + r = c = -1; |
| 26 | + cmap = ColorMap.DEFAULT; |
| 27 | + initWindow(1280, 720, title); |
| 28 | + } |
| 29 | + |
| 30 | + public Window(int width, int height, String title) { |
| 31 | + ref = 0; |
| 32 | + r = c = -1; |
| 33 | + cmap = ColorMap.DEFAULT; |
| 34 | + initWindow(width, height, title); |
| 35 | + } |
| 36 | + |
| 37 | + public Window(int width, int height) { |
| 38 | + ref = 0; |
| 39 | + r = c = -1; |
| 40 | + cmap = ColorMap.DEFAULT; |
| 41 | + initWindow(width, height, "ArrayFire"); |
| 42 | + } |
| 43 | + |
| 44 | + public Window(long ref) { |
| 45 | + this.ref = ref; |
| 46 | + r = c = -1; |
| 47 | + cmap = ColorMap.DEFAULT; |
| 48 | + } |
| 49 | + |
| 50 | + private void initWindow(int width, int height, String title) { |
| 51 | + ref = Graphics.afInitWindow(width, height, title); |
| 52 | + } |
| 53 | + |
| 54 | + protected void set(long ref) { |
| 55 | + if (this.ref != 0) { |
| 56 | + Graphics.afDestroyWindow(this.ref); |
| 57 | + } |
| 58 | + this.ref = ref; |
| 59 | + } |
| 60 | + |
| 61 | + public void setPos(@Unsigned int x, @Unsigned int y) { |
| 62 | + Graphics.afSetPos(ref, x, y); |
| 63 | + } |
| 64 | + |
| 65 | + public void setTitle(String title) { |
| 66 | + Graphics.afSetTitle(ref, title); |
| 67 | + } |
| 68 | + |
| 69 | + public void setSize(@Unsigned int w, @Unsigned int h) { |
| 70 | + Graphics.afSetSize(ref, w, h); |
| 71 | + } |
| 72 | + |
| 73 | + public void setColorMap(ColorMap cmap) { |
| 74 | + this.cmap = cmap; |
| 75 | + } |
| 76 | + |
| 77 | + public void image(final Array in, String title) { |
| 78 | + Graphics.afDrawImage(ref, in.ref, r, c, title, cmap.getMap()); |
| 79 | + } |
| 80 | + |
| 81 | + public void plot(final Array in, String title) { |
| 82 | + Graphics.afDrawPlotnd(ref, in.ref, r, c, title); |
| 83 | + } |
| 84 | + |
| 85 | + public void plot(final Array x, final Array y, String title) { |
| 86 | + Graphics.afDrawPlot2d(ref, x.ref, y.ref, r, c, title); |
| 87 | + } |
| 88 | + |
| 89 | + public void plot(final Array x, final Array y, final Array z, String title) { |
| 90 | + Graphics.afDrawPlot3d(ref, x.ref, y.ref, z.ref, r, c, title); |
| 91 | + } |
| 92 | + |
| 93 | + public void scatter(final Array in, MarkerType type, String title) { |
| 94 | + Graphics.afDrawScatternd(ref, in.ref, r, c, type.getType(), title); |
| 95 | + } |
| 96 | + |
| 97 | + public void scatter(final Array x, final Array y, MarkerType type, String title) { |
| 98 | + Graphics.afDrawScatter2d(ref, x.ref, y.ref, c, r, type.getType(), title); |
| 99 | + } |
| 100 | + |
| 101 | + public void scatter(final Array x, final Array y, final Array z, MarkerType type, String title) { |
| 102 | + Graphics.afDrawScatter3d(ref, x.ref, y.ref, z.ref, c, r, type.getType(), title); |
| 103 | + } |
| 104 | + |
| 105 | + public void hist(final Array in, double min, double max, String title) { |
| 106 | + Graphics.afDrawHist(ref, in.ref, r, c, min, max, title); |
| 107 | + } |
| 108 | + |
| 109 | + public void surface(final Array xVals, final Array yVals, final Array s, String title) { |
| 110 | + Graphics.afDrawSurface(ref, s.ref, x.ref, y.ref, r, c, title); |
| 111 | + } |
| 112 | + |
| 113 | + public void vectorField(final Array points, final Array directions, String title) { |
| 114 | + Graphics.afDrawVectorFieldnd(ref, points.ref, directions.ref, r, c, title); |
| 115 | + } |
| 116 | + |
| 117 | + public void vectorField(final Array xPoints, final Array yPoints, final Array xDirections, final Array yDirections, |
| 118 | + String title) { |
| 119 | + Graphics.afDrawVectorField2d(ref, xPoints.ref, yPoints.ref, xDirections.ref, yDirections.ref, r, c, title); |
| 120 | + } |
| 121 | + |
| 122 | + public void vectorField(final Array xPoints, final Array yPoints, final Array zPoints, final Array xDirections, |
| 123 | + final Array yDirections, final Array zDirections, String title) { |
| 124 | + Graphics.afDrawVectorField3d(ref, xPoints.ref, yPoints.ref, zPoints.ref, xDirections.ref, yDirections.ref, |
| 125 | + zDirections.ref, r, c, title); |
| 126 | + } |
| 127 | + |
| 128 | + public void grid(int rows, int cols) { |
| 129 | + Graphics.afGrid(ref, rows, cols); |
| 130 | + } |
| 131 | + |
| 132 | + public void setAxesLimits(final Array x, final Array y, boolean isExact) { |
| 133 | + Graphics.afSetAxesLimitsCompute(ref, x.ref, y.ref, 0, isExact, r, c); |
| 134 | + } |
| 135 | + |
| 136 | + public void setAxesLimits(final Array x, final Array y, final Array z, boolean isExact) { |
| 137 | + Graphics.afSetAxesLimitsCompute(ref, x.ref, y.ref, z.ref, isExact, r, c); |
| 138 | + } |
| 139 | + |
| 140 | + public void setAxesLimits(float xMin, float xMax, float yMin, float yMax, boolean isExact) { |
| 141 | + Graphics.afSetAxesLimits2d(ref, xMin, xMax, yMin, yMax, isExact, r, c); |
| 142 | + } |
| 143 | + |
| 144 | + public void setAxesLimits(float xMin, float xMax, float yMin, float yMax, float zMin, float zMax, boolean isExact) { |
| 145 | + Graphics.afSetAxesLimits3d(ref, xMin, xMax, yMin, yMax, zMin, zMax, isExact, r, c); |
| 146 | + } |
| 147 | + |
| 148 | + public void setAxesTitles(String xTitle, String yTitle, String zTitle) { |
| 149 | + Graphics.afSetAxesTitles(xTitle, yTitle, zTitle); |
| 150 | + } |
| 151 | + |
| 152 | + public void show() { |
| 153 | + Graphics.afShow(ref); |
| 154 | + r = c = -1; |
| 155 | + } |
| 156 | + |
| 157 | + public boolean closeWindow() { |
| 158 | + return Graphics.afClose(ref); |
| 159 | + } |
| 160 | + |
| 161 | + public void setVisibility(boolean isVisible) { |
| 162 | + Graphics.afSetVisibility(ref, isVisible); |
| 163 | + } |
| 164 | + |
| 165 | + @Override |
| 166 | + public void close() throws Exception { |
| 167 | + if (ref != 0) { |
| 168 | + Graphics.afDestroyWindow(ref); |
| 169 | + } |
| 170 | + } |
| 171 | +} |
0 commit comments