-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheightmap.py
32 lines (24 loc) · 1.09 KB
/
heightmap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import multiprocessing as mp
import numpy as np
import geometry
def height4position(i, j, mesh):
samplingpoint = ((j / shared_width.value) * mesh.xspan, mesh.yspan - (i / shared_height.value) * mesh.yspan)
containing_faces = mesh.faces_for_2D_point(samplingpoint)
if containing_faces: # Faces were found that enclose (i,j)
candidates = [geometry.calcMeshHeightFor2DPoint(samplingpoint, face) for face in containing_faces] # Folds in the mesh mean more than one candidate
result = max(candidates)
return result
else: # Point (i,j) falls within a mesh hole
return 0
def create(mesh, width, height, nprocs):
global shared_width
global shared_height
shared_width = mp.Value('i', width)
shared_height = mp.Value('i', height)
arguments = [(i, j, mesh) for i in range(height) for j in range(width)]
pool = mp.Pool(nprocs)
result_list = list(pool.starmap_async(height4position, arguments).get())
pool.close()
pool.join()
result_matrix = [ result_list[i*width:(i+1)*width] for i in range(height) ]
return np.array(result_matrix)