Skip to content

Commit dd348de

Browse files
committed
ifccityjson: lazy build vertex dictionary
1 parent 61e510e commit dd348de

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

src/ifccityjson/cityjson2ifc.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ def convert(self, city_model):
8484
self.city_model = city_model
8585
self.create_new_file()
8686
self.create_metadata()
87-
self.geometry.build_vertices(self.IFC_model,
88-
coords=city_model.j["vertices"],
89-
scale=self.properties["local_scale"])
87+
self.geometry.set_scale(self.properties["local_scale"])
88+
#self.geometry.build_vertices(self.IFC_model,
89+
# coords=city_model.j["vertices"],
90+
# scale=self.properties["local_scale"])
9091
# self.build_vertices()
9192
self.create_IFC_classes()
9293
if self.properties["split"]:

src/ifccityjson/geometry.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,34 @@
2020
import warnings
2121

2222
class GeometryIO:
23-
def __init__(self):
23+
def __init__(self, scale=None):
2424
self.vertices = {}
25+
self.scale = scale
2526

26-
def build_vertices(self, IFC_model, coords, scale=None):
27-
for coord in coords:
28-
if scale:
29-
IFC_vertex = tuple([float(xyz) * coord_scale
30-
for xyz, coord_scale
31-
in zip(coord, scale)])
32-
else:
33-
IFC_vertex = [float(xyz) for xyz in coord]
27+
def set_scale(self, scale):
28+
self.scale = scale
3429

35-
IFC_cartesian_point = IFC_model.create_entity("IfcCartesianPoint", IFC_vertex)
36-
self.vertices[tuple(coord)] = IFC_cartesian_point
30+
def build_vertices(self, IFC_model, vertices):
31+
for vertex in vertices:
32+
self.build_vertex(self, IFC_model, vertex)
33+
34+
def build_vertex(self, IFC_model, vertex):
35+
if self.scale:
36+
IFC_vertex = [float(xyz) * coord_scale
37+
for xyz, coord_scale
38+
in zip(vertex, self.scale)]
39+
else:
40+
IFC_vertex = [float(xyz) for xyz in vertex]
41+
42+
IFC_cartesian_point = IFC_model.create_entity("IfcCartesianPoint", IFC_vertex)
43+
self.vertices[tuple(vertex)] = IFC_cartesian_point
44+
return IFC_cartesian_point
45+
46+
def get_vertex(self, IFC_model, vertex):
47+
if tuple(vertex) in self.vertices:
48+
return self.vertices[tuple(vertex)]
49+
else:
50+
return self.build_vertex(IFC_model, vertex)
3751

3852
# See for CityJSON geometries:
3953
# https://www.cityjson.org/dev/geom-arrays/
@@ -75,7 +89,7 @@ def create_IFC_composite_curve(self, IFC_model, geometry):
7589
for line in geometry.boundaries:
7690
vertices = []
7791
for vertex in line:
78-
vertices.append(self.vertices[tuple(vertex)])
92+
vertices.append(self.get_vertex(IFC_model, vertex))
7993
polyline = IFC_model.create_entity("IfcPolyLine", vertices)
8094
IFC_geometry.append(polyline)
8195
return IFC_geometry
@@ -133,9 +147,9 @@ def create_IFC_face(self, IFC_model, face):
133147
# exterior face
134148
vertices = []
135149
for vertex in face[0]:
136-
vertices.append(self.vertices[tuple(vertex)])
137150
polyloop = IFC_model.create_entity("IfcPolyLoop", vertices)
138151
outerbound = IFC_model.create_entity("IfcFaceOuterBound", polyloop, True)
152+
vertices.append(self.get_vertex(IFC_model, vertex))
139153

140154
# return if only exterior face
141155
if len(face) == 1:
@@ -145,8 +159,8 @@ def create_IFC_face(self, IFC_model, face):
145159
innerbounds = []
146160
for interior_face in face[1:]:
147161
for vertex in interior_face:
148-
vertices.append(self.vertices[tuple(vertex)])
149162
polyloop = IFC_model.create_entity("IfcPolyLoop", vertices)
150163
innerbounds.append(IFC_model.create_entity("IfcFaceBound", polyloop, True))
151164
return IFC_model.create_entity("IfcFace", [outerbound] + innerbounds)
152165

166+
vertices.append(self.get_vertex(IFC_model, vertex))

0 commit comments

Comments
 (0)