graphics/field.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:
* https://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#include <arrayfire.h>
#include <math.h>
#include <cstdio>
using namespace af;
const static float MINIMUM = -3.0f;
const static float MAXIMUM = 3.0f;
const static float STEP = 0.18f;
int main(int, char**) {
try {
af::Window myWindow(1024, 1024, "2D Vector Field example: ArrayFire");
myWindow.grid(1, 2);
array dataRange = seq(MINIMUM, MAXIMUM, STEP);
array x = tile(dataRange, 1, dataRange.dims(0));
array y = tile(dataRange.T(), dataRange.dims(0), 1);
x.eval();
y.eval();
float scale = 2.0f;
do {
array points = join(1, flat(x), flat(y));
array saddle = join(1, flat(x), -1.0f * flat(y));
array bvals = sin(scale * (x * x + y * y));
array hbowl = join(1, constant(1, x.elements()), flat(bvals));
hbowl.eval();
myWindow(0, 0).vectorField(points, saddle, "Saddle point");
myWindow(0, 1).vectorField(
points, hbowl, "hilly bowl (in a loop with varying amplitude)");
myWindow.show();
scale -= 0.0010f;
if (scale < -0.01f) { scale = 2.0f; }
} while (!myWindow.close());
} catch (af::exception& e) {
fprintf(stderr, "%s\n", e.what());
throw;
}
return 0;
}
af::seq
seq is used to create sequences for indexing af::array
Definition: seq.h:46
af::info
AFAPI void info()
af::constant
array constant(T val, const dim4 &dims, const dtype ty=(af_dtype) dtype_traits< T >::ctype)
af::join
AFAPI array join(const int dim, const array &first, const array &second)
Join 2 arrays along dim.
af::scale
AFAPI array scale(const array &in, const float scale0, const float scale1, const dim_t odim0=0, const dim_t odim1=0, const interpType method=AF_INTERP_NEAREST)
C++ Interface for scaling an image.
af::array
A multi dimensional data container.
Definition: array.h:35
af
Definition: algorithm.h:15
af::Window::show
void show()
This function swaps the background buffer to current view and polls for any key strokes while the win...
af::array::elements
dim_t elements() const
Get the total number of elements across all dimensions of the array.
af::array::eval
void eval() const
Evaluate any JIT expressions to generate data for the array.
af::Window::close
bool close()
Check if window is marked for close.
af::flat
AFAPI array flat(const array &in)
af::sin
AFAPI array sin(const array &in)
C++ Interface for sin.
af::exception
An ArrayFire exception class.
Definition: exception.h:29
af::tile
AFAPI array tile(const array &in, const unsigned x, const unsigned y=1, const unsigned z=1, const unsigned w=1)
af::array::dims
dim4 dims() const
Get dimensions of the array.
arrayfire.h
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::exception::what
virtual const char * what() const
Returns an error message for the exception in a string format.
Definition: exception.h:60
af::array::T
array T() const
Get the transposed the array.
af::Window
Window object to render af::arrays.
Definition: graphics.h:37
af::Window::grid
void grid(const int rows, const int cols)
Setup grid layout for multiview mode in a window.