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;
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 
91  Window(const af_window wnd);
92 
98  ~Window();
99 
100  // FIXME handle copying properly
101 
107  af_window get() const { return wnd; }
108 
117  void setPos(const unsigned x, const unsigned y);
118 
126  void setTitle(const char* const title);
127 
128 #if AF_API_VERSION >= 31
129 
137  void setSize(const unsigned w, const unsigned h);
138 #endif
139 
147  void setColorMap(const ColorMap cmap);
148 
159  void image(const array& in, const char* title=NULL);
160 
161 #if AF_API_VERSION >= 32
162 
172  AF_DEPRECATED("Use plot instead")
173  void plot3(const array& in, const char* title=NULL);
174 #endif
175 
176 #if AF_API_VERSION >= 34
177 
188  void plot(const array& in, const char* const title=NULL);
189 #endif
190 
191 #if AF_API_VERSION >= 34
192 
204  void plot(const array& X, const array& Y, const array& Z, const char* const title=NULL);
205 #endif
206 
218  void plot(const array& X, const array& Y, const char* const title=NULL);
219 
220 #if AF_API_VERSION >= 34
221 
233  void scatter(const array& in, const af::markerType marker = AF_MARKER_POINT,
234  const char* const title = NULL);
235 #endif
236 
237 #if AF_API_VERSION >= 34
238 
251  void scatter(const array& X, const array& Y, const array& Z,
252  const af::markerType marker = AF_MARKER_POINT, const char* const title = NULL);
253 #endif
254 
255 #if AF_API_VERSION >= 33
256 
268  void scatter(const array& X, const array& Y,
269  const af::markerType marker = AF_MARKER_POINT, const char* const title = NULL);
270 #endif
271 
272 #if AF_API_VERSION >= 33
273 
282  AF_DEPRECATED("Use scatter instead")
283  void scatter3(const array& P, const af::markerType marker = AF_MARKER_POINT,
284  const char* const title = NULL);
285 #endif
286 
299  void hist(const array& X, const double minval, const double maxval, const char* const title=NULL);
300 
301 #if AF_API_VERSION >= 32
302 
312  void surface(const array& S, const char* const title = NULL);
313 #endif
314 
315 #if AF_API_VERSION >= 32
316 
328  void surface(const array& xVals, const array& yVals, const array& S, const char* const title = NULL);
329 #endif
330 
331 #if AF_API_VERSION >= 34
332 
348  void vectorField(const array& points, const array& directions, const char* const title = NULL);
349 #endif
350 
351 #if AF_API_VERSION >= 34
352 
367  void vectorField(const array& xPoints, const array& yPoints, const array& zPoints,
368  const array& xDirs , const array& yDirs , const array& zDirs ,
369  const char* const title = NULL);
370 #endif
371 
372 #if AF_API_VERSION >= 34
373 
386  void vectorField(const array& xPoints, const array& yPoints,
387  const array& xDirs , const array& yDirs ,
388  const char* const title = NULL);
389 #endif
390 
391 #if AF_API_VERSION >= 34
392 
405  void setAxesLimits(const array &x, const array &y, const bool exact = false);
406 #endif
407 
408 #if AF_API_VERSION >= 34
409 
423  void setAxesLimits(const array &x, const array &y, const array &z,
424  const bool exact = false);
425 #endif
426 
427 #if AF_API_VERSION >= 34
428 
443  void setAxesLimits(const float xmin, const float xmax,
444  const float ymin, const float ymax,
445  const bool exact = false);
446 #endif
447 
448 #if AF_API_VERSION >= 34
449 
466  void setAxesLimits(const float xmin, const float xmax,
467  const float ymin, const float ymax,
468  const float zmin, const float zmax,
469  const bool exact = false);
470 #endif
471 
472 #if AF_API_VERSION >= 34
473 
484  void setAxesTitles(const char * const xtitle = "X-Axis",
485  const char * const ytitle = "Y-Axis",
486  const char * const ztitle = NULL);
487 #endif
488 
489 #if AF_API_VERSION >= 37
490 
499  void setAxesLabelFormat(const char *const xformat = "4.1%f",
500  const char *const yformat = "4.1%f",
501  const char *const zformat = NULL);
502 #endif
503 
512  void grid(const int rows, const int cols);
513 
520  void show();
521 
531  bool close();
532 
533 #if AF_API_VERSION >= 33
534 
541  void setVisibility(const bool isVisible);
542 #endif
543 
559  inline Window& operator()(const int r, const int c) {
560  _r = r; _c = c;
561  return *this;
562  }
563 };
564 
565 }
566 #endif
567 
568 #ifdef __cplusplus
569 extern "C" {
570 #endif
571 
585 AFAPI af_err af_create_window(af_window *out, const int width, const int height, const char* const title);
586 
599 AFAPI af_err af_set_position(const af_window wind, const unsigned x, const unsigned y);
600 
612 AFAPI af_err af_set_title(const af_window wind, const char* const title);
613 
614 #if AF_API_VERSION >= 31
615 
627 AFAPI af_err af_set_size(const af_window wind, const unsigned w, const unsigned h);
628 #endif
629 
645 AFAPI af_err af_draw_image(const af_window wind, const af_array in, const af_cell* const props);
646 
663 AF_DEPRECATED("Use af_draw_plot_nd or af_draw_plot_2d instead")
664 AFAPI af_err af_draw_plot(const af_window wind, const af_array X, const af_array Y, const af_cell* const props);
665 
666 #if AF_API_VERSION >= 32
667 
682 AF_DEPRECATED("Use af_draw_plot_nd or af_draw_plot_3d instead")
683 AFAPI af_err af_draw_plot3(const af_window wind, const af_array P, const af_cell* const props);
684 #endif
685 
686 #if AF_API_VERSION >= 34
687 
703 AFAPI af_err af_draw_plot_nd(const af_window wind, const af_array P, const af_cell* const props);
704 #endif
705 
706 #if AF_API_VERSION >= 34
707 
723 AFAPI af_err af_draw_plot_2d(const af_window wind, const af_array X, const af_array Y,
724  const af_cell* const props);
725 #endif
726 
727 #if AF_API_VERSION >= 34
728 
746  const af_array X, const af_array Y, const af_array Z,
747  const af_cell* const props);
748 #endif
749 
750 #if AF_API_VERSION >= 33
751 
768 AF_DEPRECATED("Use af_draw_scatter_nd or af_draw_scatter_2d instead")
769 AFAPI af_err af_draw_scatter(const af_window wind, const af_array X, const af_array Y,
770  const af_marker_type marker, const af_cell* const props);
771 #endif
772 
773 #if AF_API_VERSION >= 33
774 
788 AF_DEPRECATED("Use af_draw_scatter_nd or af_draw_scatter_3d instead")
789 AFAPI af_err af_draw_scatter3(const af_window wind, const af_array P,
790  const af_marker_type marker, const af_cell* const props);
791 #endif
792 
793 #if AF_API_VERSION >= 34
794 
811 AFAPI af_err af_draw_scatter_nd(const af_window wind, const af_array P,
812  const af_marker_type marker, const af_cell* const props);
813 #endif
814 
815 #if AF_API_VERSION >= 34
816 
833 AFAPI af_err af_draw_scatter_2d(const af_window wind, const af_array X, const af_array Y,
834  const af_marker_type marker, const af_cell* const props);
835 #endif
836 
837 #if AF_API_VERSION >= 34
838 
857  const af_array X, const af_array Y, const af_array Z,
858  const af_marker_type marker, const af_cell* const props);
859 #endif
860 
878 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);
879 
880 #if AF_API_VERSION >= 32
881 
898 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);
899 #endif
900 
901 #if AF_API_VERSION >= 34
902 
926  const af_array points, const af_array directions,
927  const af_cell* const props);
928 #endif
929 
930 #if AF_API_VERSION >= 34
931 
952  const af_window wind,
953  const af_array xPoints, const af_array yPoints, const af_array zPoints,
954  const af_array xDirs, const af_array yDirs, const af_array zDirs,
955  const af_cell* const props);
956 #endif
957 
958 #if AF_API_VERSION >= 34
959 
978  const af_window wind,
979  const af_array xPoints, const af_array yPoints,
980  const af_array xDirs, const af_array yDirs,
981  const af_cell* const props);
982 #endif
983 
996 AFAPI af_err af_grid(const af_window wind, const int rows, const int cols);
997 
998 #if AF_API_VERSION >= 34
999 
1019  const af_array x, const af_array y, const af_array z,
1020  const bool exact,
1021  const af_cell* const props);
1022 #endif
1023 
1024 #if AF_API_VERSION >= 34
1025 
1044  const float xmin, const float xmax,
1045  const float ymin, const float ymax,
1046  const bool exact,
1047  const af_cell* const props);
1048 #endif
1049 
1050 #if AF_API_VERSION >= 34
1051 
1072  const float xmin, const float xmax,
1073  const float ymin, const float ymax,
1074  const float zmin, const float zmax,
1075  const bool exact,
1076  const af_cell* const props);
1077 #endif
1078 
1079 #if AF_API_VERSION >= 34
1080 
1101  const char * const xtitle,
1102  const char * const ytitle,
1103  const char * const ztitle,
1104  const af_cell* const props);
1105 #endif
1106 
1107 #if AF_API_VERSION >= 37
1108 
1130  const char *const xformat,
1131  const char *const yformat,
1132  const char *const zformat,
1133  const af_cell *const props);
1134 #endif
1135 
1146 AFAPI af_err af_show(const af_window wind);
1147 
1160 AFAPI af_err af_is_window_closed(bool *out, const af_window wind);
1161 
1162 #if AF_API_VERSION >= 33
1163 
1171 AFAPI af_err af_set_visibility(const af_window wind, const bool is_visible);
1172 #endif
1173 
1185 
1186 #ifdef __cplusplus
1187 }
1188 
1189 #endif
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_cell::title
const char * title
Definition: graphics.h:20
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_marker_type
af_marker_type
Definition: defines.h:468
af_destroy_window
AFAPI af_err af_destroy_window(const af_window wind)
C Interface wrapper for destroying a window handle.
af_window
void * af_window
Definition: graphics.h:15
AF_MARKER_POINT
@ AF_MARKER_POINT
Definition: defines.h:470
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_cell
Definition: graphics.h:17
af_cell::row
int row
Definition: graphics.h:18
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_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_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.
AFAPI
#define AFAPI
Definition: defines.h:38
af::array
A multi dimensional data container.
Definition: array.h:35
af
Definition: algorithm.h:14
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_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_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_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_cell::cmap
af_colormap cmap
Definition: graphics.h:21
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_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_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_array
void * af_array
Definition: defines.h:240
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_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_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_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_set_title
AFAPI af_err af_set_title(const af_window wind, const char *const title)
C Interface wrapper for setting window title.
af_show
AFAPI af_err af_show(const af_window wind)
C Interface wrapper for showing a window.
af_set_visibility
AFAPI af_err af_set_visibility(const af_window wind, const bool is_visible)
Hide/Show a 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_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_DEPRECATED
#define AF_DEPRECATED(msg)
Definition: defines.h:44
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.
array.h
af::Window::get
af_window get() const
Definition: graphics.h:107
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_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_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_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::Window
Window object to render af::arrays.
Definition: graphics.h:37
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_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::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:559
af_err
af_err
Definition: defines.h:71
af_colormap
af_colormap
Definition: defines.h:453
defines.h
af_cell::col
int col
Definition: graphics.h:19