question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Point data of a shallow-copied mesh is no longer a view after adding the mesh to a plotter

See original GitHub issue

Describe 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:closed
  • Created a year ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
whophilcommented, Apr 14, 2022

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 for deep_copy, and it is currently set to True. 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.

0reactions
akaszynskicommented, Jun 28, 2022

Should this be added as a test if it wasn’t already captured in #2754 ?

It’s a cheap edge case to test. Testing in #2888.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found