# activiz vtkdataarray performance

**URL:** https://discourse.vtk.org/t/activiz-vtkdataarray-performance/14649
**Category:** Support
**Created:** [October 2, 2024, 12:52pm UTC](https://discourse.vtk.org/t/activiz-vtkdataarray-performance/14649 "2024-10-02T12:52:11Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![mortifiedpenguin](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/b3f665/32.png) [@mortifiedpenguin](https://discourse.vtk.org/u/mortifiedpenguin)
#### Post date: [October 2, 2024, 12:52pm UTC](https://discourse.vtk.org/t/activiz-vtkdataarray-performance/14649/1 "2024-10-02T12:52:11Z")

</div>

Hi, I’m using Activiz and want to save the output of a vtkImageReslice. My (experimental) code regarding the export is as follows:

```auto
            var data = reslice.GetOutput().GetPointData().GetScalars();
            var imData = new ushort[data.GetNumberOfValues()];
            for (int li = 0; li < imData.Length; ++li)
            {
                var shortValue = (int)data.GetVariantValue(li).ToInt();
                imData[li] = (ushort)(Math.Max(-1024, shortValue) + 1024);
            }

```

I noticed that the GetVariantValue call is very slow, it takes 90% of the runtime, which is unexpected, as I’d expect the actual reslice operation to take more time. Is there a faster way to access the data from the vtkimagereslice?

Thanks!

---

<div class="post-metadata">

### Author: ![toddy](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@toddy](https://discourse.vtk.org/u/toddy)
#### Post date: [October 3, 2024, 10:57am UTC](https://discourse.vtk.org/t/activiz-vtkdataarray-performance/14649/2 "2024-10-03T10:57:02Z")

</div>

C# is a strictly typed language. Why are you using **var**?

You could try casting your _data_ array to vtkShortArray.

---

<div class="post-metadata">

### Author: ![LucasGandel](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lucasgandel/32/1831_2.png) [@LucasGandel](https://discourse.vtk.org/u/LucasGandel)
#### Post date: [October 3, 2024, 11:44am UTC](https://discourse.vtk.org/t/activiz-vtkdataarray-performance/14649/3 "2024-10-03T11:44:01Z")

</div>

Does using `data.GetTuple1(li)` offer better performance?

---

<div class="post-metadata">

### Author: ![mortifiedpenguin](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/b3f665/32.png) [@mortifiedpenguin](https://discourse.vtk.org/u/mortifiedpenguin)
#### Post date: [October 4, 2024, 5:26am UTC](https://discourse.vtk.org/t/activiz-vtkdataarray-performance/14649/4 "2024-10-04T05:26:26Z")

</div>

Yes that is very quick, thank you!
