Skip to content

Commit 371d89a

Browse files
fix: tessellation options were not extended to component/face methods (#1850)
Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent d3fcc9d commit 371d89a

File tree

6 files changed

+54
-13
lines changed

6 files changed

+54
-13
lines changed

doc/changelog.d/1850.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tessellation options were not extended to component/face methods

src/ansys/geometry/core/designer/body.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ def copy(self, parent: "Component", name: str = None) -> "Body":
568568

569569
@abstractmethod
570570
def tessellate(
571-
self, merge: bool = False, tessellation_options: TessellationOptions = None
571+
self, merge: bool = False, tess_options: TessellationOptions | None = None
572572
) -> Union["PolyData", "MultiBlock"]:
573573
"""Tessellate the body and return the geometry as triangles.
574574
@@ -578,7 +578,7 @@ def tessellate(
578578
Whether to merge the body into a single mesh. When ``False`` (default), the
579579
number of triangles are preserved and only the topology is merged.
580580
When ``True``, the individual faces of the tessellation are merged.
581-
tessellation_options : TessellationOptions, default: None
581+
tess_options : TessellationOptions | None, default: None
582582
A set of options to determine the tessellation quality.
583583
584584
Returns
@@ -1276,14 +1276,22 @@ def tessellate( # noqa: D102
12761276
self,
12771277
merge: bool = False,
12781278
transform: Matrix44 = IDENTITY_MATRIX44,
1279-
tess_options: TessellationOptions = None,
1279+
tess_options: TessellationOptions | None = None,
12801280
) -> Union["PolyData", "MultiBlock"]:
12811281
# lazy import here to improve initial module load time
12821282
import pyvista as pv
12831283

12841284
if not self.is_alive:
12851285
return pv.PolyData() if merge else pv.MultiBlock()
12861286

1287+
# If the server does not support tessellation options, ignore them
1288+
if tess_options is not None and self._grpc_client.backend_version < (25, 2, 0):
1289+
self._grpc_client.log.warning(
1290+
"Tessellation options are not supported by server"
1291+
f" version {self._grpc_client.backend_version}. Ignoring options."
1292+
)
1293+
tess_options = None
1294+
12871295
self._grpc_client.log.debug(f"Requesting tessellation for body {self.id}.")
12881296

12891297
# cache tessellation
@@ -1319,7 +1327,11 @@ def tessellate( # noqa: D102
13191327
str(face_id): tess_to_pd(face_tess)
13201328
for face_id, face_tess in resp.face_tessellation.items()
13211329
}
1322-
except Exception:
1330+
except Exception as err:
1331+
# Streaming is not supported in older versions...
1332+
if self._grpc_client.backend_version < (25, 2, 0):
1333+
raise err
1334+
13231335
tessellation_map = {}
13241336
request = GetTessellationRequest(self._grpc_id)
13251337
for response in self._bodies_stub.GetTessellationStream(request):
@@ -1854,7 +1866,7 @@ def copy(self, parent: "Component", name: str = None) -> "Body": # noqa: D102
18541866

18551867
@ensure_design_is_active
18561868
def tessellate( # noqa: D102
1857-
self, merge: bool = False, tess_options: TessellationOptions = None
1869+
self, merge: bool = False, tess_options: TessellationOptions | None = None
18581870
) -> Union["PolyData", "MultiBlock"]:
18591871
return self._template.tessellate(
18601872
merge, self.parent_component.get_world_transform(), tess_options

src/ansys/geometry/core/designer/component.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
min_backend_version,
9595
)
9696
from ansys.geometry.core.misc.measurements import DEFAULT_UNITS, Angle, Distance
97+
from ansys.geometry.core.misc.options import TessellationOptions
9798
from ansys.geometry.core.shapes.curves.circle import Circle
9899
from ansys.geometry.core.shapes.curves.trimmed_curve import TrimmedCurve
99100
from ansys.geometry.core.shapes.parameterization import Interval, ParamUV
@@ -1608,11 +1609,15 @@ def _kill_component_on_client(self) -> None:
16081609
self._is_alive = False
16091610

16101611
@graphics_required
1611-
def tessellate(self, _recursive_call: bool = False) -> Union["PolyData", list["MultiBlock"]]:
1612+
def tessellate(
1613+
self, tess_options: TessellationOptions | None = None, _recursive_call: bool = False
1614+
) -> Union["PolyData", list["MultiBlock"]]:
16121615
"""Tessellate the component.
16131616
16141617
Parameters
16151618
----------
1619+
tess_options : TessellationOptions | None, default: None
1620+
A set of options to determine the tessellation quality.
16161621
_recursive_call: bool, default: False
16171622
Internal flag to indicate if this method is being called recursively.
16181623
Not to be used by the user.
@@ -1627,14 +1632,16 @@ def tessellate(self, _recursive_call: bool = False) -> Union["PolyData", list["M
16271632
import pyvista as pv
16281633

16291634
# Tessellate the bodies in this component
1630-
datasets: list["MultiBlock"] = [body.tessellate(merge=False) for body in self.bodies]
1635+
datasets: list["MultiBlock"] = [
1636+
body.tessellate(merge=False, tess_options=tess_options) for body in self.bodies
1637+
]
16311638

16321639
# Now, go recursively inside its subcomponents (with no arguments) and
16331640
# merge the PolyData obtained into our blocks
16341641
for comp in self._components:
16351642
if not comp.is_alive:
16361643
continue
1637-
datasets.extend(comp.tessellate(_recursive_call=True))
1644+
datasets.extend(comp.tessellate(tess_options=tess_options, _recursive_call=True))
16381645

16391646
# Convert to polydata as it's slightly faster than extract surface
16401647
# plus this method is only for visualizing the component as a whole (no

src/ansys/geometry/core/designer/face.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
min_backend_version,
6464
)
6565
from ansys.geometry.core.misc.measurements import DEFAULT_UNITS
66+
from ansys.geometry.core.misc.options import TessellationOptions
6667
from ansys.geometry.core.shapes.box_uv import BoxUV
6768
from ansys.geometry.core.shapes.curves.trimmed_curve import TrimmedCurve
6869
from ansys.geometry.core.shapes.parameterization import Interval
@@ -598,17 +599,27 @@ def setup_offset_relationship(
598599
return result.success
599600

600601
@graphics_required
601-
def tessellate(self) -> "pv.PolyData":
602+
def tessellate(self, tess_options: TessellationOptions | None = None) -> "pv.PolyData":
602603
"""Tessellate the face and return the geometry as triangles.
603604
605+
Parameters
606+
----------
607+
tess_options : TessellationOptions | None, default: None
608+
A set of options to determine the tessellation quality.
609+
610+
Notes
611+
-----
612+
The tessellation options are ONLY used if the face has not been tessellated before.
613+
If the face has been tessellated before, the stored tessellation is returned.
614+
604615
Returns
605616
-------
606617
~pyvista.PolyData
607618
:class:`pyvista.PolyData` object holding the face.
608619
"""
609620
# If tessellation has not been called before... call it
610621
if self._body._template._tessellation is None:
611-
self._body.tessellate()
622+
self._body.tessellate(tess_options=tess_options)
612623

613624
# Search the tessellation of the face - if it exists
614625
# ---> We need to used the last element of the ID since we are looking inside

src/ansys/geometry/core/misc/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@
4949
run_if_graphics_required,
5050
)
5151
from ansys.geometry.core.misc.measurements import DEFAULT_UNITS, Angle, Distance
52-
from ansys.geometry.core.misc.options import ImportOptions
52+
from ansys.geometry.core.misc.options import ImportOptions, TessellationOptions
5353
from ansys.geometry.core.misc.units import UNITS, PhysicalQuantity

src/ansys/geometry/core/modeler.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,12 +438,22 @@ def open_file(
438438
if full_path != fp_path:
439439
if full_path.stat().st_size < pygeom_defaults.MAX_MESSAGE_LENGTH:
440440
self._upload_file(full_path)
441-
else:
441+
elif self.client.backend_version >= (25, 2, 0):
442442
self._upload_file_stream(full_path)
443+
else: # pragma: no cover
444+
raise RuntimeError(
445+
"File is too large to upload."
446+
" Service versions above 25R2 support streaming."
447+
)
448+
443449
if file_size_kb < pygeom_defaults.MAX_MESSAGE_LENGTH:
444450
self._upload_file(file_path, True, import_options)
445-
else:
451+
elif self.client.backend_version >= (25, 2, 0):
446452
self._upload_file_stream(file_path, True, import_options)
453+
else: # pragma: no cover
454+
raise RuntimeError(
455+
"File is too large to upload. Service versions above 25R2 support streaming."
456+
)
447457
else:
448458
DesignsStub(self.client.channel).Open(
449459
OpenRequest(filepath=file_path, import_options=import_options.to_dict())

0 commit comments

Comments
 (0)