Skip to content

Commit 05890b7

Browse files
ShadyBoukharyumar456
authored andcommitted
Added Window example and fixed linking error when callind Window() first
1 parent fa3d768 commit 05890b7

File tree

6 files changed

+56
-32
lines changed

6 files changed

+56
-32
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ ADD_JAR(${AF_JAR}
3232
com/arrayfire/Statistics.java
3333
com/util/JNIException.java
3434
com/arrayfire/ArrayFireException.java
35-
com/arrayfire/Window.java
3635
com/arrayfire/Graphics.java
36+
com/arrayfire/Window.java
3737
)
3838

3939
ADD_DEPENDENCIES(${AF_JAR} ${AF_LIB})

com/arrayfire/Graphics.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
package com.arrayfire;
22

3-
class Graphics {
3+
class Graphics extends ArrayFire {
44

55
public enum ColorMap {
6-
DEFAULT(0), SPECTRUM(1), COLORS(2), RED(3), MOOD(4), HEAT(5),
7-
BLUE(6), INFERNO(7), MAGMA(8), PLASMA(9), VIRIDIS(10);
6+
DEFAULT(0),
7+
SPECTRUM(1),
8+
COLORS(2),
9+
RED(3),
10+
MOOD(4),
11+
HEAT(5),
12+
BLUE(6),
13+
INFERNO(7),
14+
MAGMA(8),
15+
PLASMA(9),
16+
VIRIDIS(10);
817

918
private final int map;
1019

@@ -18,7 +27,14 @@ public int getMap() {
1827
}
1928

2029
public enum MarkerType {
21-
NONE(0), POINT(1), CIRCLE(2), SQUARE(3), TRIANGLE(4), CROSS(5), PLUS(6), STAR(7);
30+
NONE(0),
31+
POINT(1),
32+
CIRCLE(2),
33+
SQUARE(3),
34+
TRIANGLE(4),
35+
CROSS(5),
36+
PLUS(6),
37+
STAR(7);
2238

2339
private final int type;
2440

@@ -56,9 +72,9 @@ public static native void afDrawPlot3d(long wnd, long arrX, long arrY,
5672
public static native void afDrawScatternd(long wnd, long arr, int r, int c,
5773
int markerType, String title);
5874

59-
public static native void afDrawScatter2d(long wnd, long arrX, long arrY,
60-
int r, int c,
61-
int markerType, String title);
75+
public static native void afDrawScatter2d(long wnd, long arrX, long arrY,
76+
int r, int c,
77+
int markerType, String title);
6278

6379
public static native void afDrawScatter3d(long wnd, long arrX, long arrY,
6480
long arrZ, int r, int c,
@@ -112,5 +128,4 @@ public static native void afSetAxesLimits3d(long wnd, float xMin, float xMax,
112128
public static native boolean afClose(long wnd);
113129

114130
public static native void afSetVisibility(long wnd, boolean isVisible);
115-
116131
}

com/arrayfire/Window.java

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
import com.arrayfire.Graphics.ColorMap;
44
import com.arrayfire.Graphics.MarkerType;
5-
import com.sun.tools.jdeps.Graph;
6-
7-
import jdk.jfr.Unsigned;
85

96
public class Window implements AutoCloseable {
107

@@ -13,41 +10,41 @@ public class Window implements AutoCloseable {
1310
private int c;
1411
private ColorMap cmap;
1512

16-
public Window() {
13+
public Window() throws Exception {
1714
ref = 0;
1815
r = c = -1;
1916
cmap = ColorMap.DEFAULT;
2017
initWindow(1280, 720, "ArrayFire");
2118
}
2219

23-
public Window(String title) {
20+
public Window(String title) throws Exception {
2421
ref = 0;
2522
r = c = -1;
2623
cmap = ColorMap.DEFAULT;
2724
initWindow(1280, 720, title);
2825
}
2926

30-
public Window(int width, int height, String title) {
27+
public Window(int width, int height, String title) throws Exception {
3128
ref = 0;
3229
r = c = -1;
3330
cmap = ColorMap.DEFAULT;
3431
initWindow(width, height, title);
3532
}
3633

37-
public Window(int width, int height) {
34+
public Window(int width, int height) throws Exception {
3835
ref = 0;
3936
r = c = -1;
4037
cmap = ColorMap.DEFAULT;
4138
initWindow(width, height, "ArrayFire");
4239
}
4340

44-
public Window(long ref) {
41+
public Window(long ref) throws Exception {
4542
this.ref = ref;
4643
r = c = -1;
4744
cmap = ColorMap.DEFAULT;
4845
}
4946

50-
private void initWindow(int width, int height, String title) {
47+
private void initWindow(int width, int height, String title) throws Exception {
5148
ref = Graphics.afInitWindow(width, height, title);
5249
}
5350

@@ -58,15 +55,15 @@ protected void set(long ref) {
5855
this.ref = ref;
5956
}
6057

61-
public void setPos(@Unsigned int x, @Unsigned int y) {
58+
public void setPos(int x, int y) {
6259
Graphics.afSetPos(ref, x, y);
6360
}
6461

6562
public void setTitle(String title) {
6663
Graphics.afSetTitle(ref, title);
6764
}
6865

69-
public void setSize(@Unsigned int w, @Unsigned int h) {
66+
public void setSize(int w, int h) {
7067
Graphics.afSetSize(ref, w, h);
7168
}
7269

@@ -107,22 +104,27 @@ public void hist(final Array in, double min, double max, String title) {
107104
}
108105

109106
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);
107+
Graphics.afDrawSurface(ref, s.ref, xVals.ref, yVals.ref, r, c, title);
111108
}
112109

113110
public void vectorField(final Array points, final Array directions, String title) {
114111
Graphics.afDrawVectorFieldnd(ref, points.ref, directions.ref, r, c, title);
115112
}
116113

117-
public void vectorField(final Array xPoints, final Array yPoints, final Array xDirections, final Array yDirections,
114+
public void vectorField(final Array xPoints, final Array yPoints,
115+
final Array xDirections, final Array yDirections,
118116
String title) {
119-
Graphics.afDrawVectorField2d(ref, xPoints.ref, yPoints.ref, xDirections.ref, yDirections.ref, r, c, title);
117+
Graphics.afDrawVectorField2d(ref, xPoints.ref, yPoints.ref,
118+
xDirections.ref, yDirections.ref, r, c, title);
120119
}
121120

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);
121+
public void vectorField(final Array xPoints, final Array yPoints,
122+
final Array zPoints, final Array xDirections,
123+
final Array yDirections, final Array zDirections,
124+
String title) {
125+
Graphics.afDrawVectorField3d(ref, xPoints.ref, yPoints.ref, zPoints.ref,
126+
xDirections.ref, yDirections.ref,
127+
zDirections.ref, r, c, title);
126128
}
127129

128130
public void grid(int rows, int cols) {
@@ -133,16 +135,20 @@ public void setAxesLimits(final Array x, final Array y, boolean isExact) {
133135
Graphics.afSetAxesLimitsCompute(ref, x.ref, y.ref, 0, isExact, r, c);
134136
}
135137

136-
public void setAxesLimits(final Array x, final Array y, final Array z, boolean isExact) {
138+
public void setAxesLimits(final Array x, final Array y, final Array z,
139+
boolean isExact) {
137140
Graphics.afSetAxesLimitsCompute(ref, x.ref, y.ref, z.ref, isExact, r, c);
138141
}
139142

140-
public void setAxesLimits(float xMin, float xMax, float yMin, float yMax, boolean isExact) {
143+
public void setAxesLimits(float xMin, float xMax, float yMin, float yMax,
144+
boolean isExact) {
141145
Graphics.afSetAxesLimits2d(ref, xMin, xMax, yMin, yMax, isExact, r, c);
142146
}
143147

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);
148+
public void setAxesLimits(float xMin, float xMax, float yMin, float yMax,
149+
float zMin, float zMax, boolean isExact) {
150+
Graphics.afSetAxesLimits3d(ref, xMin, xMax, yMin, yMax, zMin, zMax, isExact,
151+
r, c);
146152
}
147153

148154
public void setAxesTitles(String xTitle, String yTitle, String zTitle) {

examples/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ macro(BUILD_EXAMPLE src)
2828
endmacro()
2929

3030
build_example(HelloWorld.java)
31+
build_example(WindowEx.java)
3132
build_example(MonteCarloPi.java)

examples/HelloWorld.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public static void main(String[] args) {
99
Array f = new Array();
1010
try {
1111
Util.info();
12+
1213
System.out.println("Create a 5-by-3 matrix of random floats on the GPU");
1314
Data.randu(a, new int[] { 5, 3 }, Array.FloatType);
1415
System.out.println(a.toString("a"));
@@ -113,6 +114,7 @@ public static void main(String[] args) {
113114
d.close();
114115
e.close();
115116
f.close();
117+
116118
} catch (Exception ex) {
117119
ex.printStackTrace();
118120
}

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ ADD_LIBRARY(${AF_LIB} SHARED
2525
util.cpp
2626
)
2727

28-
TARGET_LINK_LIBRARIES(${AF_LIB} ${JNI_LIBRARIES} ${ArrayFire_LIBRARIES})
28+
TARGET_LINK_LIBRARIES(${AF_LIB} ${JNI_LIBRARIES} ArrayFire::afopencl)
2929

3030
IF(${UNIX})
3131
SET(CMAKE_CXX_FLAGS "-fPIC")

0 commit comments

Comments
 (0)