procedural_city_generation.building_generation package

Submodules

procedural_city_generation.building_generation.Baeume module

import math import numpy as np from math import sin, cos, pi

def baumstamm(radius, texture, koords, height):

L=[] for x in range(12):

x/6.*pi verts=[np.array([sin(x/6.*pi), cos(x/6.*pi), 0]), np.array([sin((x+1)/6.*pi), cos((x+1)/6.*pi), 0]), np.array([sin((x+1)/6.*pi), cos((x+1)/6.*pi), height]), np.array([sin((x)/6.*pi), cos((x)/6.*pi), height]), np.array([sin((x)/6.*pi), cos((x)/6.*pi), 0])] verts= list(np.array(verts)+koords) faces=range(len(verts)) L.append(Polygon3D(verts, faces, texture))

return L

r=1 texture=”braun” koords=np.array([10, 0, 0]) height=15 print baumstamm(r, texture, koords, height)

procedural_city_generation.building_generation.BuildingHeight module

class procedural_city_generation.building_generation.BuildingHeight.BuildingHeight(savename, imagename)

Bases: object

Manages and distributes building-heights for buildings

savename: name of file we are reading input from (polygons-step of this program)

imagename: name of image or the string “diffused”. If this parameter is not “diffused”, then
this program will look for an image of that imagename in the folder procedural_ciy_generation/inputs/buildingheight_pictures
diffusion(arr, d)

Simulates diffusion. Taken from Stackoverflow user [aizquier] (https://stackoverflow.com/questions/8102781/efficiently-doing-diffusion-on-a-2d-map-in-python)

arr : np.ndarray(m, n)
Array representing the grayscale image to be diffused

d : float

np.ndarray(m, n)

getBuildingHeight(center)

Gets buildingheight for a building

center : numpy.ndarray(2, 1)
xy-coordinates of the center of the building to get buildingheight for

float

setupimage(path)

Sets up the image for the building height data As of now, always takes a diffused version of the population density image

path : String
Path to the population density image

img : np.ndarray(m, n, 3)

procedural_city_generation.building_generation.Polygon3D module

class procedural_city_generation.building_generation.Polygon3D.Polygon3D(verts, faces, texture)

Bases: object

procedural_city_generation.building_generation.Surface module

class procedural_city_generation.building_generation.Surface.Surface(input_name)

Bases: object

getSurfaceHeight(coords)

procedural_city_generation.building_generation.building_generation_params module

Module which contains all input parameters for this sudmodule, along with: - The default (recommmended) value from the developers - A short description of what the parameter changes - All values that the parameter accepts without causing this program to break.

This information can also be viewed when calling the GUI and clicking the “options” button for that specific module.

procedural_city_generation.building_generation.building_tools module

class procedural_city_generation.building_generation.building_tools.Walls(verts, l)

Bases: object

Walls object which has vertices saved as numpy arrays

getWalls()

Lazily evaluated walls as numpy array with shape (self.l, 2, 3)

np.ndarray(l, 3, 2)

selfplot()

Plots itself with matplotlib

None

procedural_city_generation.building_generation.building_tools.buildledge(walls, bottom, top, texture)

Creates one ledge Polygon object with shared vertices in the shape of the walls object

walls : procedural_city_generation.building_generation.Walls object bottom : float

z coordinate of the bottom of the walls
top : float
z coordinate of the top of the walls

texture : procedural_city_generation.building_generation.Texture object

procedural_city_generation.building_generation.Polygon3D object

>>>w=Walls([[0, 0, 0], [0, 1, 0], [1, 1, 0]], 3) >>>p= buildlege( w , 1, 2, some_tex) >>>p.verts [[0, 0, 1], [0, 1, 1], [1, 1, 1], [0, 0, 2], [0, 1, 2], [1, 1, 2]] >>>p.faces [[1, 0, 3, 4], [2, 1, 4, 5], [2, 0, 3, 5], [0, 1, 2], [3, 4, 5]]

procedural_city_generation.building_generation.building_tools.buildwalls(walls, bottom, top, texture)

Creates one walls Polygon object with shared vertices in the shape of the walls object

walls : procedural_city_generation.building_generation.Walls object bottom : float

Z coordinate of the bottom of the walls
top : float
Z coordinate of the top of the walls

texture : procedural_city_generation.building_generation.Texture object

procedural_city_generation.building_generation.Polygon3D object

>>>w=Walls([[0, 0, 0], [0, 1, 0], [1, 1, 0]], 3) >>>p= buildwalls( w , 1, 2, some_tex) >>>p.verts [[0, 0, 1], [0, 1, 1], [1, 1, 1], [0, 0, 2], [0, 1, 2], [1, 1, 2]] >>>p.faces [[1, 0, 3, 4], [2, 1, 4, 5], [2, 0, 3, 5]]

procedural_city_generation.building_generation.building_tools.flat_polygon(walls, height, texture)

Creates a flat Polygon with the shape of the walls at the given height

walls : procedural_city_generation.building_generation.Walls object height : float

Z coordinate of the polygon to be created

texture : procedural_city_generation.building_generation.Texture object

procedural_city_generation.building_generation.Polygon3D object

procedural_city_generation.building_generation.building_tools.get_windows(walls, list_of_currentheights, floorheight, windowwidth, windowheight, windowdist, texture)

Creates a Polygon3D Object containing the coordinates to all windows of a building

walls : procedural_city_generation.building_generation.Walls Object list_of_currentheights : list<float>

Which has one entry for each z-coordinate of a row of windows to be created. This always means the ‘bottom’ of each floor.
floorheight : float
Floorheight of the building, used to calculate center of each floor where windows are to be built
windowwidth : float
Width of each window
windowheight : float
Height of each window
windowdist : float
Distance between two windows if more than one window fits on the wall

procedural_city_generation.building_generation.Polygon3D object with shared vertices

procedural_city_generation.building_generation.building_tools.scale(walls, factor)

Scales a walls object by a factor

walls : procedural_city_generation.building_generation.Walls object factor : float

Number to be scaled to. E.g. 2 doubles the size, 0.5 halves the size

walls : procedural_city_generation.building_generation.Walls object

procedural_city_generation.building_generation.building_tools.scaletransform(walls, scalefactor, transformfactor=None, side=None)

Scales and transforms a procedural_city_generation.building_generation.Walls object

walls : procedural_city_generation.building_generation.walls object scalefactor : float

The factor to which the walls object is scaled down to
transformfactor (optional) : float
The factor to which the scaled down object will be moved to one of the vertices, i.e. 1 means all the way to the vertex, 0 means the object will stay centered
side (optional) : int
The vertex to which the object is transformed towards

procedural_city_generation.building_generation.walls object

procedural_city_generation.building_generation.building_tools.verticalsplit(buildingheight, floorheight)

Splits the Building vertically.

buildingheight : float
Height of the building
floorheight : float
Height of each floor
list<char>
Each character stands for one “building element” where: l=ledge f=floor b=base (Erdgeschoss) r=roof
procedural_city_generation.building_generation.building_tools.walls_from_poly(poly2d)

Creates a wall object from a Polygon3D Object by converting Poly.vertices from 2D-Arrays to 3D, np.array([x, y])->np.array([x, y, 0])

poly2d : procedural_city_generation.polygons.Polygon2D object

walls : procedural_city_generation.building_generation.Walls object

procedural_city_generation.building_generation.cuts module

Created on 2015.08.17 @author: Jonathan Sauder - jsauder@campus.tu-berlin.de

procedural_city_generation.building_generation.cuts.Ccut(walls, dist1, dist2, side)

Cuts a four-sided walls-object as follows:

+-----------+           +---+   +---+
|           |           |   |   |   |
|           |    == >     |   +---+   |
|           |           |           |
|           |           |           |
+-----------+           +-----------+

walls : procedural_city_generation.building_generation.walls object dist1 : float

Determines the length of one of the two vectors of the cut
dist2 : float
Determines the length of one of the two vectors of the cut
side : int
The pair of sides of the building which will be cut

procedural_city_generation.building_generation.walls object

procedural_city_generation.building_generation.cuts.Ccut2(walls, dist1, dist2, side)

A (n=2) recursive Ccut

procedural_city_generation.building_generation.cuts.Hcut(walls, dist1, dist2, side)

Cuts a four-sided walls object as follows:

+-----------+           +---+   +---+
|           |           |   |   |   |
|           |    == >     |   +---+   |
|           |           |   +---+   |
|           |           |   |   |   |
+-----------+           +---+   +---+

walls : procedural_city_generation.building_generation.walls object dist1 : float

Determines the length of one of the two vectors of the cut
dist2 : float
Determines the length of one of the two vectors of the cut
side : int
The pair of sides of the building which will be cut

procedural_city_generation.building_generation.walls object

procedural_city_generation.building_generation.cuts.Hcut2(walls, dist1, dist2, side)

A (n=2) recursive Hcut

procedural_city_generation.building_generation.cuts.Lcut(walls, dist1, dist2, side, v1=None, v2=None)

Cuts a four-sided walls object as follows:

+-----------+           +-----------+
|           |           |           |
|           |    == >     |           |
|           |           |       +---+
|           |           |       |
+-----------+           +-------+

walls : procedural_city_generation.building_generation.walls object dist1 : float

Determines the length of one of the two vectors of the cut
dist2 : float
Determines the length of one of the two vectors of the cut
side : int
The pair of sides of the building which will be cut

procedural_city_generation.building_generation.walls object

procedural_city_generation.building_generation.cuts.Tcut(walls, dist1, dist2, side)

Cuts a four-sided walls object as follows:

+-----------+               +---+
|           |               |   |
|           |    == >     +---+   +---+
|           |           |           |
|           |           |           |
+-----------+           +-----------+

walls : procedural_city_generation.building_generation.walls object dist1 : float

Determines the length of one of the two vectors of the cut
dist2 :
float Determines the length of one of the two vectors of the cut
side : int
The pair of sides of the building which will be cut

procedural_city_generation.building_generation.walls object

procedural_city_generation.building_generation.cuts.Xcut(walls, dist1, dist2, side)

Cuts a four-sided walls object as follows:

+-----------+           +---+   +---+
|           |           |   +---+   |
|           |    == >     +-+       +-+
|           |           +-+       +-+
|           |           |   +---+   |
+-----------+           +---+   +---+

walls : procedural_city_generation.building_generation.walls object dist1 : float

Determines the length of one of the two vectors of the cut
dist2 : float
Determines the length of one of the two vectors of the cut
side : int
The pair of sides of the building which will be cut

procedural_city_generation.building_generation.walls object

procedural_city_generation.building_generation.cuts.Ycut(walls, dist1, dist2, side)

Cuts a four-sided walls object as follows:

+-----------+               +---+
|           |               |   |
|           |    == >     +---+   +---+
|           |           |           |
|           |           |   +---+   |
+-----------+           +---+   +---+

walls : procedural_city_generation.building_generation.walls object dist1 : float

Determines the length of one of the two vectors of the cut
dist2 : float
Determines the length of one of the two vectors of the cut
side : int
The pair of sides of the building which will be cut

procedural_city_generation.building_generation.walls object

procedural_city_generation.building_generation.cuts.Zcut(walls, dist1, dist2, side)

Cuts a four-sided walls object as follows:

+-----------+               +-------+
|           |               |       |
|           |    == >     +---+       |
|           |           |       +---+
|           |           |       |
+-----------+           +-------+

walls : procedural_city_generation.building_generation.walls object dist1 : float

Determines the length of one of the two vectors of the cut
dist2 : float
Determines the length of one of the two vectors of the cut
side : int
The pair of sides of the building which will be cut

procedural_city_generation.building_generation.walls object

procedural_city_generation.building_generation.cuts.normal(arr)
procedural_city_generation.building_generation.cuts.randomcut(walls, housebool)

Chooses a Cut for the creation of the floorplan from all available cuts. Every cut functions by adding/replacing values in the numpy array of the walls’ vertices. There are two main cuts. All other cuts are a combination of these two cuts. The elementary cuts are:

Ccut
------------        ----+   +----
                == >      |   |
                        +---+
Lcut
--------+           ----+
        |      == >       |
        |               +---+
        |                   |
  • walls : procedural_city_generation.building_generation.walls object

  • housebool : boolean

    Value showing if a building is a house or not

  • procedural_city_generation.building_generation.walls object

procedural_city_generation.building_generation.getFoundation module

procedural_city_generation.building_generation.getFoundation.getFoundation(poly, grid_width=0.01, eps=1e-08)

procedural_city_generation.building_generation.main module

procedural_city_generation.building_generation.main.main()

Reads list of procedural_city_generation.polygons.Polygon2D objects from file and constructs buildings on top of these. The buildings consist of Polygon3D objects, which are saved to /outputs/polygons.txt. See merger module for more details.

procedural_city_generation.building_generation.merge_polygons module

class procedural_city_generation.building_generation.merge_polygons.Merger

Bases: object

Merger Class used to Merge polygons together while keeping track of an index

merge(poly)

merges polygons with same Texture Parameters ———- poly : procedural_city_generation.building_generation.Polygon3D Object

Polygon object to be merged to this Merger

:: >>>anotherPoly.verts [(0, 0, 0), (0, 1, 0), (1, 1, 0)] >>>anotherPoly.faces [0, 1, 2] >>>m=Merger() >>>m.allverts [(3, 3, 0), (3, 4, 0), (4, 4, 0)] >>>m.faces [(0, 1, 2)] >>>m.merge(anotherPoly) >>>m.allverts [(3, 3, 0), (3, 4, 0), (4, 4, 0), (0, 0, 0), (0, 1, 0), (1, 1, 0)] >>>m.faces [(0, 1, 2), (3, 4, 5)]

procedural_city_generation.building_generation.merge_polygons.merge_polygons(polygons, textures, output_name)

Groups Polygon3Ds with identical Texture because Blender’s mesh.from_pydata() and bpy.context.scene.objects.link take an increasing amount of time with amount of existingPolygons. Saves Polygons to /outputs/buildings.txt

polygons : list<procedural_city_generation.polygons.Polygon3D>
List of 3D polygons to be built in blender
textures : list<procedural_city_generation.building_generation.Texture>
List of textures in use

procedural_city_generation.building_generation.roofs module

procedural_city_generation.building_generation.roofs.houseroof(walls, currentheight, roofheight, texture)

Creates a “classic” roof with two triangles and two rectangles. Used only for houses and assumes that the house has 4 sides.

walls : procedural_city_generation.building_generation.Walls object currentheight : float

Current height, Z coordinate of the base of the roof
roofheight : float
Height of the roof itself

texture : procedural_city_generation.building_generation.Texture object

list<procedural_city_generation.building_generation.Polygon3D object>

procedural_city_generation.building_generation.roofs.isleft(wall, point)

Helper function for p_in_poly Taken from: http://geomalgorithms.com/a03-_inclusion.html, all credits to Dan Sunday.

wall : numpy-array with shape 3, 2 point : numpy-array with shape 3, 1

float

procedural_city_generation.building_generation.roofs.kastenroof(walls, roofwalls, currentheight, roofheight, texture, texture2=None)

Creates a flat roof with a box on top.

walls : procedural_city_generation.building_generation.Walls object
Walls object after cuts
roofwalls : procedural_city_generation.building_generation.Walls object
Walls object prior to cuts
currentheight : float
Current height, Z coordinate of the base of the roof
roofheight : float
Height of the roof itself

texture : procedural_city_generation.building_generation.Texture object texture2 (optional): procedural_city_generation.building_generation.Texture object

Will default to texture if not specified
  • list<procedural_city_generation.building_generation.Polygon3D object>
procedural_city_generation.building_generation.roofs.p_in_poly(walls, point)

Returns True if a point is in a “walls” polygon, eles False Taken from: http://geomalgorithms.com/a03-_inclusion.html, all credits to Dan Sunday.

walls : procedural_city_generation.building_generation.walls object point : np.ndarray with shape (3, )

boolean

procedural_city_generation.building_generation.roofs.roof(walls, roofwalls, currentheight, housebool, texture, texture2=None)

Builds a roof on top of a house, depending on housetype

walls : procedural_city_generation.building_generation.Walls object
Walls object with cuts
roofwalls : procedural_city_generation.building_generation.Walls object
Walls object prior to cuts
currentheight : float
Current height, Z coordinate of the base of the roof-Polygon
housebool : boolean
Decides if the building is a house or not.
texture : procedural_citY_generation.building_generation.Texture object
Texture of the roof
texture2 (optional) : procedural_citY_generation.building_generation.Texture object
Texture of other elements (such as a box in boxroof) on the roof. If not specified, will default to texture

procedural_city_generation.building_generation.Polygon3D object

procedural_city_generation.building_generation.updateTextures module

class procedural_city_generation.building_generation.updateTextures.Texture(name, scale, minP, maxP, shrinkwrap=False, index=0)

Bases: object

Texture Object

name : String
Full name of image of texture
scale : float
How many times the texture is to be scaled down. The larger the number the smaller the texture
minP : float
Minimum int between 0 and 100 so this texture is considered
maxP : float
Maximum int between 0 and 100 so this texture is considered
shrinkwrap (optional): boolean
Describes whether Polygon3Ds with this texture will be projected onto surface.
class procedural_city_generation.building_generation.updateTextures.textureGetter(textures)

Bases: object

Gets initiated with a list of textures, used for chosing a random texture for a specific buildingHeight

textures : list of procedural_city_generation.visualization.texture objects

getTexture(name, p)

Returns a random texture for a specific name and buildingHeight p between 1 and 100

name : String
Substring which has to be included in returned texture
p : int
Integer between 1 and 100, 100fold of the buildingheight in meters.

procedural_city_generation.building_generation.Texture object

:: >>>textureGetter.getTexture(“Roof”, 40) Tex_Roof03.jpeg

procedural_city_generation.building_generation.updateTextures.updateTextures()

Parses /visualization/Textures/ and compares with /visualization/texTable.json

None

List<procedural_city_generation.building_generation.Texture>

:: >>>updateTextures() [“Tex_Roof03.jpeg”, “Tex_Grass01.jpg”, “Tex_Road01.png”]

Module contents