diff --git a/cad2.py b/cad2.py new file mode 100644 index 000000000..7036adb74 --- /dev/null +++ b/cad2.py @@ -0,0 +1,20 @@ +import ifcopenshell +import multiprocessing +import ifcopenshell.geom + +ifc_filepath = "/home/frank/dev/tum-dev/Navigatum/map/data/5505_IFC4/02-55-5505-100_EG.ifc" +ifc_file = ifcopenshell.open(ifc_filepath) + +settings = ifcopenshell.geom.settings() +iterator = ifcopenshell.geom.iterator(settings, ifc_file, multiprocessing.cpu_count()) +if iterator.initialize(): + while True: + shape = iterator.get() + element = ifc_file.by_id(shape.id) + matrix = shape.transformation.matrix + faces = shape.geometry.faces + edges = shape.geometry.edges + verts = shape.geometry.verts + + if not iterator.next(): + break diff --git a/cad3.py b/cad3.py new file mode 100644 index 000000000..973232be0 --- /dev/null +++ b/cad3.py @@ -0,0 +1,30 @@ +# pip install ifcopenshell +# pip install mathutils + +import ifcopenshell +import ifcopenshell.geom +import ifcopenshell.draw +import ifcopenshell.api.context +import ifcopenshell.util.shape +import plotly.express as px +import pandas as pd + +ifc_file = "/home/frank/dev/tum-dev/Navigatum/map/data/5505_IFC4/02-55-5505-100_EG.ifc" + +model = ifcopenshell.open(ifc_file) +rooms = model.by_type('IfcSpace') +# doors = model.by_type('IfcDoor') +setttings = ifcopenshell + +settings = ifcopenshell.geom.settings() +settings.set(settings.USE_PYTHON_OPENCASCADE, True) + +try: + shape = ifcopenshell.geom.create_shape(settings, rooms[0]) + geometry = shape.geometry # see #1124 + # These are methods of the TopoDS_Shape class from pythonOCC + shape_gpXYZ = geometry.Location().Transformation().TranslationPart() + # These are methods of the gpXYZ class from pythonOCC + print(shape_gpXYZ.X(), shape_gpXYZ.Y(), shape_gpXYZ.Z()) +except: + print("Shape creation failed") diff --git a/map/cad2osm.py b/map/cad2osm.py new file mode 100644 index 000000000..5d935369b --- /dev/null +++ b/map/cad2osm.py @@ -0,0 +1,46 @@ +# pip install ifcopenshell +# pip install mathutils + +import ifcopenshell +import ifcopenshell.draw +import ifcopenshell.api.context +import ifcopenshell.util.shape +from ifcopenshell import geom +import plotly.express as px +import pandas as pd + +ifc_file = "/home/frank/dev/tum-dev/Navigatum/map/data/5505_IFC4/02-55-5505-100_EG.ifc" + +model = ifcopenshell.open(ifc_file) +rooms = model.by_type('IfcSpace') +# doors = model.by_type('IfcDoor') +vertecies = [] +for i, room in enumerate(rooms): + settings = ifcopenshell.geom.settings() + try: + shape = ifcopenshell.geom.create_shape(settings, room) + except Exception: + continue + # Since the lists are flattened, you may prefer to group them like so depending on your geometry kernel + # A nested numpy array e.g. [[v1x, v1y, v1z], [v2x, v2y, v2z], ...] + grouped_verts = ifcopenshell.util.shape.get_vertices(shape.geometry) + # A nested numpy array e.g. [[e1v1, e1v2], [e2v1, e2v2], ...] + # grouped_edges = ifcopenshell.util.shape.get_edges(shape.geometry) + # A nested numpy array e.g. [[f1v1, f1v2, f1v3], [f2v1, f2v2, f2v3], ...] + # grouped_faces = ifcopenshell.util.shape.get_faces(shape.geometry) + ifcopenshell.util.geom + matrix = shape.transformation.matrix + (raw_x, raw_y, raw_z) = matrix[12:15] + # print(location) + vertecies.extend( + dict(x=raw_x + x, y=raw_y + y, z=raw_z + z, id=i) for (x, y, z) in grouped_verts if (raw_z + z) < 2) + if i > 2: + continue + +df = pd.DataFrame(vertecies) +fig = px.line(df, x="x", y="y", color="id") +fig.update_yaxes(scaleanchor="x", scaleratio=1, overwrite=True) +fig.show() +# plan = ifcopenshell.api.context.add_context(model, context_type="Plan") +settings = ifcopenshell.draw.draw_settings() +ifcopenshell.draw.main(settings, [model])