12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import vtk, qt, ctk, slicer
- import numpy as np
- class vtkInterface:
- def __init__(self, parent):
- parent.title = "vtk Interface"
- parent.categories = ["Examples"]
- parent.dependencies = []
- parent.contributors = ["Andrej Studen (FMF/JSI)"] # replace with "Firstname Lastname (Org)"
- parent.helpText = """
- Convert native numpy data structures to vtk
- """
- parent.acknowledgementText = """
- This module was developed within the frame of the ARRS sponsored medical
- physics research programe to investigate quantitative measurements of cardiac
- function using sestamibi-like tracers
- """ # replace with organization, grant and thanks.
- self.parent = parent
- def numpyToVTK3D(numpy_array, origin, spacing):
- v=vtk.vtkImageData()
- v.SetDimensions(
- numpy_array.shape[0],
- numpy_array.shape[1],
- numpy_array.shape[2])
- v.SetOrigin(origin[0], origin[1], origin[2])
- v.SetSpacing(spacing[0], spacing[1], spacing[2])
- scalars = vtk.vtkShortArray()
- for k in range(0,numpy_array.shape[2]):
- #print '.',
- kOffset = k * numpy_array.shape[1]*numpy_array.shape[0]
- for j in range(0,numpy_array.shape[1]):
- jOffset = j * numpy_array.shape[0]
- for i in range(0,numpy_array.shape[0]):
- offset = i + jOffset + kOffset;
- scalars.InsertTuple1(offset,numpy_array[i,j,k])
- #print
- v.GetPointData().SetScalars(scalars)
- return v
- def completeOrientation(orientation):
- o=orientation
- o.append(o[1]*o[5]-o[2]*o[4])#0,3
- o.append(o[2]*o[3]-o[0]*o[5])#1,4
- o.append(o[0]*o[4]-o[1]*o[3])#2,5
- return o
|