My Project
graphics/surface.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 M = 30;
static const int N = 2 * M;
int main(int argc, char *argv[])
{
try {
// Initialize the kernel array just once
af::Window myWindow(800, 800, "3D Surface example: ArrayFire");
// Creates grid of between [-1 1] with precision of 1 / M
const array x = iota(dim4(N, 1), dim4(1, N)) / M - 1;
const array y = iota(dim4(1, N), dim4(N, 1)) / M - 1;
std::cout << x.dims() << y.dims() << std::endl;
static float t=0;
while(!myWindow.close()) {
t+=0.07;
array z = 10*x*-abs(y) * cos(x*x*(y+t))+sin(y*(x+t))-1.5;
myWindow.surface(x, y, z);
}
} catch (af::exception& e) {
fprintf(stderr, "%s\n", e.what());
throw;
}
return 0;
}
af::dim4
Definition: dim4.hpp:31
af::info
AFAPI void info()
af::abs
AFAPI array abs(const array &in)
C++ Interface for absolute value.
af::array
A multi dimensional data container.
Definition: array.h:32
af
Definition: algorithm.h:13
af::Window::close
bool close()
Check if window is marked for close.
af::array::dims
dim4 dims() const
Get dimensions of the array.
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::sin
AFAPI array sin(const array &in)
C++ Interface for sin.
af::exception
Definition: exception.h:24
af::iota
AFAPI array iota(const dim4 &dims, const dim4 &tile_dims=dim4(1), const dtype ty=f32)
arrayfire.h
af::cos
AFAPI array cos(const array &in)
C++ Interface for cos.
af::exception::what
virtual const char * what() const
Definition: exception.h:45
af::Window
Window object to render af::arrays.
Definition: graphics.h:36