-
Notifications
You must be signed in to change notification settings - Fork 551
Expand file tree
/
Copy pathfield.cpp
More file actions
67 lines (52 loc) · 2 KB
/
Copy pathfield.cpp
File metadata and controls
67 lines (52 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*******************************************************
* 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;
const static float MINIMUM = -3.0f;
const static float MAXIMUM = 3.0f;
const static float STEP = 0.18f;
int main(int, char**) {
try {
af::info();
af::Window myWindow(1024, 1024, "2D Vector Field example: ArrayFire");
myWindow.grid(2, 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();
// 2D points
myWindow(0, 0).vectorField(points, saddle, "Saddle point");
myWindow(0, 1).vectorField(
points, hbowl, "hilly bowl (in a loop with varying amplitude)");
// 2D coordinates
myWindow(1, 0).vectorField(2.0 * flat(x), flat(y), flat(x),
-flat(y), "Saddle point");
myWindow(1, 1).vectorField(
2.0 * flat(x), flat(y), constant(1., x.elements()), flat(bvals),
"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;
}