@@ -327,35 +327,8 @@ def generateWithManualControlines(self, name, layout=None, plotGrid = True):
327327 else :
328328 self .createTestGridWithHorizontalControlLines (plot = plotGrid )
329329
330- # 1.1
331- # build clockwise adjacent points structure
332- logging .info (f"{ self .name } : generateWithManualControlines: buildClockwiseAdjacentMapForControlPoints" )
333-
334- self .buildClockwiseAdjacentMapForControlPoints ()
335-
336- # 2. define lanes for each connection
337- if self .randomizeLanes :
338- logging .info (f"{ self .name } : generateWithManualControlines: randomizeLanes" )
339- self .createLaneConfigurationsForConnections ()
340- else :
341- self .laneConfigurations = None
342-
343- logging .info (f"{ self .name } : generateWithManualControlines: createIntersectionsForControlPoints" )
344- # 3. create intersections for each control point
345- self .createIntersectionsForControlPoints ()
346-
347- # now we have the intersections
348- # for each connection, find the pair of intersections, find the pair of controlpoints, create straight connection road.
349- logging .info (f"{ self .name } : generateWithManualControlines: createConnectionRoadsBetweenIntersections" )
350- self .createConnectionRoadsBetweenIntersections ()
330+ return self .generateByGrid (name , self .grid )
351331
352- logging .info (f"{ self .name } : generateWithManualControlines: adjustLaneMarkings" )
353- self .adjustLaneMarkings ()
354-
355- logging .info (f"{ self .name } : generateWithManualControlines: combine" )
356- combinedOdr = ODRHelper .combine (self .odrList , name , countryCode = self .country )
357- ODRHelper .addAdjustedRoads (combinedOdr , self .connectionRoads )
358- return combinedOdr
359332
360333 def generateWithHorizontalControlines (self , name , nLines , plotGrid = True , stopAfterCreatingIntersections = False ):
361334
@@ -364,31 +337,35 @@ def generateWithHorizontalControlines(self, name, nLines, plotGrid = True, stopA
364337 logging .info (f"{ self .name } : generateWithHorizontalControlines: creating grid" )
365338 # 1 grid creation
366339 self .createGridWithHorizontalControlLines (nLines , plot = plotGrid )
340+ return self .generateByGrid (name , self .grid , stopAfterCreatingIntersections )
367341
342+
343+
344+ def generateByGrid (self , name , grid , stopAfterCreatingIntersections = False ):
368345 # 1.1
369346 # build clockwise adjacent points structure
370347
371348 logging .info (f"{ self .name } : generateWithHorizontalControlines: buildClockwiseAdjacentMapForControlPoints" )
372- self .buildClockwiseAdjacentMapForControlPoints ()
349+ self .buildClockwiseAdjacentMapForControlPoints (grid . connections )
373350
374351 # 2. define lanes for each connection
375352 if self .randomizeLanes :
376353 logging .info (f"{ self .name } : generateWithHorizontalControlines: randomizeLanes" )
377- self .createLaneConfigurationsForConnections ()
354+ self .createLaneConfigurationsForConnections (grid . connections )
378355 else :
379356 self .laneConfigurations = None
380357
381358 # 3. create intersections for each control point
382359 logging .info (f"{ self .name } : generateWithHorizontalControlines: createIntersectionsForControlPoints" )
383- self .createIntersectionsForControlPoints ()
360+ self .createIntersectionsForControlPoints (grid . connections )
384361
385362 if stopAfterCreatingIntersections : # for stasitical concerns, we need intersections only
386363 return
387364
388365 # now we have the intersections
389366 # for each connection, find the pair of intersections, find the pair of controlpoints, create straight connection road.
390367 logging .info (f"{ self .name } : generateWithHorizontalControlines: createConnectionRoadsBetweenIntersections" )
391- self .createConnectionRoadsBetweenIntersections ()
368+ self .createConnectionRoadsBetweenIntersections (grid . connections )
392369
393370 logging .info (f"{ self .name } : generateWithHorizontalControlines: adjustLaneMarkings" )
394371 self .adjustLaneMarkings ()
@@ -397,22 +374,22 @@ def generateWithHorizontalControlines(self, name, nLines, plotGrid = True, stopA
397374 combinedOdr = ODRHelper .combine (self .odrList , name , countryCode = self .country )
398375 ODRHelper .addAdjustedRoads (combinedOdr , self .connectionRoads )
399376 return combinedOdr
400-
377+
401378 #endregion
402379
403380 #region intersection creation and placement on map
404381
405- def buildClockwiseAdjacentMapForControlPoints (self ):
406- for (line1 , line2 , point1 , point2 ) in self . grid . connections :
382+ def buildClockwiseAdjacentMapForControlPoints (self , connections ):
383+ for (line1 , line2 , point1 , point2 ) in connections :
407384 if len (point1 .adjacentPointsCWOrder ) == 0 :
408385 ControlPointIntersectionAdapter .orderAjacentCW (point1 )
409386 if len (point2 .adjacentPointsCWOrder ) == 0 :
410387 ControlPointIntersectionAdapter .orderAjacentCW (point2 )
411388 pass
412389
413- def createIntersectionsForControlPoints (self ):
390+ def createIntersectionsForControlPoints (self , connections ):
414391
415- for (line1 , line2 , point1 , point2 ) in self . grid . connections :
392+ for (line1 , line2 , point1 , point2 ) in connections :
416393
417394
418395 if point1 not in self .controlPointIntersectionMap and len (point1 .adjacentPoints ) >= 2 :
@@ -448,9 +425,9 @@ def createIntersectionsForControlPoints(self):
448425 pass
449426
450427
451- def createConnectionRoadsBetweenIntersections (self ):
428+ def createConnectionRoadsBetweenIntersections (self , connections ):
452429 # for each connection, find the pair of intersections, find the pair of controlpoints, create straight connection road.
453- for (line1 , line2 , point1 , point2 ) in self . grid . connections :
430+ for (line1 , line2 , point1 , point2 ) in connections :
454431
455432 # print(f"{self.name}: Creating connections between {point1.position} and {point2.position}")
456433
@@ -501,11 +478,11 @@ def connect(self, connectionRoadId, intersection1:Intersection, road1: ExtendedR
501478 #endregion
502479
503480 #region lane configurations for each control point
504- def createLaneConfigurationsForConnections (self ):
481+ def createLaneConfigurationsForConnections (self , connections ):
505482
506483 self .laneConfigurations = {}
507484
508- for (line1 , line2 , point1 , point2 ) in self . grid . connections :
485+ for (line1 , line2 , point1 , point2 ) in connections :
509486
510487 point1_n_left = np .random .choice ([0 , 1 , 2 , 3 ], p = self .nLaneDistributionOnASide )
511488 point1_n_right = np .random .choice ([0 , 1 , 2 , 3 ], p = self .nLaneDistributionOnASide )
0 commit comments