-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.cpp
More file actions
99 lines (84 loc) · 2.91 KB
/
Copy pathmain.cpp
File metadata and controls
99 lines (84 loc) · 2.91 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <exception>
#include <iostream>
#include <string>
#include <graphengine/filter.h>
#include "cube.h"
#include "lut.h"
namespace {
void usage()
{
std::cerr << "usage: test cubefile [x y z] [interp] [simd]\n";
}
} // namespace
int main(int argc, char **argv)
{
if (argc < 2) {
usage();
return 1;
}
std::unique_ptr<graphengine::Filter> lut[3];
alignas(64) float x = 0.0f;
alignas(64) float y = 0.0f;
alignas(64) float z = 0.0f;
timecube::Interpolation interp = timecube::Interpolation::LINEAR;
int simd = 0;
try {
if (argc >= 5) {
x = std::stof(argv[2]);
y = std::stof(argv[3]);
z = std::stof(argv[4]);
}
if (argc >= 6)
interp = static_cast<timecube::Interpolation>(std::stoi(argv[5]));
if (argc >= 7)
simd = std::stoi(argv[6]);
} catch (const std::exception &) {
usage();
return 1;
}
try {
timecube::Cube cube = timecube::read_cube_from_file(argv[1]);
std::cout << "title: " << cube.title << '\n';
std::cout << "size: " << cube.n;
if (cube.is_3d)
std::cout << 'x' << cube.n << 'x' << cube.n;
std::cout << '\n';
std::cout << "domain min: " << cube.domain_min[0] << ' ' << cube.domain_min[1] << ' ' << cube.domain_min[2] << '\n';
std::cout << "domain max: " << cube.domain_max[0] << ' ' << cube.domain_max[1] << ' ' << cube.domain_max[2] << '\n';
std::cout << "first entry: " << cube.lut[0] << ' ' << cube.lut[1] << ' ' << cube.lut[2] << '\n';
std::cout << "last entry: " << cube.lut[cube.lut.size() - 3] << ' ' << cube.lut[cube.lut.size() - 2] << ' ' << cube.lut[cube.lut.size() - 1] << '\n';
if (cube.is_3d) {
if (!(lut[0] = timecube::create_lut3d_impl(cube, 1, 1, interp, simd)))
throw std::runtime_error{ "failed to create LUT implementation" };
} else {
if (!(lut[0] = timecube::create_lut1d_impl(cube, 1, 1, 0, interp, simd)))
throw std::runtime_error{ "failed to create LUT implementation" };
if (!(lut[1] = timecube::create_lut1d_impl(cube, 1, 1, 1, interp, simd)))
throw std::runtime_error{ "failed to create LUT implementation" };
if (!(lut[2] = timecube::create_lut1d_impl(cube, 1, 1, 2, interp, simd)))
throw std::runtime_error{ "failed to create LUT implementation" };
}
} catch (const std::exception &e) {
std::cerr << "failed to load CUBE: " << e.what() << '\n';
return 1;
}
try {
graphengine::BufferDescriptor buffer[3] = {
{ &x, 64, graphengine::BUFFER_MAX },
{ &y, 64, graphengine::BUFFER_MAX },
{ &z, 64, graphengine::BUFFER_MAX },
};
if (!lut[1] /* is_3d */) {
lut[0]->process(buffer, buffer, 0, 0, 1, nullptr, nullptr);
} else {
lut[0]->process(&buffer[0], &buffer[0], 0, 0, 1, nullptr, nullptr);
lut[1]->process(&buffer[1], &buffer[1], 0, 0, 1, nullptr, nullptr);
lut[2]->process(&buffer[2], &buffer[2], 0, 0, 1, nullptr, nullptr);
}
std::cout << "result: (" << x << ", " << y << ", " << z << ")\n";
} catch (const std::exception &e) {
std::cerr << e.what() << '\n';
return 1;
}
return 0;
}