Kitware / vtk-js

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

Use vtkColorTransferFunction to set pixel data(1,2,3) to red, green, blue #1765

Closed StevenRoger closed 3 years ago

StevenRoger commented 3 years ago

There is one volume data only include value: 0, 1, 2, 3, when rendered in 2d mode(MPR), the color displayed as expected.

cfun.addRGBPoint(1, 1, 0, 0); // label '1' will be red
cfun.addRGBPoint(2, 0, 1, 0); // label '2' will be green
cfun.addRGBPoint(3, 0, 0, 1); // label '3' will be blue

but when i rendered in 3d mode(use applyPreset), i changed a preset:

{
  "name": "MY_PRESET",
  "gradientOpacity": "4 0 1 3 1",
  "specularPower": "100",
  "scalarOpacity": "8 0 0 1 1 2 1 3 1",
  "id": "vtkMRMLVolumePropertyNode27",
  "specular": "0.5",
  "shade": "1",
  "ambient": "0.3",
  "colorTransfer": "12 0 0 0 0 1 1 0 0 2 0 1 0 3 0 0 1",
  "selectable": "true",
  "diffuse": "0.9",
  "interpolation": "1",
  "effectiveRange": "1 4",
};

the volume all displayed red. Is there anything i set wrong? Could you give me some suggestion.

jourdain commented 3 years ago

Your JSON does not seems like what the applyPreset expect.

StevenRoger commented 3 years ago

I changed colorTransfer value

"colorTransfer": "16 0 0 0 0 1 1 0 0 2 0 1 0 3 0 0 1",

still not work, could you point out my JSON's errors, or give me a simple example. thx.

jourdain commented 3 years ago

https://github.com/Kitware/vtk-js/blob/master/Sources/Rendering/Core/ColorTransferFunction/LiteColorMaps.json#L2-L20

StevenRoger commented 3 years ago

https://github.com/OHIF/react-vtkjs-viewport/blob/9480282a0e/examples/presets.js

thanks a lot, I refered this preset JSON.

If i don't use these JSON config, How can i achive what i want by using vtkColorTransferFunction?

cfun.addRGBPoint(1, 1, 0, 0); // label '1' will be red
cfun.addRGBPoint(2, 0, 1, 0); // label '2' will be green
cfun.addRGBPoint(3, 0, 0, 1); // label '3' will be blue

Why doesn't it work?

jourdain commented 3 years ago

It should work but without seeing the result or what you do with your cfun it is hard to tell which part of the doesn't work you are talking about.

jourdain commented 3 years ago

Closing this issue. If you still need help, please ask your question on our discussion forum: https://discourse.vtk.org/c/web/9