Skip to content

Commit

Permalink
done changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ressay committed Jun 6, 2020
1 parent 9aff999 commit 653338b
Show file tree
Hide file tree
Showing 21 changed files with 57,982 additions and 144 deletions.
51 changes: 48 additions & 3 deletions Geometry/Geom2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ def isParallel(self,point,threshold=0):
def isInPolygon(self,poly):
return poly.containsPoint(self)



def scale(self,r):
self.pnt = Point(self.pnt.x*r, self.pnt.y*r)
return self
Expand Down Expand Up @@ -90,6 +88,53 @@ def area(pts):
return s / 2


def line_intersection(line1, line2):
xdiff = Pnt(line1[0].x() - line1[1].x(), line2[0].x() - line2[1].x())
ydiff = Pnt(line1[0].y() - line1[1].y(), line2[0].y() - line2[1].y())

def det(a, b):
return a.x() * b.y() - a.y() * b.x()

div = det(xdiff, ydiff)
if div == 0:
return None

d = Pnt(det(*line1), det(*line2))
x = det(d, xdiff) / div
y = det(d, ydiff) / div
return Pnt(x, y)

def seg_intersection(line1, line2):
pnt = line_intersection(line1, line2)
# print(str(line1[0]), str(line1[1]))
# print(str(line2[0]), str(line2[1]))
# print("result", str(pnt))

if pnt is None:
return None

def between(x1, x2, x3):
e = 0.00001
return min((x2, x3)) - e <= x1 <= (max((x2, x3)) + e)

if not between(pnt.x(), line1[0].x(), line1[1].x()):
return None

if not between(pnt.x(), line2[0].x(), line2[1].x()):
return None

if not between(pnt.y(), line1[0].y(), line1[1].y()):
return None

if not between(pnt.y(), line2[0].y(), line2[1].y()):
return None

# print(str(pnt))
# print(str(line1[0]), str(line1[1]))
# print(str(line2[0]), str(line2[1]))

return pnt

def centroid(pts):
'Location of centroid.'

Expand Down Expand Up @@ -148,7 +193,7 @@ def updatePolygon(self):
# self.poly = Polygon([(1,2),(1,1),(5,5)])

def containsPoint(self,pnt):
self.poly.contains(pnt.pnt)
return self.poly.contains(pnt.pnt)

def intersects(self,poly):
return self.poly.intersects(poly.poly)
Expand Down
56,992 changes: 56,992 additions & 0 deletions IFCFiles/B09_mod.ifc

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions Ifc/IfcUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ def getSlabShapesFromIfc(fileName):
return slab_shapes


def getSpaceShapesFromIfc(fileName):
f = ifc.open(fileName)
# Get a list of all walls in the file
spaces = f.by_type("IfcSpace")
# Create a list of wall representation shapes
space_shapes = []

for space in spaces:
shape = geom.create_shape(settings, space).geometry
space_shapes.append((space, shape))

return space_shapes


def displayShapes(shapes):
from OCC.Display.SimpleGui import init_display
Expand Down
2 changes: 1 addition & 1 deletion Optimization/Genetic/GeneticAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def mutationSelection(mutationRate,population):
if random.uniform(0,1) < mutationRate:
yield p

