-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
Currently the code at setInputAsNumpy creates a new VTK image, and also not really correct.
It should really call the converter which will not copy the data from the numpy array to the VTK image.
from ccpi.viewer.utils.conversion import Converter
vtkdata = Converter.numpy2vtkImage(data)
v.setInputData(vtkdata)CILViewer/Wrappers/Python/ccpi/viewer/CILViewer.py
Lines 595 to 623 in 1913676
| if (len(numpy.shape(numpyarray)) == 3): | |
| doubleImg = vtk.vtkImageData() | |
| shape = numpy.shape(numpyarray) | |
| doubleImg.SetDimensions(shape[0], shape[1], shape[2]) | |
| doubleImg.SetOrigin(0, 0, 0) | |
| doubleImg.SetSpacing(1, 1, 1) | |
| doubleImg.SetExtent(0, shape[0] - 1, 0, shape[1] - 1, 0, shape[2] - 1) | |
| doubleImg.AllocateScalars(vtk.VTK_DOUBLE, 1) | |
| for i in range(shape[0]): | |
| for j in range(shape[1]): | |
| for k in range(shape[2]): | |
| doubleImg.SetScalarComponentFromDouble(i, j, k, 0, numpyarray[i][j][k]) | |
| # rescale to appropriate VTK_UNSIGNED_SHORT | |
| stats = vtk.vtkImageAccumulate() | |
| stats.SetInputData(doubleImg) | |
| stats.Update() | |
| iMin = stats.GetMin()[0] | |
| iMax = stats.GetMax()[0] | |
| scale = vtk.VTK_UNSIGNED_SHORT_MAX / (iMax - iMin) | |
| shiftScaler = vtk.vtkImageShiftScale() | |
| shiftScaler.SetInputData(doubleImg) | |
| shiftScaler.SetScale(scale) | |
| shiftScaler.SetShift(iMin) | |
| shiftScaler.SetOutputScalarType(vtk.VTK_UNSIGNED_SHORT) | |
| shiftScaler.Update() | |
| self.img3D = shiftScaler.GetOutput() |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels