Skip to content

Commit ff662fd

Browse files
committed
Merging projects now accomodates models with different project norths
1 parent f075b0c commit ff662fd

3 files changed

Lines changed: 80 additions & 14 deletions

File tree

src/blenderbim/test/bim/feature/project.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,6 @@ Scenario: Link IFC - automatic false origin mode - two different false origins a
780780
And the object "Col:IfcProject/geolocation.ifc:Chunk" has a vertex at "-17.696,-7.866,0"
781781
And the object "Col:IfcProject/geolocation.ifc:Chunk" has a vertex at "-13.268,0.464,0"
782782

783-
784783
Scenario: Toggle link visibility - wireframe mode
785784
Given an empty IFC project
786785
And I press "bim.link_ifc(filepath='{cwd}/test/files/basic.ifc')"

src/ifcpatch/ifcpatch/recipes/MergeProject.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,41 @@ def patch(self):
6161
if (main_unit := self.get_unit_name(self.file)) != self.get_unit_name(other):
6262
other = ifcopenshell.util.unit.convert_file_length_units(other, main_unit)
6363

64-
existing_enh = np.array(
64+
existing_origin = np.array(
6565
ifcopenshell.util.geolocation.auto_xyz2enh(self.file, 0, 0, 0, should_return_in_map_units=False)
6666
)
67-
other_enh = np.array(
67+
other_origin = np.array(
6868
ifcopenshell.util.geolocation.auto_xyz2enh(other, 0, 0, 0, should_return_in_map_units=False)
6969
)
7070

71-
if not np.allclose(existing_enh, other_enh):
72-
x, y, z = ifcopenshell.util.geolocation.auto_enh2xyz(other, *existing_enh, is_specified_in_map_units=False)
73-
e, n, h = existing_enh
74-
# For now don't handle rotation because my brain is going to explode
75-
SetFalseOrigin("", other, self.logger, name="", x=x, y=y, z=z, e=e, n=n, h=h).patch()
71+
existing_angle = ifcopenshell.util.geolocation.get_grid_north(self.file)
72+
other_angle = ifcopenshell.util.geolocation.get_grid_north(other)
73+
74+
model_rotation = existing_angle - other_angle
75+
if model_rotation > 180:
76+
model_rotation = (360 - model_rotation) * -1
77+
elif model_rotation < -180:
78+
model_rotation = (model_rotation * -1) - 360
79+
80+
if not np.allclose(existing_origin, other_origin) or not np.isclose(existing_angle, other_angle):
81+
x, y, z = ifcopenshell.util.geolocation.auto_enh2xyz(
82+
other, *existing_origin, is_specified_in_map_units=False
83+
)
84+
e, n, h = existing_origin
85+
SetFalseOrigin(
86+
"",
87+
other,
88+
self.logger,
89+
name="",
90+
x=x,
91+
y=y,
92+
z=z,
93+
e=e,
94+
n=n,
95+
h=h,
96+
gn_angle=existing_angle,
97+
rotate_angle=model_rotation,
98+
).patch()
7699

77100
self.existing_contexts: list[ifcopenshell.entity_instance] = self.file.by_type(
78101
"IfcGeometricRepresentationContext"

src/ifcpatch/test/test_MergeProject.py

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import ifcopenshell
2121
import ifcopenshell.api.georeference
2222
import ifcopenshell.util.placement
23+
import ifcopenshell.util.shape_builder
2324
import test.bootstrap
2425
import tempfile
2526
import numpy as np
@@ -81,31 +82,60 @@ def test_using_the_georeferencing_of_the_original_project(self):
8182
assert len(output.by_type("IfcProjectedCRS")) == 1
8283
assert len(output.by_type("IfcMapConversion")) == 1
8384

84-
def test_shifting_the_source_project_to_match_the_original_project_origin(self):
85+
def test_shifting_the_other_project_to_match_the_original_project_origin(self):
8586
self.file = self.setup_project(self.file)
8687
second_file = self.setup_project()
8788
ifcopenshell.api.georeference.add_georeferencing(self.file)
89+
xaa1, xao1 = ifcopenshell.util.geolocation.angle2xaxis(10)
8890
ifcopenshell.api.georeference.edit_georeferencing(
89-
self.file, coordinate_operation={"Eastings": 10, "Northings": 20}, projected_crs={"Name": "EPSG:1234"}
91+
self.file,
92+
coordinate_operation={"Eastings": 10, "Northings": 20, "XAxisAbscissa": xaa1, "XAxisOrdinate": xao1},
93+
projected_crs={"Name": "EPSG:1234"},
9094
)
9195
ifcopenshell.api.georeference.add_georeferencing(second_file)
96+
xaa, xao = ifcopenshell.util.geolocation.angle2xaxis(30)
9297
ifcopenshell.api.georeference.edit_georeferencing(
93-
second_file, coordinate_operation={"Eastings": 30000, "Northings": 40000}, projected_crs={"Name": "EPSG:0"}
98+
second_file,
99+
coordinate_operation={"Eastings": 30000, "Northings": 40000, "XAxisAbscissa": xaa, "XAxisOrdinate": xao},
100+
projected_crs={"Name": "EPSG:0"},
94101
)
95102

103+
builder1 = ifcopenshell.util.shape_builder.ShapeBuilder(self.file)
104+
builder2 = ifcopenshell.util.shape_builder.ShapeBuilder(second_file)
105+
o1 = builder1.create_axis2_placement_3d()
106+
o2 = builder2.create_axis2_placement_3d()
107+
body1 = ifcopenshell.util.representation.get_context(self.file, "Model", "Body", "MODEL_VIEW")
108+
body2 = ifcopenshell.util.representation.get_context(second_file, "Model", "Body", "MODEL_VIEW")
109+
96110
# Original file is in meters
97111
wall1 = self.file.by_type("IfcWall")[0]
98112
m1 = ifcopenshell.util.placement.get_local_placement(wall1.ObjectPlacement)
99113
assert np.allclose(m1[:, 3], (1, 2, 3, 1))
100114
global_m1 = ifcopenshell.util.geolocation.auto_local2global(self.file, m1, should_return_in_map_units=False)
101-
assert np.allclose(global_m1[:, 3], (11, 22, 3, 1))
115+
assert np.allclose(global_m1[:, 3], (11.332, 21.796, 3, 1))
116+
117+
block = self.file.createIfcCsgSolid(self.file.createIfcBlock(o1, 2, 2, 2))
118+
rep = builder1.get_representation(context=body1, items=[block])
119+
ifcopenshell.api.geometry.assign_representation(self.file, product=wall1, representation=rep)
120+
shape = ifcopenshell.geom.create_shape(ifcopenshell.geom.settings(), wall1)
121+
verts = ifcopenshell.util.shape.get_shape_vertices(shape, shape.geometry)
122+
assert np.any(np.all(np.isclose(np.array((1., 2., 3.)), verts), axis=1))
123+
assert np.any(np.all(np.isclose(np.array((3., 4., 5.)), verts), axis=1))
102124

103125
# Second file is in millimeters with a different false origin
104126
wall1 = second_file.by_type("IfcWall")[0]
105127
m1 = ifcopenshell.util.placement.get_local_placement(wall1.ObjectPlacement)
106128
assert np.allclose(m1[:, 3], (1000, 2000, 3000, 1))
107129
global_m1 = ifcopenshell.util.geolocation.auto_local2global(second_file, m1, should_return_in_map_units=False)
108-
assert np.allclose(global_m1[:, 3], (31000, 42000, 3000, 1))
130+
assert np.allclose(global_m1[:, 3], (31866, 41232, 3000, 1))
131+
132+
block = second_file.createIfcCsgSolid(second_file.createIfcBlock(o2, 2000, 2000, 2000))
133+
rep = builder2.get_representation(context=body2, items=[block])
134+
ifcopenshell.api.geometry.assign_representation(second_file, product=wall1, representation=rep)
135+
shape = ifcopenshell.geom.create_shape(ifcopenshell.geom.settings(), wall1)
136+
verts = ifcopenshell.util.shape.get_shape_vertices(shape, shape.geometry)
137+
assert np.any(np.all(np.isclose(np.array((1., 2., 3.)), verts), axis=1))
138+
assert np.any(np.all(np.isclose(np.array((3., 4., 5.)), verts), axis=1))
109139

110140
output = ifcpatch.execute({"file": self.file, "recipe": "MergeProject", "arguments": [second_file]})
111141

@@ -117,11 +147,25 @@ def test_shifting_the_source_project_to_match_the_original_project_origin(self):
117147
params = ifcopenshell.util.geolocation.get_helmert_transformation_parameters(output)
118148
assert params.e == 10
119149
assert params.n == 20
150+
assert params.xaa == xaa1
151+
assert params.xao == xao1
152+
120153
wall1, wall2 = output.by_type("IfcWall")
121154
m1 = ifcopenshell.util.placement.get_local_placement(wall1.ObjectPlacement)
122155
m2 = ifcopenshell.util.placement.get_local_placement(wall2.ObjectPlacement)
123156
assert np.allclose(m1[:, 3], (1, 2, 3, 1))
124-
assert np.allclose(m2[:, 3], (21, 22, 3, 1))
157+
# assert np.allclose(m2[:, 3], (8.321, 29.321, 3, 1), atol=1e-3)
158+
assert np.allclose(m2[:, 3], (17.847, 24.707, 3., 1.), atol=1e-3)
159+
160+
shape = ifcopenshell.geom.create_shape(ifcopenshell.geom.settings(), wall1)
161+
verts = ifcopenshell.util.shape.get_shape_vertices(shape, shape.geometry)
162+
assert np.any(np.all(np.isclose(np.array((1., 2., 3.)), verts), axis=1))
163+
assert np.any(np.all(np.isclose(np.array((3., 4., 5.)), verts), axis=1))
164+
165+
shape = ifcopenshell.geom.create_shape(ifcopenshell.geom.settings(), wall2)
166+
verts = ifcopenshell.util.shape.get_shape_vertices(shape, shape.geometry)
167+
assert np.any(np.all(np.isclose(np.array((17.847, 24.707, 3.)), verts, atol=1e-3), axis=1))
168+
assert np.any(np.all(np.isclose(np.array((20.410, 25.902, 5.)), verts, atol=1e-3), axis=1))
125169

126170

127171
class TestMergeProjectIFC2X3(test.bootstrap.IFC2X3, TestMergeProject):

0 commit comments

Comments
 (0)