tvaLib
Public Member Functions | Public Attributes | List of all members
lib.scene.Route Class Reference
Inheritance diagram for lib.scene.Route:

Public Member Functions

def __init__ (self, alignIx=None, connectorIx=None, level=0, parent=None, branch_length=0, upstreamVerificationDistance=0)
 
def addBranch (self, kwargs)
 
def loopBackBranch (self, parentBranchPointer)
 
def startSearch (self, alignments, links, corridors)
 
def searchForChildBranches (self, alignments, links, corridors)
 
def getCumDistance (self, lowestLevel=0)
 
def searchTreeForChildPosition (self, alignment, S, path=[])
 
def goToChildPosition (self, alignment, S)
 
def searchParentsForLoopBack (self, alignIx, connectorIx, upstreamVerificationDistance)
 
def intersectHorizon (self, routeMatch, horizonThis, horizonMatch=None)
 
def printTree (self)
 

Public Attributes

 branch_length
 Hard limit on recursion: More...
 
 upstreamVerificationDistance
 
 alignIx
 Hard limit on recursion: More...
 
 connectorIx
 
 level
 

Detailed Description

Definition at line 1134 of file scene.py.

Constructor & Destructor Documentation

◆ __init__()

def lib.scene.Route.__init__ (   self,
  alignIx = None,
  connectorIx = None,
  level = 0,
  parent = None,
  branch_length = 0,
  upstreamVerificationDistance = 0 
)
This is a recursive object representing a branch on a route
    tree with parent and child branches. A route is defined as a
    sequence of branch ids to follow throughout. 
    
    Input:
    ======
    alignIx = Index of alignment corresponding to scenery alignment data
    connectorIx = Index of connector (link) corresponding to scenery connector data
    branch_length = Length of branch
    upstreamVerificationDistance = Start of branch along alignIx's spline (measured in S)

Definition at line 1135 of file scene.py.

1135  def __init__(self, alignIx=None, connectorIx=None, level=0, parent=None, branch_length=0, upstreamVerificationDistance=0):
1136  ''' This is a recursive object representing a branch on a route
1137  tree with parent and child branches. A route is defined as a
1138  sequence of branch ids to follow throughout.
1139 
1140  Input:
1141  ======
1142  alignIx = Index of alignment corresponding to scenery alignment data
1143  connectorIx = Index of connector (link) corresponding to scenery connector data
1144  branch_length = Length of branch
1145  upstreamVerificationDistance = Start of branch along alignIx's spline (measured in S)
1146 
1147  '''
1148  self.branch_length = branch_length
1149  self.upstreamVerificationDistance = upstreamVerificationDistance
1150  self.alignIx = alignIx
1151  self.connectorIx = connectorIx
1152  tvaLib.Constructors.Tree.__init__(self, level, parent)
1153 

Member Function Documentation

◆ addBranch()

def lib.scene.Route.addBranch (   self,
  kwargs 
)
Add a new branhc to the tree. 

Definition at line 1154 of file scene.py.

1154  def addBranch(self, **kwargs):
1155  ''' Add a new branhc to the tree. '''
1156  self.branches.append(Route(level=self.level+1, parent=self, **kwargs))
1157 

◆ getCumDistance()

def lib.scene.Route.getCumDistance (   self,
  lowestLevel = 0 
)
Return cumulative distance between start of current branch and
    start of tree.

Definition at line 1225 of file scene.py.

1225  def getCumDistance(self, lowestLevel=0):
1226  ''' Return cumulative distance between start of current branch and
1227  start of tree.
1228  '''
1229  if(self.parent and self.level > lowestLevel): return self.parent.getCumDistance()+self.branch_length
1230  else: return self.branch_length
1231 

◆ goToChildPosition()

def lib.scene.Route.goToChildPosition (   self,
  alignment,
  S 
)
Returns the branch corresponding to alignment, S, reachable
    from the current branch (False otherwise).

Definition at line 1251 of file scene.py.

1251  def goToChildPosition(self, alignment, S):
1252  ''' Returns the branch corresponding to alignment, S, reachable
1253  from the current branch (False otherwise).
1254  '''
1255  return self.goToBranch(self.searchTreeForChildPosition(alignment,S))
1256 

◆ intersectHorizon()

