# Read gifti file written by CAT toolbox

**URL:** https://discourse.itk.org/t/read-gifti-file-written-by-cat-toolbox/3588
**Category:** Beginner Questions
**Created:** [November 2, 2020, 9:00am UTC](https://discourse.itk.org/t/read-gifti-file-written-by-cat-toolbox/3588 "2020-11-02T09:00:28Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![crossmanith](https://discourse.itk.org/user_avatar/discourse.itk.org/crossmanith/32/569_2.png) [@crossmanith](https://discourse.itk.org/u/crossmanith)
#### Post date: [November 2, 2020, 9:00am UTC](https://discourse.itk.org/t/read-gifti-file-written-by-cat-toolbox/3588/1 "2020-11-02T09:00:28Z")

</div>

Hi,

I’d like to postprocess a gifti file written by the CAT toolbox (matlab). It contains one data array with scalar values, one data array with vertices and a third data array with triangles. itk::MeshFileReader offers readers for cells and points but not for scalar values.

I could use gifticlib in addition to ITK to read the scalar values. Is there a way to combine scalar values and mesh data in ITK?

Regards,  
Christina Rossmanith

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [November 2, 2020, 2:52pm UTC](https://discourse.itk.org/t/read-gifti-file-written-by-cat-toolbox/3588/2 "2020-11-02T14:52:21Z")

</div>

Meshes can have [point data](https://itk.org/Doxygen/html/classitk_1_1Mesh.html#af7dc580f3830fbd379fea427dd108776) and cell (triangle) data. And ITK should already [read both](https://github.com/InsightSoftwareConsortium/ITK/blob/v5.1.1/Modules/IO/MeshGifti/src/itkGiftiMeshIO.cxx#L1027-L1085) from a GIFTI file. Can you double check that? If not read properly, can you debug to find out what is the problem?

---

<div class="post-metadata">

### Author: ![crossmanith](https://discourse.itk.org/user_avatar/discourse.itk.org/crossmanith/32/569_2.png) [@crossmanith](https://discourse.itk.org/u/crossmanith)
#### Post date: [November 3, 2020, 10:10am UTC](https://discourse.itk.org/t/read-gifti-file-written-by-cat-toolbox/3588/3 "2020-11-03T10:10:50Z")

</div>

My question was if there is a way to combine scalar data with mesh data (e.g. cortical thickness values across a brain surface). Point data seem to be transposed, I’ll open an issue for that.

---

<div class="post-metadata">

### Author: ![crossmanith](https://discourse.itk.org/user_avatar/discourse.itk.org/crossmanith/32/569_2.png) [@crossmanith](https://discourse.itk.org/u/crossmanith)
#### Post date: [November 3, 2020, 10:17am UTC](https://discourse.itk.org/t/read-gifti-file-written-by-cat-toolbox/3588/4 "2020-11-03T10:17:41Z")

</div>

![screenshot_giftisurfaceformat](https://discourse.itk.org/uploads/default/original/2X/6/66adbad699b8a0bf4532000896585297bf3f64f7.jpeg)

Just to double check that I understand the gifti format correctly: In row major order “1 2 3 4” means two 2D points P1(1 3) and P2(2 4), in column major order P1(1 2) and P2(3 4).

(screenshot taken from GIFTI\_Surface\_Format.pdf, p6)

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [November 3, 2020, 2:44pm UTC](https://discourse.itk.org/t/read-gifti-file-written-by-cat-toolbox/3588/5 "2020-11-03T14:44:16Z")

</div>

> [@crossmanith](#):
>
> there is a way to combine scalar data with mesh data

Yes. Vertices (points) and triangles (cells) can hold values, so you can put e.g. cortical thickness there.

I think that question of row/column major boils down whether to store xyzxyzxyzxyz or xxxxyyyyzzzz.

---

<div class="post-metadata">

### Author: ![crossmanith](https://discourse.itk.org/user_avatar/discourse.itk.org/crossmanith/32/569_2.png) [@crossmanith](https://discourse.itk.org/u/crossmanith)
#### Post date: [November 3, 2020, 4:29pm UTC](https://discourse.itk.org/t/read-gifti-file-written-by-cat-toolbox/3588/6 "2020-11-03T16:29:45Z")

</div>

Fine, then I’ll try to get points with values working.

row/column major order: I just want to be sure, that “1 2 3 4” in row major order means P(1|3) and Q(2|4). When reading the file with itk::MeshFileReader and printing the points accessed with GetPoint() the output is [1 2] and [3 4] what would be expected with column major order (and vice versa).

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [November 3, 2020, 4:33pm UTC](https://discourse.itk.org/t/read-gifti-file-written-by-cat-toolbox/3588/7 "2020-11-03T16:33:05Z")

</div>

The [reading code](https://github.com/InsightSoftwareConsortium/ITK/blob/v5.1.1/Modules/IO/MeshGifti/src/itkGiftiMeshIO.cxx#L1027-L1055) does not mention row/column major possibilities, it might assume one. If you have the other one it might be reading it the wrong.

---

<div class="post-metadata">

### Author: ![crossmanith](https://discourse.itk.org/user_avatar/discourse.itk.org/crossmanith/32/569_2.png) [@crossmanith](https://discourse.itk.org/u/crossmanith)
#### Post date: [November 3, 2020, 4:42pm UTC](https://discourse.itk.org/t/read-gifti-file-written-by-cat-toolbox/3588/8 "2020-11-03T16:42:00Z")

</div>

Well, I think it always reads wrong - at least my tiny sample file.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [November 3, 2020, 4:42pm UTC](https://discourse.itk.org/t/read-gifti-file-written-by-cat-toolbox/3588/9 "2020-11-03T16:42:52Z")

</div>

PR to support both row major and column major would be welcome!
