activiz vtkdataarray performance

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

            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!

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

You could try casting your data array to vtkShortArray.

1 Like

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

1 Like

Yes that is very quick, thank you!