Kitware / vtk-js

Visualization Toolkit for the Web
https://kitware.github.io/vtk-js/
BSD 3-Clause "New" or "Revised" License
1.24k stars 373 forks source link

Auto-detection of scalar range in Mapper #2270

Open eino opened 2 years ago

eino commented 2 years ago

Hi,

Need

I use vtk.js to map multiple values on a polydata, while allowing the user to switch visualized value. For now setScalarRange needs to be called manually, and so I need to keep track of the range of every visualizable data (including each component of vector arrays). I was thinking it would be really convenient if the Mapper could auto-detect the data range according to the current data.

Feature

The auto-detection by the mapper according to the current scalars array could be done in mapScalars(), after the scalars have been computed. Basically, it could be a simple , model.scalarRange = scalars.getRange(model.fieldDataTupleId);. To let the user override this range, the code could leave model.scalarRange untouched and only use detected range if the user didn't provide a scalarRange. I started on this in this commit. What do you think?

The drawback of leaving model.scalarRange untouched is that the calling code can't call mapper.getScalarRange() to get the detected range.

jourdain commented 2 years ago

@martinken what do you think?

I definitely see the motivation but that can easily be handled at the application layer. So I'm not sure if it is a logic we want to add to the mapper or not. My concern is mainly to keep VTK/C++ behavior as close as vtk.js. But maybe that is something we want for both. I'm not sure.