4 import iv
.glbinds
.utils
;
12 // ////////////////////////////////////////////////////////////////////////// //
14 this is just a voxel cube, where each voxel represents by one bit.
15 it is useful for fast "yes/no" queries and modifications, and is used
16 in "hollow fill" and t-junction fixer algorithms.
19 uint xsize
= 0, ysize
= 0, zsize
= 0;
20 uint xwdt
= 0, xywdt
= 0;
21 uint[] bmp
; // bit per voxel
25 delete bmp
; bmp
= null;
26 xsize
= ysize
= zsize
= xwdt
= xywdt
= 0;
29 void setSize (uint xs
, uint ys
, uint zs
) {
31 if (!xs ||
!ys ||
!zs
) return;
36 assert(xwdt
<<5 >= xs
);
38 bmp
= new uint[xywdt
*zsize
];
43 uint setPixel (int x
, int y
, int z
) nothrow @trusted @nogc {
45 if (x
< 0 || y
< 0 || z
< 0) return 1;
46 if (cast(uint)x
>= xsize ||
cast(uint)y
>= ysize ||
cast(uint)z
>= zsize
) return 1;
47 uint *bp
= bmp
.ptr
+cast(uint)z
*xywdt
+cast(uint)y
*xwdt
+(cast(uint)x
>>5);
48 const uint bmask
= 1U<<(cast(uint)x
&0x1f);
49 const uint res
= (*bp
)&bmask
;
54 void resetPixel (int x
, int y
, int z
) nothrow @trusted @nogc {
56 if (x
< 0 || y
< 0 || z
< 0) return;
57 if (cast(uint)x
>= xsize ||
cast(uint)y
>= ysize ||
cast(uint)z
>= zsize
) return;
58 bmp
.ptr
[cast(uint)z
*xywdt
+cast(uint)y
*xwdt
+(cast(uint)x
>>5)] &= ~(1U<<(cast(uint)x
&0x1f));
61 uint getPixel (int x
, int y
, int z
) const nothrow @trusted @nogc {
63 if (x
< 0 || y
< 0 || z
< 0) return 1;
64 if (cast(uint)x
>= xsize ||
cast(uint)y
>= ysize ||
cast(uint)z
>= zsize
) return 1;
65 return (bmp
.ptr
[cast(uint)z
*xywdt
+cast(uint)y
*xwdt
+(cast(uint)x
>>5)]&(1U<<(cast(uint)x
&0x1f)));