def test_ParamPoly(self): tangentX = np.array([9.389829642616592, -7.596531772501544]) tangentY = np.array([0.0, 5.5192033616035365]) t = np.array([0, 1]) x = np.array([0, 17.8605173461395]) y = np.array([0, -5.803233839653106]) hermiteX = CubicHermiteSpline(t, x, tangentX) hermiteY = CubicHermiteSpline(t, y, tangentY) xCoeffs = hermiteX.c.flatten() yCoeffs = hermiteY.c.flatten() # scipy coefficient and open drive coefficents have opposite order. myRoad = self.roadBuilder.curveBuilder.createParamPoly3( 0, isJunction=False, au=xCoeffs[3], bu=xCoeffs[2], cu=xCoeffs[1], du=xCoeffs[0], av=yCoeffs[3], bv=yCoeffs[2], cv=yCoeffs[1], dv=yCoeffs[0]) odr = pyodrx.OpenDrive("test") odr.add_road(myRoad) odr.adjust_roads_and_lanes() extensions.printRoadPositions(odr) extensions.view_road( odr, os.path.join('..', self.configuration.get("esminipath")))
def test_getIncidentPoints(self): maxNumberOfRoadsPerJunction = 4 path = self.configuration.get("harvested_straight_roads") intersection = self.builder.createWithRandomLaneConfigurations( path, 0, maxNumberOfRoadsPerJunction=maxNumberOfRoadsPerJunction, maxLanePerSide=2, minLanePerSide=0, internalConnections=True, cp1=pyodrx.ContactPoint.end, internalLinkStrategy=LaneConfigurationStrategies.SPLIT_FIRST, getAsOdr=False) odr = intersection.odr xmlPath = f"output/test_getIncidentPoints-split-first-{maxNumberOfRoadsPerJunction}.xodr" odr.write_xml(xmlPath) incidentPoints = intersection.getIncidentPoints() translatedPoints = intersection.getIncidentPointsTranslatedToCenter() print(f"width and height: {intersection.getWH()}") print(incidentPoints) print(translatedPoints) extensions.printRoadPositions(odr) extensions.view_road( odr, os.path.join('..', self.configuration.get("esminipath")))
def test_buildSimpleRoundAboutAndCheckInternalConnection(self): numRoads = 3 odr = self.junctionBuilder.buildSimpleRoundAbout( odrId=0, numRoads=numRoads, radius=10, cp1=pyodrx.ContactPoint.end) xmlPath = f"output/test-SimpleRoundAbout-{numRoads}.xodr" odr.write_xml(xmlPath) extensions.printRoadPositions(odr) extensions.saveRoadImageFromFile(xmlPath, self.esminiPath) extensions.view_road(odr, os.path.join('..', self.esminiPath)) # what's the problem with internal connections? internalConnection = odr.roads['12'].shallowCopy() internalConnection.clearRoadLinks() odr = extensions.createOdr("12 only", [internalConnection], []) xmlPath = f"output/test-SimpleRoundAbout-{numRoads}-road-12.xodr" odr.write_xml(xmlPath) extensions.printRoadPositions(odr) extensions.saveRoadImageFromFile(xmlPath, self.esminiPath) extensions.view_road(odr, os.path.join('..', self.esminiPath))
def test_drawLikeAPainter2LWihtoutInternalConnections(self): maxNumberOfRoadsPerJunction = 5 odr = self.builder.drawLikeAPainter2L( odrId=0, maxNumberOfRoadsPerJunction=maxNumberOfRoadsPerJunction, internalConnections=False) extensions.printRoadPositions(odr) extensions.view_road( odr, os.path.join('..', self.configuration.get("esminipath"))) xmlPath = f"output/test_drawLikeAPainter2LWihtoutInternalConnections.xodr" odr.write_xml(xmlPath)
def test_buildSimpleRoundAbout(self): numRoads = 6 odr = self.junctionBuilder.buildSimpleRoundAbout( odrId=0, numRoads=numRoads, radius=10, cp1=pyodrx.ContactPoint.end) xmlPath = f"output/test-SimpleRoundAbout-{numRoads}.xodr" odr.write_xml(xmlPath) extensions.printRoadPositions(odr) extensions.saveRoadImageFromFile(xmlPath, self.esminiPath) extensions.view_road(odr, os.path.join('..', self.esminiPath))
def test_ThreeWayJunctionWithAngle(self): angleBetweenRoads = np.pi / 4 odr = self.builder.ThreeWayJunctionWithAngle( odrId=1, angleBetweenRoads=angleBetweenRoads, maxLanePerSide=4, minLanePerSide=2, cp1=pyodrx.ContactPoint.end) extensions.printRoadPositions(odr) extensions.view_road( odr, os.path.join('..', self.configuration.get("esminipath"))) # extensions.view_road_odrviewer(odr, os.path.join('..',self.configuration.get("esminipath"))) xmlPath = f"output/test_ThreeWayJunctionWithAngle.xodr" odr.write_xml(xmlPath)
def test_getLanePosition(self): roads = [] roads.append( self.straightRoadBuilder.createWithDifferentLanes(0, length=10, junction=-1, n_lanes_left=2, n_lanes_right=2)) roads.append( self.straightRoadBuilder.createWithRightTurnLanesOnLeft( 1, length=10, n_lanes=2, junction=1, isLeftTurnLane=True, isRightTurnLane=True, numberOfRightTurnLanesOnLeft=2, mergeLaneOnTheOppositeSideForInternalTurn=False)) roads.append( self.straightRoadBuilder.createWithDifferentLanes(2, length=10, junction=-1, n_lanes_left=5, n_lanes_right=3)) self.roadLinker.linkConsecutiveRoadsWithNoBranches(roads) roads[1].updatePredecessorOffset(-2) odrName = "test_getBorderDistanceOfLane" odr = extensions.createOdrByPredecessor(odrName, roads, []) extensions.printRoadPositions(odr) print(roads[0].getLanePosition(0, pyodrx.ContactPoint.end)) print(roads[0].getLanePosition(1, pyodrx.ContactPoint.end)) print(roads[0].getLanePosition(2, pyodrx.ContactPoint.end)) positionLeftMost = roads[0].getLanePosition(2, pyodrx.ContactPoint.end) assert positionLeftMost[0] == 10.0 assert positionLeftMost[1] == 6.0 assert positionLeftMost[2] == 0 extensions.view_road( odr, os.path.join('..', self.configuration.get("esminipath")))
def test_RotateOpenDrive(self): angleBetweenRoads = np.pi / 4 odr = self.threeWayJunctionBuilder.ThreeWayJunctionWithAngle( odrId=1, angleBetweenRoads=angleBetweenRoads, maxLanePerSide=4, minLanePerSide=2, cp1=pyodrx.ContactPoint.end) # extensions.view_road(odr, os.path.join('..', self.configuration.get("esminipath"))) # extensions.printRoadPositions(odr) RotatedODR = extensions.rotateOpenDrive(odr=odr, startX=0.0, startY=0.0, heading=np.pi) extensions.printRoadPositions(RotatedODR) extensions.view_road( RotatedODR, os.path.join('..', self.configuration.get("esminipath")))
def test_7WayJunctionsEQA(self): maxNumberOfRoadsPerJunction = 7 maxLanePerSide = 2 minLanePerSide = 0 for sl in range(5): path = self.configuration.get("harvested_straight_roads") intersection = self.builder.createWithRandomLaneConfigurations( path, sl, maxNumberOfRoadsPerJunction=maxNumberOfRoadsPerJunction, maxLanePerSide=maxLanePerSide, minLanePerSide=minLanePerSide, internalConnections=True, cp1=pyodrx.ContactPoint.end, internalLinkStrategy=LaneConfigurationStrategies.SPLIT_ANY, equalAngles=True, getAsOdr=False) odr = intersection.odr # xmlPath = f"output/test_createWithRandomLaneConfigurations-split-any-{maxNumberOfRoadsPerJunction}-{sl}.xodr" xmlPath = f"output/seed-{self.seed}-{maxNumberOfRoadsPerJunction}-way-{sl}.xodr" odr.write_xml(xmlPath) extensions.printRoadPositions(odr) isValid = self.validator.validateIncidentPoints( intersection, self.builder.minConnectionLength) # if isValid == False: # print(f"{sl} is an invalid intersection") plt = extensions.view_road( odr, os.path.join('..', self.configuration.get("esminipath")), returnPlt=True) if isValid == False: plt.title(f"Invalid - {xmlPath}") else: plt.title(f"Valid - {xmlPath}") plt.show() extensions.saveRoadImageFromFile( xmlPath, self.configuration.get("esminipath"))
def test_drawLikeAPainter2L(self): maxNumberOfRoadsPerJunction = 3 odr = self.builder.drawLikeAPainter2L( odrId=0, maxNumberOfRoadsPerJunction=maxNumberOfRoadsPerJunction) extensions.printRoadPositions(odr) extensions.view_road( odr, os.path.join('..', self.configuration.get("esminipath"))) xmlPath = f"output/test_drawLikeAPainter2L-{maxNumberOfRoadsPerJunction}.xodr" odr.write_xml(xmlPath) maxNumberOfRoadsPerJunction = 4 odr = self.builder.drawLikeAPainter2L( odrId=0, maxNumberOfRoadsPerJunction=maxNumberOfRoadsPerJunction) extensions.printRoadPositions(odr) extensions.view_road( odr, os.path.join('..', self.configuration.get("esminipath"))) xmlPath = f"output/test_drawLikeAPainter2L-{maxNumberOfRoadsPerJunction}.xodr" odr.write_xml(xmlPath) maxNumberOfRoadsPerJunction = 5 odr = self.builder.drawLikeAPainter2L( odrId=0, maxNumberOfRoadsPerJunction=maxNumberOfRoadsPerJunction) extensions.printRoadPositions(odr) extensions.view_road( odr, os.path.join('..', self.configuration.get("esminipath"))) xmlPath = f"output/test_drawLikeAPainter2L-{maxNumberOfRoadsPerJunction}.xodr" odr.write_xml(xmlPath) maxNumberOfRoadsPerJunction = 6 odr = self.builder.drawLikeAPainter2L( odrId=0, maxNumberOfRoadsPerJunction=maxNumberOfRoadsPerJunction) extensions.printRoadPositions(odr) extensions.view_road( odr, os.path.join('..', self.configuration.get("esminipath"))) xmlPath = f"output/test_drawLikeAPainter2L-{maxNumberOfRoadsPerJunction}.xodr" odr.write_xml(xmlPath)
def test_AdjustStartPointsForAnyRoadCombinations(self): # test scenario for connection road roads = [] roads.append(pyodrx.create_straight_road(0, 10)) roads.append( self.roadBuilder.curveBuilder.createSimpleCurveWithLongArc( 1, np.pi / 4, False, curvature=0.2)) roads.append(pyodrx.create_straight_road(2, 10)) roads.append( self.roadBuilder.curveBuilder.createSimpleCurveWithLongArc( 3, np.pi / 3, True, curvature=0.2)) roads.append(pyodrx.create_straight_road(4, 10)) roads.append( self.roadBuilder.curveBuilder.createSimpleCurveWithLongArc( 5, np.pi / 2, True, curvature=0.2)) roads.append(pyodrx.create_straight_road(6, 10)) roads[0].add_successor(pyodrx.ElementType.road, 1, pyodrx.ContactPoint.start) # roads[1].add_predecessor(pyodrx.ElementType.road,0,pyodrx.ContactPoint.end) roads[1].add_predecessor(pyodrx.ElementType.road, 0, pyodrx.ContactPoint.start) roads[1].add_successor(pyodrx.ElementType.road, 2, pyodrx.ContactPoint.start) roads[2].add_predecessor(pyodrx.ElementType.road, 1, pyodrx.ContactPoint.end) roads[2].add_successor(pyodrx.ElementType.junction, 3) roads[3].add_predecessor(pyodrx.ElementType.road, 2, pyodrx.ContactPoint.start) roads[3].add_successor(pyodrx.ElementType.road, 4, pyodrx.ContactPoint.start) roads[4].add_predecessor(pyodrx.ElementType.junction, 3) roads[4].add_successor(pyodrx.ElementType.junction, 5) roads[5].add_predecessor(pyodrx.ElementType.road, 4, pyodrx.ContactPoint.start) roads[5].add_successor(pyodrx.ElementType.road, 6, pyodrx.ContactPoint.start) roads[6].add_predecessor(pyodrx.ElementType.junction, 5) junction = self.junctionBuilder.createJunctionForASeriesOfRoads(roads) odrName = "test_connectionRoad" odr = extensions.createOdr(odrName, roads, [junction]) lastConnection = self.harvester.junctionBuilder.createLastConnectionForLastAndFirstRoad( 7, roads, junction, cp1=pyodrx.ContactPoint.start) roads.append(lastConnection) odr.add_road(lastConnection) # randConnection = self.harvester.junctionBuilder.createConnectionFor2Roads(8, roads[0], roads[4], junction, cp1=pyodrx.ContactPoint.start) # roads.append(randConnection) # odr.add_road(randConnection) # randConnection2 = self.harvester.junctionBuilder.createConnectionFor2Roads(9, roads[2], roads[6], junction, cp1=pyodrx.ContactPoint.start) # roads.append(randConnection2) # odr.add_road(randConnection2) odr.resetAndReadjust() extensions.printRoadPositions(odr) extensions.view_road( odr, os.path.join('..', self.configuration.get("esminipath"))) pass
def test_drawLikeAPainter2L(self): odr = self.harvester.drawLikeAPainter2L(3) extensions.printRoadPositions(odr) extensions.view_road(odr, os.path.join('..', 'F:\\myProjects\\av\\esmini'))
def test_createSingleLaneConnectionRoad(self): roads = [] roads.append( self.straightRoadBuilder.createWithDifferentLanes(0, length=10, junction=-1, n_lanes_left=2, n_lanes_right=2)) roads.append( self.curveRoadBuilder.createSimple(1, np.pi / 3, isJunction=True, n_lanes=2)) roads.append( self.straightRoadBuilder.createWithDifferentLanes(2, length=10, junction=-1, n_lanes_left=2, n_lanes_right=2)) RoadLinker.createExtendedPredSuc(predRoad=roads[0], predCp=pyodrx.ContactPoint.end, sucRoad=roads[1], sucCP=pyodrx.ContactPoint.start) RoadLinker.createExtendedPredSuc(predRoad=roads[1], predCp=pyodrx.ContactPoint.end, sucRoad=roads[2], sucCP=pyodrx.ContactPoint.start) odrName = "test_createSingleLaneConnectionRoad" odr = extensions.createOdrByPredecessor(odrName, roads, []) # extensions.view_road(odr, os.path.join('..', self.configuration.get("esminipath"))) newConnection = self.connectionBuilder.createSingleLaneConnectionRoad( 3, roads[0], roads[2], -2, -2, pyodrx.ContactPoint.end, pyodrx.ContactPoint.start) RoadLinker.createExtendedPredSuc(predRoad=roads[0], predCp=pyodrx.ContactPoint.end, sucRoad=newConnection, sucCP=pyodrx.ContactPoint.start) RoadLinker.createExtendedPredSuc(predRoad=newConnection, predCp=pyodrx.ContactPoint.end, sucRoad=roads[2], sucCP=pyodrx.ContactPoint.start) newConnection.updatePredecessorOffset(-1) roads.append(newConnection) odr.add_road(newConnection) newConnection = self.connectionBuilder.createSingleLaneConnectionRoad( 4, roads[2], roads[0], 2, 2, pyodrx.ContactPoint.start, pyodrx.ContactPoint.end) RoadLinker.createExtendedPredSuc(predRoad=roads[2], predCp=pyodrx.ContactPoint.start, sucRoad=newConnection, sucCP=pyodrx.ContactPoint.start) RoadLinker.createExtendedPredSuc(predRoad=newConnection, predCp=pyodrx.ContactPoint.end, sucRoad=roads[0], sucCP=pyodrx.ContactPoint.end) newConnection.updatePredecessorOffset(1) roads.append(newConnection) odr.add_road(newConnection) odr.resetAndReadjust(byPredecessor=True) extensions.printRoadPositions(odr) extensions.view_road(odr, os.path.join('..', self.esminipath)) xmlPath = f"output/test_createSingleLaneConnectionRoad.xodr" odr.write_xml(xmlPath)