Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating scalar field on Mapper does not work preoperly #635

Open
zspasztori opened this issue Sep 26, 2024 · 1 comment
Open

Updating scalar field on Mapper does not work preoperly #635

zspasztori opened this issue Sep 26, 2024 · 1 comment

Comments

@zspasztori
Copy link

zspasztori commented Sep 26, 2024

I am working with point cloud data, which has multiple scalars associated.
I am changing the active scalar based on user input.
However, for some reason the color scale does not change.
eg. if first scalar was bool, and next scalar will be float, the maximum color value will still be at 1 after the change

import numpy as np
import pyvista as pv
from pyvistaqt import BackgroundPlotter

coordinates = np.random.randint(0, 100, size=(100, 3))
bool_scalar = np.random.randint(0, 100, size=(100)) > 50 
int_scalar  = np.random.randint(0, 100, size=(100))

mesh = pv.PolyData(coordinates)
mesh['bool_scalar'] = bool_scalar
mesh['int_scalar'] = int_scalar

plotter = BackgroundPlotter()
actor = plotter.add_mesh(mesh, scalars='bool_scalar')

scalars = ['bool_scalar', 'int_scalar']
idx = 0
def my_key_callback():
    global idx
    print("You pressed the 's' key!", scalars, scalars[idx])
    idx = 1 - idx
    actor.mapper.array_name = scalars[idx]
    actor.mapper.scalar_range = mesh.get_data_range(scalars[idx])

plotter.add_key_event('s', my_key_callback)

Screenshot from 2024-09-26 13-18-07
Screenshot from 2024-09-26 13-18-24

@zspasztori
Copy link
Author

it seems that the function get_data_range hasa bug
the bool array is not working because of this condition, should I make a PR with fix?
pyvista/core/dataset.py:893-894

  if arr.size == 0 or not np.issubdtype(arr.dtype, np.number):
      return (np.nan, np.nan)

also the scalar color mapping seems to work with :

mesh.set_active_scalars("my_scalar")
actor.mapper.scalar_range = mesh.get_data_range("my_scalar")

most likely the renderer is missing the automatic update of scalar range when after/during the set_active_scalars call

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant