# Byte array in vtk pipeline

**URL:** https://discourse.vtk.org/t/byte-array-in-vtk-pipeline/6195
**Category:** Support
**Created:** [July 15, 2021, 8:49am UTC](https://discourse.vtk.org/t/byte-array-in-vtk-pipeline/6195 "2021-07-15T08:49:33Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![kit](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/k/9fc29f/32.png) [@kit](https://discourse.vtk.org/u/kit)
#### Post date: [July 15, 2021, 8:49am UTC](https://discourse.vtk.org/t/byte-array-in-vtk-pipeline/6195/1 "2021-07-15T08:49:33Z")

</div>

Hi All,

I am looking to create a vtk pipeline that passes a byte array as data. The data array does not contain any topological structure and can be any length (it’s a custom encoding of a data array). As such I am not really sure which VTK data set type (if any) it fits best too. I was thinking vtkUnsignedCharArray but have not found examples using that in the pipeline.

If anyone can point me to an example of this sort of thing it would really help.

cheers

Kit

---

<div class="post-metadata">

### Author: ![Yohann\_Bearzi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yohann_bearzi/32/671_2.png) [@Yohann\_Bearzi](https://discourse.vtk.org/u/Yohann_Bearzi)
#### Post date: [July 15, 2021, 11:45am UTC](https://discourse.vtk.org/t/byte-array-in-vtk-pipeline/6195/2 "2021-07-15T11:45:35Z")

</div>

If you want a pipeline that only passes a `vtkUnsignedCharArray`, I think that the best data set type to carry it would be `vtkImageData`, setting its extent to be one dimensional. You can put the data array as cell data or point data as you prefer. I’m proposing to use this data set type because the entire geometry is implicit, so you won’t have anything big allocated besides your data array.

To clarify, calling `N` the number of elements in your data array, you can create a 1D `vtkImageData` of extent `[0, N, 0, 0, 0, 0]` and put your data array as cell data, or of extent `[0, N-1, 0, 0, 0, 0]` and put your data as point data.

---

<div class="post-metadata">

### Author: ![kit](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/k/9fc29f/32.png) [@kit](https://discourse.vtk.org/u/kit)
#### Post date: [July 15, 2021, 12:01pm UTC](https://discourse.vtk.org/t/byte-array-in-vtk-pipeline/6195/3 "2021-07-15T12:01:04Z")

</div>

Fair enough. I had considered using vtkTable in the same way, but I guess vtkImageData works just as well.

Thanks

---

<div class="post-metadata">

### Author: ![Yohann\_Bearzi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yohann_bearzi/32/671_2.png) [@Yohann\_Bearzi](https://discourse.vtk.org/u/Yohann_Bearzi)
#### Post date: [July 15, 2021, 12:33pm UTC](https://discourse.vtk.org/t/byte-array-in-vtk-pipeline/6195/4 "2021-07-15T12:33:52Z")

</div>

Yeah, I think `vtkTable` would be pretty equivalent. It’s up to you to decide what you want to use I guess. The advantages of `vtkImageData` is that the data is spatially located: you can compute gradients, this kind of things. So this is to be considered.

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [July 15, 2021, 4:08pm UTC](https://discourse.vtk.org/t/byte-array-in-vtk-pipeline/6195/5 "2021-07-15T16:08:17Z")

</div>

One limitation of vtkImageData is that its size is limited to 2147483647 per dimension, so a 1D image can be max 2GB for byte-sized data. The [vtkArrayData](https://vtk.org/doc/nightly/html/classvtkArrayData.html) class is worth looking at if you want to pass an array down the pipeline.

---

<div class="post-metadata">

### Author: ![kit](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/k/9fc29f/32.png) [@kit](https://discourse.vtk.org/u/kit)
#### Post date: [July 15, 2021, 4:47pm UTC](https://discourse.vtk.org/t/byte-array-in-vtk-pipeline/6195/6 "2021-07-15T16:47:09Z")

</div>

Thanks. So I guess I would make a vtkArray contained in a vtkArrayData object.

Is there an algorithm class for vtkArrayData methods? Like an equivalent of vtkImageDataAlgorithm.

Kit

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [July 15, 2021, 5:43pm UTC](https://discourse.vtk.org/t/byte-array-in-vtk-pipeline/6195/7 "2021-07-15T17:43:02Z")

</div>

The algorithm class is vtkArrayDataAlgorithm. See [vtkExtractArray](https://vtk.org/doc/nightly/html/classvtkExtractArray.html) as a simple example of a concrete class that operates on vtkArrayData data objects.

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [July 15, 2021, 5:56pm UTC](https://discourse.vtk.org/t/byte-array-in-vtk-pipeline/6195/8 "2021-07-15T17:56:14Z")

</div>

Ah… I just realized that vtkArrayData uses “[vtkArray](https://vtk.org/doc/nightly/html/classvtkArray.html)” instead of “vtkDataArray”. This might impact your decision about whether to use it, since “vtkArray” is a alternative way of storing array data as compared to vtkDataArray (that is, a vtkArray is not a vtkDataArray and a vtkDataArray is not a vtkArray). The vtkArray class is a special-purpose class like vtkTable.

So perhaps the easiest way to pass a vtkDataArray down the pipeline is to attach it to the [vtkFieldData](https://vtk.org/doc/nightly/html/classvtkFieldData.html) of an otherwise empty vtkPolyData object. What I mean is, create an empty vtkPolyData and add arrays to data-\>GetFieldData().
