nipy / mindboggle

Automated anatomical brain label/shape analysis software (+ website)
http://mindboggle.info
Other
145 stars 54 forks source link

Colormap in vtkviewer? #29

Closed binarybottle closed 11 years ago

binarybottle commented 11 years ago

Hal Canary and Arno Klein (8/25/2013):

Arno: vtkviewer.py works great. is there a way to change the colormap?

Hal: Look at the line: colorMap = vtk.vtkColorTransferFunction() You can change those next few lines to anything you like.

Hal: Check out the most recent version of vtkviewer.py from github/master. I've modified the VTKViewer.AddPolyData() method to accept an optional colorMap argument. If you use vtkviewer as a module, you should be able to do this: (I haven't tested this).

3

import vtk import vtkviewer

my_poly_data = vtk.vtkPolyData()

do something to generate your meshes and scalars:

my_color_map = vtk.vtkColorTransferFunction() my_color_map.SetColorSpaceToLab() my_color_map.AddRGBPoint(-1, 0,0,0) # background is black colors = [ [0.6706, 0.2196, 0.2196], [0.4471, 0.6706, 0.2196], [0.2196, 0.6706, 0.6706], [0.4471, 0.2196, 0.6706], [1.0, 0.8706, 0.6078], [0.5843, 0.6667, 0.6235], [1.0, 0.9843, 0.9020], [0.9020, 0.9020, 1.0], [0.5, 0.5, 0.95], [0.7451, 0.7843, 0.7098]]

use whatever colors you like. But be aware that some are

    # better than others.  Or read Colin Ware's book.

for i, color in enumerate(colors): my_color_map.AddRGBPoint(i, *color) my_color_map.Build()

vtkviewer = vtkviewer.VTKViewer() vtkviewer.AddPolyData(my_poly_data,my_color_map) vtkviewer.Start()

binarybottle commented 11 years ago

Hal Canary and Arno Klein (8/25/2013):

Arno: i haven't had a chance to test this out yet, but it looks like it will be very useful for applying colormaps when viewing meshes as i create them. but what about existing files -- would i have to read in the file, extract the poly data, and then start the viewer?

Hal: There are two ways to do that. First, you could modify the vtkviewer.py program to read a color map from a file. A better way may be to encode the colors directly as scalar values in the vtkPolyData, as a vtkUnsignedCharArray called "rgb_colors" with three components.

POINT_DATA 98 SCALARS rgb_colors unsigned_char 3 LOOKUP_TABLE default 34 194 36 34 194 218 34 255 36 34 255 218 220 194 36 ...

binarybottle commented 11 years ago

Hal Canary (8/25/2013):

I have just modified vtkviewer.py to do just this, using the ParaView XML colormap file format. It uses an environment variable to specify the filename. Check out the latest version and:

COLORMAP=blackbody.xml ./vtkviewer.py wave0.vtp

binarybottle commented 11 years ago

i have written a function, vtkviewer(), to call vtkviewer.py, but it doesn't seem to use the colormap file i created (mindboggle_tools/colormap.xml):

https://github.com/binarybottle/mindboggle/blob/master/mindboggle/utils/plots.py#L60

binarybottle commented 11 years ago

fixed with pull request #30

binarybottle commented 11 years ago

screen shot 2013-08-26 at 6 32 20 pm