bloboland
view src/volume.inl @ 2:1757973feaed
added stereoscopic rendering for no apparent reason
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 16 Dec 2012 00:37:35 +0200 |
parents | |
children |
line source
1 Volume::Volume(int xsz, int ysz, int zsz)
2 {
3 this->xsz = xsz;
4 this->ysz = ysz;
5 this->zsz = zsz;
6 slice_size = xsz * ysz;
8 voxels = new Vector4[xsz * ysz * zsz];
10 // precalculate slice start pointers, cause why not...
11 slices = new Vector4*[zsz];
12 for(int i=0; i<zsz; i++) {
13 slices[i] = voxels + i * slice_size;
14 }
15 }
17 Volume::~Volume()
18 {
19 delete [] voxels;
20 }
22 int Volume::get_size(int idx) const
23 {
24 switch(idx) {
25 case 0:
26 return xsz;
27 case 1:
28 return ysz;
29 case 2:
30 return zsz;
31 default:
32 break;
33 }
34 return xsz * ysz * zsz;
35 }
37 void Volume::set_voxel(int x, int y, int z, const Vector4 &val)
38 {
39 slices[z][y * xsz + x] = val;
40 }
42 void Volume::set_voxel_color(int x, int y, int z, const Vector3 &col)
43 {
44 Vector4 *ptr = slices[z] + y * xsz + x;
45 ptr->x = col.x;
46 ptr->y = col.y;
47 ptr->z = col.z;
48 }
50 void Volume::set_voxel_alpha(int x, int y, int z, float alpha)
51 {
52 slices[z][y * xsz + x].w = alpha;
53 }
56 const Vector4 &Volume::get_voxel(int x, int y, int z) const
57 {
58 return slices[z][y * xsz + x];
59 }
61 const Vector3 Volume::get_voxel_color(int x, int y, int z) const
62 {
63 Vector4 *ptr = slices[z] + y * xsz + x;
64 return Vector3(ptr->x, ptr->y, ptr->z);
65 }
67 float Volume::get_voxel_alpha(int x, int y, int z) const
68 {
69 return slices[z][y * xsz + x].w;
70 }
73 Vector4 &Volume::operator [](int idx)
74 {
75 return voxels[idx];
76 }
78 const Vector4 &Volume::operator [](int idx) const
79 {
80 return voxels[idx];
81 }
84 const Vector4 *Volume::get_data_ptr() const
85 {
86 return voxels;
87 }