def lib.scene.Route.intersectHorizon (   self,
  routeMatch,
  horizonThis,
  horizonMatch = None 
)
With the current branch, verify with another branch (presumably
    from a different part of this' parent route tree) if there is
    overlap up to the defined horizon. 

Definition at line 1262 of file scene.py.

1262  def intersectHorizon(self, routeMatch, horizonThis, horizonMatch=None):
1263  ''' With the current branch, verify with another branch (presumably
1264  from a different part of this' parent route tree) if there is
1265  overlap up to the defined horizon. '''
1266  if(not horizonMatch): horizonMatch = horizonThis
1267  pathsA = self.getPathsToBranchEnds()
1268  pathsB = routeMatch.getPathsToBranchEnds()
1269 
1270  alignsA = set()
1271  alignsA.add((self.alignIx,self.branch_length,self.upstreamVerificationDistance))
1272  for path in pathsA:
1273  traversal = self
1274  for branch in path:
1275  traversal = traversal.goToBranch([branch])
1276  if(not isinstance(traversal, Route) or (traversal.getCumDistance(lowestLevel=self.level) > horizonThis)): break
1277  alignsA.add((traversal.alignIx,traversal.branch_length,traversal.upstreamVerificationDistance))
1278  alignsB = set()
1279  alignsB.add((routeMatch.alignIx,routeMatch.branch_length,routeMatch.upstreamVerificationDistance))
1280  for path in pathsB:
1281  traversal = routeMatch
1282  for branch in path:
1283  traversal = traversal.goToBranch([branch])
1284  if(not isinstance(traversal, Route) or (traversal.getCumDistance(lowestLevel=routeMatch.level) > horizonMatch)): break
1285  alignsB.add((traversal.alignIx,traversal.branch_length,traversal.upstreamVerificationDistance))
1286  return True in [x in alignsB for x in alignsA]
1287 

◆ loopBackBranch()

def lib.scene.Route.loopBackBranch (   self,
  parentBranchPointer 
)
Add a pointer to a parent branch closing a loop in the tree.
    Counterpart of method: addBranch()

Definition at line 1158 of file scene.py.

1158  def loopBackBranch(self, parentBranchPointer):
1159  ''' Add a pointer to a parent branch closing a loop in the tree.
1160  Counterpart of method: addBranch()
1161  '''
1162  self.branches.append(parentBranchPointer)
1163 

◆ printTree()

def lib.scene.Route.printTree (   self)
Prints human-readable schematic of the tree with values.

Definition at line 1288 of file scene.py.

1288  def printTree(self):
1289  ''' Prints human-readable schematic of the tree with values.
1290  '''
1291  print(self.level*'-'+'Align ('+str(self.alignIx)+') Con ('+str(self.connectorIx)+') B_Len ('+str(self.branch_length)+') UVD ('+str(self.upstreamVerificationDistance)+')')
1292  for branch in self.branches:
1293  if(branch.level < self.level): print(self.level*'-'+'Loopback to level '+str(branch.level))
1294  else: branch.printTree()
1295  return True
1296 

◆ searchForChildBranches()

def lib.scene.Route.searchForChildBranches (   self,
  alignments,
  links,
  corridors 
)
Recursive function to search branches during tree generation. 
    Counterpart of method: startSearch()
   
    Link connector type 0 is a divergence
    Link connector type 1 is a convergence
    Link connector type 2 is a convergence and divergence.

Definition at line 1173 of file scene.py.

1173  def searchForChildBranches(self, alignments, links, corridors):
1174  ''' Recursive function to search branches during tree generation.
1175  Counterpart of method: startSearch()
1176 
1177  Link connector type 0 is a divergence
1178  Link connector type 1 is a convergence
1179  Link connector type 2 is a convergence and divergence.
1180  '''
1181 
1182  if(self.level > route_recursion_hard_limit): return False
1183  for link in range(len(links)):
1184  #Skip parent links
1185  if(self.parent and self.parent.connectorIx == link): continue
1186 
1187 
1188  localAlignGroup=None
1189  for corridor in corridors:
1190  if(self.alignIx in corridor): localAlignGroup = corridor
1191  if(not localAlignGroup): localAlignGroup = [self.alignIx]
1192 
1193 
1194  if(links[link][1] in localAlignGroup and self.parent.alignIx != links[link][5] and self.upstreamVerificationDistance < links[link][4]):
1195  self.branch_length = links[link][4] - self.upstreamVerificationDistance
1196  opposingAlignIx = links[link][5]
1197  UVD = links[link][8]
1198  opposingUVD = links[link][4]
1199  elif(links[link][5] in localAlignGroup and self.parent.alignIx != links[link][1] and self.upstreamVerificationDistance < links[link][8]):
1200  self.branch_length = links[link][8] - self.upstreamVerificationDistance
1201  opposingAlignIx = links[link][1]
1202  UVD = links[link][4]
1203  opposingUVD = links[link][8]
1204  else: continue
1205 
1206 
1207  parentLooBackSearch = self.searchParentsForLoopBack(alignIx=self.alignIx, connectorIx=link, upstreamVerificationDistance=UVD)
1208  if(parentLooBackSearch is not False):
1209  self.loopBackBranch(parentLooBackSearch)
1210  continue
1211 
1212  self.addBranch(alignIx=opposingAlignIx, connectorIx=link, upstreamVerificationDistance=UVD)
1213  self.branches[-1].searchForChildBranches(alignments, links, corridors)
1214  if(links[link][0]==0 or links[link][0]==2):
1215 
1216  self.addBranch(alignIx=self.alignIx, connectorIx=link, upstreamVerificationDistance=opposingUVD)
1217  self.branches[-1].searchForChildBranches(alignments, links, corridors)
1218 
1219 
1220  if(not self.branches):
1221  ss_spline_c = tvaLib.Geo.subsec_spline_dist_cumulative(alignments[self.alignIx])
1222  self.branch_length = ss_spline_c[-1] - self.upstreamVerificationDistance
1223  return True
1224 

◆ searchParentsForLoopBack()

def lib.scene.Route.searchParentsForLoopBack (   self,
  alignIx,
  connectorIx,
  upstreamVerificationDistance 
)

Definition at line 1257 of file scene.py.

1257  def searchParentsForLoopBack(self, alignIx, connectorIx, upstreamVerificationDistance):
1258  if(self.level==0): return False
1259  if(self.parent.alignIx==alignIx and self.connectorIx==connectorIx and self.upstreamVerificationDistance==upstreamVerificationDistance): return self.parent
1260  else: return self.parent.searchParentsForLoopBack(alignIx, connectorIx, upstreamVerificationDistance)
1261 

◆ searchTreeForChildPosition()

def lib.scene.Route.searchTreeForChildPosition (   self,
  alignment,
  S,
  path = [] 
)
From current branch, search child branches for path to location
    defined by alignment and curvilinear distance S. Path is only
    passed during internal recursion (do not call it).
    
    Output:
    =======
    Relative path to tip in the format of a list of branch indeces
    to traverse. E.g. [0,1,0,2] (four levels)

Definition at line 1232 of file scene.py.

1232  def searchTreeForChildPosition(self, alignment, S, path=[]):
1233  ''' From current branch, search child branches for path to location
1234  defined by alignment and curvilinear distance S. Path is only
1235  passed during internal recursion (do not call it).
1236 
1237  Output:
1238  =======
1239  Relative path to tip in the format of a list of branch indeces
1240  to traverse. E.g. [0,1,0,2] (four levels)
1241  '''
1242 
1243  if(len(path) > route_recursion_hard_limit): return False
1244 
1245  if(self.alignIx == alignment and self.upstreamVerificationDistance < S): return path
1246  for branch in range(len(self.branches)):
1247  searchResult = self.branches[branch].searchTreeForChildPosition(alignment, S, path=path+[branch])
1248  if(searchResult): return searchResult
1249  return False
1250 

◆ startSearch()

def lib.scene.Route.startSearch (   self,
  alignments,
  links,
  corridors 
)
Starting point for tree generation. 
    Counterpart of method: searchForChildBranches()

Definition at line 1164 of file scene.py.

1164  def startSearch(self, alignments, links, corridors):
1165  ''' Starting point for tree generation.
1166  Counterpart of method: searchForChildBranches()
1167  '''
1168  for align in range(len(alignments)):
1169  self.addBranch(alignIx=align)
1170  self.branches[-1].searchForChildBranches(alignments, links, corridors)
1171  return True
1172 

Member Data Documentation

◆ alignIx

lib.scene.Route.alignIx

Hard limit on recursion:

Conditional limit on recursion:

Definition at line 1150 of file scene.py.

◆ branch_length

lib.scene.Route.branch_length

Hard limit on recursion:

Check upstream for loopback.

Find local align group Verify alignment connections

New branch from convergence and divergence action Continue old branch from divergence only Add final branch length

Definition at line 1148 of file scene.py.

◆ connectorIx

lib.scene.Route.connectorIx

Definition at line 1151 of file scene.py.

◆ level

lib.scene.Route.level

Definition at line 1258 of file scene.py.

◆ upstreamVerificationDistance

lib.scene.Route.upstreamVerificationDistance

Definition at line 1149 of file scene.py.


The documentation for this class was generated from the following file: