-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfile_utils.py
80 lines (76 loc) · 2.77 KB
/
file_utils.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
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
import numpy as np
from constants import mp3d_region_label2id
def parse_house(file_name):
f = open(file_name, 'r')
data = f.readlines()
f.close()
l_id = 0
r_id = 0
object2region = np.load(file_name.split('.')[0]+'_object2region.npy', allow_pickle=True).tolist()
temp = np.zeros(len(object2region.keys()))
for key in object2region.keys():
temp[key] = object2region[key]
object2region = temp
house = {'name': file_name, 'levels': [], 'regions': [], 'obj2region': object2region}
for line in data:
if line[0] == 'L':
# level
prim = line.split(' ')
prim = [x for x in prim if x]
xl = float(prim[7])
yl = float(prim[8])
zl = float(prim[9])
xh = float(prim[10])
yh = float(prim[11])
zh = float(prim[12])
xc = (xl + xh) / 2
yc = (zl + zh) / 2
zc = -(yl + yh) / 2
xdim = xh - xl
ydim = zh - zl
zdim = yh - yl
assert xdim >= 0 and ydim >= 0 and zdim >= 0
level = {'id': l_id, 'regions': [], 'center': (xc, yc, zc),
'dim': (xdim, ydim, zdim)}
house['levels'].append(level)
l_id += 1
elif line[0] == 'R':
# region
prim = line.split(' ')
prim = [x for x in prim if x]
level_id = int(prim[2])
label = prim[5]
xl = float(prim[9])
yl = float(prim[10])
zl = float(prim[11])
xh = float(prim[12])
yh = float(prim[13])
zh = float(prim[14])
xc = (xl + xh) / 2
yc = (zl + zh) / 2
zc = -(yl + yh) / 2
xdim = xh - xl
ydim = zh - zl
zdim = yh - yl
assert xdim >= 0 and ydim >= 0 and zdim >= 0
region = {'id': r_id, 'vertices': [], 'level_id': level_id,
'label': label, 'center': (xc, yc, zc), 'dim': (xdim, ydim, zdim)}
house['regions'].append(region)
house['levels'][level_id]['regions'].append(region)
r_id += 1
elif line[0] == 'V':
# boundary vertices
prim = line.split(' ')
prim = [x for x in prim if x]
x = float(prim[4])
y = float(prim[6])
z = -float(prim[5])
region_id = int(prim[2])
house['regions'][region_id]['vertices'].append((x,y,z))
region2typeid = np.zeros(len(house['regions']), dtype=np.int)
for idx, region in enumerate(house['regions']):
label = region['label']
region_type_id = mp3d_region_label2id[label]
region2typeid[idx] = region_type_id
house['region2typeid'] = region2typeid
return house