def test_cubicParams(self): roads = [] roads.append(pyodrx.create_straight_road(0, 10)) roads.append(self.roadBuilder.createParamPoly3(1, isJunction=True)) roads.append(pyodrx.create_straight_road(2, 1)) roads[0].add_successor(pyodrx.ElementType.junction, 1) roads[1].add_predecessor(pyodrx.ElementType.road, 0, pyodrx.ContactPoint.end) roads[1].add_successor(pyodrx.ElementType.road, 2, pyodrx.ContactPoint.start) roads[2].add_predecessor(pyodrx.ElementType.junction, 1) con1 = pyodrx.Connection(0, 1, pyodrx.ContactPoint.start) con1.add_lanelink(-1, -1) junction = pyodrx.Junction('test', 1) junction.add_connection(con1) odr = pyodrx.OpenDrive('test') for r in roads: odr.add_road(r) odr.add_junction(junction) odr.adjust_roads_and_lanes() extensions.view_road(odr, os.path.join('..', 'F:\\myProjects\\av\\esmini'))
def create2RoadJunction(self, roads): """[summary] Args: roads ([type]): 3 roads with mid as the junction type. """ connection = self.connect2LaneRoads(0, 1) junction = pyodrx.Junction('test',1) junction.add_connection(connection) return junction
def test_junction(): con1 = pyodrx.Connection(1,2,pyodrx.ContactPoint.start) con1.add_lanelink(1,-1) con1.add_lanelink(2,-2) con2 = pyodrx.Connection(2,1,pyodrx.ContactPoint.start) con2.add_lanelink(1,-1) con2.add_lanelink(2,-2) con2.add_lanelink(3,-3) junciton = pyodrx.Junction('',1) junciton.add_connection(con1) junciton.add_connection(con2) pyodrx.prettyprint(junciton.get_element())
def createJunctionFor2Connections(self, roadFirstPred, connectionRoadFirst, roadFirstSuc, connectionRoadSecond): # TODO experiment with connecting more lanes for a single connection road. con1 = pyodrx.Connection(roadFirstPred.id, connectionRoadFirst.id, pyodrx.ContactPoint.start) con1.add_lanelink(-1, -1) con2 = pyodrx.Connection(roadFirstSuc.id, connectionRoadSecond.id, pyodrx.ContactPoint.start) con2.add_lanelink(-1, -1) junction = pyodrx.Junction('junc', 1) junction.add_connection(con1) junction.add_connection(con1) return junction
def createJunctionForASeriesOfRoads(self, roads, id=0): """[summary] Args: roads ([type]): even indices are roads, odd indices are connection roads of the junction Returns: [type]: [description] """ # TODO it does not support all lanes. # ID is wrong junction = pyodrx.Junction("spiderJunction", id) connectionId = 1 while (connectionId < len(roads)): print(f"connecting roads {connectionId-1} {connectionId}") connectionL = pyodrx.Connection(connectionId - 1, connectionId, pyodrx.ContactPoint.start) connectionL.add_lanelink(-1, -1) # if (connectionId + 1) < len(roads): # connectionR = pyodrx.Connection(connectionId+1, connectionId, pyodrx.ContactPoint.end) # else: # connectionR = pyodrx.Connection(0, connectionId, pyodrx.ContactPoint.end) # connectionR.add_lanelink(1,1) junction.add_connection(connectionL) # junction.add_connection(connectionR) connectionId += 2 return junction
roads[3].add_successor(pyodrx.ElementType.road,4,pyodrx.ContactPoint.start) roads[4].add_predecessor(pyodrx.ElementType.junction,1) roads[5].add_predecessor(pyodrx.ElementType.road,0,pyodrx.ContactPoint.end) roads[5].add_successor(pyodrx.ElementType.road,6,pyodrx.ContactPoint.start) roads[6].add_predecessor(pyodrx.ElementType.junction,1) # create the opendrive odr = pyodrx.OpenDrive('myroad') for r in roads: odr.add_road(r) # create junction junction = pyodrx.Junction('test',1) con1 = pyodrx.Connection(0,1,pyodrx.ContactPoint.start) con1.add_lanelink(-1,-1) con2 = pyodrx.Connection(0,3,pyodrx.ContactPoint.start) con2.add_lanelink(-1,-1) con3 = pyodrx.Connection(0,5,pyodrx.ContactPoint.start) con3.add_lanelink(-1,-1) con4 = pyodrx.Connection(2,1,pyodrx.ContactPoint.end) con4.add_lanelink(1,1) con5 = pyodrx.Connection(4,3,pyodrx.ContactPoint.end) con5.add_lanelink(1,1) con6 = pyodrx.Connection(6,5,pyodrx.ContactPoint.end) con6.add_lanelink(1,1) junction.add_connection(con1)
def createWithRandomLaneConfigurations(self, straightRoadsPath, id, maxNumberOfRoadsPerJunction, firstRoadId=0, maxLanePerSide=2, minLanePerSide=0, internalConnections=True, cp1=pyodrx.ContactPoint.end, randomState=None, internalLinkStrategy = LaneConfigurationStrategies.SPLIT_ANY, uTurnLanes=1, equalAngles=False, getAsOdr=True): """All the incoming roads, except for the first, will have their start endpoint connected to the junction. Args: straightRoadsPath ([type]): [description] odrId ([type]): [description] maxNumberOfRoadsPerJunction ([type]): [description] maxLanePerSide (int, optional): [description]. Defaults to 2. minLanePerSide (int, optional): [description]. Defaults to 0. internalConnections (bool, optional): [description]. Defaults to True. cp1 ([type], optional): [description]. Defaults to pyodrx.ContactPoint.start. randomState ([type], optional): [description]. Defaults to None. Raises: Exception: [description] Returns: [type]: [description] """ if maxNumberOfRoadsPerJunction < 2: raise Exception("Please add more than 1 roads") if uTurnLanes > 1: raise Exception("U-turn from more than one lanes is not implemented") harvestedStraightRoads = [] # if restrictedLanes: # harvestedStraightRoads = [] # else: # harvestedStraightRoads = extensions.getObjectsFromDill(straightRoadsPath) if randomState is not None: np.random.set_state(randomState) incidentContactPoints = [] outsideRoads = [] # all the incoming/outgoing roads in this junction geoConnectionRoads = [] # connections roads which are for geometric positions, having no lanes laneConnectionRoads = [] # connection roads that have lanes. roads = [] if cp1 == pyodrx.ContactPoint.end: roads.append(self.createRandomStraightRoad(0, maxLanePerSide=maxLanePerSide, minLanePerSide=minLanePerSide, skipEndpoint=pyodrx.ContactPoint.start)) # first road else: roads.append(self.createRandomStraightRoad(0, maxLanePerSide=maxLanePerSide, minLanePerSide=minLanePerSide, skipEndpoint=pyodrx.ContactPoint.end)) # first road # if restrictedLanes: # if cp1 == pyodrx.ContactPoint.end: # roads.append(self.createRandomStraightRoad(0, maxLanePerSide=maxLanePerSide, minLanePerSide=minLanePerSide, skipEndpoint=pyodrx.ContactPoint.start)) # first road # else: # roads.append(self.createRandomStraightRoad(0, maxLanePerSide=maxLanePerSide, minLanePerSide=minLanePerSide, skipEndpoint=pyodrx.ContactPoint.end)) # first road # else: # roads.append(self.getRandomHarvestedStraightRoad(0, harvestedStraightRoads, maxLanePerSide, minLanePerSide)) # first road roads[0].id = firstRoadId outsideRoads.append(roads[0]) incidentContactPoints.append(cp1) availableAngle = 1.8 * np.pi # 360 degrees if equalAngles: availableAngle = np.pi * 2 maxAnglePerConnection = availableAngle / maxNumberOfRoadsPerJunction action = self.actionAfterDrawingOne(roads, availableAngle, maxNumberOfRoadsPerJunction) nextRoadId = firstRoadId + 1 otherContactPoints = pyodrx.ContactPoint.start nIncidentAdded = 1 while (action != "end"): logging.debug(f"{self.name}: availableAngle {math.degrees(availableAngle)}, number of roads: {len(roads) / 2}") # 0. road id generation previousRoadId = nextRoadId - 1 prevIncidentRoad = roads[-1] newConnectionId = nextRoadId nextRoadId += 1 newRoadId = nextRoadId nextRoadId += 1 prevCp = otherContactPoints if len(roads) == 1: # first road prevCp = cp1 # 1. create a road # newRoad = self.getRandomHarvestedStraightRoad(newRoadId, harvestedStraightRoads, maxLanePerSide, minLanePerSide) newRoad = self.createRandomStraightRoad(newRoadId, maxLanePerSide, minLanePerSide, skipEndpoint=pyodrx.ContactPoint.end) # if restrictedLanes: # newRoad = self.createRandomStraightRoad(newRoadId, maxLanePerSide, minLanePerSide, skipEndpoint=pyodrx.ContactPoint.end) # else: # newRoad = self.getRandomHarvestedStraightRoad(newRoadId, harvestedStraightRoads, maxLanePerSide, minLanePerSide) outsideRoads.append(newRoad) incidentContactPoints.append(otherContactPoints) # 2. create a new connection road prevLanes, nextLanes = self.laneBuilder.getClockwiseAdjacentLanes(prevIncidentRoad, prevCp, newRoad, otherContactPoints) # maxLaneWidth = ((len(prevLanes) + len(nextLanes)) * self.laneWidth) / 2 maxLaneWidth = max(len(prevLanes), len(nextLanes)) * self.laneWidth if len(prevLanes) == 0 or len(nextLanes) == 0: maxLaneWidth = ((len(prevLanes) + len(nextLanes)) * self.laneWidth) / 2 availableAngle -= (maxNumberOfRoadsPerJunction - nIncidentAdded - 1) * self.minAngle # print(f"Before connection road: minAngle: remaining roads:{maxNumberOfRoadsPerJunction - nIncidentAdded - 1}, {math.degrees(self.minAngle)}, available Angle: {math.degrees(availableAngle)}") newConnection, availableAngle = self.createGeoConnectionRoad(action, newConnectionId, availableAngle, maxAnglePerConnection, maxLaneWidth=maxLaneWidth, equalAngles=equalAngles) geoConnectionRoads.append(newConnection) availableAngle += (maxNumberOfRoadsPerJunction - nIncidentAdded - 1) * self.minAngle # print(f"after connection road: minAngle: {math.degrees(self.minAngle)}, available Angle: {math.degrees(availableAngle)}") # 5 add new roads roads.append(newConnection) roads.append(newRoad) RoadLinker.createExtendedPredSuc(predRoad=prevIncidentRoad, predCp=prevCp, sucRoad=newConnection, sucCP=pyodrx.ContactPoint.start) RoadLinker.createExtendedPredSuc(predRoad=newConnection, predCp=pyodrx.ContactPoint.end, sucRoad=newRoad, sucCP=otherContactPoints) self.laneBuilder.createLanesForConnectionRoad(newConnection, prevIncidentRoad, newRoad) # 6 get next action action = self.actionAfterDrawingOne(roads, availableAngle, maxNumberOfRoadsPerJunction) nIncidentAdded += 1 pass # 3.0 fix outgoing lane numbers self.fixNumOutgoingLanes(outsideRoads, cp1) # 3. create connections and junction # TODO this is not correct anymore. # junction = self.createJunctionForASeriesOfRoads(roads) junction = pyodrx.Junction("singleConnectionsJunction", id) # junction = pyodrx.Junction("singleConnectionsJunction", firstRoadId) odrName = 'Draw_Rmax' + str(maxNumberOfRoadsPerJunction) + '_L2_' + str(id) odr = extensions.createOdrByPredecessor(odrName, roads, [junction]) logging.debug(f"{self.name}: roads before internal connections {len(roads)}") # Permanent connection roads if internalConnections: internalConnections = self.connectionBuilder.createSingleLaneConnectionRoads(nextRoadId, outsideRoads, cp1, internalLinkStrategy) nextRoadId += len(internalConnections) roads += internalConnections odr.updateRoads(roads) # remove lanes from connection roads which are used for geometric positioning of roads for geoRoad in geoConnectionRoads: geoRoad.clearLanes() # TODO create the junction self.addInternalConnectionsToJunction(junction, internalConnections) # U-Turns if uTurnLanes == 1: uTurnConnections = self.connectionBuilder.createUTurnConnectionRoads(nextRoadId, outsideRoads, cp1) nextRoadId += 1 roads += uTurnConnections odr.updateRoads(roads) self.addInternalConnectionsToJunction(junction, internalConnections) logging.debug(f"{self.name}: roads after internal connections {len(roads)}") odr.resetAndReadjust(byPredecessor=True) if getAsOdr: return odr intersection = Intersection(id, outsideRoads, incidentContactPoints, geoConnectionRoads=geoConnectionRoads, odr=odr) return intersection