-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathgraphics.cpp
243 lines (209 loc) · 11 KB
/
graphics.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#include "jni_helper.h"
BEGIN_EXTERN_C
#define GRAPHICS_FUNC(FUNC) AF_MANGLE(Graphics, FUNC)
#define WND(ref) (void *)ref
JNIEXPORT jlong JNICALL GRAPHICS_FUNC(afInitWindow)(JNIEnv *env, jclass clazz,
jint width, jint height,
jstring name) {
af_window wnd;
const char *cName = env->GetStringUTFChars(name, 0);
AF_CHECK(af_create_window(&wnd, width, height, cName));
env->ReleaseStringUTFChars(name, cName);
return JLONG(wnd);
}
JNIEXPORT void JNICALL GRAPHICS_FUNC(afDestroyWindow)(JNIEnv *env, jclass clazz,
jlong wnd) {
AF_CHECK_VOID(af_destroy_window(WND(wnd)));
}
JNIEXPORT void JNICALL GRAPHICS_FUNC(afSetPos)(JNIEnv *env, jclass clazz,
jlong wnd, jint x, jint y) {
AF_CHECK_VOID(af_set_position(WND(wnd), x, y));
}
JNIEXPORT void JNICALL GRAPHICS_FUNC(afSetTitle)(JNIEnv *env, jclass clazz,
jlong wnd, jstring title) {
const char *cTitle = env->GetStringUTFChars(title, 0);
AF_CHECK_VOID(af_set_title(WND(wnd), cTitle));
env->ReleaseStringUTFChars(title, cTitle);
}
JNIEXPORT void JNICALL GRAPHICS_FUNC(afSetSize)(JNIEnv *env, jclass clazz,
jlong wnd, jint w, jint h) {
AF_CHECK_VOID(af_set_size(WND(wnd), w, h));
}
JNIEXPORT void JNICALL GRAPHICS_FUNC(afDrawImage)(JNIEnv *env, jclass clazz,
jlong wnd, jlong arr, jint r,
jint c, jstring title,
int cmap) {
const char *cTitle = env->GetStringUTFChars(title, 0);
af_cell props{r, c, cTitle, static_cast<af_colormap>(cmap)};
AF_CHECK_VOID(af_draw_image(WND(wnd), ARRAY(arr), &props));
env->ReleaseStringUTFChars(title, cTitle);
}
JNIEXPORT void JNICALL GRAPHICS_FUNC(afDrawPlotnd)(JNIEnv *env, jclass clazz,
jlong wnd, jlong arr, jint r,
jint c, jstring title) {
const char *cTitle = env->GetStringUTFChars(title, 0);
af_cell props{r, c, cTitle, AF_COLORMAP_DEFAULT};
AF_CHECK_VOID(af_draw_plot_nd(WND(wnd), ARRAY(arr), &props));
env->ReleaseStringUTFChars(title, cTitle);
}
JNIEXPORT void JNICALL GRAPHICS_FUNC(afDrawPlot2d)(JNIEnv *env, jclass clazz,
jlong wnd, jlong arrX,
jlong arrY, jint r, jint c,
jstring title) {
const char *cTitle = env->GetStringUTFChars(title, 0);
af_cell props{r, c, cTitle, AF_COLORMAP_DEFAULT};
AF_CHECK_VOID(af_draw_plot_2d(WND(wnd), ARRAY(arrX), ARRAY(arrY), &props));
env->ReleaseStringUTFChars(title, cTitle);
}
JNIEXPORT void JNICALL GRAPHICS_FUNC(afDrawPlot3d)(JNIEnv *env, jclass clazz,
jlong wnd, jlong arrX,
jlong arrY, jlong arrZ,
jint r, jint c,
jstring title) {
const char *cTitle = env->GetStringUTFChars(title, 0);
af_cell props{r, c, cTitle, AF_COLORMAP_DEFAULT};
AF_CHECK_VOID(
af_draw_plot_3d(WND(wnd), ARRAY(arrX), ARRAY(arrY), ARRAY(arrZ), &props));
env->ReleaseStringUTFChars(title, cTitle);
}
JNIEXPORT void JNICALL GRAPHICS_FUNC(afDrawScatternd)(JNIEnv *env, jclass clazz,
jlong wnd, jlong arr,
jint r, jint c,
jint markerType,
jstring title) {
const char *cTitle = env->GetStringUTFChars(title, 0);
af_cell props{r, c, cTitle, AF_COLORMAP_DEFAULT};
AF_CHECK_VOID(af_draw_scatter_nd(
WND(wnd), ARRAY(arr), static_cast<af_marker_type>(markerType), &props));
env->ReleaseStringUTFChars(title, cTitle);
}
JNIEXPORT void JNICALL GRAPHICS_FUNC(afDrawScatter2d)(JNIEnv *env, jclass clazz,
jlong wnd, jlong arrX,
jlong arrY, jint r,
jint c, jint markerType,
jstring title) {
const char *cTitle = env->GetStringUTFChars(title, 0);
af_cell props{r, c, cTitle, AF_COLORMAP_DEFAULT};
AF_CHECK_VOID(af_draw_scatter_2d(WND(wnd), ARRAY(arrX), ARRAY(arrY),
static_cast<af_marker_type>(markerType),
&props));
env->ReleaseStringUTFChars(title, cTitle);
}
JNIEXPORT void JNICALL GRAPHICS_FUNC(afDrawScatter3d)(
JNIEnv *env, jclass clazz, jlong wnd, jlong arrX, jlong arrY, jlong arrZ,
jint r, jint c, jint markerType, jstring title) {
const char *cTitle = env->GetStringUTFChars(title, 0);
af_cell props{r, c, cTitle, AF_COLORMAP_DEFAULT};
AF_CHECK_VOID(
af_draw_scatter_3d(WND(wnd), ARRAY(arrX), ARRAY(arrY), ARRAY(arrZ),
static_cast<af_marker_type>(markerType), &props));
env->ReleaseStringUTFChars(title, cTitle);
}
JNIEXPORT void JNICALL GRAPHICS_FUNC(afDrawHist)(JNIEnv *env, jclass clazz,
jlong wnd, jlong arr, jint r,
jint c, jdouble min,
jdouble max, jstring title) {
const char *cTitle = env->GetStringUTFChars(title, 0);
af_cell props{r, c, cTitle, AF_COLORMAP_DEFAULT};
AF_CHECK_VOID(af_draw_hist(WND(wnd), ARRAY(arr), min, max, &props));
env->ReleaseStringUTFChars(title, cTitle);
}
JNIEXPORT void JNICALL GRAPHICS_FUNC(afDrawSurface)(JNIEnv *env, jclass clazz,
jlong wnd, jlong arr,
jlong xVals, jlong yVals,
jint r, jint c,
jstring title) {
const char *cTitle = env->GetStringUTFChars(title, 0);
af_cell props{r, c, cTitle, AF_COLORMAP_DEFAULT};
AF_CHECK_VOID(af_draw_surface(WND(wnd), ARRAY(xVals), ARRAY(yVals),
ARRAY(arr), &props));
env->ReleaseStringUTFChars(title, cTitle);
}
JNIEXPORT void JNICALL GRAPHICS_FUNC(afDrawVectorFieldnd)(
JNIEnv *env, jclass clazz, jlong wnd, jlong points, jlong directions,
jint r, jint c, jstring title) {
const char *cTitle = env->GetStringUTFChars(title, 0);
af_cell props{r, c, cTitle, AF_COLORMAP_DEFAULT};
AF_CHECK_VOID(af_draw_vector_field_nd(WND(wnd), ARRAY(points),
ARRAY(directions), &props));
env->ReleaseStringUTFChars(title, cTitle);
}
JNIEXPORT void JNICALL GRAPHICS_FUNC(afDrawVectorField2d)(
JNIEnv *env, jclass clazz, jlong wnd, jlong xPoints, jlong yPoints,
jlong xDirections, jlong yDirections, jint r, jint c, jstring title) {
const char *cTitle = env->GetStringUTFChars(title, 0);
af_cell props{r, c, cTitle, AF_COLORMAP_DEFAULT};
AF_CHECK_VOID(af_draw_vector_field_2d(WND(wnd), ARRAY(xPoints),
ARRAY(yPoints), ARRAY(xDirections),
ARRAY(yDirections), &props));
env->ReleaseStringUTFChars(title, cTitle);
}
JNIEXPORT void JNICALL GRAPHICS_FUNC(afDrawVectorField3d)(
JNIEnv *env, jclass clazz, jlong wnd, jlong xPoints, jlong yPoints,
jlong zPoints, jlong xDirections, jlong yDirections, jlong zDirections,
jint r, jint c, jstring title) {
const char *cTitle = env->GetStringUTFChars(title, 0);
af_cell props{r, c, cTitle, AF_COLORMAP_DEFAULT};
AF_CHECK_VOID(af_draw_vector_field_3d(
WND(wnd), ARRAY(xPoints), ARRAY(yPoints), ARRAY(zPoints),
ARRAY(xDirections), ARRAY(yDirections), ARRAY(zDirections), &props));
env->ReleaseStringUTFChars(title, cTitle);
}
JNIEXPORT void JNICALL GRAPHICS_FUNC(afGrid)(JNIEnv *env, jclass clazz,
jlong wnd, jint rows,
jint columns) {
AF_CHECK_VOID(af_grid(WND(wnd), rows, columns));
}
JNIEXPORT void JNICALL GRAPHICS_FUNC(afSetAxesLimitsCompute)(
JNIEnv *env, jclass clazz, jlong wnd, jlong arrX, jlong arrY, jlong arrZ,
jboolean isExact, jint r, jint c) {
af_cell props{r, c, NULL, AF_COLORMAP_DEFAULT};
AF_CHECK_VOID(af_set_axes_limits_compute(WND(wnd), ARRAY(arrX), ARRAY(arrY),
arrZ > 0 ? ARRAY(arrZ) : NULL,
isExact, &props));
}
JNIEXPORT void JNICALL GRAPHICS_FUNC(afSetAxesLimits2d)(
JNIEnv *env, jclass clazz, jlong wnd, jfloat xMin, jfloat xMax, jfloat yMin,
jfloat yMax, jboolean isExact, jint r, jint c) {
af_cell props{r, c, NULL, AF_COLORMAP_DEFAULT};
AF_CHECK_VOID(
af_set_axes_limits_2d(WND(wnd), xMin, xMax, yMin, yMax, isExact, &props));
}
JNIEXPORT void JNICALL GRAPHICS_FUNC(afSetAxesLimits3d)(
JNIEnv *env, jclass clazz, jlong wnd, jfloat xMin, jfloat xMax, jfloat yMin,
jfloat yMax, jfloat zMin, jfloat zMax, jboolean isExact, jint r, jint c) {
af_cell props{r, c, NULL, AF_COLORMAP_DEFAULT};
AF_CHECK_VOID(af_set_axes_limits_3d(WND(wnd), xMin, xMax, yMin, yMax, zMin,
zMax, isExact, &props));
}
JNIEXPORT void JNICALL GRAPHICS_FUNC(afSetAxesTitles)(JNIEnv *env, jclass clazz,
jlong wnd, jstring xTitle,
jstring yTitle,
jstring zTitle, jint r,
jint c) {
af_cell props{r, c, NULL, AF_COLORMAP_DEFAULT};
const char *cXTitle = env->GetStringUTFChars(xTitle, 0);
const char *cYTitle = env->GetStringUTFChars(yTitle, 0);
const char *cZTitle = env->GetStringUTFChars(zTitle, 0);
AF_CHECK_VOID(
af_set_axes_titles(WND(wnd), cXTitle, cYTitle, cZTitle, &props));
env->ReleaseStringUTFChars(xTitle, cXTitle);
env->ReleaseStringUTFChars(yTitle, cYTitle);
env->ReleaseStringUTFChars(zTitle, cZTitle);
}
JNIEXPORT void JNICALL GRAPHICS_FUNC(afShow)(JNIEnv *env, jclass clazz,
jlong wnd) {
AF_CHECK_VOID(af_show(WND(wnd)));
}
JNIEXPORT jboolean JNICALL GRAPHICS_FUNC(afClose)(JNIEnv *env, jclass clazz,
jlong wnd) {
bool closed = true;
AF_CHECK(af_is_window_closed(&closed, WND(wnd)));
return (jboolean)closed;
}
JNIEXPORT void JNICALL GRAPHICS_FUNC(afSetVisibility)(JNIEnv *env, jclass clazz,
jlong wnd,
jboolean isVisible) {
AF_CHECK_VOID(af_set_visibility(WND(wnd), isVisible));
}
END_EXTERN_C