A high-performance general-purpose compute library
graphics.h
Go to the documentation of this file.
1/*******************************************************
2 * Copyright (c) 2014, ArrayFire
3 * All rights reserved.
4 *
5 * This file is distributed under 3-clause BSD license.
6 * The complete license agreement can be obtained at:
7 * http://arrayfire.com/licenses/BSD-3-Clause
8 ********************************************************/
9
10#pragma once
11
12#include <af/defines.h>
13#include <af/array.h>
14
15typedef void* af_window;
16
17typedef struct {
18 int row;
19 int col;
20 const char* title;
22} af_cell;
23
24#ifdef __cplusplus
25namespace af
26{
27
38 private:
39 af_window wnd;
40 /* below attributes are used to track which
41 * cell in the grid is being rendered currently */
42 int _r;
43 int _c;
44 ColorMap _cmap;
45
46 void initWindow(const int width, const int height, const char* const title);
47
48 Window(const Window&); // Prevent copy-construction
49 Window& operator=(const Window&); // Prevent assignment
50
51 public:
59
68 Window(const char* const title);
69
80 Window(const int width, const int height, const char* const title="ArrayFire");
81
92 Window(const af_window window);
93
100
101 // FIXME handle copying properly
102
108 af_window get() const { return wnd; }
109
118 void setPos(const unsigned x, const unsigned y);
119
127 void setTitle(const char* const title);
128
129#if AF_API_VERSION >= 31
138 void setSize(const unsigned w, const unsigned h);
139#endif
140
148 void setColorMap(const ColorMap cmap);
149
160 void image(const array& in, const char* title=NULL);
161
162#if AF_API_VERSION >= 32
173 AF_DEPRECATED("Use plot instead")
174 void plot3(const array& in, const char* title=NULL);
175#endif
176
177#if AF_API_VERSION >= 34
189 void plot(const array& in, const char* const title=NULL);
190#endif
191
192#if AF_API_VERSION >= 34
205 void plot(const array& X, const array& Y, const array& Z, const char* const title=NULL);
206#endif
207
219 void plot(const array& X, const array& Y, const char* const title=NULL);
220
221#if AF_API_VERSION >= 34
234 void scatter(const array& in, const af::markerType marker = AF_MARKER_POINT,
235 const char* const title = NULL);
236#endif
237
238#if AF_API_VERSION >= 34
252 void scatter(const array& X, const array& Y, const array& Z,
253 const af::markerType marker = AF_MARKER_POINT, const char* const title = NULL);
254#endif
255
256#if AF_API_VERSION >= 33
269 void scatter(const array& X, const array& Y,
270 const af::markerType marker = AF_MARKER_POINT, const char* const title = NULL);
271#endif
272
273#if AF_API_VERSION >= 33
283 AF_DEPRECATED("Use scatter instead")
284 void scatter3(const array& P, const af::markerType marker = AF_MARKER_POINT,
285 const char* const title = NULL);
286#endif
287
300 void hist(const array& X, const double minval, const double maxval, const char* const title=NULL);
301
302#if AF_API_VERSION >= 32
313 void surface(const array& S, const char* const title = NULL);
314#endif
315
316#if AF_API_VERSION >= 32
329 void surface(const array& xVals, const array& yVals, const array& S, const char* const title = NULL);
330#endif
331
332#if AF_API_VERSION >= 34
349 void vectorField(const array& points, const array& directions, const char* const title = NULL);
350#endif
351
352#if AF_API_VERSION >= 34
368 void vectorField(const array& xPoints, const array& yPoints, const array& zPoints,
369 const array& xDirs , const array& yDirs , const array& zDirs ,
370 const char* const title = NULL);
371#endif
372
373#if AF_API_VERSION >= 34
387 void vectorField(const array& xPoints, const array& yPoints,
388 const array& xDirs , const array& yDirs ,
389 const char* const title = NULL);
390#endif
391
392#if AF_API_VERSION >= 34
406 void setAxesLimits(const array &x, const array &y, const bool exact = false);
407#endif
408
409#if AF_API_VERSION >= 34
424 void setAxesLimits(const array &x, const array &y, const array &z,
425 const bool exact = false);
426#endif
427
428#if AF_API_VERSION >= 34
444 void setAxesLimits(const float xmin, const float xmax,
445 const float ymin, const float ymax,
446 const bool exact = false);
447#endif
448
449#if AF_API_VERSION >= 34
467 void setAxesLimits(const float xmin, const float xmax,
468 const float ymin, const float ymax,
469 const float zmin, const float zmax,
470 const bool exact = false);
471#endif
472
473#if AF_API_VERSION >= 34
485 void setAxesTitles(const char * const xtitle = "X-Axis",
486 const char * const ytitle = "Y-Axis",
487 const char * const ztitle = NULL);
488#endif
489
490#if AF_API_VERSION >= 37
500 void setAxesLabelFormat(const char *const xformat = "4.1%f",
501 const char *const yformat = "4.1%f",
502 const char *const zformat = NULL);
503#endif
504
513 void grid(const int rows, const int cols);
514
521 void show();
522
532 bool close();
533
534#if AF_API_VERSION >= 33
542 void setVisibility(const bool isVisible);
543#endif
544
560 inline Window& operator()(const int r, const int c) {
561 _r = r; _c = c;
562 return *this;
563 }
564};
565
566}
567#endif
568
569#ifdef __cplusplus
570extern "C" {
571#endif
572
586AFAPI af_err af_create_window(af_window *out, const int width, const int height, const char* const title);
587
600AFAPI af_err af_set_position(const af_window wind, const unsigned x, const unsigned y);
601
613AFAPI af_err af_set_title(const af_window wind, const char* const title);
614
615#if AF_API_VERSION >= 31
628AFAPI af_err af_set_size(const af_window wind, const unsigned w, const unsigned h);
629#endif
630
646AFAPI af_err af_draw_image(const af_window wind, const af_array in, const af_cell* const props);
647
664AF_DEPRECATED("Use af_draw_plot_nd or af_draw_plot_2d instead")
665AFAPI af_err af_draw_plot(const af_window wind, const af_array X, const af_array Y, const af_cell* const props);
666
667#if AF_API_VERSION >= 32
683AF_DEPRECATED("Use af_draw_plot_nd or af_draw_plot_3d instead")
684AFAPI af_err af_draw_plot3(const af_window wind, const af_array P, const af_cell* const props);
685#endif
686
687#if AF_API_VERSION >= 34
704AFAPI af_err af_draw_plot_nd(const af_window wind, const af_array P, const af_cell* const props);
705#endif
706
707#if AF_API_VERSION >= 34
725 const af_cell* const props);
726#endif
727
728#if AF_API_VERSION >= 34
747 const af_array X, const af_array Y, const af_array Z,
748 const af_cell* const props);
749#endif
750
751#if AF_API_VERSION >= 33
769AF_DEPRECATED("Use af_draw_scatter_nd or af_draw_scatter_2d instead")
771 const af_marker_type marker, const af_cell* const props);
772#endif
773
774#if AF_API_VERSION >= 33
789AF_DEPRECATED("Use af_draw_scatter_nd or af_draw_scatter_3d instead")
791 const af_marker_type marker, const af_cell* const props);
792#endif
793
794#if AF_API_VERSION >= 34
813 const af_marker_type marker, const af_cell* const props);
814#endif
815
816#if AF_API_VERSION >= 34
835 const af_marker_type marker, const af_cell* const props);
836#endif
837
838#if AF_API_VERSION >= 34
858 const af_array X, const af_array Y, const af_array Z,
859 const af_marker_type marker, const af_cell* const props);
860#endif
861
879AFAPI af_err af_draw_hist(const af_window wind, const af_array X, const double minval, const double maxval, const af_cell* const props);
880
881#if AF_API_VERSION >= 32
899AFAPI af_err af_draw_surface(const af_window wind, const af_array xVals, const af_array yVals, const af_array S, const af_cell* const props);
900#endif
901
902#if AF_API_VERSION >= 34
927 const af_array points, const af_array directions,
928 const af_cell* const props);
929#endif
930
931#if AF_API_VERSION >= 34
953 const af_window wind,
954 const af_array xPoints, const af_array yPoints, const af_array zPoints,
955 const af_array xDirs, const af_array yDirs, const af_array zDirs,
956 const af_cell* const props);
957#endif
958
959#if AF_API_VERSION >= 34
979 const af_window wind,
980 const af_array xPoints, const af_array yPoints,
981 const af_array xDirs, const af_array yDirs,
982 const af_cell* const props);
983#endif
984
997AFAPI af_err af_grid(const af_window wind, const int rows, const int cols);
998
999#if AF_API_VERSION >= 34
1020 const af_array x, const af_array y, const af_array z,
1021 const bool exact,
1022 const af_cell* const props);
1023#endif
1024
1025#if AF_API_VERSION >= 34
1045 const float xmin, const float xmax,
1046 const float ymin, const float ymax,
1047 const bool exact,
1048 const af_cell* const props);
1049#endif
1050
1051#if AF_API_VERSION >= 34
1073 const float xmin, const float xmax,
1074 const float ymin, const float ymax,
1075 const float zmin, const float zmax,
1076 const bool exact,
1077 const af_cell* const props);
1078#endif
1079
1080#if AF_API_VERSION >= 34
1102 const char * const xtitle,
1103 const char * const ytitle,
1104 const char * const ztitle,
1105 const af_cell* const props);
1106#endif
1107
1108#if AF_API_VERSION >= 37
1131 const char *const xformat,
1132 const char *const yformat,
1133 const char *const zformat,
1134 const af_cell *const props);
1135#endif
1136
1148
1162
1163#if AF_API_VERSION >= 33
1172AFAPI af_err af_set_visibility(const af_window wind, const bool is_visible);
1173#endif
1174
1186
1187#ifdef __cplusplus
1188}
1189
1190#endif
Window object to render af::arrays.
Definition: graphics.h:37
Window & operator()(const int r, const int c)
This function is used to keep track of which cell in the grid mode is being currently rendered.
Definition: graphics.h:560
A multi dimensional data container.
Definition: array.h:37
af_colormap
Definition: defines.h:454
af_err
Definition: defines.h:71
void * af_array
Definition: defines.h:240
#define AF_DEPRECATED(msg)
Definition: defines.h:44
#define AFAPI
Definition: defines.h:38
af_marker_type
Definition: defines.h:469
@ AF_MARKER_POINT
Definition: defines.h:471
void * af_window
Definition: graphics.h:15
void surface(const array &S, const char *const title=NULL)
Renders the input arrays as a 3D surface plot to the window.
void plot(const array &X, const array &Y, const array &Z, const char *const title=NULL)
Renders the input arrays as a 3D plot to the window.
AFAPI af_err af_draw_scatter_3d(const af_window wind, const af_array X, const af_array Y, const af_array Z, const af_marker_type marker, const af_cell *const props)
C Interface wrapper for drawing an array as a 3D plot.
void surface(const array &xVals, const array &yVals, const array &S, const char *const title=NULL)
Renders the input arrays as a 3D surface plot to the window.
AFAPI af_err af_draw_vector_field_nd(const af_window wind, const af_array points, const af_array directions, const af_cell *const props)
C Interface wrapper for drawing array's as a 2D or 3D vector field.
AFAPI af_err af_draw_scatter(const af_window wind, const af_array X, const af_array Y, const af_marker_type marker, const af_cell *const props)
C Interface wrapper for drawing an array as a plot.
void vectorField(const array &xPoints, const array &yPoints, const array &zPoints, const array &xDirs, const array &yDirs, const array &zDirs, const char *const title=NULL)
Renders the input arrays as a 3D vector field plot to the window.
void vectorField(const array &points, const array &directions, const char *const title=NULL)
Renders the input arrays as a 2D or 3D vector field plot to the window.
AFAPI af_err af_draw_image(const af_window wind, const af_array in, const af_cell *const props)
C Interface wrapper for drawing an array as an image.
AFAPI af_err af_draw_plot_2d(const af_window wind, const af_array X, const af_array Y, const af_cell *const props)
C Interface wrapper for drawing an array as a 2D plot.
void scatter(const array &X, const array &Y, const af::markerType marker=AF_MARKER_POINT, const char *const title=NULL)
Renders the input arrays as a 2D scatter-plot to the window.
AFAPI af_err af_draw_scatter3(const af_window wind, const af_array P, const af_marker_type marker, const af_cell *const props)
C Interface wrapper for drawing an array as a plot.
AFAPI af_err af_draw_scatter_2d(const af_window wind, const af_array X, const af_array Y, const af_marker_type marker, const af_cell *const props)
C Interface wrapper for drawing an array as a 2D plot.
void plot(const array &X, const array &Y, const char *const title=NULL)
Renders the input arrays as a 2D plot to the window.
AFAPI af_err af_draw_scatter_nd(const af_window wind, const af_array P, const af_marker_type marker, const af_cell *const props)
C Interface wrapper for drawing an array as a plot.
AFAPI af_err af_draw_vector_field_2d(const af_window wind, const af_array xPoints, const af_array yPoints, const af_array xDirs, const af_array yDirs, const af_cell *const props)
C Interface wrapper for drawing array's as a 2D vector field.
void vectorField(const array &xPoints, const array &yPoints, const array &xDirs, const array &yDirs, const char *const title=NULL)
Renders the input arrays as a 2D vector field plot to the window.
AFAPI af_err af_draw_surface(const af_window wind, const af_array xVals, const af_array yVals, const af_array S, const af_cell *const props)
C Interface wrapper for drawing array's as a surface.
AFAPI af_err af_draw_plot_3d(const af_window wind, const af_array X, const af_array Y, const af_array Z, const af_cell *const props)
C Interface wrapper for drawing an array as a 3D plot.
AFAPI af_err af_draw_plot3(const af_window wind, const af_array P, const af_cell *const props)
C Interface wrapper for drawing an array as a plot.
void scatter(const array &X, const array &Y, const array &Z, const af::markerType marker=AF_MARKER_POINT, const char *const title=NULL)
Renders the input arrays as a 3D scatter-plot to the window.
AFAPI af_err af_draw_plot_nd(const af_window wind, const af_array P, const af_cell *const props)
C Interface wrapper for drawing an array as a 2D or 3D plot.
AFAPI af_err af_draw_plot(const af_window wind, const af_array X, const af_array Y, const af_cell *const props)
C Interface wrapper for drawing an array as a plot.
void image(const array &in, const char *title=NULL)
Renders the input array as an image to the window.
void plot(const array &in, const char *const title=NULL)
Renders the input arrays as a 2D or 3D plot to the window.
AFAPI af_err af_draw_hist(const af_window wind, const af_array X, const double minval, const double maxval, const af_cell *const props)
C Interface wrapper for drawing an array as a histogram.
AFAPI af_err af_draw_vector_field_3d(const af_window wind, const af_array xPoints, const af_array yPoints, const af_array zPoints, const af_array xDirs, const af_array yDirs, const af_array zDirs, const af_cell *const props)
C Interface wrapper for drawing array's as a 3D vector field.
void scatter(const array &in, const af::markerType marker=AF_MARKER_POINT, const char *const title=NULL)
Renders the input arrays as a 2D or 3D scatter-plot to the window.
void hist(const array &X, const double minval, const double maxval, const char *const title=NULL)
Renders the input array as a histogram to the window.
Window()
Creates a window object with default width and height with title set to "ArrayFire".
Window(const int width, const int height, const char *const title="ArrayFire")
Creates a window object using the parameters provided by the user.
void setAxesLimits(const float xmin, const float xmax, const float ymin, const float ymax, const float zmin, const float zmax, const bool exact=false)
Setup the axes limits for a histogram/plot/surface/vector field.
af_window get() const
Definition: graphics.h:108
void setAxesLimits(const array &x, const array &y, const bool exact=false)
Setup the axes limits for a 2D histogram/plot/vector field.
void setAxesLabelFormat(const char *const xformat="4.1%f", const char *const yformat="4.1%f", const char *const zformat=NULL)
Setup the axes label formats for charts.
~Window()
Destroys the window handle.
void setSize(const unsigned w, const unsigned h)
Set the window size.
AFAPI af_err af_grid(const af_window wind, const int rows, const int cols)
C Interface wrapper for grid setup in a window.
AFAPI af_err af_set_title(const af_window wind, const char *const title)
C Interface wrapper for setting window title.
AFAPI af_err af_set_axes_titles(const af_window wind, const char *const xtitle, const char *const ytitle, const char *const ztitle, const af_cell *const props)
C Interface wrapper for setting axes titles for histogram/plot/surface/vector field.
bool close()
Check if window is marked for close.
AFAPI af_err af_destroy_window(const af_window wind)
C Interface wrapper for destroying a window handle.
void show()
This function swaps the background buffer to current view and polls for any key strokes while the win...
AFAPI af_err af_show(const af_window wind)
C Interface wrapper for showing a window.
void setAxesLimits(const float xmin, const float xmax, const float ymin, const float ymax, const bool exact=false)
Setup the axes limits for a histogram/plot/surface/vector field.
void setTitle(const char *const title)
Set the window title.
AFAPI af_err af_set_axes_limits_compute(const af_window wind, const af_array x, const af_array y, const af_array z, const bool exact, const af_cell *const props)
C Interface for setting axes limits for a histogram/plot/surface/vector field.
Window(const af_window window)
Creates a window object with default width and height with title set to "ArrayFire".
AFAPI af_err af_create_window(af_window *out, const int width, const int height, const char *const title)
C Interface wrapper for creating a window.
AFAPI af_err af_set_position(const af_window wind, const unsigned x, const unsigned y)
C Interface wrapper for setting the start position when window is displayed.
void setPos(const unsigned x, const unsigned y)
Set the start position where the window will appear.
void setVisibility(const bool isVisible)
Hide/Show the window.
void setAxesLimits(const array &x, const array &y, const array &z, const bool exact=false)
Setup the axes limits for a histogram/plot/surface/vector field.
AFAPI af_err af_set_size(const af_window wind, const unsigned w, const unsigned h)
C Interface wrapper for setting window position.
AFAPI af_err af_is_window_closed(bool *out, const af_window wind)
C Interface wrapper for checking if window is marked for close.
void setColorMap(const ColorMap cmap)
Set the colormap to be used for subsequent rendering calls.
AFAPI af_err af_set_visibility(const af_window wind, const bool is_visible)
Hide/Show a window.
Window(const char *const title)
Creates a window object with default width and height using the title provided by the user.
AFAPI af_err af_set_axes_limits_3d(const af_window wind, const float xmin, const float xmax, const float ymin, const float ymax, const float zmin, const float zmax, const bool exact, const af_cell *const props)
C Interface for setting axes limits for a 3D plot/surface/vector field.
AFAPI af_err af_set_axes_limits_2d(const af_window wind, const float xmin, const float xmax, const float ymin, const float ymax, const bool exact, const af_cell *const props)
C Interface for setting axes limits for a 2D histogram/plot/vector field.
void grid(const int rows, const int cols)
Setup grid layout for multiview mode in a window.
AFAPI af_err af_set_axes_label_format(const af_window wind, const char *const xformat, const char *const yformat, const char *const zformat, const af_cell *const props)
C Interface wrapper for setting axes labels formats for charts.
void setAxesTitles(const char *const xtitle="X-Axis", const char *const ytitle="Y-Axis", const char *const ztitle=NULL)
Setup the axes titles for a plot/surface/vector field.
Definition: algorithm.h:15
af_colormap cmap
Definition: graphics.h:21
const char * title
Definition: graphics.h:20
int row
Definition: graphics.h:18
int col
Definition: graphics.h:19