consider a specific float value as a NaN in a vtkColorTransferFunction

(Patrick Brockmann) #1

Hi,

I am wondering if it could be interesting to add a function to vtkColorTransferFunction to define a specific float value to act as Nan values.
Nan values are indeed perfectly well handled by the lookup.setNanColor() function.

A typical case, I have to figure out is read and represent variables from netCDF files. In this format, an attribut specify the missing value to be considered for each variables. This floating value is not a Nan but rather a value taken outside the range of the variable.
For example, if the range of the variable is -100:100 then a missing value could be set to -1E+34

Now when you want to set up a lookup table in VTK to handle this case, you need to transform all values equal to the missing value (-1E+34) to Nan. This operation has a cost of course (filter all points, compare and replace if needed) and could be avoided if a setValueAsNan() function would exist.

Let me know, if this a bad idea or a good request.

(Luca Pallozzi Lavorante) #2

Patrick, I think vtkDiscretizableColorTransferFunction does what you need. It is a subclass of vtkColorTransferFunction, so you can use the same methods to build the valid colors intervals. I used it some time ago to work with discrete color tables, but I needed to add some ranges with different colors. Finally I had to turn some other value ranges completely off.
This is part of the code I used. Here, min and max are the minimum and maximum values from the data attribute you are going to render.

vtkSmartPointer table = vtkSmartPointer< vtkDiscretizableColorTransferFunction >::New();
vtkSmartPointer< vtkPiecewiseFunction > opacityFunction;
if (min > 0) { // A min value greater than 0 means that 0 is to be considered as invalid.
opacityFunction = vtkSmartPointer::New();
opacityFunction->AddSegment(0, 0, min, 0); // Range [0, min] will have zero opacity.
opacityFunction->AddSegment(min, 1, max, 1); // Range [min, max] will have full (1) opacity.
}
}
table->EnableOpacityMappingOn();
table->SetScalarOpacityFunction(opacityFunction);

In the final part of your post, you mention the need of transforming all unwanted values into Nan. If I have understood the question correctly, I don’t think it would be necessary using vtkDiscretizableColorTransferFunction.