# Tractography color display from ASCII .vtk Polydata

**URL:** <https://discourse.slicer.org/t/tractography-color-display-from-ascii-vtk-polydata/871>\
**Category:** Support\
**Tags:** tractography, vtk\
**Created:** [August 15, 2017, 11:58am UTC](https://discourse.slicer.org/t/tractography-color-display-from-ascii-vtk-polydata/871 "2017-08-15T11:58:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bartbols](https://avatars.discourse-cdn.com/v4/letter/b/a183cd/32.png) [@bartbols](https://discourse.slicer.org/u/bartbols)\
**Post date:** [August 15, 2017, 11:58am UTC](https://discourse.slicer.org/t/tractography-color-display-from-ascii-vtk-polydata/871/1 "2017-08-15T11:58:54Z")

</div>

Hi,

I’m trying to visualize some fibre tracts in 3D slicer form a ASCII vtkPolydata file that I generate through Matlab. The file reads in well and displays the fibres in the correct position, however, I cannot assign colors based on the scalar-values assigned to each line segment (as defined in the .vtk Polydata file). In the ‘Tractography display’ module my scalar variable is recognized because it shows up in the dropdown list next to “Of scalar value”, but when I select it the color does not change. I’m wondering if I haven’t defined the color-specs correctly in my VTK file, or if this is a (known?) bug in 3D slicer. I’ve copied an example .vtk ASCII file below (copy/paste it into a text editor and save with extension .vtk, then open in 3D slicer). I’m using Slicer 4.5.0-1 r24735.

Any help is greatly appreciated!

Bart

# vtk DataFile Version 3.0

example data  
ASCII  
DATASET POLYDATA  
POINTS 46 float  
-73.482 69.594 181.997  
-73.848 69.446 181.078  
-74.203 69.283 180.157  
-74.529 69.070 179.236  
-74.835 68.828 178.316  
-75.134 68.577 177.395  
-75.422 68.322 176.472  
-75.701 68.057 175.549  
-75.976 67.788 174.626  
-76.254 67.515 173.705  
-76.540 67.246 172.785  
-76.852 66.976 171.874  
-77.198 66.704 170.977  
-77.581 66.431 170.094  
-77.987 66.159 169.221  
-78.392 65.887 168.349  
-78.807 65.611 167.481  
-79.226 65.332 166.617  
-79.634 65.049 165.749  
-80.027 64.759 164.877  
-82.538 67.717 165.874  
-82.298 67.992 166.805  
-82.054 68.267 167.735  
-81.816 68.547 168.665  
-81.588 68.831 169.596  
-81.360 69.115 170.528  
-81.127 69.398 171.458  
-80.886 69.680 172.387  
-80.633 69.958 173.313  
-80.359 70.228 174.236  
-80.084 70.499 175.159  
-79.790 70.760 176.078  
-79.476 71.008 176.995  
-79.146 71.238 177.910  
-78.813 71.446 178.830  
-78.486 71.622 179.758  
-78.161 71.769 180.693  
-77.835 71.884 181.631  
-77.509 71.967 182.573  
-77.176 72.021 183.514  
-76.845 72.057 184.457  
-76.517 72.079 185.401  
-76.233 72.049 186.360  
-75.978 71.990 187.325  
-75.754 71.913 188.296  
-75.541 71.810 189.268

LINES 2 48  
20 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19  
26 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

CELL\_DATA 2  
SCALARS scalar\_value int 1  
LOOKUP\_TABLE my\_table  
2  
2  
LOOKUP\_TABLE my\_table 8  
0.2 0.8 0.4 0.0  
0.8 0.1 0.5 0.9  
0.9 1.0 0.9 0.3  
1.0 0.7 0.3 0.1  
0.2 0.3 0.8 0.7  
0.5 0.4 0.4 0.4  
0.9 0.0 0.8 0.7  
0.6 0.7 0.0 0.3

---

<div class="post-metadata">

**Author:** ![ljod](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ljod/32/652_2.png) [@ljod](https://discourse.slicer.org/u/ljod)\
**Post date:** [August 15, 2017, 3:02pm UTC](https://discourse.slicer.org/t/tractography-color-display-from-ascii-vtk-polydata/871/2 "2017-08-15T15:02:55Z")

</div>

Hi you are seeing the expected behavior. Currently the support is for coloring point data, not cell data, since that is the typical use case (e.g. color by FA at all points on the polyline or fiber). You can easily store your desired scalars as point data (one scalar per point) instead of cell data (one scalar per line). Also, in your vtk example, I don’t actually see any scalar array data, so that can be another issue. There is no need to include a lookup table, since you can choose from the options in Slicer for lookup color options.

---

<div class="post-metadata">

**Author:** ![bartbols](https://avatars.discourse-cdn.com/v4/letter/b/a183cd/32.png) [@bartbols](https://discourse.slicer.org/u/bartbols)\
**Post date:** [August 15, 2017, 10:32pm UTC](https://discourse.slicer.org/t/tractography-color-display-from-ascii-vtk-polydata/871/3 "2017-08-15T22:32:30Z")

</div>

Ok, that works! Thanks!  
Is it also possible to append multiple scalar sets to the same point dataset, so you can then select from the dropdown menu in Slicer which value you want to display? I’ve only figured out how to append one scalar so far.  
Bart

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [August 15, 2017, 11:15pm UTC](https://discourse.slicer.org/t/tractography-color-display-from-ascii-vtk-polydata/871/4 "2017-08-15T23:15:01Z")

</div>

Yes, you can add any number of scalars and choose which one to display in the Scalars section of Models module.

---

<div class="post-metadata">

**Author:** ![bartbols](https://avatars.discourse-cdn.com/v4/letter/b/a183cd/32.png) [@bartbols](https://discourse.slicer.org/u/bartbols)\
**Post date:** [August 16, 2017, 12:01am UTC](https://discourse.slicer.org/t/tractography-color-display-from-ascii-vtk-polydata/871/5 "2017-08-16T00:01:03Z")

</div>

Ok, so how do you add that to the vtk file then? When I append something like this at the end of the ASCII-file, it only reads in scalar1:

POINT\_DATA 40  
SCALARS scalar1 float 1  
LOOKUP\_TABLE default

POINT\_DATA 40  
SCALARS scalar2 float 1  
LOOKUP\_TABLE default

Any suggestions on how to also get scalar2 to show up in Slicer?  
Bart

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [August 16, 2017, 2:32am UTC](https://discourse.slicer.org/t/tractography-color-display-from-ascii-vtk-polydata/871/6 "2017-08-16T02:32:52Z")

</div>

You can choose which scalar to display in the Scalars section of Models module.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/9/d967661055ccace8b17055c3dde43d11ad136c7e.png)

There are lots of sample data sets in [VTKData/Data at master · naucoin/VTKData · GitHub](https://github.com/naucoin/VTKData/tree/master/Data)

For example, this data set has lots of scalars: [https://raw.githubusercontent.com/naucoin/VTKData/master/Data/blow.vtk](https://raw.githubusercontent.com/naucoin/VTKData/master/Data/blow.vtk)

---

<div class="post-metadata">

**Author:** ![bartbols](https://avatars.discourse-cdn.com/v4/letter/b/a183cd/32.png) [@bartbols](https://discourse.slicer.org/u/bartbols)\
**Post date:** [August 16, 2017, 5:12am UTC](https://discourse.slicer.org/t/tractography-color-display-from-ascii-vtk-polydata/871/7 "2017-08-16T05:12:34Z")

</div>

Hi Andras,  
thanks for your response again. I understand how I should be able to select a different scalar, but the problem is that only the first scalar defined in my .vtk file shows up. The other scalars do not appear in the dropdown menu. There is no error when loading the file. Also, when I open the file in ParaView it does detect all the scalars, which makes me think there’s something wrong with 3D slicer’s vtkreader.

For example, in the following file, only ‘scalar1’ shows up. Is my syntax wrong?

# vtk DataFile Version 3.0

Title  
ASCII  
DATASET POLYDATA  
POINTS 24 float  
-84.232 52.932 175.120  
-87.560 56.327 181.491  
-88.757 57.499 183.553  
-90.092 58.723 185.504  
-91.515 59.973 187.384  
-92.980 61.223 189.239  
-94.440 62.448 191.110  
-95.847 63.620 193.040  
-97.154 64.714 195.073  
-98.313 65.703 197.252  
-99.278 66.563 199.618  
-107.554 74.195 223.673  
-75.512 59.065 109.771  
-75.664 59.053 109.885  
-77.933 58.896 111.714  
-80.054 58.804 113.678  
-82.043 58.783 115.758  
-83.915 58.839 117.936  
-85.689 58.980 120.195  
-87.381 59.212 122.517  
-89.006 59.542 124.882  
-90.582 59.975 127.275  
-92.126 60.520 129.675  
-93.754 61.160 132.225

LINES 2 26  
12 0 1 2 3 4 5 6 7 8 9 10 11  
12 12 13 14 15 16 17 18 19 20 21 22 23  
POINT\_DATA 24  
SCALARS scalar1 float  
LOOKUP\_TABLE default  
58.538  
58.538  
58.538  
58.538  
58.538  
58.538  
58.538  
58.538  
58.538  
58.538  
58.538  
58.538  
29.324  
29.324  
29.324  
29.324  
29.324  
29.324  
29.324  
29.324  
29.324  
29.324  
29.324  
29.324  
SCALARS scalar2 float  
LOOKUP\_TABLE default  
14.789  
14.789  
14.789  
14.789  
14.789  
14.789  
14.789  
14.789  
14.789  
14.789  
14.789  
14.789  
35.250  
35.250  
35.250  
35.250  
35.250  
35.250  
35.250  
35.250  
35.250  
35.250  
35.250  
35.250

---

<div class="post-metadata">

**Author:** ![bartbols](https://avatars.discourse-cdn.com/v4/letter/b/a183cd/32.png) [@bartbols](https://discourse.slicer.org/u/bartbols)\
**Post date:** [August 16, 2017, 5:44am UTC](https://discourse.slicer.org/t/tractography-color-display-from-ascii-vtk-polydata/871/8 "2017-08-16T05:44:05Z")

</div>

UPDATE: issue resolved

After upgrading to the latest Slicer version (4.7.0) it does recognise all the scalars stored in the vtk-file. So it was a problem with my previous Slicer version (4.5) which has been resolved now.  
Bart
