A high-performance general-purpose compute library

- Main Page
- Tutorials
- Release Notes
- Examples

graphics/plot2d.cpp
/*******************************************************
* Copyright (c) 2014, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* http://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#include <arrayfire.h>
#include <math.h>
#include <cstdio>
using namespace af;
static const int ITERATIONS = 50;
static const float PRECISION = 1.0f / ITERATIONS;
int main(int, char**) {
try {
// Initialize the kernel array just once
af::info();
af::Window myWindow(800, 800, "2D Plot example: ArrayFire");
array Y;
int sign = 1;
array X = seq(-af::Pi, af::Pi, PRECISION);
array noise = randn(X.dims(0)) / 5.f;
myWindow.grid(2, 1);
for (double val = 0; !myWindow.close();) {
Y = sin(X);
myWindow(0, 0).plot(X, Y);
myWindow(1, 0).scatter(X, Y + noise, AF_MARKER_POINT);
myWindow.show();
X = X + PRECISION * float(sign);
val += PRECISION * float(sign);
if (val > af::Pi) {
sign = -1;
} else if (val < -af::Pi) {
sign = 1;
}
}
} catch (af::exception& e) {
fprintf(stderr, "%s\n", e.what());
throw;
}
return 0;
}
arrayfire.h
af::Window
Window object to render af::arrays.
Definition graphics.h:37
af::array
A multi dimensional data container.
Definition array.h:37
af::array::dims
dim4 dims() const
Get dimensions of the array.
af::exception
An ArrayFire exception class.
Definition exception.h:22
af::exception::what
virtual const char * what() const
Returns an error message for the exception in a string format.
Definition exception.h:46
af::seq
seq is used to create sequences for indexing af::array
Definition seq.h:46
AF_MARKER_POINT
@ AF_MARKER_POINT
Definition defines.h:471
af::info
AFAPI void info()
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::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::close
bool close()
Check if window is marked for close.
af::Window::show
void show()
This function swaps the background buffer to current view and polls for any key strokes while the win...
af::Window::grid
void grid(const int rows, const int cols)
Setup grid layout for multiview mode in a window.
af
Definition algorithm.h:15
af::Pi
AFAPI const double Pi