Specifing vtkDataSet::GetScalarRange()

Current Implementation:

  • .vtk UnstrucredGrid file of 2D mesh that contains multiple point and cell scalar fields
  • Example Fields: material (cell), grid function solution (point)

Goal:

  • Set the scalar range of a mapper’s lookup table only using my solution scalar

Current Attempt:

unGridReader->SetFileName(fileName);
unGridReader->Update();
mapper->SetInputData(unGridReader->GetOutput());
mapper->SetLookupTable(lut);
mapper->SetScalarRange(unGridReader->GetOutput()->GetScalarRange());

Problems:

  • I do not understand how to specify what scalar to use when getting the scalar range, or how to get the information of a specified scalar in general.

Convenience method to get the range of the first component (and only the first component) of any scalars in the data set.
If the data has both point data and cell data, it returns the (min/max) range of combined point and cell data

  • Does the above mean that I cannot specify which scalar to use?

You can try unGridReader->GetOutput()->[ GetPointData() or GetCellData() ]->GetScalars()->GetRange( integer ). See doc here: https://vtk.org/doc/nightly/html/classvtkDataArray.html#a825000e3c1a9d8c1177ec1df549f347f . vtkAbstractArray::GetNumberOfComponents() can return the number of scalars per data/cell. The number you pass to GetRange() should be between 0 and vtkAbstractArray::GetNumberOfComponents()-1.

ComputeFiniteScalarRange in LoadVolume is too Slow…is it able to optimize or not use the ScalarRange?

The first render is slow mostly because of this range computation. Successive calls to compute range use the cached range in the data. You could speed up the first call by caching the range separately. The most straightforward way is to call compute range when loading data before the first render.

1 Like

Thanks!
what if use fixed values for ScalarRange, eg. use short_min and short_max instead of the computed values? decrease the precision while store and sample the transFunc as texture?

could you please advise some good place to do this, which function? Thanks

Once you load some data, make sure that you call the range getter

vtkDataArray* da = data->GetScalars();
  
// cache the scalar range
double* range = da->GetRange();
  
// do the rendering
mapper->SetInputData(data);

thanks