-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathrawUtilities.cpp
27 lines (24 loc) · 956 Bytes
/
rawUtilities.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
#include "rawUtilities.hpp"
unsigned char * readRawFile(char * filename, int sizeX, int sizeY, int sizeZ, int stepSizeX, int stepSizeY, int stepSizeZ) {
// Parse the specified raw file
int rawDataSize = sizeX*sizeY*sizeZ;
unsigned char * rawVoxels = new unsigned char[rawDataSize];
FILE * file = fopen(filename, "rb");
if(file == NULL)
return NULL;
fread(rawVoxels, sizeof(unsigned char), rawDataSize, file);
if(stepSizeX == 1 && stepSizeY == 1 && stepSizeZ == 1)
return rawVoxels;
unsigned char * voxels = new unsigned char[rawDataSize / ( stepSizeX*stepSizeY*stepSizeZ)];
int i = 0;
for(int z = 0; z < sizeZ; z += stepSizeZ) {
for(int y = 0; y < sizeY; y += stepSizeY) {
for(int x = 0; x < sizeX; x += stepSizeX) {
voxels[i] = rawVoxels[x + y*sizeX + z*sizeX*sizeY];
i++;
}
}
}
delete rawVoxels;
return voxels;
}