This repository has been archived by the owner on Aug 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvolume.c
63 lines (50 loc) · 1.46 KB
/
volume.c
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
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
// Include SSE intrinsics
#if defined(_MSC_VER)
#include <intrin.h>
#elif defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__))
#include <immintrin.h>
#include <x86intrin.h>
#endif
// Include OpenMP
#include <omp.h>
#include "volume.h"
inline double volume_get(volume_t* v, int x, int y, int d) {
return v->weights[((v->width * y) + x) * v->depth + d];
}
inline void volume_set(volume_t* v, int x, int y, int d, double value) {
v->weights[((v->width * y) + x) * v->depth + d] = value;
}
volume_t* make_volume(int width, int height, int depth, double value) {
volume_t* new_vol = malloc(sizeof(struct volume));
new_vol->weights = malloc(sizeof(double) * width * height * depth);
new_vol->width = width;
new_vol->height = height;
new_vol->depth = depth;
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
for (int d = 0; d < depth; d++) {
volume_set(new_vol, x, y, d, value);
}
}
}
return new_vol;
}
void copy_volume(volume_t* dest, volume_t* src) {
assert(dest->width == src->width);
assert(dest->height == src->height);
assert(dest->depth == src->depth);
for (int x = 0; x < dest->width; x++) {
for (int y = 0; y < dest->height; y++) {
for (int d = 0; d < dest->depth; d++) {
volume_set(dest, x, y, d, volume_get(src, x, y, d));
}
}
}
}
void free_volume(volume_t* v) {
free(v->weights);
free(v);
}