vcasellesb / stl2nii

.stl to .nii(.gz) file converter
0 stars 0 forks source link

Code Efficiency Recommendations #2

Closed jiaomei222 closed 1 month ago

jiaomei222 commented 1 month ago

Thanks for your great jobs! I found this code to be very inefficient:

for i in range(image.GetNumberOfPoints()): image.GetPointData().GetScalars().SetTuple1(i, inval)

Maybe you can try the following code:

scalars = image.GetPointData().GetScalars()

from vtkmodules.util.numpy_support import vtk_to_numpy

scalar_array = vtk_to_numpy(scalars)

scalar_array[:] = inval

scalars.Modified()
vcasellesb commented 1 month ago

Hi,

Thanks so much! Code has been updated with your suggestions. It's true that it was highly inefficient, your method is waaaaay faster. Thanks again!

Best, Vicent