-
Notifications
You must be signed in to change notification settings - Fork 3
/
get_all_pictures_in_area.py
145 lines (123 loc) · 3.97 KB
/
get_all_pictures_in_area.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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# Example on how to get a complete trajectory of a SHERPA agent
#
# to test it call
# python add_area.py
# cd ../sherpa/mission_scripts
# python swm.py add picture genius ok 45 13 2199 0 0 0 1
import zmq
import sys
import time
import datetime
import json
import os
### Variables ###
objectAttribute = "sherpa:agent_name"
agent = "genius"
fbxPath = os.environ['FBX_MODULES']
fbxPath = fbxPath + "/lib/"
if len(sys.argv) > 1:
agent = sys.argv[1]
print("Reqesting pose history for agent : %s " % (agent))
### Communication Setup ###
port = "22422"
context = zmq.Context()
def querySWM(queryMessage):
socket = context.socket(zmq.REQ)
socket.connect("tcp://localhost:%s" % port)
socket.send_string(json.dumps(queryMessage))
queryResult = socket.recv_json()
print ("Query: " + str(queryMessage))
print ("Query result: " + str(queryResult))
if queryResult['querySuccess']:
return queryResult
else:
return ""
def updateSWM(updateMessage):
socket = context.socket(zmq.REQ)
socket.connect("tcp://localhost:%s" % port)
socket.send_string(json.dumps(updateMessage))
updateResult = socket.recv_json()
print ("Update: " + str(updateMessage))
print ("Update result: " + str(updateResult))
if updateResult['updateSuccess']:
print ("[DCM updateSWM:] updateSuccess = " + str(updateResult['updateSuccess']))
return updateResult
else:
return ""
def functionBlockOperation(operation):
socket = context.socket(zmq.REQ)
socket.connect("tcp://localhost:%s" % port)
socket.send_string(json.dumps(operation))
operationResult = socket.recv_json()
print ("Operation: " + str(operation))
print ("Operation result: " + str(operationResult))
if operationResult['operationSuccess']:
print ("[DCM updateSWM:] operationSuccess = " + str(operationResult['operationSuccess']))
return operationResult
else:
return ""
# Get area object Id
getAreas = {
"@worldmodeltype": "RSGQuery",
"query": "GET_NODES",
"attributes": [
{"key": "geo:area", "value": "polygon"},
]
}
result = querySWM(getAreas)
ids = result["ids"]
print("ids = %s " % ids)
if (len(ids) > 0):
### Prepare nodesinarea functionblock ###
blockName = "nodesinarea"
unloadFunctionBlock = {
"@worldmodeltype": "RSGFunctionBlock",
"metamodel": "rsg-functionBlock-schema.json",
"name": blockName,
"operation": "UNLOAD",
"input": {
"metamodel": "rsg-functionBlock-path-schema.json",
"path": fbxPath,
"comment": "path is the same as the FBX_MODULES environment variable appended with a lib/ folder"
}
}
functionBlockOperation(unloadFunctionBlock)
loadFunctionBlock = {
"@worldmodeltype": "RSGFunctionBlock",
"metamodel": "rsg-functionBlock-schema.json",
"name": blockName,
"operation": "LOAD",
"input": {
"metamodel": "rsg-functionBlock-path-schema.json",
"path": fbxPath,
"comment": "path is the same as the FBX_MODULES environment variable appended with a lib/ folder"
}
}
functionBlockOperation(loadFunctionBlock)
### Request picture nodes witin area ###
getNodesInAreaQuery = {
"@worldmodeltype": "RSGFunctionBlock",
"metamodel": "rsg-functionBlock-schema.json",
"name": blockName,
"operation": "EXECUTE",
"input": {
"metamodel": "fbx-nodesinarea-input-schema.json",
"areaId": ids[0],
"attributes": [
{"key": "name", "value": "picture"},
],
}
}
result = functionBlockOperation(getNodesInAreaQuery)
pictureIds = result["output"]["ids"]
if (len(pictureIds) > 0):
print("Found one or more pictures in the given area.")
for i in pictureIds:
print(i)
attibutesMsg = {
"@worldmodeltype": "RSGQuery",
"query": "GET_NODE_ATTRIBUTES",
"id": i
}
result = querySWM(attibutesMsg)
print("attributes = %s " % result["attributes"])