def minor_road(vertex, b): #Sammelt Numerische Werte aus Variables-Objekt pForward=singleton.minor_roadpForward pTurn=singleton.minor_roadpTurn lMin=singleton.minor_roadlMin lMax=singleton.minor_roadlMax suggested_vertices=[] #Berechnet den Vektor des letzten Weges zu diesem Punkt previous_vector=np.array(vertex.coords-vertex.neighbours[len(vertex.neighbours)-1].coords) previous_vector=previous_vector/np.linalg.norm(previous_vector) n=np.array([-previous_vector[1], previous_vector[0]]) #Geradeaus v=random.uniform(lMin, lMax)*previous_vector random_number=random.randint(0, 100) if random_number<pForward*b: k=Vertex(vertex.coords+v) #k.neighbours.append(vertex) k.minor_road=True suggested_vertices.append(k) #Rechts v=random.uniform(lMin, lMax)*previous_vector random_number=random.randint(0, 100) if random_number<pTurn*b: k=Vertex(vertex.coords+n) #k.neighbours.append(vertex) k.minor_road=True suggested_vertices.append(k) #Links v=random.uniform(lMin, lMax)*previous_vector random_number=random.randint(0, 100) if random_number<pTurn*b: k=Vertex(vertex.coords-n) #k.neighbours.append(vertex) k.minor_road=True suggested_vertices.append(k) return suggested_vertices
def minor_road(vertex, b): # Sammelt Numerische Werte aus Variables-Objekt pForward = singleton.minor_roadpForward pTurn = singleton.minor_roadpTurn lMin = singleton.minor_roadlMin lMax = singleton.minor_roadlMax suggested_vertices = [] # Berechnet den Vektor des letzten Weges zu diesem Punkt previous_vector = np.array(vertex.coords - vertex.neighbours[len(vertex.neighbours) - 1].coords) previous_vector = previous_vector / np.linalg.norm(previous_vector) n = np.array([-previous_vector[1], previous_vector[0]]) # Geradeaus v = random.uniform(lMin, lMax) * previous_vector random_number = random.randint(0, 100) if random_number < pForward * b: k = Vertex(vertex.coords + v) # k.neighbours.append(vertex) k.minor_road = True suggested_vertices.append(k) # Rechts v = random.uniform(lMin, lMax) * previous_vector random_number = random.randint(0, 100) if random_number < pTurn * b: k = Vertex(vertex.coords + n) # k.neighbours.append(vertex) k.minor_road = True suggested_vertices.append(k) # Links v = random.uniform(lMin, lMax) * previous_vector random_number = random.randint(0, 100) if random_number < pTurn * b: k = Vertex(vertex.coords - n) # k.neighbours.append(vertex) k.minor_road = True suggested_vertices.append(k) return suggested_vertices
def seed(vertex,b): pSeed=singleton.pSeed lMin=singleton.seedlMin lMax=singleton.seedlMax suggested_vertices=[] l=len(vertex.neighbours) v1=rotate(90,vertex.neighbours[0].coords-vertex.coords) v2=None if l==1: v2=v1 elif l==2: v2=rotate(90,vertex.neighbours[1].coords-vertex.coords)*-1 else: return [] v1=v1/np.linalg.norm(v1) v2=v2/np.linalg.norm(v2) #Rechts if b*b*pSeed>np.random.randint(0,100): l=np.random.uniform(lMin,lMax) k=np.random.uniform(0,1) coords=((1-k)*v1+k*v2)*l k=Vertex(vertex.coords+coords) k.minor_road=True suggested_vertices.append(k) v1=v1*-1 v2=v2*-1 #Links if b*b*pSeed>np.random.randint(0,100): l=np.random.uniform(lMin,lMax) k=np.random.uniform(0,1) coords=((1-k)*v1+k*v2)*l k=Vertex(vertex.coords+coords) k.minor_road=True suggested_vertices.append(k) return suggested_vertices
def seed(vertex, b): pSeed = singleton.pSeed lMin = singleton.seedlMin lMax = singleton.seedlMax suggested_vertices = [] l = len(vertex.neighbours) v1 = rotate(90, vertex.neighbours[0].coords - vertex.coords) v2 = None if l == 1: v2 = v1 elif l == 2: v2 = rotate(90, vertex.neighbours[1].coords - vertex.coords) * -1 else: return [] v1 = v1 / np.linalg.norm(v1) v2 = v2 / np.linalg.norm(v2) #Rechts if b * b * pSeed > np.random.randint(0, 100): l = np.random.uniform(lMin, lMax) k = np.random.uniform(0, 1) coords = ((1 - k) * v1 + k * v2) * l k = Vertex(vertex.coords + coords) k.minor_road = True suggested_vertices.append(k) v1 = v1 * -1 v2 = v2 * -1 #Links if b * b * pSeed > np.random.randint(0, 100): l = np.random.uniform(lMin, lMax) k = np.random.uniform(0, 1) coords = ((1 - k) * v1 + k * v2) * l k = Vertex(vertex.coords + coords) k.minor_road = True suggested_vertices.append(k) return suggested_vertices
def reconstruct(path=None): if path is None: import os import procedural_city_generation path=os.path.dirname(procedural_city_generation.__file__)+"/outputs/output.json" import json try: with open(path,'r') as d: data=d.read() except IOError: print "Input could not be located. Try to run the previous program in the chain first." return 0 data=json.loads(data) from procedural_city_generation.roadmap.Vertex import Vertex import numpy as np vertex_list=[] vertex_list=[0]*len(data) for x in data: y=data[x] k=Vertex(np.array(y[0])) k.minor_road,k.seed,k.neighboursindizes=y[1],y[2],y[3] vertex_list[int(x)]=k index=0 for k in vertex_list: for x in k.neighboursindizes: k.neighbours.append(vertex_list[x]) k.selfindex=index index+=1 setliste=[] return vertex_list
def reconstruct(path=None): if path is None: import os import procedural_city_generation path=os.path.dirname(procedural_city_generation.__file__)+"/outputs/output.json" import json try: with open(path,'r') as d: data=d.read() except IOError: print "Input could not be located. Try to run the previous program in the chain first." return 0 data=json.loads(data) from procedural_city_generation.roadmap.Vertex import Vertex import numpy as np vertex_list=[] vertex_list=[0]*len(data) for x in data: y=data[x] k=Vertex(np.array(y[0])) k.minor_road,k.seed,k.neighboursindizes=y[1],y[2],y[3] vertex_list[int(x)]=k index=0 for k in vertex_list: for x in k.neighboursindizes: k.neighbours.append(vertex_list[x]) k.selfindex=index index+=1 setliste=[] return vertex_list