Skip to content

Commit bcde6f0

Browse files
committed
linear deflection
1 parent 3689172 commit bcde6f0

File tree

3 files changed

+11
-18
lines changed

3 files changed

+11
-18
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
* Added `linear_deflection` parameter to `Model.show()`, defaulting to 100 for faster BRep tesselation.
13+
1214
### Changed
1315

1416
### Removed
1517

18+
* Removed `Model.update_linear_deflection()`
1619

1720
## [1.6.0] 2025-06-04
1821

src/compas_ifc/brep/ifcbrepobject.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
try:
22
import numpy as np
33
from compas.colors import Color
4-
from compas.tolerance import TOL
54
from compas_occ.brep import OCCBrep
65
from compas_viewer.scene.brepobject import BRepObject
76

87
class IFCBrepObject(BRepObject):
9-
def __init__(self, shellcolors=None, **kwargs):
8+
def __init__(self, shellcolors=None, linear_deflection=100, **kwargs):
109
brep = kwargs["item"]
1110
brep.simplify()
1211
brep.heal()
1312

1413
super().__init__(**kwargs)
15-
self.shells = [shell.to_tesselation(TOL.lineardeflection)[0] for shell in self.brep.shells]
14+
self.shells = [shell.to_tesselation(linear_deflection)[0] for shell in self.brep.shells]
1615
self.shellcolors = shellcolors or [self.facecolor.rgba for _ in self.shells]
1716
self._bounding_box_center = None
1817

src/compas_ifc/model.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from compas.geometry import Frame
1010
from compas.geometry import Geometry
1111
from compas.geometry import Transformation
12-
from compas.tolerance import TOL
1312

1413
from compas_ifc.file import IFCFile
1514

@@ -74,8 +73,6 @@ def __init__(self, filepath: str = None, schema: str = "IFC4", use_occ: bool = F
7473
7574
"""
7675
self.file = IFCFile(self, filepath=filepath, schema=schema, use_occ=use_occ, load_geometries=load_geometries, verbose=verbose, extensions=extensions)
77-
if filepath:
78-
self.update_linear_deflection()
7976

8077
@property
8178
def schema(self) -> "ifcopenshell.ifcopenshell_wrapper.schema_definition":
@@ -257,13 +254,16 @@ def export(self, path: str, entities: list["Base"] = [], as_snippet: bool = Fals
257254
"""
258255
self.file.export(path, entities=entities, as_snippet=as_snippet, export_materials=export_materials, export_properties=export_properties, export_styles=export_styles)
259256

260-
def show(self, entity: "Base" = None):
257+
def show(self, entity: "Base" = None, linear_deflection: float = 100):
261258
"""Show the IFC file in a viewer, either the entire project or a single entity.
262259
263260
Parameters
264261
----------
265262
entity : :class:`compas_ifc.entities.base.Base`
266263
The entity to show. If None, the entire project will be shown.
264+
linear_deflection : float
265+
The linear deflection to use for the tesselation of BREP geometries.
266+
Should be adjusted based on the size of the model.
267267
"""
268268
try:
269269
from compas_viewer import Viewer
@@ -274,6 +274,7 @@ def show(self, entity: "Base" = None):
274274

275275
viewer = Viewer()
276276
print(f"Unit: {self.unit}")
277+
print(f"Using Linear Deflection: {linear_deflection}")
277278
viewer.unit = self.unit
278279
viewer.ui.sidebar.show_objectsetting = False
279280

@@ -284,7 +285,7 @@ def parse_entity(entity, parent=None):
284285
name = f"[{entity.__class__.__name__}]{entity.Name}"
285286
transformation = Transformation.from_frame(entity.frame) if entity.frame else None
286287
if getattr(entity, "geometry", None) and not entity.is_a("IfcSpace"):
287-
obj = viewer.scene.add(entity.geometry, name=name, parent=parent, hide_coplanaredges=True, **entity.style)
288+
obj = viewer.scene.add(entity.geometry, name=name, parent=parent, hide_coplanaredges=True, **entity.style, linear_deflection=linear_deflection)
288289
obj.transformation = transformation
289290
else:
290291
obj = viewer.scene.add_group(name=name, parent=parent)
@@ -358,16 +359,6 @@ def remove(self, entity: Union["Base", list["Base"]]):
358359
"""
359360
self.file.remove(entity)
360361

361-
def update_linear_deflection(self):
362-
"""Update the linear deflection tolerance settings in COMPAS based on the unit of the model."""
363-
# TODO: deal with conversion based units like "FOOT"
364-
if self.unit == "mm":
365-
TOL.lineardeflection = 1
366-
elif self.unit == "cm":
367-
TOL.lineardeflection = 1e-1
368-
elif self.unit == "m":
369-
TOL.lineardeflection = 1e-3
370-
371362
@classmethod
372363
def template(cls, schema: str = "IFC4", building_count: int = 1, storey_count: int = 1, unit: str = "mm", use_occ: bool = False) -> "Model":
373364
"""Create a template model with a default project, site, building, and storey.

0 commit comments

Comments
 (0)