bloboland

annotate 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
rev   line source
nuclear@1 1 Volume::Volume(int xsz, int ysz, int zsz)
nuclear@1 2 {
nuclear@1 3 this->xsz = xsz;
nuclear@1 4 this->ysz = ysz;
nuclear@1 5 this->zsz = zsz;
nuclear@1 6 slice_size = xsz * ysz;
nuclear@1 7
nuclear@1 8 voxels = new Vector4[xsz * ysz * zsz];
nuclear@1 9
nuclear@1 10 // precalculate slice start pointers, cause why not...
nuclear@1 11 slices = new Vector4*[zsz];
nuclear@1 12 for(int i=0; i<zsz; i++) {
nuclear@1 13 slices[i] = voxels + i * slice_size;
nuclear@1 14 }
nuclear@1 15 }
nuclear@1 16
nuclear@1 17 Volume::~Volume()
nuclear@1 18 {
nuclear@1 19 delete [] voxels;
nuclear@1 20 }
nuclear@1 21
nuclear@1 22 int Volume::get_size(int idx) const
nuclear@1 23 {
nuclear@1 24 switch(idx) {
nuclear@1 25 case 0:
nuclear@1 26 return xsz;
nuclear@1 27 case 1:
nuclear@1 28 return ysz;
nuclear@1 29 case 2:
nuclear@1 30 return zsz;
nuclear@1 31 default:
nuclear@1 32 break;
nuclear@1 33 }
nuclear@1 34 return xsz * ysz * zsz;
nuclear@1 35 }
nuclear@1 36
nuclear@1 37 void Volume::set_voxel(int x, int y, int z, const Vector4 &val)
nuclear@1 38 {
nuclear@1 39 slices[z][y * xsz + x] = val;
nuclear@1 40 }
nuclear@1 41
nuclear@1 42 void Volume::set_voxel_color(int x, int y, int z, const Vector3 &col)
nuclear@1 43 {
nuclear@1 44 Vector4 *ptr = slices[z] + y * xsz + x;
nuclear@1 45 ptr->x = col.x;
nuclear@1 46 ptr->y = col.y;
nuclear@1 47 ptr->z = col.z;
nuclear@1 48 }
nuclear@1 49
nuclear@1 50 void Volume::set_voxel_alpha(int x, int y, int z, float alpha)
nuclear@1 51 {
nuclear@1 52 slices[z][y * xsz + x].w = alpha;
nuclear@1 53 }
nuclear@1 54
nuclear@1 55
nuclear@1 56 const Vector4 &Volume::get_voxel(int x, int y, int z) const
nuclear@1 57 {
nuclear@1 58 return slices[z][y * xsz + x];
nuclear@1 59 }
nuclear@1 60
nuclear@1 61 const Vector3 Volume::get_voxel_color(int x, int y, int z) const
nuclear@1 62 {
nuclear@1 63 Vector4 *ptr = slices[z] + y * xsz + x;
nuclear@1 64 return Vector3(ptr->x, ptr->y, ptr->z);
nuclear@1 65 }
nuclear@1 66
nuclear@1 67 float Volume::get_voxel_alpha(int x, int y, int z) const
nuclear@1 68 {
nuclear@1 69 return slices[z][y * xsz + x].w;
nuclear@1 70 }
nuclear@1 71
nuclear@1 72
nuclear@1 73 Vector4 &Volume::operator [](int idx)
nuclear@1 74 {
nuclear@1 75 return voxels[idx];
nuclear@1 76 }
nuclear@1 77
nuclear@1 78 const Vector4 &Volume::operator [](int idx) const
nuclear@1 79 {
nuclear@1 80 return voxels[idx];
nuclear@1 81 }
nuclear@1 82
nuclear@1 83
nuclear@1 84 const Vector4 *Volume::get_data_ptr() const
nuclear@1 85 {
nuclear@1 86 return voxels;
nuclear@1 87 }
nuclear@1 88