biomedisa 2024.5.14__py3-none-any.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.
- biomedisa/__init__.py +53 -0
- biomedisa/__main__.py +18 -0
- biomedisa/biomedisa_features/DataGenerator.py +299 -0
- biomedisa/biomedisa_features/DataGeneratorCrop.py +121 -0
- biomedisa/biomedisa_features/PredictDataGenerator.py +87 -0
- biomedisa/biomedisa_features/PredictDataGeneratorCrop.py +74 -0
- biomedisa/biomedisa_features/__init__.py +0 -0
- biomedisa/biomedisa_features/active_contour.py +434 -0
- biomedisa/biomedisa_features/amira_to_np/__init__.py +0 -0
- biomedisa/biomedisa_features/amira_to_np/amira_data_stream.py +980 -0
- biomedisa/biomedisa_features/amira_to_np/amira_grammar.py +369 -0
- biomedisa/biomedisa_features/amira_to_np/amira_header.py +290 -0
- biomedisa/biomedisa_features/amira_to_np/amira_helper.py +72 -0
- biomedisa/biomedisa_features/assd.py +167 -0
- biomedisa/biomedisa_features/biomedisa_helper.py +801 -0
- biomedisa/biomedisa_features/create_slices.py +286 -0
- biomedisa/biomedisa_features/crop_helper.py +586 -0
- biomedisa/biomedisa_features/curvop_numba.py +149 -0
- biomedisa/biomedisa_features/django_env.py +172 -0
- biomedisa/biomedisa_features/keras_helper.py +1219 -0
- biomedisa/biomedisa_features/nc_reader.py +179 -0
- biomedisa/biomedisa_features/pid.py +52 -0
- biomedisa/biomedisa_features/process_image.py +253 -0
- biomedisa/biomedisa_features/pycuda_test.py +84 -0
- biomedisa/biomedisa_features/random_walk/__init__.py +0 -0
- biomedisa/biomedisa_features/random_walk/gpu_kernels.py +183 -0
- biomedisa/biomedisa_features/random_walk/pycuda_large.py +826 -0
- biomedisa/biomedisa_features/random_walk/pycuda_large_allx.py +806 -0
- biomedisa/biomedisa_features/random_walk/pycuda_small.py +414 -0
- biomedisa/biomedisa_features/random_walk/pycuda_small_allx.py +493 -0
- biomedisa/biomedisa_features/random_walk/pyopencl_large.py +760 -0
- biomedisa/biomedisa_features/random_walk/pyopencl_small.py +441 -0
- biomedisa/biomedisa_features/random_walk/rw_large.py +390 -0
- biomedisa/biomedisa_features/random_walk/rw_small.py +310 -0
- biomedisa/biomedisa_features/remove_outlier.py +399 -0
- biomedisa/biomedisa_features/split_volume.py +274 -0
- biomedisa/deeplearning.py +519 -0
- biomedisa/interpolation.py +371 -0
- biomedisa/mesh.py +406 -0
- biomedisa-2024.5.14.dist-info/LICENSE +191 -0
- biomedisa-2024.5.14.dist-info/METADATA +306 -0
- biomedisa-2024.5.14.dist-info/RECORD +44 -0
- biomedisa-2024.5.14.dist-info/WHEEL +5 -0
- biomedisa-2024.5.14.dist-info/top_level.txt +1 -0
@@ -0,0 +1,441 @@
|
|
1
|
+
##########################################################################
|
2
|
+
## ##
|
3
|
+
## Copyright (c) 2023 Philipp Lösel. All rights reserved. ##
|
4
|
+
## ##
|
5
|
+
## This file is part of the open source project biomedisa. ##
|
6
|
+
## ##
|
7
|
+
## Licensed under the European Union Public Licence (EUPL) ##
|
8
|
+
## v1.2, or - as soon as they will be approved by the ##
|
9
|
+
## European Commission - subsequent versions of the EUPL; ##
|
10
|
+
## ##
|
11
|
+
## You may redistribute it and/or modify it under the terms ##
|
12
|
+
## of the EUPL v1.2. You may not use this work except in ##
|
13
|
+
## compliance with this Licence. ##
|
14
|
+
## ##
|
15
|
+
## You can obtain a copy of the Licence at: ##
|
16
|
+
## ##
|
17
|
+
## https://joinup.ec.europa.eu/page/eupl-text-11-12 ##
|
18
|
+
## ##
|
19
|
+
## Unless required by applicable law or agreed to in ##
|
20
|
+
## writing, software distributed under the Licence is ##
|
21
|
+
## distributed on an "AS IS" basis, WITHOUT WARRANTIES ##
|
22
|
+
## OR CONDITIONS OF ANY KIND, either express or implied. ##
|
23
|
+
## ##
|
24
|
+
## See the Licence for the specific language governing ##
|
25
|
+
## permissions and limitations under the Licence. ##
|
26
|
+
## ##
|
27
|
+
##########################################################################
|
28
|
+
|
29
|
+
import numpy as np
|
30
|
+
import pyopencl as cl
|
31
|
+
import os
|
32
|
+
|
33
|
+
def walk(data, slices, indices, indices_child, nbrw, sorw, name, ctx, queue):
|
34
|
+
|
35
|
+
labels = np.unique(slices)
|
36
|
+
slicesChunk = _extract_slices(slices, indices, indices_child)
|
37
|
+
labelsChunk = np.unique(slicesChunk)
|
38
|
+
|
39
|
+
# remove negative labels from list
|
40
|
+
index = np.argwhere(labels<0)
|
41
|
+
labels = np.delete(labels, index)
|
42
|
+
index = np.argwhere(labelsChunk<0)
|
43
|
+
labelsChunk = np.delete(labelsChunk, index)
|
44
|
+
|
45
|
+
walkmapChunk = _walk_on_current_gpu(data, slicesChunk, labelsChunk, indices_child, nbrw, sorw, name, ctx, queue)
|
46
|
+
|
47
|
+
if walkmapChunk.shape[0] != len(labels):
|
48
|
+
walkmap = np.zeros((len(labels),)+data.shape, dtype=np.float32)
|
49
|
+
chunk2Walkmap = np.nonzero(np.in1d(labels, labelsChunk))[0]
|
50
|
+
for chunkIndex, walkmapIndex in enumerate(chunk2Walkmap):
|
51
|
+
walkmap[walkmapIndex] += walkmapChunk[chunkIndex]
|
52
|
+
else:
|
53
|
+
walkmap = walkmapChunk
|
54
|
+
|
55
|
+
return walkmap
|
56
|
+
|
57
|
+
def _extract_slices(slices, indices, indicesChunk):
|
58
|
+
extracted = np.zeros((0, slices.shape[1], slices.shape[2]), dtype=np.int32)
|
59
|
+
slicesIndicesToExtract = np.nonzero(np.in1d(indices, indicesChunk))[0]
|
60
|
+
for arraySliceIndex in slicesIndicesToExtract:
|
61
|
+
extracted = np.append(extracted, [slices[arraySliceIndex]], axis=0)
|
62
|
+
return extracted
|
63
|
+
|
64
|
+
def _walk_on_current_gpu(raw, slices, allLabels, indices, nbrw, sorw, name, ctx, queue):
|
65
|
+
|
66
|
+
# build kernels
|
67
|
+
if raw.dtype == 'uint8':
|
68
|
+
src = _build_kernel_int8()
|
69
|
+
raw = (raw-128).astype('int8')
|
70
|
+
else:
|
71
|
+
src = _build_kernel_float32()
|
72
|
+
raw = raw.astype(np.float32)
|
73
|
+
|
74
|
+
indices = np.array(indices, dtype=np.int32)
|
75
|
+
slices = np.array(slices, dtype=np.int32)
|
76
|
+
walkmap = np.zeros((len(allLabels),)+raw.shape, dtype=np.float32)
|
77
|
+
a = np.empty(raw.shape, dtype=np.int32)
|
78
|
+
|
79
|
+
# image size
|
80
|
+
zsh, ysh, xsh = raw.shape
|
81
|
+
slshape = slices.shape[0]
|
82
|
+
|
83
|
+
# kernel function instantiation
|
84
|
+
mf = cl.mem_flags
|
85
|
+
prg = cl.Program(ctx, src).build()
|
86
|
+
|
87
|
+
# allocate memory for variables on the device
|
88
|
+
indices_cl = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=indices)
|
89
|
+
slices_cl = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=slices)
|
90
|
+
raw_cl = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=raw)
|
91
|
+
a_cl = cl.Buffer(ctx, mf.WRITE_ONLY | mf.COPY_HOST_PTR, hostbuf=a)
|
92
|
+
|
93
|
+
xsh_cl = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=np.int32(xsh))
|
94
|
+
ysh_cl = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=np.int32(ysh))
|
95
|
+
zsh_cl = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=np.int32(zsh))
|
96
|
+
sorw_cl = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=np.int32(sorw))
|
97
|
+
nbrw_cl = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=np.int32(nbrw))
|
98
|
+
segment_cl = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=np.int32(0))
|
99
|
+
|
100
|
+
# block and grid size
|
101
|
+
#block = (1, 32, 32)
|
102
|
+
#x_grid = ((xsh // 32) + 1)*32
|
103
|
+
#y_grid = ((ysh // 32) + 1)*32
|
104
|
+
#grid = (slshape, y_grid, x_grid)
|
105
|
+
|
106
|
+
block = None
|
107
|
+
grid = (slshape, ysh, xsh)
|
108
|
+
|
109
|
+
# call Kernel
|
110
|
+
for label_counter, segment in enumerate(allLabels):
|
111
|
+
print('%s:' %(name) + ' ' + str(label_counter+1) + '/' + str(len(allLabels)))
|
112
|
+
cl.enqueue_fill_buffer(queue, a_cl, np.int32(0), offset=0, size=a.nbytes)
|
113
|
+
cl.enqueue_fill_buffer(queue, segment_cl, np.int32(segment), offset=0, size=4, wait_for=None)
|
114
|
+
prg.randomWalk(queue, grid, block, segment_cl, raw_cl, slices_cl, a_cl, xsh_cl, ysh_cl, zsh_cl, indices_cl, sorw_cl, nbrw_cl)
|
115
|
+
cl.enqueue_copy(queue, a, a_cl)
|
116
|
+
walkmap[label_counter] += a
|
117
|
+
return walkmap
|
118
|
+
|
119
|
+
def _build_kernel_int8():
|
120
|
+
src = '''
|
121
|
+
|
122
|
+
float _calc_var(int position, int index, int B, __global char *raw, int segment, __global int *labels, int xsh) {
|
123
|
+
float dev = 0;
|
124
|
+
float summe = 0;
|
125
|
+
for (int n = -1; n < 2; n++) {
|
126
|
+
for (int o = -1; o < 2; o++) {
|
127
|
+
if (labels[index + n*xsh + o] == segment) {
|
128
|
+
float tmp = B - raw[position + n*xsh + o];
|
129
|
+
dev += tmp * tmp;
|
130
|
+
summe += 1;
|
131
|
+
}
|
132
|
+
}
|
133
|
+
}
|
134
|
+
float var = dev / summe;
|
135
|
+
if (var < 1.0) {
|
136
|
+
var = 1.0;
|
137
|
+
}
|
138
|
+
return var;
|
139
|
+
}
|
140
|
+
|
141
|
+
float weight(int B, int A, float div1) {
|
142
|
+
int tmp = B - A;
|
143
|
+
return exp( - tmp * tmp * div1 );
|
144
|
+
}
|
145
|
+
|
146
|
+
__kernel void randomWalk(__global int *Segment, __global char *raw, __global int *slices, __global int *a, __global int *Xsh, __global int *Ysh, __global int *Zsh, __global int *indices, __global int *Sorw, __global int *Nbrw) {
|
147
|
+
|
148
|
+
int sorw = *Sorw;
|
149
|
+
int nbrw = *Nbrw;
|
150
|
+
int xsh = *Xsh;
|
151
|
+
int ysh = *Ysh;
|
152
|
+
int zsh = *Zsh;
|
153
|
+
int segment = *Segment;
|
154
|
+
|
155
|
+
// get_global_id(0) // blockIdx.z * blockDim.z + threadIdx.z
|
156
|
+
// get_local_id(0) // threadIdx.z
|
157
|
+
// get_global_size(0) // gridDim.z * blockDim.z
|
158
|
+
// get_local_size(0) // blockDim.z
|
159
|
+
|
160
|
+
int flat = xsh * ysh;
|
161
|
+
int column = get_global_id(2);
|
162
|
+
int row = get_global_id(1);
|
163
|
+
int slice = get_global_id(0);
|
164
|
+
int plane = indices[slice];
|
165
|
+
int index = slice * flat + row * xsh + column;
|
166
|
+
int position = plane*flat + row*xsh + column;
|
167
|
+
|
168
|
+
if (index < get_global_size(0)*flat && plane>0 && row>0 && column>0 && plane<zsh-1 && row<ysh-1 && column<xsh-1) {
|
169
|
+
|
170
|
+
if (slices[index]==segment) {
|
171
|
+
|
172
|
+
float rand;
|
173
|
+
float W0,W1,W2,W3,W4,W5;
|
174
|
+
int n,o,p;
|
175
|
+
|
176
|
+
/* Initialize MRG32k3a */
|
177
|
+
float norm = 2.328306549295728e-10;
|
178
|
+
float m1 = 4294967087.0;
|
179
|
+
float m2 = 4294944443.0;
|
180
|
+
float a12 = 1403580.0;
|
181
|
+
float a13n = 810728.0;
|
182
|
+
float a21 = 527612.0;
|
183
|
+
float a23n = 1370589.0;
|
184
|
+
long k1;
|
185
|
+
float p1, p2;
|
186
|
+
float s10 = index, s11 = index, s12 = index, s20 = index, s21 = index, s22 = index;
|
187
|
+
|
188
|
+
/* Compute standard deviation */
|
189
|
+
int B = raw[position];
|
190
|
+
float var = _calc_var(position, index, B, raw, segment, slices, xsh);
|
191
|
+
float div1 = 1 / (2 * var);
|
192
|
+
|
193
|
+
int k = plane;
|
194
|
+
int l = row;
|
195
|
+
int m = column;
|
196
|
+
|
197
|
+
int step = 0;
|
198
|
+
int n_rw = 0;
|
199
|
+
|
200
|
+
/* Compute random walks */
|
201
|
+
while (n_rw < nbrw) {
|
202
|
+
|
203
|
+
/* Compute weights */
|
204
|
+
W0 = weight(B, raw[position + flat], div1);
|
205
|
+
W1 = weight(B, raw[position - flat], div1);
|
206
|
+
W2 = weight(B, raw[position + xsh], div1);
|
207
|
+
W3 = weight(B, raw[position - xsh], div1);
|
208
|
+
W4 = weight(B, raw[position + 1], div1);
|
209
|
+
W5 = weight(B, raw[position - 1], div1);
|
210
|
+
|
211
|
+
W1 += W0;
|
212
|
+
W2 += W1;
|
213
|
+
W3 += W2;
|
214
|
+
W4 += W3;
|
215
|
+
W5 += W4;
|
216
|
+
|
217
|
+
/* Compute random numbers with MRG32k3a */
|
218
|
+
|
219
|
+
/* Component 1 */
|
220
|
+
p1 = a12 * s11 - a13n * s10;
|
221
|
+
k1 = p1 / m1;
|
222
|
+
p1 -= k1 * m1;
|
223
|
+
if (p1 < 0.0){
|
224
|
+
p1 += m1;}
|
225
|
+
s10 = s11;
|
226
|
+
s11 = s12;
|
227
|
+
s12 = p1;
|
228
|
+
|
229
|
+
/* Component 2 */
|
230
|
+
p2 = a21 * s22 - a23n * s20;
|
231
|
+
k1 = p2 / m2;
|
232
|
+
p2 -= k1 * m2;
|
233
|
+
if (p2 < 0.0){
|
234
|
+
p2 += m2;}
|
235
|
+
s20 = s21;
|
236
|
+
s21 = s22;
|
237
|
+
s22 = p2;
|
238
|
+
|
239
|
+
/* Combination */
|
240
|
+
if (p1 <= p2) {
|
241
|
+
rand = W5 * ((p1 - p2 + m1) * norm);
|
242
|
+
}
|
243
|
+
else {
|
244
|
+
rand = W5 * ((p1 - p2) * norm);
|
245
|
+
}
|
246
|
+
|
247
|
+
/* Determine new direction of random walk */
|
248
|
+
if (rand<W0 || rand==0){n=1; o=0; p=0;}
|
249
|
+
else if (rand>=W0 && rand<W1){n=-1; o=0; p=0;}
|
250
|
+
else if (rand>=W1 && rand<W2){n=0; o=1; p=0;}
|
251
|
+
else if (rand>=W2 && rand<W3){n=0; o=-1; p=0;}
|
252
|
+
else if (rand>=W3 && rand<W4){n=0; o=0; p=1;}
|
253
|
+
else if (rand>=W4 && rand<=W5){n=0; o=0; p=-1;}
|
254
|
+
|
255
|
+
/* Move in new direction */
|
256
|
+
if (k+n>0 && k+n<zsh-1 && l+o>0 && l+o<ysh-1 && m+p>0 && m+p<xsh-1) {
|
257
|
+
k += n;
|
258
|
+
l += o;
|
259
|
+
m += p;
|
260
|
+
position = k*flat + l*xsh + m;
|
261
|
+
atomic_add(&a[position], 1);
|
262
|
+
}
|
263
|
+
|
264
|
+
step += 1;
|
265
|
+
|
266
|
+
if (step==sorw) {
|
267
|
+
k = plane;
|
268
|
+
l = row;
|
269
|
+
m = column;
|
270
|
+
position = k*flat + l*xsh + m;
|
271
|
+
n_rw += 1;
|
272
|
+
step = 0;
|
273
|
+
}
|
274
|
+
}
|
275
|
+
}
|
276
|
+
}
|
277
|
+
}
|
278
|
+
'''
|
279
|
+
return src
|
280
|
+
|
281
|
+
def _build_kernel_float32():
|
282
|
+
src = '''
|
283
|
+
|
284
|
+
float _calc_var(int position, int index, float B, __global float *raw, int segment, __global int *labels, int xsh) {
|
285
|
+
float dev = 0;
|
286
|
+
float summe = 0;
|
287
|
+
for (int n = -1; n < 2; n++) {
|
288
|
+
for (int o = -1; o < 2; o++) {
|
289
|
+
if (labels[index + n*xsh + o] == segment) {
|
290
|
+
float tmp = B - raw[position + n*xsh + o];
|
291
|
+
dev += tmp * tmp;
|
292
|
+
summe += 1;
|
293
|
+
}
|
294
|
+
}
|
295
|
+
}
|
296
|
+
float var = dev / summe;
|
297
|
+
if (var < 1.0) {
|
298
|
+
var = 1.0;
|
299
|
+
}
|
300
|
+
return var;
|
301
|
+
}
|
302
|
+
|
303
|
+
float weight(float B, float A, float div1) {
|
304
|
+
float tmp = B - A;
|
305
|
+
return exp( - tmp * tmp * div1 );
|
306
|
+
}
|
307
|
+
|
308
|
+
__kernel void randomWalk(__global int *Segment, __global float *raw, __global int *slices, __global int *a, __global int *Xsh, __global int *Ysh, __global int *Zsh, __global int *indices, __global int *Sorw, __global int *Nbrw)
|
309
|
+
{
|
310
|
+
int sorw = *Sorw;
|
311
|
+
int nbrw = *Nbrw;
|
312
|
+
int xsh = *Xsh;
|
313
|
+
int ysh = *Ysh;
|
314
|
+
int zsh = *Zsh;
|
315
|
+
int segment = *Segment;
|
316
|
+
|
317
|
+
// get_global_id(0) // blockIdx.z * blockDim.z + threadIdx.z
|
318
|
+
// get_local_id(0) // threadIdx.z
|
319
|
+
// get_global_size(0) // gridDim.z * blockDim.z
|
320
|
+
// get_local_size(0) // blockDim.z
|
321
|
+
|
322
|
+
int flat = xsh * ysh;
|
323
|
+
int column = get_global_id(2);
|
324
|
+
int row = get_global_id(1);
|
325
|
+
int slice = get_global_id(0);
|
326
|
+
int plane = indices[slice];
|
327
|
+
int index = slice * flat + row * xsh + column;
|
328
|
+
int position = plane*flat + row*xsh + column;
|
329
|
+
|
330
|
+
if (index < get_global_size(0)*flat && plane>0 && row>0 && column>0 && plane<zsh-1 && row<ysh-1 && column<xsh-1) {
|
331
|
+
|
332
|
+
if (slices[index]==segment) {
|
333
|
+
|
334
|
+
float rand;
|
335
|
+
float W0,W1,W2,W3,W4,W5;
|
336
|
+
int n,o,p;
|
337
|
+
|
338
|
+
/* Initialize MRG32k3a */
|
339
|
+
float norm = 2.328306549295728e-10;
|
340
|
+
float m1 = 4294967087.0;
|
341
|
+
float m2 = 4294944443.0;
|
342
|
+
float a12 = 1403580.0;
|
343
|
+
float a13n = 810728.0;
|
344
|
+
float a21 = 527612.0;
|
345
|
+
float a23n = 1370589.0;
|
346
|
+
long k1;
|
347
|
+
float p1, p2;
|
348
|
+
float s10 = index, s11 = index, s12 = index, s20 = index, s21 = index, s22 = index;
|
349
|
+
|
350
|
+
/* Compute standard deviation */
|
351
|
+
float B = raw[position];
|
352
|
+
float var = _calc_var(position, index, B, raw, segment, slices, xsh);
|
353
|
+
float div1 = 1 / (2 * var);
|
354
|
+
|
355
|
+
int k = plane;
|
356
|
+
int l = row;
|
357
|
+
int m = column;
|
358
|
+
|
359
|
+
int step = 0;
|
360
|
+
int n_rw = 0;
|
361
|
+
|
362
|
+
/* Compute random walks */
|
363
|
+
while (n_rw < nbrw) {
|
364
|
+
|
365
|
+
W0 = weight(B, raw[position + flat], div1);
|
366
|
+
W1 = weight(B, raw[position - flat], div1);
|
367
|
+
W2 = weight(B, raw[position + xsh], div1);
|
368
|
+
W3 = weight(B, raw[position - xsh], div1);
|
369
|
+
W4 = weight(B, raw[position + 1], div1);
|
370
|
+
W5 = weight(B, raw[position - 1], div1);
|
371
|
+
|
372
|
+
W1 += W0;
|
373
|
+
W2 += W1;
|
374
|
+
W3 += W2;
|
375
|
+
W4 += W3;
|
376
|
+
W5 += W4;
|
377
|
+
|
378
|
+
/* Compute random numbers with MRG32k3a */
|
379
|
+
|
380
|
+
/* Component 1 */
|
381
|
+
p1 = a12 * s11 - a13n * s10;
|
382
|
+
k1 = p1 / m1;
|
383
|
+
p1 -= k1 * m1;
|
384
|
+
if (p1 < 0.0){
|
385
|
+
p1 += m1;}
|
386
|
+
s10 = s11;
|
387
|
+
s11 = s12;
|
388
|
+
s12 = p1;
|
389
|
+
|
390
|
+
/* Component 2 */
|
391
|
+
p2 = a21 * s22 - a23n * s20;
|
392
|
+
k1 = p2 / m2;
|
393
|
+
p2 -= k1 * m2;
|
394
|
+
if (p2 < 0.0){
|
395
|
+
p2 += m2;}
|
396
|
+
s20 = s21;
|
397
|
+
s21 = s22;
|
398
|
+
s22 = p2;
|
399
|
+
|
400
|
+
/* Combination */
|
401
|
+
if (p1 <= p2) {
|
402
|
+
rand = W5 * ((p1 - p2 + m1) * norm);
|
403
|
+
}
|
404
|
+
else {
|
405
|
+
rand = W5 * ((p1 - p2) * norm);
|
406
|
+
}
|
407
|
+
|
408
|
+
/* Determine new direction of random walk */
|
409
|
+
if (rand<W0 || rand==0){n=1; o=0; p=0;}
|
410
|
+
else if (rand>=W0 && rand<W1){n=-1; o=0; p=0;}
|
411
|
+
else if (rand>=W1 && rand<W2){n=0; o=1; p=0;}
|
412
|
+
else if (rand>=W2 && rand<W3){n=0; o=-1; p=0;}
|
413
|
+
else if (rand>=W3 && rand<W4){n=0; o=0; p=1;}
|
414
|
+
else if (rand>=W4 && rand<=W5){n=0; o=0; p=-1;}
|
415
|
+
|
416
|
+
/* Move in new direction */
|
417
|
+
if (k+n>0 && k+n<zsh-1 && l+o>0 && l+o<ysh-1 && m+p>0 && m+p<xsh-1) {
|
418
|
+
k += n;
|
419
|
+
l += o;
|
420
|
+
m += p;
|
421
|
+
position = k*flat + l*xsh + m;
|
422
|
+
atomic_add(&a[position], 1);
|
423
|
+
}
|
424
|
+
|
425
|
+
step += 1;
|
426
|
+
|
427
|
+
if (step==sorw) {
|
428
|
+
k = plane;
|
429
|
+
l = row;
|
430
|
+
m = column;
|
431
|
+
position = k*flat + l*xsh + m;
|
432
|
+
n_rw += 1;
|
433
|
+
step = 0;
|
434
|
+
}
|
435
|
+
}
|
436
|
+
}
|
437
|
+
}
|
438
|
+
}
|
439
|
+
'''
|
440
|
+
return src
|
441
|
+
|