Skip to content

Commit

Permalink
Make composite mapper dataset optional (#4879)
Browse files Browse the repository at this point in the history
* make composite mapper dataset optional

* add test

* Explicit is better than implicit. (The Zen of Python)

---------

Co-authored-by: Tetsuo Koyama <tkoyama010@gmail.com>
  • Loading branch information
akaszynski and tkoyama010 committed Sep 15, 2023
1 parent b351345 commit cd8e8f9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
14 changes: 9 additions & 5 deletions pyvista/plotting/composite_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ class CompositePolyDataMapper(_vtk.vtkCompositePolyDataMapper2, _BaseMapper):
Parameters
----------
dataset : pyvista.MultiBlock
dataset : pyvista.MultiBlock, optional
Multiblock dataset.
theme : pyvista.plotting.themes.Theme, optional
Expand All @@ -541,16 +541,14 @@ class CompositePolyDataMapper(_vtk.vtkCompositePolyDataMapper2, _BaseMapper):
"""

def __init__(
self, dataset, theme=None, color_missing_with_nan=None, interpolate_before_map=None
self, dataset=None, theme=None, color_missing_with_nan=None, interpolate_before_map=None
):
"""Initialize this composite mapper."""
super().__init__(theme=theme)
self.SetInputDataObject(dataset)

# this must be added to set the color, opacity, and visibility of
# individual blocks
self._attr = CompositeAttributes(self, dataset)
self._dataset = dataset
self.dataset = dataset

if color_missing_with_nan is not None:
self.color_missing_with_nan = color_missing_with_nan
Expand Down Expand Up @@ -579,6 +577,12 @@ def dataset(self) -> 'pv.MultiBlock': # numpydoc ignore=RT01
"""
return self._dataset

@dataset.setter
def dataset(self, obj: 'pv.MultiBlock'): # numpydoc ignore=GL08
self.SetInputDataObject(obj)
self._dataset = obj
self._attr._dataset = obj

@property
def block_attr(self) -> CompositeAttributes: # numpydoc ignore=RT01
"""Return the block attributes.
Expand Down
13 changes: 13 additions & 0 deletions tests/plotting/test_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ def actor():
return pv.Plotter().add_mesh(pv.Plane())


@pytest.fixture()
def actor_from_multi_block():
return pv.Plotter().add_mesh(pv.MultiBlock([pv.Plane()]))


@pytest.fixture()
def vol_actor():
vol = pv.ImageData(dimensions=(10, 10, 10))
Expand Down Expand Up @@ -68,6 +73,14 @@ def test_actor_copy_shallow(actor):
assert actor_copy.mapper is actor.mapper


def test_actor_mblock_copy_shallow(actor_from_multi_block):
actor_copy = actor_from_multi_block.copy(deep=False)
assert actor_copy is not actor_from_multi_block
assert actor_copy.prop is actor_from_multi_block.prop
assert actor_copy.mapper is actor_from_multi_block.mapper
assert actor_copy.mapper.dataset is actor_from_multi_block.mapper.dataset


@skip_mac
def test_actor_texture(actor):
texture = examples.download_masonry_texture()
Expand Down

0 comments on commit cd8e8f9

Please sign in to comment.