bloboland
diff src/volume.inl @ 1:cfe68befb7cc
some progress
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 15 Dec 2012 23:43:03 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/volume.inl Sat Dec 15 23:43:03 2012 +0200 1.3 @@ -0,0 +1,88 @@ 1.4 +Volume::Volume(int xsz, int ysz, int zsz) 1.5 +{ 1.6 + this->xsz = xsz; 1.7 + this->ysz = ysz; 1.8 + this->zsz = zsz; 1.9 + slice_size = xsz * ysz; 1.10 + 1.11 + voxels = new Vector4[xsz * ysz * zsz]; 1.12 + 1.13 + // precalculate slice start pointers, cause why not... 1.14 + slices = new Vector4*[zsz]; 1.15 + for(int i=0; i<zsz; i++) { 1.16 + slices[i] = voxels + i * slice_size; 1.17 + } 1.18 +} 1.19 + 1.20 +Volume::~Volume() 1.21 +{ 1.22 + delete [] voxels; 1.23 +} 1.24 + 1.25 +int Volume::get_size(int idx) const 1.26 +{ 1.27 + switch(idx) { 1.28 + case 0: 1.29 + return xsz; 1.30 + case 1: 1.31 + return ysz; 1.32 + case 2: 1.33 + return zsz; 1.34 + default: 1.35 + break; 1.36 + } 1.37 + return xsz * ysz * zsz; 1.38 +} 1.39 + 1.40 +void Volume::set_voxel(int x, int y, int z, const Vector4 &val) 1.41 +{ 1.42 + slices[z][y * xsz + x] = val; 1.43 +} 1.44 + 1.45 +void Volume::set_voxel_color(int x, int y, int z, const Vector3 &col) 1.46 +{ 1.47 + Vector4 *ptr = slices[z] + y * xsz + x; 1.48 + ptr->x = col.x; 1.49 + ptr->y = col.y; 1.50 + ptr->z = col.z; 1.51 +} 1.52 + 1.53 +void Volume::set_voxel_alpha(int x, int y, int z, float alpha) 1.54 +{ 1.55 + slices[z][y * xsz + x].w = alpha; 1.56 +} 1.57 + 1.58 + 1.59 +const Vector4 &Volume::get_voxel(int x, int y, int z) const 1.60 +{ 1.61 + return slices[z][y * xsz + x]; 1.62 +} 1.63 + 1.64 +const Vector3 Volume::get_voxel_color(int x, int y, int z) const 1.65 +{ 1.66 + Vector4 *ptr = slices[z] + y * xsz + x; 1.67 + return Vector3(ptr->x, ptr->y, ptr->z); 1.68 +} 1.69 + 1.70 +float Volume::get_voxel_alpha(int x, int y, int z) const 1.71 +{ 1.72 + return slices[z][y * xsz + x].w; 1.73 +} 1.74 + 1.75 + 1.76 +Vector4 &Volume::operator [](int idx) 1.77 +{ 1.78 + return voxels[idx]; 1.79 +} 1.80 + 1.81 +const Vector4 &Volume::operator [](int idx) const 1.82 +{ 1.83 + return voxels[idx]; 1.84 +} 1.85 + 1.86 + 1.87 +const Vector4 *Volume::get_data_ptr() const 1.88 +{ 1.89 + return voxels; 1.90 +} 1.91 +