@@ -566,7 +566,7 @@ def copy(self, parent: "Component", name: str = None) -> "Body":
566
566
return
567
567
568
568
@abstractmethod
569
- def tessellate (self , merge : bool = False ) -> Union ["PolyData" , "MultiBlock" ]:
569
+ def tessellate (self , merge : bool = False , tessellationOptions : TessellationOptions = None ) -> Union ["PolyData" , "MultiBlock" ]:
570
570
"""Tessellate the body and return the geometry as triangles.
571
571
572
572
Parameters
@@ -575,6 +575,8 @@ def tessellate(self, merge: bool = False) -> Union["PolyData", "MultiBlock"]:
575
575
Whether to merge the body into a single mesh. When ``False`` (default), the
576
576
number of triangles are preserved and only the topology is merged.
577
577
When ``True``, the individual faces of the tessellation are merged.
578
+ tessellationOptions : TessellationOptions, default: None
579
+ A set of options to determine the tessellation quality.
578
580
579
581
Returns
580
582
-------
@@ -620,42 +622,6 @@ def tessellate(self, merge: bool = False) -> Union["PolyData", "MultiBlock"]:
620
622
"""
621
623
return
622
624
623
- @abstractmethod
624
- def tessellate_with_options (
625
- self ,
626
- surf_deviation : Real ,
627
- ang_deviation : Real ,
628
- aspect_ratio : Real = 0.0 ,
629
- edge_length : Real = 0.0 ,
630
- watertight : bool = False ,
631
- merge : bool = False ,
632
- ) -> Union ["PolyData" , "MultiBlock" ]:
633
- """Tessellate the body and return the geometry as triangles.
634
-
635
- Parameters
636
- ----------
637
- surf_deviation : Real
638
- The maximum deviation from the true surface position.
639
- ang_deviation : Real
640
- The maximum deviation from the true surface normal.
641
- aspect_ratio : Real, default: 0.0
642
- The maximum aspect ratio of facets.
643
- edge_length : Real, default: 0.0
644
- The maximum facet edge length.
645
- watertight : bool, default: False
646
- Whether triangles on opposite sides of an edge match.
647
- merge : bool, default: False
648
- Whether to merge the body into a single mesh. When ``False`` (default), the
649
- number of triangles are preserved and only the topology is merged.
650
- When ``True``, the individual faces of the tessellation are merged.
651
-
652
- Returns
653
- -------
654
- ~pyvista.PolyData, ~pyvista.MultiBlock
655
- Merged :class:`pyvista.PolyData` if ``merge=True`` or a composite dataset.
656
- """
657
- return
658
-
659
625
@abstractmethod
660
626
def shell_body (self , offset : Real ) -> bool :
661
627
"""Shell the body to the thickness specified.
@@ -1304,7 +1270,7 @@ def copy(self, parent: "Component", name: str = None) -> "Body": # noqa: D102
1304
1270
@protect_grpc
1305
1271
@graphics_required
1306
1272
def tessellate ( # noqa: D102
1307
- self , merge : bool = False , transform : Matrix44 = IDENTITY_MATRIX44
1273
+ self , merge : bool = False , tessellationOptions : TessellationOptions = None , transform : Matrix44 = IDENTITY_MATRIX44
1308
1274
) -> Union ["PolyData" , "MultiBlock" ]:
1309
1275
# lazy import here to improve initial module load time
1310
1276
import pyvista as pv
@@ -1316,69 +1282,45 @@ def tessellate( # noqa: D102
1316
1282
1317
1283
# cache tessellation
1318
1284
if not self ._tessellation :
1319
- resp = self ._bodies_stub .GetTessellation (self ._grpc_id )
1320
- self ._tessellation = {
1321
- str (face_id ): tess_to_pd (face_tess )
1322
- for face_id , face_tess in resp .face_tessellation .items ()
1323
- }
1324
-
1325
- pdata = [tess .transform (transform , inplace = False ) for tess in self ._tessellation .values ()]
1326
- comp = pv .MultiBlock (pdata )
1327
-
1328
- if merge :
1329
- ugrid = comp .combine ()
1330
- return pv .PolyData (var_inp = ugrid .points , faces = ugrid .cells )
1331
- else :
1332
- return comp
1333
-
1334
- @protect_grpc
1335
- @graphics_required
1336
- @check_input_types
1337
- @min_backend_version (25 , 2 , 0 )
1338
- def tessellate_with_options ( # noqa: D102
1339
- self ,
1340
- surf_deviation : Real ,
1341
- ang_deviation : Real ,
1342
- aspect_ratio : Real = 0.0 ,
1343
- edge_length : Real = 0.0 ,
1344
- watertight : bool = False ,
1345
- merge : bool = False ,
1346
- transform : Matrix44 = IDENTITY_MATRIX44 ,
1347
- ) -> Union ["PolyData" , "MultiBlock" ]:
1348
- # lazy import here to improve initial module load time
1349
- import pyvista as pv
1350
-
1351
- if not self .is_alive :
1352
- return pv .PolyData () if merge else pv .MultiBlock ()
1353
-
1354
- self ._grpc_client .log .debug (f"Requesting tessellation for body { self .id } ." )
1355
-
1356
- request = GetTessellationRequest (
1357
- id = self ._grpc_id ,
1358
- options = TessellationOptions (
1359
- surface_deviation = surf_deviation ,
1360
- angle_deviation = ang_deviation ,
1361
- maximum_aspect_ratio = aspect_ratio ,
1362
- maximum_edge_length = edge_length ,
1363
- watertight = watertight ,
1364
- ),
1365
- )
1366
-
1367
- # cache tessellation
1368
- if not self ._tessellation :
1369
- try :
1370
- resp = self ._bodies_stub .GetTessellationWithOptions (request )
1371
- self ._tessellation = {
1372
- str (face_id ): tess_to_pd (face_tess )
1373
- for face_id , face_tess in resp .face_tessellation .items ()
1374
- }
1375
- except Exception :
1376
- tessellation_map = {}
1377
- for response in self ._bodies_stub .GetTessellationStream (request ):
1378
- for key , value in response .face_tessellation .items ():
1379
- tessellation_map [key ] = tess_to_pd (value )
1285
+ if tessellationOptions is not None :
1286
+ request = GetTessellationRequest (
1287
+ id = self ._grpc_id ,
1288
+ options = TessellationOptions (
1289
+ surface_deviation = tessellationOptions .surface_deviation ,
1290
+ angle_deviation = tessellationOptions .angle_deviation ,
1291
+ maximum_aspect_ratio = tessellationOptions .maximum_aspect_ratio ,
1292
+ maximum_edge_length = tessellationOptions .maximum_edge_length ,
1293
+ watertight = tessellationOptions .watertight ,
1294
+ ),
1295
+ )
1296
+ try :
1297
+ resp = self ._bodies_stub .GetTessellationWithOptions (request )
1298
+ self ._tessellation = {
1299
+ str (face_id ): tess_to_pd (face_tess )
1300
+ for face_id , face_tess in resp .face_tessellation .items ()
1301
+ }
1302
+ except Exception :
1303
+ tessellation_map = {}
1304
+ for response in self ._bodies_stub .GetTessellationStream (request ):
1305
+ for key , value in response .face_tessellation .items ():
1306
+ tessellation_map [key ] = tess_to_pd (value )
1380
1307
1381
1308
self ._tessellation = tessellation_map
1309
+ else :
1310
+ try :
1311
+ resp = self ._bodies_stub .GetTessellation (self ._grpc_id )
1312
+ self ._tessellation = {
1313
+ str (face_id ): tess_to_pd (face_tess )
1314
+ for face_id , face_tess in resp .face_tessellation .items ()
1315
+ }
1316
+ except Exception :
1317
+ tessellation_map = {}
1318
+ request = GetTessellationRequest (self ._grpc_id )
1319
+ for response in self ._bodies_stub .GetTessellationStream (request ):
1320
+ for key , value in response .face_tessellation .items ():
1321
+ tessellation_map [key ] = tess_to_pd (value )
1322
+
1323
+ self ._tessellation = tessellation_map
1382
1324
1383
1325
pdata = [tess .transform (transform , inplace = False ) for tess in self ._tessellation .values ()]
1384
1326
comp = pv .MultiBlock (pdata )
@@ -1906,29 +1848,9 @@ def copy(self, parent: "Component", name: str = None) -> "Body": # noqa: D102
1906
1848
1907
1849
@ensure_design_is_active
1908
1850
def tessellate ( # noqa: D102
1909
- self , merge : bool = False
1910
- ) -> Union ["PolyData" , "MultiBlock" ]:
1911
- return self ._template .tessellate (merge , self .parent_component .get_world_transform ())
1912
-
1913
- @ensure_design_is_active
1914
- def tessellate_with_options ( # noqa: D102
1915
- self ,
1916
- surf_deviation : Real ,
1917
- ang_deviation : Real ,
1918
- aspect_ratio : Real = 0.0 ,
1919
- edge_length : Real = 0.0 ,
1920
- watertight : bool = False ,
1921
- merge : bool = False ,
1851
+ self , merge : bool = False , tessellationOptions : TessellationOptions = None
1922
1852
) -> Union ["PolyData" , "MultiBlock" ]:
1923
- return self ._template .tessellate_with_options (
1924
- surf_deviation ,
1925
- ang_deviation ,
1926
- aspect_ratio ,
1927
- edge_length ,
1928
- watertight ,
1929
- merge ,
1930
- self .parent_component .get_world_transform (),
1931
- )
1853
+ return self ._template .tessellate (merge , tessellationOptions , self .parent_component .get_world_transform ())
1932
1854
1933
1855
@ensure_design_is_active
1934
1856
def shell_body (self , offset : Real ) -> bool : # noqa: D102
0 commit comments