MCPcopy Create free account
hub / github.com/Project-OSRM/osrm-backend / Facade

Method Facade

scripts/gdb_printers.py:220–356  ·  view source on GitHub ↗
(facade, width, height, arg)

Source from the content-addressed store, hash-verified

218
219 @staticmethod
220 def Facade(facade, width, height, arg):
221
222 result = ''
223
224 ## parse additional facade arguments
225 re_float = '[-+]?[0-9]*\.?[0-9]+'
226 bbox = re.search('(' + re_float + '),(' + re_float + ');(' + re_float + '),(' + re_float +')', arg)
227 bbox = [float(x) for x in bbox.groups()] if bbox else [-180, -90, 180, 90]
228 mld_level = re.search('L:([0-9]+)', arg)
229 mld_level = int(mld_level.group(1)) if mld_level else 0
230
231 marginx, marginy = 75, 75
232 INVALID_SEGMENT_WEIGHT, MAX_SEGMENT_WEIGHT = gdb.parse_and_eval('INVALID_SEGMENT_WEIGHT'), gdb.parse_and_eval('INVALID_SEGMENT_WEIGHT')
233 segment_weight = lambda x: str(x) + (' invalid' if x == INVALID_SEGMENT_WEIGHT else ' max' if x == MAX_SEGMENT_WEIGHT else '')
234
235 if mld_level > 0:
236 mld_facade = facade.cast(gdb.lookup_type('osrm::engine::datafacade::ContiguousInternalMemoryAlgorithmDataFacade<osrm::engine::routing_algorithms::mld::Algorithm>'))
237 mld_partition = mld_facade['mld_partition']
238 mld_levels = call(mld_partition, 'GetNumberOfLevels')
239 if mld_level < mld_levels:
240 sentinel_node = call(mld_partition['partition'], 'size') - 1 # GetSentinelNode
241 number_of_cells = call(mld_partition, 'GetCell', mld_level, sentinel_node) # GetNumberOfCells
242 result += "<defs>"
243 for cell in range(number_of_cells):
244 result += """
245<filter x="0" y="0" width="1" height="1" id="cellid-{}"><feFlood flood-color="hsl({}, 100%, 82%)"/><feComposite in="SourceGraphic"/></filter>""" \
246 .format(cell, int(256 * cell / number_of_cells))
247 result += "\n</defs>"
248 else:
249 mld_level = 0
250 else:
251 mld_levels = 0
252
253 ## get nodes
254 nodes, longitudes, latitudes = SVGPrinter.getNodesInBoundingBox(facade, bbox)
255 if len(nodes) == 0:
256 return ''
257
258 ## create transformations (lon,lat) -> (x,y)
259 minx, miny, maxx, maxy = min(longitudes), min(latitudes), max(longitudes), max(latitudes)
260 if abs(maxx - minx) < 1e-8:
261 maxx += (maxy - miny) / 2
262 minx -= (maxy - miny) / 2
263 if abs(maxy - miny) < 1e-8:
264 maxy += (maxx - minx) / 2
265 miny -= (maxx - minx) / 2
266 tx = lambda x: marginx + (x - minx) * (width - 2 * marginx) / (maxx - minx)
267 ty = lambda y: marginy + (maxy - y) * (height - 2 * marginy) / (maxy - miny)
268 t = lambda x: str(tx(x[0])) + ',' + str(ty(x[1]))
269
270 print ('Graph has {} nodes and {} edges and {} nodes in the input bounding box {},{};{},{} -> {},{};{},{}'
271 .format(call(facade, 'GetNumberOfNodes'), call(facade, 'GetNumberOfEdges'), len(nodes), *bbox, minx, miny, maxx, maxy))
272
273 for node in nodes:
274 geometry_id = call(facade, 'GetGeometryIndex', node)
275 direction = 'forward' if geometry_id['forward'] else 'reverse'
276 print (geometry_id, direction)
277 geometry = SVGPrinter.getByGeometryId(facade, geometry_id, 'Geometry')

Callers

nothing calls this directly

Calls 9

intFunction · 0.85
strFunction · 0.85
callFunction · 0.85
rangeClass · 0.85
iterateFunction · 0.85
segment_weightClass · 0.85
getNodesInBoundingBoxMethod · 0.80
getByGeometryIdMethod · 0.80
joinMethod · 0.80

Tested by

no test coverage detected