Point data of a shallow-copied mesh is no longer a view after adding the mesh to a plotter
See original GitHub issueDescribe the bug, what’s wrong, and what you expect:
If I make a shallow copy of a mesh, I would expect that the point data of the copied mesh is a view into that of the original mesh (rather than a copy). As such, by modifying the point data of one mesh, the point data of the second mesh should also be modified. This is indeed the case currently. However, if one of the meshes is then added to a plotter, this behaviour breaks.
Note, this was not an issue in version 0.33.2 (point data were still modified after adding the mesh to a plotter), but I think versions >=0.33.3 all have this behaviour.
To Reproduce
import pyvista as pv
sphere = pv.Sphere()
sphere.point_data['numbers'] = np.arange(sphere.n_points)
sphere2 = sphere.copy(deep=False)
sphere['numbers'] *= -1 # sphere2 'numbers' are also modified
plotter = pv.Plotter()
plotter.add_mesh(sphere, scalars=None)
sphere['numbers'] *= -1 # sphere2 'numbers' are NOT modified
System Information:
--------------------------------------------------------------------------------
Date: Wed Apr 13 09:42:15 2022 BST
OS : Linux
CPU(s) : 16
Machine : x86_64
Architecture : 64bit
Environment : Jupyter
GPU Vendor : NVIDIA Corporation
GPU Renderer : NVS 310/PCIe/SSE2
GPU Version : 4.5.0 NVIDIA 390.144
Python 3.8.12 | packaged by conda-forge | (default, Oct 12 2021, 21:57:06)
[GCC 9.4.0]
pyvista : 0.34.0
vtk : 9.0.3
numpy : 1.21.4
imageio : 2.10.3
appdirs : 1.4.4
scooby : 0.5.7
matplotlib : 3.5.1
pyvistaqt : 0.7.0
IPython : 7.29.0
scipy : 1.7.2
tqdm : 4.62.3
meshio : 4.4.6
--------------------------------------------------------------------------------
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Volumes and large point cloud interpolation #2752 - GitHub
I'm currently trying to create a 3D GPR data volume using Uniform grids. ... The problem of this process is that the resulting...
Read more >Mesh fixes settings - MakerBot Support
When polygons are missing in the shell of the model, Ultimaker Cura won't be able to slice the model correctly. In this instance,...
Read more >vedo.pointcloud API documentation
Build a Mesh made of only vertex points for a list of 2D/3D points. Both shapes (N, 3) or (3, N) are accepted...
Read more >Drawing objects do not plot and are missing from print preview ...
Issue: When plotting from AutoCAD, one or more drawing elements or lines do not show up in the output (PDF, hard copy) and...
Read more >Mesh Tools - Ultimaker Cura Marketplace
Adds several mesh analysis and manipulation tools. The development of this plugin can be sponsored via Github Sponsors (https://github.com/ ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The root cause seems to be that
MapperHelper.configure_scalars_mode
creates a deep copy of the scalar point/cell data and reassigns it to the mesh.https://github.com/pyvista/pyvista/blob/b50614a0034d6d4890fac22f162b0f739754e8d5/pyvista/plotting/mapper.py#L254-L263
Note that the third positional argument for
point_data.set_array()
is the flag fordeep_copy
, and it is currently set toTrue
. I’m not sure why this is needed - perhaps @akaszynski knows?Other note: The method
np.shares_memory()
can tell you whether one array is a view of another, and is extremely useful for debugging and testing this type of thing.It’s a cheap edge case to test. Testing in #2888.