mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-21 14:13:41 +00:00
Fix regression in point cloud loading in refactoring the new item mode.
This commit is contained in:
@@ -761,12 +761,9 @@ class IfcImporter:
|
|||||||
def create_pointclouds(self, products: set[ifcopenshell.entity_instance]) -> set[ifcopenshell.entity_instance]:
|
def create_pointclouds(self, products: set[ifcopenshell.entity_instance]) -> set[ifcopenshell.entity_instance]:
|
||||||
result = set()
|
result = set()
|
||||||
for product in products:
|
for product in products:
|
||||||
representation = self.get_pointcloud_representation(product)
|
if representation := self.get_pointcloud_representation(product):
|
||||||
if representation is not None:
|
if pointcloud := self.create_pointcloud(product, representation):
|
||||||
pointcloud = self.create_pointcloud(product, representation)
|
|
||||||
if pointcloud is not None:
|
|
||||||
result.add(pointcloud)
|
result.add(pointcloud)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def create_pointcloud(
|
def create_pointcloud(
|
||||||
|
|||||||
@@ -766,16 +766,15 @@ class Loader(bonsai.core.tool.Loader):
|
|||||||
coords = None
|
coords = None
|
||||||
if item.is_a("IfcCartesianPointList3D"): # PointCloud.c
|
if item.is_a("IfcCartesianPointList3D"): # PointCloud.c
|
||||||
coords = np.array(item.CoordList)
|
coords = np.array(item.CoordList)
|
||||||
vertex_list.extend(Vector(list(coordinates)) * unit_scale for coordinates in item.CoordList)
|
|
||||||
# Is it ever used? In IFC4+ PointCloud is requiring 3D list, before IFC4 there were no coord lists at all.
|
# Is it ever used? In IFC4+ PointCloud is requiring 3D list, before IFC4 there were no coord lists at all.
|
||||||
elif item.is_a("IfcCartesianPointList2D"):
|
elif item.is_a("IfcCartesianPointList2D"):
|
||||||
vertex_list.extend(Vector(list(coordinates)).to_3d() * unit_scale for coordinates in item.CoordList)
|
coords = np.array(item.CoordList)
|
||||||
elif item.is_a("IfcPoint"): # Point
|
coords = np.column_stack((coords, np.zeros(coords.shape[0])))
|
||||||
if item.is_a("IfcCartesianPoint"):
|
elif item.is_a("IfcCartesianPoint"): # Point
|
||||||
vertex_list.append(Vector(list(item.Coordinates)) * unit_scale)
|
coord = np.array(item.Coordinates)
|
||||||
else:
|
if len(coord) == 2:
|
||||||
# TODO: implement non cartesian point vertices.
|
coord = np.append(coord, (0.0,))
|
||||||
continue
|
coords = np.array((coord,))
|
||||||
else:
|
else:
|
||||||
assert False
|
assert False
|
||||||
assert coords is not None
|
assert coords is not None
|
||||||
|
|||||||
@@ -549,3 +549,51 @@ class TestSetupActiveBsddClassification(NewFile):
|
|||||||
|
|
||||||
def test_set_load_and_set_active_bsdd_ifc4x3(self):
|
def test_set_load_and_set_active_bsdd_ifc4x3(self):
|
||||||
self.run_test("IFC4X3")
|
self.run_test("IFC4X3")
|
||||||
|
|
||||||
|
|
||||||
|
class TestCreatePointCloudMesh(NewFile):
|
||||||
|
def test_cartesian_point_list_3d(self):
|
||||||
|
bpy.ops.bim.create_project()
|
||||||
|
ifc_file = tool.Ifc.get()
|
||||||
|
coords = ((1., 2., 3.), (4., 5., 6.))
|
||||||
|
item = ifc_file.createIfcCartesianPointList3D(coords)
|
||||||
|
rep = ifc_file.createIfcShapeRepresentation(Items=[item])
|
||||||
|
mesh = subject.create_point_cloud_mesh(rep)
|
||||||
|
assert len(mesh.vertices) == 2
|
||||||
|
verts = np.array([v.co for v in mesh.vertices])
|
||||||
|
assert np.allclose(verts, np.array([np.array(c) for c in coords]))
|
||||||
|
|
||||||
|
def test_cartesian_point_list_2d(self):
|
||||||
|
bpy.ops.bim.create_project()
|
||||||
|
ifc_file = tool.Ifc.get()
|
||||||
|
coords = ((1., 2.), (4., 5.))
|
||||||
|
coords3d = ((1., 2., 0.), (4., 5., 0.))
|
||||||
|
item = ifc_file.createIfcCartesianPointList2D(coords)
|
||||||
|
rep = ifc_file.createIfcShapeRepresentation(Items=[item])
|
||||||
|
mesh = subject.create_point_cloud_mesh(rep)
|
||||||
|
assert len(mesh.vertices) == 2
|
||||||
|
verts = np.array([v.co for v in mesh.vertices])
|
||||||
|
assert np.allclose(verts, np.array([np.array(c) for c in coords3d]))
|
||||||
|
|
||||||
|
def test_point_3d(self):
|
||||||
|
bpy.ops.bim.create_project()
|
||||||
|
ifc_file = tool.Ifc.get()
|
||||||
|
coords = ((1., 2., 0.),)
|
||||||
|
item = ifc_file.createIfcCartesianPoint(Coordinates=coords[0])
|
||||||
|
rep = ifc_file.createIfcShapeRepresentation(Items=[item])
|
||||||
|
mesh = subject.create_point_cloud_mesh(rep)
|
||||||
|
assert len(mesh.vertices) == 1
|
||||||
|
verts = np.array([v.co for v in mesh.vertices])
|
||||||
|
assert np.allclose(verts, np.array([np.array(c) for c in coords]))
|
||||||
|
|
||||||
|
def test_point_2d(self):
|
||||||
|
bpy.ops.bim.create_project()
|
||||||
|
ifc_file = tool.Ifc.get()
|
||||||
|
coords = ((1., 2.),)
|
||||||
|
coords3d = ((1., 2., 0.),)
|
||||||
|
item = ifc_file.createIfcCartesianPoint(Coordinates=coords[0])
|
||||||
|
rep = ifc_file.createIfcShapeRepresentation(Items=[item])
|
||||||
|
mesh = subject.create_point_cloud_mesh(rep)
|
||||||
|
assert len(mesh.vertices) == 1
|
||||||
|
verts = np.array([v.co for v in mesh.vertices])
|
||||||
|
assert np.allclose(verts, np.array([np.array(c) for c in coords3d]))
|
||||||
|
|||||||
Reference in New Issue
Block a user