Multiple coloring for one volume

Hi all, (using vtkjs)

As stated in the title, I need to implement a feature where the user is able to render a single Volume with different colors (color mapping) for different sections. The sections are to be defined along the z-axis, and the user is able to change the colors for various sections of the volume.

One possible way (but rather expensive) is to just have multiple volumes and render with each volume being set a different color transfer function. However, I would like to avoid doing that as the image file I am using can be quite big… Is there a filter or something that I can use to achieve this without having multiple volumes?

Thank you!

Here’s an untested idea: offset your data values in each section such that the data min/max do not overlap between sections. Then, take the colormaps you’ve defined for each section, add the specific offset to the colormap, and concatenate your colormaps into one single colormap.

Note that your voxel storage requirements may increase. For instance, if your volume is stored in a Uint8Array and your first section and second section both have a data range of 0-255, you’ll need to change to using a Uint16Array if you shift your second section by 256 to get a data range of 256-511.

Hmm… that may work. Actually by offset, how do I do the offset? I’m parsing it via vtkXMLImageDataReader, should I be offsetting it before parsing into the reader?

You can apply the offset to your pixel sections after you’ve read in the file. For instance, here is how you’d offset the first 2 slices along K:

const data = imageData.getPointData().getScalars().getData();
const start = 0;
const end = dims[0]*dims[1]*2;
for (let i = start; i < end; i++) data[i] += offset;