Colorize Model for VR

Hello, is it possible to colorize different parts of an imported STL model(heart) for VR viewing? is this only possible by taking apart or creating two segments of heart and putting them together as different colors?
system: Mac or Windows 10 latest

You can select the vertices you want to be the same color in ParaView, export the indices, then assign scalars to those vertices with a simple python script. Do this for every color. Then you can use a color table to assign colors to the scalars. Although I only recommend this if you have a low numbre of colors and you need to do it only once (and not for every patient for example).

Here’s a pretty ugly and unorganized but working snippet that I used for this in the past:

for i in xrange(ca.GetNumberOfTuples()):
  ca.SetValue(i, 0)
for r in xrange(tt.GetNumberOfRows()):
  i = tt.GetValue(r,0).ToInt()
  ca.SetValue(i, 1)

How do you generate the heart model?

If you have downloaded the model from a 3D model database then usually they come with textures that you can apply (using SlicerIGT extension’s “Texture model” module). If the model did not come with a texture or you don’t like it then you can paint texture using Blender or MeshMixer. If you don’t paint to texture but save the color data as point or cell scalars then you can use the code snippets provided by @cpinter above to colorize the model.

If you want to show/hide or change the color of pieces independently, then probably the best is to split the mesh into multiple pieces (e.g., in MeshMixer or ParaView) and load each piece as a separate model. You can place the pieces in a hierarchy (in Data module) and show/hide groups of pieces at once.

If you have a cardiac CT or MRI image then you can create a colored model using Segment Editor module as shown in this video: