@@ -1350,85 +1350,47 @@ def _kill_component_on_client(self) -> None:
13501350 # Kill itself
13511351 self ._is_alive = False
13521352
1353- def tessellate (
1354- self , merge_component : bool = False , merge_bodies : bool = False
1355- ) -> Union ["PolyData" , "MultiBlock" ]:
1353+ def tessellate (self , _recursive_call : bool = False ) -> Union ["PolyData" , list ["MultiBlock" ]]:
13561354 """Tessellate the component.
13571355
13581356 Parameters
13591357 ----------
1360- merge_component : bool, default: False
1361- Whether to merge this component into a single dataset. When ``True``,
1362- all the individual bodies are effectively combined into a single
1363- dataset without any hierarchy.
1364- merge_bodies : bool, default: False
1365- Whether to merge each body into a single dataset. When ``True``,
1366- all the faces of each individual body are effectively
1367- merged into a single dataset without separating faces.
1358+ _recursive_call: bool, default: False
1359+ Internal flag to indicate if this method is being called recursively.
1360+ Not to be used by the user.
13681361
13691362 Returns
13701363 -------
1371- ~pyvista.PolyData, ~pyvista.MultiBlock
1372- Merged :class:`pyvista.PolyData` if ``merge_component=True`` or a
1373- composite dataset .
1364+ ~pyvista.PolyData, list[ ~pyvista.MultiBlock]
1365+ Tessellated component as a single PolyData object.
1366+ If the method is called recursively, a list of MultiBlock objects is returned .
13741367
1375- Examples
1376- --------
1377- Create two stacked bodies and return the tessellation as two merged bodies:
1378-
1379- >>> from ansys.geometry.core.sketch import Sketch
1380- >>> from ansys.geometry.core import Modeler
1381- >>> from ansys.geometry.core.math import Point2D, Point3D, Plane
1382- >>> from ansys.geometry.core.misc import UNITS
1383- >>> modeler = Modeler("10.54.0.72", "50051")
1384- >>> sketch_1 = Sketch()
1385- >>> box = sketch_1.box(
1386- >>> Point2D([10, 10], UNITS.m), Quantity(10, UNITS.m), Quantity(5, UNITS.m))
1387- >>> sketch_1.circle(Point2D([0, 0], UNITS.m), Quantity(25, UNITS.m))
1388- >>> design = modeler.create_design("MyDesign")
1389- >>> comp = design.add_component("MyComponent")
1390- >>> distance = Quantity(10, UNITS.m)
1391- >>> body = comp.extrude_sketch("Body", sketch=sketch_1, distance=distance)
1392- >>> sketch_2 = Sketch(Plane([0, 0, 10]))
1393- >>> box = sketch_2.box(
1394- >>> Point2D([10, 10], UNITS.m), Quantity(10, UNITS.m), Quantity(5, UNITS.m))
1395- >>> circle = sketch_2.circle(Point2D([0, 0], UNITS.m), Quantity(25, UNITS.m))
1396- >>> body = comp.extrude_sketch("Body", sketch=sketch_2, distance=distance)
1397- >>> dataset = comp.tessellate(merge_bodies=True)
1398- >>> dataset
1399- MultiBlock (0x7ff6bcb511e0)
1400- N Blocks: 2
1401- X Bounds: -25.000, 25.000
1402- Y Bounds: -24.991, 24.991
1403- Z Bounds: 0.000, 20.000
14041368 """
14051369 import pyvista as pv
14061370
14071371 # Tessellate the bodies in this component
1408- datasets = [body .tessellate (merge_bodies ) for body in self .bodies ]
1409-
1410- blocks_list = [pv .MultiBlock (datasets )]
1372+ datasets : list ["MultiBlock" ] = [body .tessellate (merge = False ) for body in self .bodies ]
14111373
14121374 # Now, go recursively inside its subcomponents (with no arguments) and
14131375 # merge the PolyData obtained into our blocks
14141376 for comp in self ._components :
14151377 if not comp .is_alive :
14161378 continue
1417- blocks_list .append (comp .tessellate (merge_bodies = merge_bodies ))
1418-
1419- # Transform the list of MultiBlock objects into a single MultiBlock
1420- blocks = pv .MultiBlock (blocks_list )
1379+ datasets .extend (comp .tessellate (_recursive_call = True ))
14211380
1422- if merge_component :
1423- ugrid = blocks .combine ()
1424- # Convert to polydata as it's slightly faster than extract surface
1425- return pv .PolyData (ugrid .points , ugrid .cells , n_faces = ugrid .n_cells )
1426- return blocks
1381+ # Convert to polydata as it's slightly faster than extract surface
1382+ # plus this method is only for visualizing the component as a whole (no
1383+ # need to keep the hierarchy)
1384+ if _recursive_call :
1385+ return datasets
1386+ else :
1387+ ugrid = pv .MultiBlock (datasets ).combine ()
1388+ return pv .PolyData (var_inp = ugrid .points , faces = ugrid .cells )
14271389
14281390 def plot (
14291391 self ,
1430- merge_component : bool = False ,
1431- merge_bodies : bool = False ,
1392+ merge_component : bool = True ,
1393+ merge_bodies : bool = True ,
14321394 screenshot : str | None = None ,
14331395 use_trame : bool | None = None ,
14341396 use_service_colors : bool | None = None ,
@@ -1438,14 +1400,15 @@ def plot(
14381400
14391401 Parameters
14401402 ----------
1441- merge_component : bool, default: False
1442- Whether to merge the component into a single dataset. When ``True``,
1443- all the individual bodies are effectively merged into a single
1444- dataset without any hierarchy.
1445- merge_bodies : bool, default: False
1446- Whether to merge each body into a single dataset. When ``True``,
1447- all the faces of each individual body are effectively merged
1448- into a single dataset without separating faces.
1403+ merge_component : bool, default: True
1404+ Whether to merge the component into a single dataset. By default, ``True``.
1405+ Performance improved. When ``True``, all the faces of the component are effectively
1406+ merged into a single dataset. If ``False``, the individual bodies are kept separate.
1407+ merge_bodies : bool, default: True
1408+ Whether to merge each body into a single dataset. By default, ``True``.
1409+ Performance improved. When ``True``, all the faces of each individual body are
1410+ effectively merged into a single dataset. If ``False``, the individual faces are kept
1411+ separate.
14491412 screenshot : str, default: None
14501413 Path for saving a screenshot of the image being represented.
14511414 use_trame : bool, default: None
@@ -1496,24 +1459,28 @@ def plot(
14961459 """
14971460 import ansys .geometry .core as pyansys_geometry
14981461 from ansys .geometry .core .plotting import GeometryPlotter
1499- from ansys .tools .visualization_interface .types .mesh_object_plot import MeshObjectPlot
15001462
15011463 use_service_colors = (
15021464 use_service_colors
15031465 if use_service_colors is not None
15041466 else pyansys_geometry .USE_SERVICE_COLORS
15051467 )
15061468
1507- mesh_object = (
1508- self
1509- if use_service_colors
1510- else MeshObjectPlot (
1511- custom_object = self ,
1512- mesh = self .tessellate (merge_component = merge_component , merge_bodies = merge_bodies ),
1469+ # Add merge_component and merge_bodies to the plotting options
1470+ plotting_options ["merge_component" ] = merge_component
1471+ plotting_options ["merge_bodies" ] = merge_bodies
1472+
1473+ # At component level, if ``multi_colors`` or ``use_service_colors`` are defined
1474+ # we should not merge the component.
1475+ if plotting_options .get ("multi_colors" , False ) or use_service_colors :
1476+ plotting_options ["merge_component" ] = False
1477+ self ._grpc_client .log .info (
1478+ "Ignoring 'merge_component=True' (default behavior) as "
1479+ "'multi_colors' or 'use_service_colors' are defined."
15131480 )
1514- )
1481+
15151482 pl = GeometryPlotter (use_trame = use_trame , use_service_colors = use_service_colors )
1516- pl .plot (mesh_object , ** plotting_options )
1483+ pl .plot (self , ** plotting_options )
15171484 pl .show (screenshot = screenshot , ** plotting_options )
15181485
15191486 def __repr__ (self ) -> str :
0 commit comments