Commit 1a5b94beb249a5d73f68955befaa73fd592cb47a
1 parent
480ea163
Exists in
master
Using lock in cy_mesh
Showing
1 changed file
with
11 additions
and
4 deletions
Show diff stats
invesalius_cy/cy_mesh.pyx
@@ -22,6 +22,7 @@ from libcpp.pair cimport pair | @@ -22,6 +22,7 @@ from libcpp.pair cimport pair | ||
22 | from libcpp cimport bool | 22 | from libcpp cimport bool |
23 | from libcpp.deque cimport deque as cdeque | 23 | from libcpp.deque cimport deque as cdeque |
24 | from cython.parallel import prange | 24 | from cython.parallel import prange |
25 | +cimport openmp | ||
25 | 26 | ||
26 | from .cy_my_types cimport vertex_t, normal_t, vertex_id_t | 27 | from .cy_my_types cimport vertex_t, normal_t, vertex_id_t |
27 | 28 | ||
@@ -193,6 +194,7 @@ cdef class Mesh: | @@ -193,6 +194,7 @@ cdef class Mesh: | ||
193 | 194 | ||
194 | vip = &self.vertices[v_id, 0] | 195 | vip = &self.vertices[v_id, 0] |
195 | to_visit.push_back(v_id) | 196 | to_visit.push_back(v_id) |
197 | + dmax = dmax * dmax | ||
196 | while(not to_visit.empty()): | 198 | while(not to_visit.empty()): |
197 | v_id = to_visit.front() | 199 | v_id = to_visit.front() |
198 | to_visit.pop_front() | 200 | to_visit.pop_front() |
@@ -212,9 +214,9 @@ cdef class Mesh: | @@ -212,9 +214,9 @@ cdef class Mesh: | ||
212 | if status_v.find(vj) == status_v.end(): | 214 | if status_v.find(vj) == status_v.end(): |
213 | status_v[vj] = True | 215 | status_v[vj] = True |
214 | vjp = &self.vertices[vj, 0] | 216 | vjp = &self.vertices[vj, 0] |
215 | - distance = sqrt((vip[0] - vjp[0]) * (vip[0] - vjp[0]) \ | ||
216 | - + (vip[1] - vjp[1]) * (vip[1] - vjp[1]) \ | ||
217 | - + (vip[2] - vjp[2]) * (vip[2] - vjp[2])) | 217 | + distance = (vip[0] - vjp[0]) * (vip[0] - vjp[0]) \ |
218 | + + (vip[1] - vjp[1]) * (vip[1] - vjp[1]) \ | ||
219 | + + (vip[2] - vjp[2]) * (vip[2] - vjp[2]) | ||
218 | if distance <= dmax: | 220 | if distance <= dmax: |
219 | near_vertices.push_back(vj) | 221 | near_vertices.push_back(vj) |
220 | to_visit.push_back(vj) | 222 | to_visit.push_back(vj) |
@@ -248,7 +250,10 @@ cdef vector[weight_t]* calc_artifacts_weight(Mesh mesh, vector[vertex_id_t]& ver | @@ -248,7 +250,10 @@ cdef vector[weight_t]* calc_artifacts_weight(Mesh mesh, vector[vertex_id_t]& ver | ||
248 | cdef vector[weight_t]* weights = new vector[weight_t](msize) | 250 | cdef vector[weight_t]* weights = new vector[weight_t](msize) |
249 | weights.assign(msize, bmin) | 251 | weights.assign(msize, bmin) |
250 | 252 | ||
251 | - for i in prange(n_ids, nogil=True): | 253 | + cdef openmp.omp_lock_t lock |
254 | + openmp.omp_init_lock(&lock) | ||
255 | + | ||
256 | + for i in prange(n_ids): | ||
252 | vi_id = vertices_staircase[i] | 257 | vi_id = vertices_staircase[i] |
253 | deref(weights)[vi_id] = 1.0 | 258 | deref(weights)[vi_id] = 1.0 |
254 | 259 | ||
@@ -266,7 +271,9 @@ cdef vector[weight_t]* calc_artifacts_weight(Mesh mesh, vector[vertex_id_t]& ver | @@ -266,7 +271,9 @@ cdef vector[weight_t]* calc_artifacts_weight(Mesh mesh, vector[vertex_id_t]& ver | ||
266 | value = (1.0 - d/tmax) * (1.0 - bmin) + bmin | 271 | value = (1.0 - d/tmax) * (1.0 - bmin) + bmin |
267 | 272 | ||
268 | if value > deref(weights)[vj_id]: | 273 | if value > deref(weights)[vj_id]: |
274 | + openmp.omp_set_lock(&lock) | ||
269 | deref(weights)[vj_id] = value | 275 | deref(weights)[vj_id] = value |
276 | + openmp.omp_unset_lock(&lock) | ||
270 | 277 | ||
271 | del near_vertices | 278 | del near_vertices |
272 | 279 |