A high-performance general-purpose compute library

- Main Page
- Tutorials
- Release Notes
- Examples

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
15 typedef void* af_window;
16
17 typedef struct {
18 int row;
19 int col;
20 const char* title;
21 af_colormap cmap;
22} af_cell;
23
24#ifdef __cplusplus
25 namespace af
26{
27
37 class AFAPI Window {
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:
58 Window();
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
99 ~Window();
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
570 extern "C" {
571#endif
572
586 AFAPI af_err af_create_window(af_window *out, const int width, const int height, const char* const title);
587
600 AFAPI af_err af_set_position(const af_window wind, const unsigned x, const unsigned y);
601
613 AFAPI af_err af_set_title(const af_window wind, const char* const title);
614
615#if AF_API_VERSION >= 31
628 AFAPI af_err af_set_size(const af_window wind, const unsigned w, const unsigned h);
629#endif
630
646 AFAPI af_err af_draw_image(const af_window wind, const af_array in, const af_cell* const props);
647
664 AF_DEPRECATED("Use af_draw_plot_nd or af_draw_plot_2d instead")
665 AFAPI 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
683 AF_DEPRECATED("Use af_draw_plot_nd or af_draw_plot_3d instead")
684 AFAPI 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
704 AFAPI 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
724 AFAPI af_err af_draw_plot_2d(const af_window wind, const af_array X, const af_array Y,
725 const af_cell* const props);
726#endif
727
728#if AF_API_VERSION >= 34
746 AFAPI af_err af_draw_plot_3d(const af_window wind,
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
769 AF_DEPRECATED("Use af_draw_scatter_nd or af_draw_scatter_2d instead")
770 AFAPI af_err af_draw_scatter(const af_window wind, const af_array X, const af_array Y,
771 const af_marker_type marker, const af_cell* const props);
772#endif
773
774#if AF_API_VERSION >= 33
789 AF_DEPRECATED("Use af_draw_scatter_nd or af_draw_scatter_3d instead")
790 AFAPI af_err af_draw_scatter3(const af_window wind, const af_array P,
791 const af_marker_type marker, const af_cell* const props);
792#endif
793
794#if AF_API_VERSION >= 34
812 AFAPI af_err af_draw_scatter_nd(const af_window wind, const af_array P,
813 const af_marker_type marker, const af_cell* const props);
814#endif
815
816#if AF_API_VERSION >= 34
834 AFAPI af_err af_draw_scatter_2d(const af_window wind, const af_array X, const af_array Y,
835 const af_marker_type marker, const af_cell* const props);
836#endif
837
838#if AF_API_VERSION >= 34
857 AFAPI af_err af_draw_scatter_3d(const af_window wind,
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
879 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);
880
881#if AF_API_VERSION >= 32
899 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);
900#endif
901
902#if AF_API_VERSION >= 34
926 AFAPI af_err af_draw_vector_field_nd(const af_window wind,
927 const af_array points, const af_array directions,
928 const af_cell* const props);
929#endif
930
931#if AF_API_VERSION >= 34
952 AFAPI af_err af_draw_vector_field_3d(
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
978 AFAPI af_err af_draw_vector_field_2d(
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
997 AFAPI af_err af_grid(const af_window wind, const int rows, const int cols);
998
999#if AF_API_VERSION >= 34
1019 AFAPI af_err af_set_axes_limits_compute(const af_window wind,
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
1044 AFAPI af_err af_set_axes_limits_2d(const af_window wind,
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
1072 AFAPI af_err af_set_axes_limits_3d(const af_window wind,
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
1101 AFAPI af_err af_set_axes_titles(const af_window wind,
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
1130 AFAPI af_err af_set_axes_label_format(const af_window wind,
1131 const char *const xformat,
1132 const char *const yformat,
1133 const char *const zformat,
1134 const af_cell *const props);
1135#endif
1136
1147 AFAPI af_err af_show(const af_window wind);
1148
1161 AFAPI af_err af_is_window_closed(bool *out, const af_window wind);
1162
1163#if AF_API_VERSION >= 33
1172 AFAPI af_err af_set_visibility(const af_window wind, const bool is_visible);
1173#endif
1174
1185 AFAPI af_err af_destroy_window(const af_window wind);
1186
1187#ifdef __cplusplus
1188}
1189
1190#endif
array.h
af::Window
Window object to render af::arrays.
Definition graphics.h:37
af::Window::operator()
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
af::array
A multi dimensional data container.
Definition array.h:37
defines.h
af_colormap
af_colormap
Definition defines.h:454
af_err
af_err
Definition defines.h:71
af_array
void * af_array
Definition defines.h:240
AF_DEPRECATED
#define AF_DEPRECATED(msg)
Definition defines.h:44
AFAPI
#define AFAPI
Definition defines.h:38
af_marker_type
af_marker_type
Definition defines.h:469
AF_MARKER_POINT
@ AF_MARKER_POINT
Definition defines.h:471
af_window
void * af_window
Definition graphics.h:15
af::Window::surface
void surface(const array &S, const char *const title=NULL)
Renders the input arrays as a 3D surface plot to the window.
af::Window::plot
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.
af_draw_scatter_3d
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.
af::Window::surface
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.
af_draw_vector_field_nd
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.
af_draw_scatter
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.
af::Window::vectorField
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.
af::Window::vectorField
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.
af_draw_image
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.
af_draw_plot_2d
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.
af::Window::scatter
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.
af_draw_scatter3
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.
af_draw_scatter_2d
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.
af::Window::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.
af_draw_scatter_nd
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.
af_draw_vector_field_2d
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.
af::Window::vectorField
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.
af_draw_surface
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.
af_draw_plot_3d
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.
af_draw_plot3
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.
af::Window::scatter
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.
af_draw_plot_nd
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.
af_draw_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.
af::Window::image
void image(const array &in, const char *title=NULL)
Renders the input array as an image to the window.
af::Window::plot
void plot(const array &in, const char *const title=NULL)
Renders the input arrays as a 2D or 3D plot to the window.
af_draw_hist
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.
af_draw_vector_field_3d
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.
af::Window::scatter
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.
af::Window::hist
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.
af::Window::Window
Window()
Creates a window object with default width and height with title set to "ArrayFire".
af::Window::Window
Window(const int width, const int height, const char *const title="ArrayFire")
Creates a window object using the parameters provided by the user.
af::Window::setAxesLimits
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
af_window get() const
Definition graphics.h:108
af::Window::setAxesLimits
void setAxesLimits(const array &x, const array &y, const bool exact=false)
Setup the axes limits for a 2D histogram/plot/vector field.
af::Window::setAxesLabelFormat
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.
af::Window::~Window
~Window()
Destroys the window handle.
af::Window::setSize
void setSize(const unsigned w, const unsigned h)
Set the window size.
af_grid
AFAPI af_err af_grid(const af_window wind, const int rows, const int cols)
C Interface wrapper for grid setup in a window.
af_set_title
AFAPI af_err af_set_title(const af_window wind, const char *const title)
C Interface wrapper for setting window title.
af_set_axes_titles
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.
af::Window::close
bool close()
Check if window is marked for close.
af_destroy_window
AFAPI af_err af_destroy_window(const af_window wind)
C Interface wrapper for destroying a window handle.
af::Window::show
void show()
This function swaps the background buffer to current view and polls for any key strokes while the win...
af_show
AFAPI af_err af_show(const af_window wind)
C Interface wrapper for showing a window.
af::Window::setAxesLimits
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.
af::Window::setTitle
void setTitle(const char *const title)
Set the window title.
af_set_axes_limits_compute
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.
af::Window::Window
Window(const af_window window)
Creates a window object with default width and height with title set to "ArrayFire".
af_create_window
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.
af_set_position
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.
af::Window::setPos
void setPos(const unsigned x, const unsigned y)
Set the start position where the window will appear.
af::Window::setVisibility
void setVisibility(const bool isVisible)
Hide/Show the window.
af::Window::setAxesLimits
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.
af_set_size
AFAPI af_err af_set_size(const af_window wind, const unsigned w, const unsigned h)
C Interface wrapper for setting window position.
af_is_window_closed
AFAPI af_err af_is_window_closed(bool *out, const af_window wind)
C Interface wrapper for checking if window is marked for close.
af::Window::setColorMap
void setColorMap(const ColorMap cmap)
Set the colormap to be used for subsequent rendering calls.
af_set_visibility
AFAPI af_err af_set_visibility(const af_window wind, const bool is_visible)
Hide/Show a window.
af::Window::Window
Window(const char *const title)
Creates a window object with default width and height using the title provided by the user.
af_set_axes_limits_3d
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.
af_set_axes_limits_2d
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.
af::Window::grid
void grid(const int rows, const int cols)
Setup grid layout for multiview mode in a window.
af_set_axes_label_format
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.
af::Window::setAxesTitles
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.
af
Definition algorithm.h:15
af_cell
Definition graphics.h:17
af_cell::cmap
af_colormap cmap
Definition graphics.h:21
af_cell::title
const char * title
Definition graphics.h:20
af_cell::row
int row
Definition graphics.h:18
af_cell::col
int col
Definition graphics.h:19