-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLayoutDesignTaskJsonParser.py
75 lines (63 loc) · 2.47 KB
/
LayoutDesignTaskJsonParser.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
from SpatialObject import SpatialObject
from ConstraintType import *
from ConstraintTemplates import TERRAIN_TYPES
import sys
VISION_BLOCKING_TERRAIN_TYPES = ['MOUNTAIN', 'FOREST', 'HILLS', 'WOODED_HILLS']
VISION_BLOCKING_TAG = 'VISION_BLOCKING'
def LoadConstraints(iptJson):
constraintField = 'requirements'
constraintTypeField = 'constraint'
#negatedField = 'negated'
argumentField = 'arguments'
utteranceField = 'utterance'
constraints = []
constraintText = []
try:
for jobj in iptJson[constraintField]:
if jobj[constraintTypeField] not in ConstraintType.constraint_library:
continue
constraintType = ConstraintType.constraint_library[jobj[constraintTypeField]]
constraint = (constraintType, jobj[argumentField])
constraints.append(constraint)
if utteranceField in jobj:
text = jobj[utteranceField]
constraintText.append((text, jobj[argumentField]))
except Exception:
raise Exception("Loading constraints failed.")
return constraints, constraintText
def LoadObjectsToPlace(iptJson):
objectsToPlaceField = 'plotFacilities'
objectIdField = 'id'
objectTagsField = 'tags'
initialLocationField = 'initial-location'
objectsToplace = []
objectsToplaceMapping = {}
try:
for jobj in iptJson[objectsToPlaceField]:
obj = SpatialObject(jobj[objectIdField], [[0., 0.]], jobj[objectTagsField])
if initialLocationField in jobj:
obj.Polygon.append(jobj[initialLocationField])
objectsToplace.append(obj)
objectsToplaceMapping[jobj[objectIdField]] = len(objectsToplace) - 1
except Exception:
raise Exception("Loading objects to place failed.")
return objectsToplace, objectsToplaceMapping
def LoadTerrainObjects(iptJson):
existingObjectField = 'zones'
objectIdField = 'id'
objectPolygonField = 'polygon'
objectTagsField = 'tags'
objectDisplayNameField = 'display_name'
existingObjects = []
existingObjectMapping = {}
try:
for jobj in iptJson[existingObjectField]:
tags = list(set(jobj[objectTagsField]).intersection(set(TERRAIN_TYPES)))
if len(set(tags).intersection(set(VISION_BLOCKING_TERRAIN_TYPES))) > 0:
tags.append(VISION_BLOCKING_TAG)
obj = SpatialObject(jobj[objectIdField], jobj[objectPolygonField], tags, jobj[objectDisplayNameField])
existingObjects.append(obj)
existingObjectMapping[jobj[objectIdField]] = len(existingObjects) - 1
except Exception:
raise Exception("Loading terrain objects failed.")
return existingObjects, existingObjectMapping