-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRead_Raw_Volume.cpp
43 lines (40 loc) · 1.43 KB
/
Read_Raw_Volume.cpp
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
#include <time.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <omp.h>
/*!
* Read uncompressed volume from a binary file.
* 2024.10.27: hijacked this method to replace reading a binary with generating a volume from sinusoids + random
*/
void Read_Raw_Volume(const char* filename, int& nx, int& ny, int& nz, float*& vol) {
nx = 151;
ny = 101;
nz = 51;
size_t nn = (size_t)nx * (size_t)ny * (size_t)nz;
posix_memalign((void**)&vol, 64, nn * (size_t)sizeof(float));
int x0 = (nx-1) / 2;
int y0 = (ny-1) / 2;
int z0 = (nz-1) / 2;
#pragma omp parallel for schedule(static,1)
for (long iz = 0; iz < nz; ++iz)
{
memset((void*)(vol+iz*(long)nx*(long)ny),0,(long)sizeof(float)*(long)nx*(long)ny);
}
#pragma omp parallel for schedule(static,1)
for (long iz = 0; iz < nz; ++iz)
{
for (long iy = 0; iy < ny; ++iy)
{
for (long ix = 0; ix < nx; ++ix)
{
double x = ix - x0;
double y = iy - y0;
double z = iz - z0;
double r = sqrt(x*x + y*y + z*z);
vol[iz*nx*ny + ix*ny + iy] = sin(r / 10) + drand48() / 100;
}
}
}
}