lavavu-osmesa 1.8.43__cp311-cp311-manylinux_2_24_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. lavavu/LavaVuPython.py +578 -0
  2. lavavu/_LavaVuPython.cpython-311-x86_64-linux-gnu.so +0 -0
  3. lavavu/__init__.py +15 -0
  4. lavavu/__main__.py +12 -0
  5. lavavu/amalgamate.py +11 -0
  6. lavavu/aserver.py +357 -0
  7. lavavu/control.py +1699 -0
  8. lavavu/convert.py +853 -0
  9. lavavu/dict.json +2485 -0
  10. lavavu/font.bin +0 -0
  11. lavavu/html/LavaVu-amalgamated.css +282 -0
  12. lavavu/html/OK-min.js +99 -0
  13. lavavu/html/baseviewer.js +307 -0
  14. lavavu/html/control.css +104 -0
  15. lavavu/html/control.js +335 -0
  16. lavavu/html/dat-gui-light-theme.css +68 -0
  17. lavavu/html/dat.gui.min.js +2 -0
  18. lavavu/html/draw.js +2259 -0
  19. lavavu/html/drawbox.js +1030 -0
  20. lavavu/html/emscripten-template.js +184 -0
  21. lavavu/html/emscripten.css +92 -0
  22. lavavu/html/favicon.ico +0 -0
  23. lavavu/html/gl-matrix-min.js +47 -0
  24. lavavu/html/gui.css +25 -0
  25. lavavu/html/menu.js +609 -0
  26. lavavu/html/server.js +226 -0
  27. lavavu/html/stats.min.js +5 -0
  28. lavavu/html/styles.css +58 -0
  29. lavavu/html/webview-template.html +43 -0
  30. lavavu/html/webview.html +43 -0
  31. lavavu/lavavu.py +5635 -0
  32. lavavu/points.py +191 -0
  33. lavavu/server.py +343 -0
  34. lavavu/shaders/default.frag +20 -0
  35. lavavu/shaders/default.vert +17 -0
  36. lavavu/shaders/fontShader.frag +25 -0
  37. lavavu/shaders/fontShader.vert +18 -0
  38. lavavu/shaders/lineShader.frag +43 -0
  39. lavavu/shaders/lineShader.vert +28 -0
  40. lavavu/shaders/pointShader.frag +132 -0
  41. lavavu/shaders/pointShader.vert +57 -0
  42. lavavu/shaders/triShader.frag +170 -0
  43. lavavu/shaders/triShader.vert +55 -0
  44. lavavu/shaders/volumeShader.frag +463 -0
  45. lavavu/shaders/volumeShader.vert +5 -0
  46. lavavu/tracers.py +124 -0
  47. lavavu/vutils.py +213 -0
  48. lavavu_osmesa-1.8.43.dist-info/LICENSE.md +179 -0
  49. lavavu_osmesa-1.8.43.dist-info/METADATA +33 -0
  50. lavavu_osmesa-1.8.43.dist-info/RECORD +138 -0
  51. lavavu_osmesa-1.8.43.dist-info/WHEEL +5 -0
  52. lavavu_osmesa-1.8.43.dist-info/entry_points.txt +3 -0
  53. lavavu_osmesa-1.8.43.dist-info/top_level.txt +1 -0
  54. lavavu_osmesa.libs/libLLVM-3-6d00db57.8.so.1 +0 -0
  55. lavavu_osmesa.libs/libOSMesa-29f606eb.so.8.0.0 +0 -0
  56. lavavu_osmesa.libs/libXau-6ab8808d.so.6.0.0 +0 -0
  57. lavavu_osmesa.libs/libXdmcp-911ecd1c.so.6.0.0 +0 -0
  58. lavavu_osmesa.libs/libXfixes-af4baa9b.so.3.1.0 +0 -0
  59. lavavu_osmesa.libs/libavcodec-10cacdd4.so.57.64.101 +0 -0
  60. lavavu_osmesa.libs/libavformat-afa92877.so.57.56.101 +0 -0
  61. lavavu_osmesa.libs/libavutil-837eb790.so.55.34.101 +0 -0
  62. lavavu_osmesa.libs/libbluray-0b5d9dbd.so.1.10.0 +0 -0
  63. lavavu_osmesa.libs/libbsd-4a4ec721.so.0.8.3 +0 -0
  64. lavavu_osmesa.libs/libbz2-9ebec8ea.so.1.0.4 +0 -0
  65. lavavu_osmesa.libs/libcairo-4217ca50.so.2.11400.8 +0 -0
  66. lavavu_osmesa.libs/libchromaprint-c4f82352.so.1.4.2 +0 -0
  67. lavavu_osmesa.libs/libcom_err-b4bd5c72.so.2.1 +0 -0
  68. lavavu_osmesa.libs/libcrystalhd-e4ea0de0.so.3.6 +0 -0
  69. lavavu_osmesa.libs/libdrm-28f5b5e7.so.2.4.0 +0 -0
  70. lavavu_osmesa.libs/libedit-7f8577df.so.2.0.55 +0 -0
  71. lavavu_osmesa.libs/libffi-1c6807d3.so.6.0.4 +0 -0
  72. lavavu_osmesa.libs/libfontconfig-e9a06300.so.1.8.0 +0 -0
  73. lavavu_osmesa.libs/libfreetype-851758a3.so.6.12.3 +0 -0
  74. lavavu_osmesa.libs/libgcrypt-0005395c.so.20.1.6 +0 -0
  75. lavavu_osmesa.libs/libglapi-cf95372b.so.0.0.0 +0 -0
  76. lavavu_osmesa.libs/libgme-5f850ce8.so.0.6.0 +0 -0
  77. lavavu_osmesa.libs/libgmp-742f5e74.so.10.3.2 +0 -0
  78. lavavu_osmesa.libs/libgnutls-1ec2cd13.so.30.13.1 +0 -0
  79. lavavu_osmesa.libs/libgomp-ce6cf6a9.so.1.0.0 +0 -0
  80. lavavu_osmesa.libs/libgpg-error-24781f22.so.0.21.0 +0 -0
  81. lavavu_osmesa.libs/libgsm-aa736f52.so.1.0.12 +0 -0
  82. lavavu_osmesa.libs/libgssapi_krb5-e296a08d.so.2.2 +0 -0
  83. lavavu_osmesa.libs/libhogweed-9d325a8d.so.4.3 +0 -0
  84. lavavu_osmesa.libs/libicudata-79cf9efa.so.57.1 +0 -0
  85. lavavu_osmesa.libs/libicui18n-03536ef3.so.57.1 +0 -0
  86. lavavu_osmesa.libs/libicuuc-5743fca1.so.57.1 +0 -0
  87. lavavu_osmesa.libs/libidn-fd653b64.so.11.6.16 +0 -0
  88. lavavu_osmesa.libs/libjbig-b30cd8bd.so.0 +0 -0
  89. lavavu_osmesa.libs/libjpeg-8afa139c.so.62.2.0 +0 -0
  90. lavavu_osmesa.libs/libk5crypto-93afd15e.so.3.1 +0 -0
  91. lavavu_osmesa.libs/libkeyutils-46318358.so.1.5 +0 -0
  92. lavavu_osmesa.libs/libkrb5-061fe33b.so.3.3 +0 -0
  93. lavavu_osmesa.libs/libkrb5support-86ac49ad.so.0.1 +0 -0
  94. lavavu_osmesa.libs/liblzma-9c0610aa.so.5.2.2 +0 -0
  95. lavavu_osmesa.libs/libmp3lame-249ae4b0.so.0.0.0 +0 -0
  96. lavavu_osmesa.libs/libmpg123-13a39b0e.so.0.42.3 +0 -0
  97. lavavu_osmesa.libs/libncurses-09dfda50.so.5.9 +0 -0
  98. lavavu_osmesa.libs/libnettle-2482db45.so.6.3 +0 -0
  99. lavavu_osmesa.libs/libnuma-c8473f23.so.1.0.0 +0 -0
  100. lavavu_osmesa.libs/libogg-b6ceea65.so.0.8.2 +0 -0
  101. lavavu_osmesa.libs/libopenjp2-a0c5d12e.so.2.1.2 +0 -0
  102. lavavu_osmesa.libs/libopenmpt-58b855da.so.0.0.20 +0 -0
  103. lavavu_osmesa.libs/libopus-37a3229e.so.0.5.3 +0 -0
  104. lavavu_osmesa.libs/libp11-kit-d06ac4a7.so.0.2.0 +0 -0
  105. lavavu_osmesa.libs/libpixman-1-7369dbb3.so.0.34.0 +0 -0
  106. lavavu_osmesa.libs/libpng16-121b9de7.so.16.28.0 +0 -0
  107. lavavu_osmesa.libs/libshine-b48eced9.so.3.0.1 +0 -0
  108. lavavu_osmesa.libs/libsnappy-1125e350.so.1.3.0 +0 -0
  109. lavavu_osmesa.libs/libsoxr-e0d4d3e4.so.0.1.1 +0 -0
  110. lavavu_osmesa.libs/libspeex-6f258c6c.so.1.5.0 +0 -0
  111. lavavu_osmesa.libs/libssh-gcrypt-90c7dd19.so.4.5.1 +0 -0
  112. lavavu_osmesa.libs/libswresample-cb1bf771.so.2.3.100 +0 -0
  113. lavavu_osmesa.libs/libswscale-876dcddb.so.4.2.100 +0 -0
  114. lavavu_osmesa.libs/libtasn1-44938221.so.6.5.3 +0 -0
  115. lavavu_osmesa.libs/libtheoradec-02a81176.so.1.1.4 +0 -0
  116. lavavu_osmesa.libs/libtheoraenc-b508ccf1.so.1.1.2 +0 -0
  117. lavavu_osmesa.libs/libtiff-e2a5092b.so.5.2.6 +0 -0
  118. lavavu_osmesa.libs/libtinfo-33626a82.so.5.9 +0 -0
  119. lavavu_osmesa.libs/libtwolame-6fcc2d32.so.0.0.0 +0 -0
  120. lavavu_osmesa.libs/libva-0f7a824e.so.1.3904.0 +0 -0
  121. lavavu_osmesa.libs/libva-drm-178eb7ac.so.1.3904.0 +0 -0
  122. lavavu_osmesa.libs/libva-x11-d220c497.so.1.3904.0 +0 -0
  123. lavavu_osmesa.libs/libvdpau-0391b780.so.1.0.0 +0 -0
  124. lavavu_osmesa.libs/libvorbis-378bad15.so.0.4.8 +0 -0
  125. lavavu_osmesa.libs/libvorbisenc-d605e0e1.so.2.0.11 +0 -0
  126. lavavu_osmesa.libs/libvorbisfile-5692671f.so.3.3.7 +0 -0
  127. lavavu_osmesa.libs/libvpx-560f7a88.so.4.1.0 +0 -0
  128. lavavu_osmesa.libs/libwavpack-8339806a.so.1.2.0 +0 -0
  129. lavavu_osmesa.libs/libwebp-63152597.so.6.0.2 +0 -0
  130. lavavu_osmesa.libs/libwebpmux-38ab8eb3.so.2.0.2 +0 -0
  131. lavavu_osmesa.libs/libx264-1c898326.so.148 +0 -0
  132. lavavu_osmesa.libs/libx265-51947861.so.95 +0 -0
  133. lavavu_osmesa.libs/libxcb-ffedb2d4.so.1.1.0 +0 -0
  134. lavavu_osmesa.libs/libxcb-render-f7692d1d.so.0.0.0 +0 -0
  135. lavavu_osmesa.libs/libxcb-shm-5702672e.so.0.0.0 +0 -0
  136. lavavu_osmesa.libs/libxml2-b8b306ab.so.2.9.4 +0 -0
  137. lavavu_osmesa.libs/libxvidcore-a773eded.so.4.3 +0 -0
  138. lavavu_osmesa.libs/libzvbi-2db02ce4.so.0.13.2 +0 -0