def search(levelSkeleton,popSize=80,crossRate=0.3,mutRate=0.3,maxIterations=100
def search(levelSkeleton,popSize=50,crossRate=0.3,mutRate=0.5,maxIterations=200
,geneticOps=GeneticOperations2,filename='default', constraints=None):
start1 = timeit.default_timer()
population = generatePopulation(levelSkeleton,popSize, constraints['ratio'])
Expand Down
7 changes: 7 additions & 0 deletions Skeleton/BoxSkeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ def _getTopLeftPoint(self):
# print "mVec: " + str(maxVec.magn()) + " mVec2: " + str(maxVec2.magn())
self.vecLength = maxVec
self.vecWidth = endPnt - topPnt
if self.vecWidth.magn() == 0:
self.vecWidth = Pnt(0.00000001, 0.00000001)
# print ("end", endPnt, "start", topPnt, "1", endPnt.x(), endPnt.y(), topPnt.x(), topPnt.y())
# for pnt in pnts:
# print (pnt, pnt.x(), pnt.y())
#
# print "ennnnnddddd"
self.topLeftPnt = topPnt


Expand Down
35 changes: 35 additions & 0 deletions Skeleton/StoreySkeleton.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from shapely.geometry import Polygon
from shapely.ops import cascaded_union

from Geometry.Geom2D import Pnt
from Skeleton.BoxSkeleton import NotBoxError
from Skeleton.SlabSkeleton import SlabSkeleton
from Skeleton.WallSkeleton import WallSkeleton
from Skeleton.Skelet import Skelet
import math


class StoreySkeleton(Skelet):
def __init__(self, levelSkeletons):
super(StoreySkeleton, self).__init__()
self.levels = [levelSkeleton.level for levelSkeleton in levelSkeletons]
self.levelSkeletons = levelSkeletons
self.wallSkeletons = [wallSkeleton for levelSkeleton in levelSkeletons
for wallSkeleton in levelSkeleton.wallSkeletons]
self.walls = [wall for level in self.levels
for wall in level.walls]
self.notModifiedWalls = [levelSkeleton.wallSkeletons for levelSkeleton in levelSkeletons]
self.slabSkeletons = [levelSkeleton.slabSkeleton for levelSkeleton in levelSkeletons]
self.height = self.levels[0].getHeightOverLowerLevel()

def getWallsTotalLength(self):
length = 0
for wallSkeleton in self.wallSkeletons:
length += wallSkeleton.vecLength.magn()
return length

def getVoilesTotalLength(self):
return sum(wallSkeleton.getVoilesLength() for wallSkeleton in self.wallSkeletons)

def getPolys(self):
return [wallSkeleton.poly for wallSkeleton in self.wallSkeletons]
2 changes: 2 additions & 0 deletions Skeleton/VoileSkeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ def getSurrondingBox(self, d_ratio):
return self.surrondingBox
distance = 4*d_ratio
wid = Pnt(self.vecLength.y(),-self.vecLength.x())
# if distance == 0 or self.vecWidth.magn() == 0:
# print ("distance: ", distance, "vecWidth: ", self.vecWidth.magn())
wid = wid.copy().resize(distance)*2 + wid.copy().resize(self.vecWidth.magn())
# leng = self.vecLength.copy().resize(distance)*2 + self.vecLength
leng = self.vecLength
Expand Down
15 changes: 0 additions & 15 deletions Skeleton/WallSkeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,6 @@ def __init__(self, poly,pnts=None):
def createSkeletonFromWall(wall):
return WallSkeleton(wall.getBasePolygon())

# @staticmethod
# def createSkeletonsFromWall(wall, minZ=None,maxZ=None):
# polygons = wall.getBasePolygons()
# print("size is: ", len(polygons))
# wallSkeletons = []
# for polygon in polygons:
# try:
# wallSkeleton = WallSkeleton(polygon)
# except NotBoxError:
# print("not box error damn")
# continue
# wallSkeletons.append(wallSkeleton)
#
# return wallSkeletons

@staticmethod
def createSkeletonsFromWall(wall, minZ=None,maxZ=None):
e = 0.2
Expand Down
3 changes: 2 additions & 1 deletion Structures/Level.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ def isOver(self,level):
def isUnder(self,level):
return self.getHeight() < level.getHeight()

def isRightUnder(self,level):
def isRightUnder(self, level):
if level.getHeight() <= self.getHeight():
return False
return True
lowerLevels = [lvl for lvl in level.relatedLevels if lvl.getHeight() < level.getHeight()]
# print('LOWERLEVELS SIZE BEFORE FILTER: ', len(lowerLevels))
lowerLevels = [lvl for lvl in lowerLevels if lvl.getHeight() > self.getHeight()]
Expand Down
10 changes: 5 additions & 5 deletions Structures/Wall.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ def __init__(self,shape):

def isSupporting(self,slab):
tolerance = 0.2
miniArea = self.getBasePolygon().area()/5
# miniArea = self.getBasePolygon().area()/5
lowestW = self.getLowestPoint()
lowestS = slab.getLowestPoint()

if lowestS and lowestW and lowestW.z < lowestS.z:
if self.getHighestPoint().z >= lowestS.z-tolerance and self._isUnderSlab(slab):
if self.getHighestPoint().z >= lowestS.z-tolerance:# and self._isUnderSlab(slab):
polygons = self.getBasePolygons()
s = 0
# s = 0
for poly in polygons:
inters = poly.intersection(slab.getBasePolygon())
if inters:
s += inters.area()
return float(s) > miniArea
return True
return False

return False

Expand Down
Loading

0 comments on commit 653338b

Please sign in to comment.