wassimj / topologicpy

The python bindings for topologic
MIT License
83 stars 23 forks source link

Topology.ByIFCFile - Topology of two layered Wall has three Cells #66

Closed chrzbrk closed 1 month ago

chrzbrk commented 1 month ago

Hello Professor,

I have noticed a strange behavior when I import my IFC test file using Topology.ByIFCFile.

This file was exported from Revit and contains a wall with the GUID “3iln0jDazAuRap$f6vl5mq”. This wall consists of two wall layers - as can also be seen in the two images (1x Revit and 1x IFCViewer).

After the import, however, the topology has three cells. I have specified the coordinates of the vertices for all three cells below. Cells 1 and 2 have exactly the same coordinates but in a different order. I assume that this behavior is not intended?

Thank you very much!

Link to the IFC: https://drive.google.com/drive/folders/1U5NyPApw_2KXIS07WEYTOyqJFvSTizuz?usp=sharing

Github1 Github2

Coordinates Cell 0: 20.179948,12.776,0.0 20.179948,12.776,6.096 20.179948,12.792,6.096 20.179948,12.792,0.0 14.440948,12.776,0.0 14.440948,12.776,6.096 20.008448,12.792,0.0 20.008448,12.792,6.096 14.495948,12.792,0.0 14.440948,12.792,0.0 14.495948,12.792,6.096 14.440948,12.792,6.096

Coordinates Cell 1: 14.495948,12.792,0.0 14.495948,12.792,6.096 20.008448,12.792,6.096 20.008448,12.792,0.0 14.495948,12.942,0.0 14.495948,12.942,6.096 20.008448,12.942,6.096 20.008448,12.942,0.0

Coordinates Cell 2: 14.495948,12.942,0.0 14.495948,12.942,6.096 14.495948,12.792,6.096 14.495948,12.792,0.0 20.008448,12.792,6.096 20.008448,12.792,0.0 20.008448,12.942,6.096 20.008448,12.942,0.0

My Test Code: import ifcopenshell from topologicpy.Topology import Topology from topologicpy.Cell import Cell from topologicpy.Vertex import Vertex from topologicpy.Dictionary import Dictionary

Path to the IFC file

ifc_file_path = '../Test_Walls.ifc' specific_guid = "3iln0jDazAuRap$f6vl5mq"

Open the IFC file

ifc_file = ifcopenshell.open(ifc_file_path) print("IFC file opened successfully.")

Create topologies for all walls in the IFC model

wall_topologies = Topology.ByIFCFile(file=ifc_file, transferDictionaries=True, includeTypes=['IfcWall']) print("Initial wall topologies created successfully.")

Filter the topology for the specific GUID

specific_wall_topology = None for topo in wall_topologies: topo_dict = Topology.Dictionary(topo) topo_guid = Dictionary.ValueAtKey(topo_dict, "IFC_guid") if topo_guid == specific_guid: specific_wall_topology = topo break

if specific_wall_topology is None: print("No wall topology found with the specific GUID.") else: print(f"Wall topology with GUID '{specific_guid}' loaded.")

# Analyze the coordinates of each Cell in the wall and find duplicates
cells = Topology.Cells(specific_wall_topology)
for i, cell_a in enumerate(cells):
    coords_a = frozenset((Vertex.X(v), Vertex.Y(v), Vertex.Z(v)) for v in Cell.Vertices(cell_a))
    for j, cell_b in enumerate(cells):
        if i < j:  # Compare each Cell only with subsequent Cells to avoid double comparisons
            coords_b = frozenset((Vertex.X(v), Vertex.Y(v), Vertex.Z(v)) for v in Cell.Vertices(cell_b))
            if coords_a == coords_b:
                print(f"Cells {i + 1} and {j + 1} are identical.")
wassimj commented 1 month ago

Can you please try with the new version (v0.7.50). In this version, the wall you are referring to is a Cluster and has two cells. Here is the code I used to display the wall in question:


ifc_file_path = r"C:\Users\sarwj\Downloads\Test_Walls.ifc"
specific_guid = "3iln0jDazAuRap$f6vl5mq"
wall_topologies = Topology.ByIFCPath(path=ifc_file_path, includeTypes=["IfcWall"], transferDictionaries=True)

specific_wall_topology = None
for topo in wall_topologies:
    d = Topology.Dictionary(topo)
    topo_dict = Topology.Dictionary(topo)
    type  = Dictionary.ValueAtKey(topo_dict, "IFC_type")
    topo_guid = Dictionary.ValueAtKey(topo_dict, "IFC_guid")
    if topo_guid == specific_guid:
        print("Topology:", topo, "Type:", type)
        cells = Topology.Cells(topo)
        print("Number of Cells:", len(cells))
        specific_wall_topology = topo
        break

Topology.Show(specific_wall_topology, colorKey="TOPOLOGIC_color", faceOpacity=0.5)

output

specific_wall

chrzbrk commented 1 month ago

I have now updated the version and the number of cells is correct. Sorry for the effort and thanks for the help!