@@ -0,0 +1,463 @@
1
+ /*
2
+ * Copyright (c) 2014, Monash University. All rights reserved.
3
+ * Author: Owen Kaluza - owen.kaluza ( at ) monash.edu
4
+ *
5
+ * Licensed under the GNU Lesser General Public License
6
+ * https://www.gnu.org/licenses/lgpl.html
7
+ * (volume shader from sharevol https://github.com/OKaluza/sharevol)
8
+ */
9
+ #ifdef WEBGL
10
+ uniform sampler2D uVolume;
11
+ #define NO_DEPTH_WRITE
12
+ #define outColour gl_FragColor
13
+ #define texture(a,b) texture2D(a,b)
14
+ #else
15
+ //Included dynamically before compile in WebGL mode...
16
+ const int maxSamples = 2048;
17
+ uniform sampler3D uVolume;
18
+ out vec4 outColour;
19
+ #endif
20
+
21
+ const float depthT = 0.99; //Transmissivity threshold below which depth write applied
22
+
23
+ uniform sampler2D uTransferFunction;
24
+
25
+ uniform vec3 uBBMin;
26
+ uniform vec3 uBBMax;
27
+ uniform vec3 uResolution;
28
+
29
+ uniform bool uEnableColour;
30
+
31
+ uniform float uBrightness;
32
+ uniform float uContrast;
33
+ uniform float uSaturation;
34
+ uniform float uPower;
35
+ uniform float uBloom;
36
+
37
+ uniform mat4 uMVMatrix;
38
+ uniform mat4 uTMVMatrix;
39
+ uniform mat4 uMVPMatrix;
40
+ uniform mat4 uInvMVPMatrix;
41
+ uniform mat4 uNMatrix;
42
+ uniform vec4 uViewport;
43
+ uniform int uSamples;
44
+ uniform float uDensityFactor;
45
+ uniform float uIsoValue;
46
+ uniform vec4 uIsoColour;
47
+ uniform float uIsoSmooth;
48
+ uniform int uIsoWalls;
49
+ uniform int uFilter;
50
+ uniform vec2 uRange;
51
+ uniform vec2 uDenMinMax;
52
+
53
+ uniform float uAmbient;
54
+ uniform float uDiffuse;
55
+ uniform float uSpecular;
56
+ uniform vec3 uLightPos;
57
+ uniform bool uLighting;
58
+
59
+ vec3 bbMin;
60
+ vec3 bbMax;
61
+
62
+ #ifdef ENABLE_TRICUBIC
63
+ float interpolate_tricubic_fast(vec3 coord);
64
+ #endif
65
+
66
+ #ifdef WEBGL
67
+
68
+ vec2 islices = vec2(1.0 / slices.x, 1.0 / slices.y);
69
+ float maxslice = slices.x * slices.y - 1.0;
70
+ //Clamp to a bit before halfway for the edge voxels
71
+ vec2 cmin = vec2(0.55/(slices.x*slices.y), 0.55/(slices.x*slices.y));
72
+ vec2 cmax = vec2(1.0, 1.0) - cmin;
73
+
74
+ float sample(vec3 pos)
75
+ {
76
+ //Get z slice index and position between two slices
77
+ float Z = pos.z * maxslice;
78
+ float slice = floor(Z); //Index of first slice
79
+ Z = fract(Z);
80
+ //Edge case at z min (possible with tricubic filtering)
81
+ if (int(slice) < 0)
82
+ {
83
+ slice = 0.0;
84
+ Z = 0.0;
85
+ }
86
+ //Edge case at z max
87
+ else if (int(slice) > int(maxslice)-1)
88
+ {
89
+ slice = maxslice-1.0;
90
+ Z = 1.0;
91
+ }
92
+ //Only start interpolation with next Z slice 1/3 from edges at first & last z slice
93
+ //(this approximates how 3d texture volume is sampled at edges with linear filtering
94
+ // due to edge sample being included in weighted average twice)
95
+ // - min z slice
96
+ else if (int(slice) == 0)
97
+ {
98
+ Z = max(0.0, (Z-0.33) * 1.5);
99
+ }
100
+ // - max z slice
101
+ else if (int(slice) == int(maxslice)-1)
102
+ {
103
+ Z = min(1.0, Z*1.5);
104
+ }
105
+
106
+ //X & Y coords of sample scaled to slice size
107
+ //(Clamp range at borders to prevent bleeding between tiles due to linear filtering)
108
+ vec2 sampleOffset = clamp(pos.xy, cmin, cmax) * islices;
109
+ //Offsets in 2D texture of given slice indices
110
+ //(add offsets to scaled position within slice to get sample positions)
111
+ float A = slice * islices.x;
112
+ float B = (slice+1.0) * islices.x;
113
+ vec2 z1offset = vec2(fract(A), floor(A) / slices.y) + sampleOffset;
114
+ vec2 z2offset = vec2(fract(B), floor(B) / slices.y) + sampleOffset;
115
+
116
+ //Interpolate the final value by position between slices [0,1]
117
+ return mix(texture2D(uVolume, z1offset).x, texture2D(uVolume, z2offset).x, Z);
118
+ }
119
+
120
+ #else
121
+ #define sample(pos) (texture(uVolume, pos).x)
122
+ #endif
123
+
124
+ float tex3D(vec3 pos)
125
+ {
126
+ float density;
127
+ //TODO: this can't be enabled outside WebGL currently
128
+ #ifdef ENABLE_TRICUBIC
129
+ if (uFilter > 0)
130
+ density = interpolate_tricubic_fast(pos);
131
+ else
132
+ #endif
133
+ density = sample(pos);
134
+
135
+ //Normalise the density over provided range
136
+ //(used for float textures only, all other formats are already [0,1])
137
+ density = (density - uRange.x) / (uRange.y - uRange.x);
138
+ //density = (density - uRange.x) * irange;
139
+ return density;
140
+ }
141
+
142
+ void lighting(in vec3 pos, in vec3 normal, inout vec3 colour)
143
+ {
144
+ vec4 vertPos = uMVMatrix * vec4(pos, 1.0);
145
+ //Light moves with camera at specified offset
146
+ vec3 lightDir = normalize(uLightPos - vertPos.xyz);
147
+ float diffuse = clamp(abs(dot(normal, lightDir)), 0.1, 1.0);
148
+ vec3 lightWeighting = vec3(uAmbient + diffuse * uDiffuse);
149
+ colour *= lightWeighting;
150
+ }
151
+
152
+ vec3 isoNormal(in vec3 pos, in vec3 shift)
153
+ {
154
+ //Detect bounding box hit (walls)
155
+ if (uIsoWalls > 0)
156
+ {
157
+ if (pos.x <= bbMin.x) return vec3(-1.0, 0.0, 0.0);
158
+ if (pos.x >= bbMax.x) return vec3(1.0, 0.0, 0.0);
159
+ if (pos.y <= bbMin.y) return vec3(0.0, -1.0, 0.0);
160
+ if (pos.y >= bbMax.y) return vec3(0.0, 1.0, 0.0);
161
+ if (pos.z <= bbMin.z) return vec3(0.0, 0.0, -1.0);
162
+ if (pos.z >= bbMax.z) return vec3(0.0, 0.0, 1.0);
163
+ }
164
+
165
+ //Calculate normal
166
+ //by central difference gradient
167
+ //(slower, faster way would be to precompute a gradient texture)
168
+ vec3 pos1 = vec3(tex3D(vec3(pos.x+shift.x, pos.y, pos.z)),
169
+ tex3D(vec3(pos.x, pos.y+shift.y, pos.z)),
170
+ tex3D(vec3(pos.x, pos.y, pos.z+shift.z)));
171
+ vec3 pos2 = vec3(tex3D(vec3(pos.x-shift.x, pos.y, pos.z)),
172
+ tex3D(vec3(pos.x, pos.y-shift.y, pos.z)),
173
+ tex3D(vec3(pos.x, pos.y, pos.z-shift.z)));
174
+ return normalize(pos1 - pos2);
175
+ }
176
+
177
+ vec2 rayIntersectBox(vec3 rayDirection, vec3 rayOrigin)
178
+ {
179
+ //Intersect ray with bounding box
180
+ vec3 rayInvDirection = 1.0 / rayDirection;
181
+ vec3 bbMinDiff = (bbMin - rayOrigin) * rayInvDirection;
182
+ vec3 bbMaxDiff = (bbMax - rayOrigin) * rayInvDirection;
183
+ vec3 imax = max(bbMaxDiff, bbMinDiff);
184
+ vec3 imin = min(bbMaxDiff, bbMinDiff);
185
+ float back = min(imax.x, min(imax.y, imax.z));
186
+ float front = max(max(imin.x, 0.0), max(imin.y, imin.z));
187
+ return vec2(back, front);
188
+ }
189
+
190
+ void main()
191
+ {
192
+ if (any(greaterThan(uBBMin, uBBMax)))
193
+ {
194
+ bbMin = vec3(0.0);
195
+ bbMax = vec3(1.0);
196
+ }
197
+ else
198
+ {
199
+ bbMin = clamp(uBBMin, vec3(0.0), vec3(1.0));
200
+ bbMax = clamp(uBBMax, vec3(0.0), vec3(1.0));
201
+ }
202
+
203
+ //Compute eye space coord from window space to get the ray direction
204
+ //ObjectSpace *[MV] = EyeSpace *[P] = Clip /w = Normalised device coords ->VP-> Window
205
+ //Window ->[VP^]-> NDC ->[/w]-> Clip ->[P^]-> EyeSpace ->[MV^]-> ObjectSpace
206
+ vec4 ndcPos;
207
+ ndcPos.xy = ((2.0 * gl_FragCoord.xy) - (2.0 * uViewport.xy)) / (uViewport.zw) - 1.0;
208
+ //ndcPos.z = (2.0 * gl_FragCoord.z - gl_DepthRange.near - gl_DepthRange.far) /
209
+ // (gl_DepthRange.far - gl_DepthRange.near);
210
+ ndcPos.z = 2.0 * gl_FragCoord.z - 1.0;
211
+ ndcPos.w = 1.0;
212
+ vec4 clipPos = ndcPos / gl_FragCoord.w;
213
+ //vec4 eyeSpacePos = uInvPMatrix * clipPos;
214
+ vec3 rayDirection = normalize((uInvMVPMatrix * clipPos).xyz);
215
+
216
+ //Ray origin from the camera position
217
+ vec4 camPos = -vec4(uMVMatrix[3]); //4th column of modelview
218
+ vec3 rayOrigin = (uTMVMatrix * camPos).xyz;
219
+
220
+ //Calc step
221
+ float stepSize = 1.732 / float(uSamples); //diagonal of [0,1] normalised coord cube = sqrt(3)
222
+
223
+ //Intersect ray with bounding box
224
+ vec2 intersection = rayIntersectBox(rayDirection, rayOrigin);
225
+ //Subtract small increment to avoid errors on front boundary
226
+ intersection.y -= 0.000001;
227
+ //Discard points outside the box (no intersection)
228
+ if (intersection.x <= intersection.y) discard;
229
+
230
+ vec3 rayStart = rayOrigin + rayDirection * intersection.y;
231
+ vec3 rayStop = rayOrigin + rayDirection * intersection.x;
232
+
233
+ vec3 step = normalize(rayStop-rayStart) * stepSize;
234
+ vec3 pos = rayStart;
235
+
236
+ float T = 1.0;
237
+ vec3 colour = vec3(0.0);
238
+ bool inside = false;
239
+ vec3 shift = uIsoSmooth / uResolution;
240
+ //Number of samples to take along this ray before we pass out back of volume...
241
+ float travel = distance(rayStop, rayStart) / stepSize;
242
+ int samples = int(ceil(travel));
243
+ float irange = uRange.y - uRange.x;
244
+ if (irange <= 0.0) irange = 1.0;
245
+ irange = 1.0 / irange;
246
+
247
+ //Map colour over valid density range only
248
+ float dRange = uDenMinMax[1] - uDenMinMax[0];
249
+
250
+ //Raymarch, front to back
251
+ vec3 depthHit = rayStart;
252
+ for (int i=0; i < maxSamples; ++i)
253
+ {
254
+ //Render samples until we pass out back of cube or fully opaque
255
+ if (i == samples || T < 0.01) break;
256
+ {
257
+ //Get density
258
+ float density = tex3D(pos);
259
+
260
+ //Set the depth point to where transmissivity drops below threshold
261
+ if (T > depthT)
262
+ depthHit = pos;
263
+
264
+ #define ISOSURFACE
265
+ #ifdef ISOSURFACE
266
+ //Passed through isosurface?
267
+ if (uIsoColour.a > 0.0 && ((!inside && density >= uIsoValue) || (inside && density < uIsoValue)))
268
+ {
269
+ inside = !inside;
270
+ //Find closer to exact position by iteration
271
+ //http://sizecoding.blogspot.com.au/2008/08/isosurfaces-in-glsl.html
272
+ float exact;
273
+ float a = intersection.y + (float(i)*stepSize);
274
+ float b = a - stepSize;
275
+ for (int j = 0; j < 5; j++)
276
+ {
277
+ exact = (b + a) * 0.5;
278
+ pos = rayDirection * exact + rayOrigin;
279
+ density = tex3D(pos);
280
+ if (density - uIsoValue < 0.0)
281
+ b = exact;
282
+ else
283
+ a = exact;
284
+ }
285
+
286
+ //Skip edges unless flagged to draw
287
+ if (uIsoWalls > 0 || all(greaterThanEqual(pos, bbMin)) && all(lessThanEqual(pos, bbMax)))
288
+ {
289
+ vec4 value = vec4(uIsoColour.rgb, 1.0);
290
+ vec3 light = vec3(1.0, 1.0, 1.0);
291
+ if (uLighting)
292
+ {
293
+ vec3 normal = normalize((uNMatrix * vec4(isoNormal(pos, shift), 1.0)).xyz);
294
+ light = value.rgb;
295
+ lighting(pos, normal, light);
296
+ }
297
+
298
+ //Front-to-back blend equation
299
+ colour += T * uIsoColour.a * light;
300
+ //Render normals
301
+ //colour += T * abs(isoNormal(pos, shift, density));
302
+ T *= (1.0 - uIsoColour.a);
303
+ }
304
+ }
305
+ #endif
306
+
307
+ if (uDensityFactor > 0.0)
308
+ {
309
+ density = clamp(density, 0.0, 1.0);
310
+ if (density < uDenMinMax[0] || density > uDenMinMax[1])
311
+ {
312
+ //Skip to next sample...
313
+ pos += step;
314
+ continue;
315
+ }
316
+
317
+ //Scale to density range - fits colourmap to only the displayed data range
318
+ density = density / dRange;
319
+
320
+ density = pow(density, uPower); //Apply power
321
+
322
+ vec4 value;
323
+ if (uEnableColour)
324
+ {
325
+ value = texture(uTransferFunction, vec2(density, 0.5));
326
+ //Premultiply alpha
327
+ value.rgb *= value.a;
328
+ //Apply bloom power, makes the blending more additive
329
+ value.a = pow(value.a, 1.0 + 3.0*uBloom);
330
+ }
331
+ else
332
+ value = vec4(density);
333
+
334
+ value *= uDensityFactor * stepSize;
335
+
336
+ //Blending is front to back
337
+ //Color
338
+ colour += T * value.rgb;
339
+ //Alpha
340
+ T *= 1.0 - value.a;
341
+ }
342
+ }
343
+
344
+ //Next sample...
345
+ pos += step;
346
+ }
347
+
348
+ //Apply brightness, saturation & contrast
349
+ colour += uBrightness;
350
+ const vec3 LumCoeff = vec3(0.2125, 0.7154, 0.0721);
351
+ vec3 AvgLumin = vec3(0.5, 0.5, 0.5);
352
+ vec3 intensity = vec3(dot(colour, LumCoeff));
353
+ colour = mix(intensity, colour, uSaturation);
354
+ colour = mix(AvgLumin, colour, uContrast);
355
+
356
+ //TODO: alpha threshold uniform?
357
+ //if (T > depthT) discard;
358
+ outColour = vec4(colour, 1.0 - T);
359
+
360
+ #ifndef NO_DEPTH_WRITE
361
+ // Write the depth (!Not supported in WebGL without extension)
362
+ float depth = 1.0; //Default to far limit
363
+ if (T < depthT)
364
+ {
365
+ //ObjectSpace *[MV] = EyeSpace *[P] = Clip /w = Normalised device coords ->VP-> Window
366
+ vec4 clip_space_pos = vec4(depthHit, 1.0);
367
+ clip_space_pos = uMVPMatrix * clip_space_pos;
368
+ //Get in normalised device coords [-1,1]
369
+ float ndc_depth = clip_space_pos.z / clip_space_pos.w;
370
+ //Convert to depth range, default [0,1] but may have been modified
371
+ if (ndc_depth >= -1.0 && ndc_depth <= 1.0)
372
+ depth = 0.5 * ndc_depth + 0.5;
373
+ else
374
+ depth = 0.0;
375
+
376
+ //depth = 0.5 * (((gl_DepthRange.far - gl_DepthRange.near) * ndc_depth) +
377
+ // gl_DepthRange.near + gl_DepthRange.far);
378
+ }
379
+
380
+ gl_FragDepth = depth;
381
+ #endif
382
+ }
383
+
384
+ #ifdef ENABLE_TRICUBIC
385
+ float interpolate_tricubic_fast(vec3 coord)
386
+ {
387
+ /* License applicable to this function:
388
+ Copyright (c) 2008-2013, Danny Ruijters. All rights reserved.
389
+
390
+ Redistribution and use in source and binary forms, with or without
391
+ modification, are permitted provided that the following conditions are met:
392
+ * Redistributions of source code must retain the above copyright
393
+ notice, this list of conditions and the following disclaimer.
394
+ * Redistributions in binary form must reproduce the above copyright
395
+ notice, this list of conditions and the following disclaimer in the
396
+ documentation and/or other materials provided with the distribution.
397
+ * Neither the name of the copyright holders nor the names of its
398
+ contributors may be used to endorse or promote products derived from
399
+ this software without specific prior written permission.
400
+
401
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
402
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
403
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
404
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
405
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
406
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
407
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
408
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
409
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
410
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
411
+ POSSIBILITY OF SUCH DAMAGE.
412
+
413
+ The views and conclusions contained in the software and documentation are
414
+ those of the authors and should not be interpreted as representing official
415
+ policies, either expressed or implied.
416
+
417
+ When using this code in a scientific project, please cite one or all of the
418
+ following papers:
419
+ * Daniel Ruijters and Philippe Thevenaz,
420
+ GPU Prefilter for Accurate Cubic B-Spline Interpolation,
421
+ The Computer Journal, vol. 55, no. 1, pp. 15-20, January 2012.
422
+ * Daniel Ruijters, Bart M. ter Haar Romeny, and Paul Suetens,
423
+ Efficient GPU-Based Texture Interpolation using Uniform B-Splines,
424
+ Journal of Graphics Tools, vol. 13, no. 4, pp. 61-69, 2008.
425
+ */
426
+ // shift the coordinate from [0,1] to [-0.5, nrOfVoxels-0.5]
427
+ vec3 nrOfVoxels = uResolution;
428
+ vec3 coord_grid = coord * nrOfVoxels - 0.5;
429
+ vec3 index = floor(coord_grid);
430
+ vec3 fraction = coord_grid - index;
431
+ vec3 one_frac = 1.0 - fraction;
432
+
433
+ vec3 w0 = 1.0/6.0 * one_frac*one_frac*one_frac;
434
+ vec3 w1 = 2.0/3.0 - 0.5 * fraction*fraction*(2.0-fraction);
435
+ vec3 w2 = 2.0/3.0 - 0.5 * one_frac*one_frac*(2.0-one_frac);
436
+ vec3 w3 = 1.0/6.0 * fraction*fraction*fraction;
437
+
438
+ vec3 g0 = w0 + w1;
439
+ vec3 g1 = w2 + w3;
440
+ vec3 mult = 1.0 / nrOfVoxels;
441
+ vec3 h0 = mult * ((w1 / g0) - 0.5 + index); //h0 = w1/g0 - 1, move from [-0.5, nrOfVoxels-0.5] to [0,1]
442
+ vec3 h1 = mult * ((w3 / g1) + 1.5 + index); //h1 = w3/g1 + 1, move from [-0.5, nrOfVoxels-0.5] to [0,1]
443
+
444
+ // fetch the eight linear interpolations
445
+ // weighting and fetching is interleaved for performance and stability reasons
446
+ float tex000 = sample(h0);
447
+ float tex100 = sample(vec3(h1.x, h0.y, h0.z));
448
+ tex000 = mix(tex100, tex000, g0.x); //weigh along the x-direction
449
+ float tex010 = sample(vec3(h0.x, h1.y, h0.z));
450
+ float tex110 = sample(vec3(h1.x, h1.y, h0.z));
451
+ tex010 = mix(tex110, tex010, g0.x); //weigh along the x-direction
452
+ tex000 = mix(tex010, tex000, g0.y); //weigh along the y-direction
453
+ float tex001 = sample(vec3(h0.x, h0.y, h1.z));
454
+ float tex101 = sample(vec3(h1.x, h0.y, h1.z));
455
+ tex001 = mix(tex101, tex001, g0.x); //weigh along the x-direction
456
+ float tex011 = sample(vec3(h0.x, h1.y, h1.z));
457
+ float tex111 = sample(h1);
458
+ tex011 = mix(tex111, tex011, g0.x); //weigh along the x-direction
459
+ tex001 = mix(tex011, tex001, g0.y); //weigh along the y-direction
460
+
461
+ return mix(tex001, tex000, g0.z); //weigh along the z-direction
462
+ }
463
+ #endif
@@ -0,0 +1,5 @@
1
+ in vec4 aVertexPosition;
2
+ void main(void)
3
+ {
4
+ gl_Position = aVertexPosition;
5
+ }
lavavu/tracers.py ADDED
@@ -0,0 +1,124 @@
1
+ """
2
+ Warning! EXPERIMENTAL:
3
+ these features and functions are under development, will have bugs,
4
+ and may be heavily modified in the future
5
+
6
+ Tracer particles in a vector field
7
+ Uses a KDTree to find nearest vector to advect the particles
8
+
9
+ - Requires scipy.spatial
10
+ """
11
+ import numpy
12
+ import os
13
+ import sys
14
+ import random
15
+ import math
16
+ from scipy import spatial
17
+
18
+ #Necessary? for large trees, detect?
19
+ #sys.setrecursionlimit(10000)
20
+
21
+ class TracerState(object):
22
+ def __init__(self, verts, N=5000):
23
+ self.tree = spatial.cKDTree(verts)
24
+ self.tracers = None
25
+ self.steps = [0]*N
26
+ self.values = None
27
+ self.positions = None
28
+ self.velocities = None
29
+
30
+ def trace_particles(state, verts, vecs, N=5000, limit=0.5, speed=1.0, noise=0.0, height=None):
31
+ """
32
+ Take a list of tracer vertices and matching velocity grid points (verts) & vectors (vecs)
33
+ For each tracer
34
+
35
+ - find the nearest velocity grid point
36
+ - if within max dist: Multiply position by velocity vector
37
+ - otherwise: Generate a new start position for tracer
38
+
39
+ Parameters
40
+ ----------
41
+ state : TracerState
42
+ Object returned from first call, pass None on first pass
43
+ verts : array or list
44
+ vertices of the vector field
45
+ vecs : array or list
46
+ vector values of the vector field
47
+ N : int
48
+ Number of particles to seed
49
+ limit : float
50
+ Distance limit over which tracers are not connected,
51
+ For example if using a periodic boundary, setting limit to
52
+ half the bounding box size will prevent tracer lines being
53
+ connected when passing through the boundary
54
+ speed : float
55
+ Speed multiplier, scaling factor for the velocity taken from the vector values
56
+ noise : float
57
+ A noise factor, if set a random value is generated, multiplied by noise factor
58
+ and added to each new position
59
+ height : float
60
+ A fixed height value, all positions will be given this height as their Z component
61
+
62
+ Returns
63
+ -------
64
+ TracerState
65
+ Object to hold the tracer state and track particles
66
+ Pass this as first paramter on subsequent calls
67
+ """
68
+
69
+ #KDstate.tree for finding nearest velocity grid point
70
+ if state is None:
71
+ state = TracerState(verts, N)
72
+
73
+ lastid = 0
74
+ def rand_vert():
75
+ #Get a random velocity grid point
76
+ lastid = random.randint(0, len(verts)-1)
77
+ pos = verts[lastid]
78
+ #Generate some random noise to offset
79
+ noise3 = numpy.array((0.,0.,0.))
80
+ if noise > 0.0:
81
+ noise3 = numpy.random.rand(3) * noise
82
+ #Fixed height?
83
+ if height:
84
+ noise3[2] = height
85
+ #Return the sum
86
+ return pos + noise3
87
+
88
+ if state.positions is None:
89
+ state.positions = numpy.zeros(shape=(N,3))
90
+ state.velocities = numpy.zeros(shape=(N,3))
91
+ state.values = numpy.zeros(shape=(N))
92
+ for i in range(N):
93
+ state.positions[i] = rand_vert()
94
+ state.steps[i] = 0
95
+ state.values[i] = numpy.linalg.norm(vecs[lastid])
96
+
97
+ #Query all tracer state.positions
98
+ q = state.tree.query(state.positions, k=1)
99
+ for r in range(len(q[0])):
100
+ #print("result, distance, point")
101
+ #print(r, q[0][r], state.tree.data[q[1][r]], state.positions[r])
102
+
103
+ #Increasing random chance as steps exceed 5 of a new start pos
104
+ if random.randint(0,state.steps[r]) > 5:
105
+ #Pick a new random grid vertex to start from
106
+ #(Must be farther away than distance criteria)
107
+ old = numpy.array(state.positions[r])
108
+ while True:
109
+ state.positions[r] = rand_vert()
110
+ if numpy.linalg.norm(state.positions[r]-old) > limit:
111
+ break
112
+ state.steps[r] = 0
113
+ state.values[r] = numpy.linalg.norm(vecs[lastid])
114
+ else:
115
+ #Index of nearest grid point is in q[1][r]
116
+ #Lookup vector at this index, multiply by position to get delta and add
117
+ state.velocities[r] = vecs[q[1][r]] #Store velocity
118
+ state.positions[r] += speed * vecs[q[1][r]]
119
+ #Increment step tracking
120
+ state.steps[r] += 1
121
+ state.values[r] = numpy.linalg.norm(vecs[q[1][r]])
122
+
123
+ return state
124
+