My Project
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 <cstdio>
#include <math.h>
using namespace af;
static const int ITERATIONS = 50;
static const float PRECISION = 1.0f/ITERATIONS;
int main(int argc, char *argv[])
{
try {
// Initialize the kernel array just once
af::Window myWindow(1024, 512, "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(1, 2);
for (double val=-af::Pi; !myWindow.close(); ) {
Y = sin(X);
myWindow(0,0).plot(X, Y);
myWindow(0,1).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;
}
af::seq
seq is used to create seq for indexing af::array
Definition: seq.h:44
AF_MARKER_POINT
Definition: defines.h:386
af::info
AFAPI void info()
af::array
A multi dimensional data container.
Definition: array.h:32
af
Definition: algorithm.h:13
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::close
bool close()
Check if window is marked for close.
af::array::dims
dim4 dims() const
Get dimensions of the array.
af::Pi
const AFAPI double Pi
af::sin
AFAPI array sin(const array &in)
C++ Interface for sin.
af::sign
AFAPI array sign(const array &in)
C++ Interface for getting the sign of input.
af::exception
Definition: exception.h:24
af::randn
AFAPI array randn(const dim4 &dims, const dtype ty=f32)
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.
arrayfire.h
af::exception::what
virtual const char * what() const
Definition: exception.h:45
af::Window
Window object to render af::arrays.
Definition: graphics.h:36
af::Window::grid
void grid(const int rows, const int cols)
Setup grid layout for multiview mode in a window.
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.