-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmakeRandomScene.py
More file actions
executable file
·111 lines (97 loc) · 3.49 KB
/
Copy pathmakeRandomScene.py
File metadata and controls
executable file
·111 lines (97 loc) · 3.49 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/python
import sys
import numpy as np
import random
import math
import pickle
import voronizator
import tetrahedron
if len(sys.argv) >= 14 and len(sys.argv) <= 15:
i = 1
minX = float(sys.argv[i])
i += 1
minY = float(sys.argv[i])
i += 1
minZ = float(sys.argv[i])
i += 1
maxX = float(sys.argv[i])
i += 1
maxY = float(sys.argv[i])
i += 1
maxZ = float(sys.argv[i])
i += 1
bbMargin = float(sys.argv[i])
i += 1
fixedRadius = bool(eval(sys.argv[i]))
i += 1
if fixedRadius:
radius = float(sys.argv[i])
i += 1
else:
minRadius = float(sys.argv[i])
i += 1
maxRadius = float(sys.argv[i])
i += 1
avoidCollisions = bool(eval(sys.argv[i]))
i += 1
numObstacles = int(sys.argv[i])
i += 1
maxEmptyArea = float(sys.argv[i])
i += 1
fileName = sys.argv[i]
else:
minX = float(input('Insert min scene X: '))
minY = float(input('Insert min scene Y: '))
minZ = float(input('Insert min scene Z: '))
maxX = float(input('Insert max scene X: '))
maxY = float(input('Insert max scene Y: '))
maxZ = float(input('Insert max scene Z: '))
bbMargin = float(input('Insert bounding box margin: '))
fixedRadius = bool(eval(input('Do you want fixed obstacle radius? (True/False): ')))
if fixedRadius:
radius = float(input('Insert obstacle radius: '))
else:
minRadius = float(input('Insert min obstacle radius: '))
maxRadius = float(input('Insert max obstacle radius: '))
avoidCollisions = bool(eval(input('Do you want to avoid collisions between obstacles? (True/False): ')))
numObstacles = int(input('Insert obstacles number: '))
maxEmptyArea = float(input('Insert max empty area (for points distribution in obstacles): '))
fileName = input('Insert file name: ')
voronoi = voronizator.Voronizator()
obstacles = []
for ob in range(numObstacles):
print('Creating obstacle {} '.format(ob+1), end='', flush=True)
ok = False
while not ok:
print('.', end='', flush=True)
if not fixedRadius:
radius = random.uniform(minRadius,maxRadius)
center = np.array([random.uniform(minX+radius,maxX-radius), random.uniform(minY+radius,maxY-radius), random.uniform(minZ+radius,maxZ-radius)])
points = []
for pt in range(4):
elev = random.uniform(-math.pi/2., math.pi/2.)
azim = random.uniform(0., 2.*math.pi)
points[:0] = [center+np.array([
radius*math.cos(elev)*math.cos(azim),
radius*math.cos(elev)*math.sin(azim),
radius*math.sin(elev)])]
newObstacle = tetrahedron.Tetrahedron(a = points[0], b = points[1], c = points[2], d = points[3], distributePoints = True, maxEmptyArea = maxEmptyArea)
ok = True
if avoidCollisions:
for obstacle in obstacles:
if newObstacle.intersectPolyhedron(obstacle):
ok = False
break
if ok:
voronoi.addPolyhedron(newObstacle)
if avoidCollisions:
obstacles[:0] = [newObstacle]
print(' done', flush=True)
voronoi.addBoundingBox([minX-bbMargin, minY-bbMargin, minZ-bbMargin], [maxX+bbMargin, maxY+bbMargin, maxZ+bbMargin], maxEmptyArea, verbose=True)
voronoi.setPolyhedronsSites(verbose=True)
voronoi.makeVoroGraph(verbose=True)
print('Write file', flush=True)
record = {}
record['voronoi'] = voronoi
with open(fileName, 'wb') as f:
pickle.dump(record, f)