def RequestData(self, vtkself, request, inputs, output):
     vtkin = vtkImageData.GetData(inputs[0])
     vtkout = vtkImageData.GetData(output)
     vtkout.CopyStructure(vtkin)
     indata = dsa.WrapDataObject(vtkin)
     outdata = dsa.WrapDataObject(vtkout)
     for k in indata.PointData.keys():
         arr = indata.PointData[k]
         arr *= self.params['a']
         outdata.PointData.append(arr, "{}*{}".format(k, self.params['a']))
Esempio n. 2
0
def getSlice(vol, volShape, y):
    # Create slice
    slicer = Slice(Input=vol)
    slicer.SliceType = 'Plane'
    slicer.SliceOffsetValues = [0.0]
    slicer.Crinkleslice = 0
    slicer.Triangulatetheslice = 1
    slicer.Mergeduplicatedpointsintheslice = 1

    # Get slice through chosen Y value
    slicer.SliceType.Origin = [0, y, 0]

    # Get Y slices
    slicer.SliceType.Normal = [0, 1, 0]

    # Update pipeline
    slicer.UpdatePipeline()

    # Convert slice to numpy array
    slice_numpy = sm.Fetch(slicer)
    slice_numpy = dsa.WrapDataObject(slice_numpy)
    slice_numpy = slice_numpy.PointData[0]

    # Re-shape vector into 2D slice
    # Re-shaping with transpose because the other way messes up the layout
    # Should probably read into how striding works in NumPy...
    slice_numpy = np.array(slice_numpy).reshape((volShape[2], volShape[0])).T

    # Convert from int16 back to LVF as float
    slice_numpy = slice_numpy.astype('float32') / 1000

    return slice_numpy
Esempio n. 3
0
def extractVTK(vtk_path, clipVal):
    vol = XMLImageDataReader(FileName=vtk_path)
    vol.UpdatePipeline()

    # Get extents (voxels) and bounds (mm)
    extents = vol.GetDataInformation().GetExtent()
    bounds = vol.GetDataInformation().GetBounds()
    volShape = np.array(extents[1::2]) + 1

    # Get slices
    slice_jets = getSlice(vol, volShape, y=-3)
    slice_impingement = getSlice(vol, volShape, y=1)
    slice_near = getSlice(vol, volShape, y=5)
    slice_far = getSlice(vol, volShape, y=9)
    slices = [slice_jets, slice_impingement, slice_near, slice_far]

    # Get smoothed surface
    surface = getSurface(vol, clipVal)

    # Get grid information as vectors for X/Y/Z (mm)
    grid = [None] * 3
    grid[0] = np.linspace(bounds[0], bounds[1], volShape[0])
    grid[1] = np.linspace(bounds[2], bounds[3], volShape[1])
    grid[2] = np.linspace(bounds[4], bounds[5], volShape[2])

    # Get dx/dy/dz
    dx = np.abs(grid[0][1] - grid[0][0])
    dy = np.abs(grid[1][1] - grid[1][0])
    dz = np.abs(grid[2][1] - grid[2][0])

    # Get volume mass
    mass = dsa.WrapDataObject(sm.Fetch(vol)).PointData[0].sum()
    mass *= (dx * dy * dz)

    return slices, grid, surface, mass
    def asdf_to_mbds(self, tree, mbds):
        def shape_3d(shape):
            if len(shape) == 3:
                return shape
            elif len(shape) == 2:
                return (1, ) + shape
            elif len(shape) == 1:
                return (1, 1) + shape
            else:
                return (1, 1, np.prod(shape))
#        mbds = vtk.MultiBlockDataSet()

        for (i, k) in enumerate(tree):
            obj = tree[k]
            #            print(obj)
            if isinstance(obj, dict):
                child_mbds = vtk.vtkMultiBlockDataSet()
                self.asdf_to_mbds(obj, child_mbds)
                mbds.SetBlock(i, child_mbds)
                mbds.GetMetaData(i).Set(vtk.vtkCompositeDataSet.NAME(), k)
            elif hasattr(obj, 'shape'):
                vtkdata = vtk.vtkImageData()
                dim = tuple(reversed(shape_3d(obj.shape[0:-1])))
                arr = obj[:]
                arr.shape = (np.prod(dim), arr.shape[-1])
                vtkdata.SetDimensions(dim)
                data = dsa.WrapDataObject(vtkdata)
                data.PointData.append(arr, k)
                mbds.SetBlock(i, vtkdata)
                mbds.GetMetaData(i).Set(vtk.vtkCompositeDataSet.NAME(), k)
Esempio n. 5
0
    def h5_to_mbds(self, group, mbds):
        def shape_3d(shape):
            if len(shape) == 3:
                return shape
            elif len(shape) == 2:
                return (1,) + shape
            elif len(shape) == 1:
                return (1, 1) + shape
            else:
                return (0, 0, 0)
#        mbds = vtk.MultiBlockDataSet()
        for (i, k) in enumerate(group):
            obj = group[k]
#            print(obj)
            if isinstance(obj, h5py.Group):
                child_mbds = vtk.vtkMultiBlockDataSet()
                self.h5_to_mbds(obj, child_mbds)
                mbds.SetBlock(i, child_mbds)
                mbds.GetMetaData(i).Set(vtk.vtkCompositeDataSet.NAME(), k)
            elif isinstance(obj, h5py.Dataset):
                vtkdata = vtk.vtkImageData()
                shape = tuple(reversed(shape_3d(obj.shape)))
#                print(shape)
                vtkdata.SetDimensions(shape)
                data = dsa.WrapDataObject(vtkdata)
                arr = obj[:].flatten()
#                print(arr)
                data.PointData.append(arr, k)
                mbds.SetBlock(i, vtkdata)
                mbds.GetMetaData(i).Set(vtk.vtkCompositeDataSet.NAME(), k)
 def generateSinData(self, vtkdata, s):
     params = self.params
     t = np.arange(params['t0'], params['t1'], 1.0/params['fs'])
     print('t: {}'.format(t))
     x = np.sin(2*np.pi*params['f']*t)
     data = dsa.WrapDataObject(vtkdata)
     vtkdata.SetDimensions((x.size, 1, 1))
     vtkdata.SetOrigin((params['t0'], 0, 0))
     vtkdata.SetSpacing(1/params['fs'], 0, 0)
     data.PointData.append(x*s, 'sin')
     data.PointData.append(t, 't')
 def RequestData(self, vtkself, request, inputs, output):
     params = self.params
     N = int((params['t1'] - params['t0']) * params['fs'])
     vtkdata = output.GetInformationObject(0).Get(vtkDataObject.DATA_OBJECT())
     t = np.arange(params['t0'], params['t1'], 1.0/params['fs'])
     x = np.sin(2*np.pi*params['f']*t)
     data = dsa.WrapDataObject(vtkdata)
     vtkdata.SetDimensions((x.size, 1, 1))
     vtkdata.SetOrigin((params['t0'], 0, 0))
     vtkdata.SetSpacing(1/params['fs'], 0, 0)
     data.PointData.append(x, 'sin')
Esempio n. 8
0
 def point_data(self):
     vtk_object = sm.Fetch(self.filter)
     vtk_object = dsa.WrapDataObject(vtk_object)
     pd_df = pd.DataFrame()
     for key in self.point_keys:
         temp_dataset = np.array(vtk_object.PointData[key]).transpose()
         if len(temp_dataset.shape) != 1:
             # The dataset is a vector:
             for idx, vector_element in enumerate(temp_dataset):
                 new_key = f"{key}{self.vector_keys[idx]}"
                 pd_df[new_key] = vector_element
         else:
             pd_df[key] = temp_dataset
     return pd_df.dropna()
Esempio n. 9
0
 def data_values(self):
     _vtk_object = sm.Fetch(self.vtk_file)
     _vtk_object = dsa.WrapDataObject(_vtk_object)
     return _vtk_object.PointData
Esempio n. 10
0
 def values(self):
     _vtk_object = sm.Fetch(self.current_array)
     _vtk_object = dsa.WrapDataObject(_vtk_object)
     return _vtk_object.PointData
Esempio n. 11
0
import numpy as np
from paraview.vtk.numpy_interface import dataset_adapter as dsa

# Script to get total volume of a thresholded tumor of all timesteps
# Pipeline: Input -> Threshold -> GroupTimeSteps -> ProgrammableFilter with this script
# Output: Outputs the #cells and the total volume of these cells per time-step

input = inputs[0]
print("Found input with keys ", dsa.WrapDataObject(input).PointData.keys())
if input.IsA("vtkCompositeDataSet"):
    numTimesteps = input.GetNumberOfBlocks()

    # process block
    for i in range(numTimesteps):
        print("Process timestep ", i)
        # get block
        block = input.GetBlock(
            i)  # type vtkCommonDataModelPython.vtkUnstructuredGrid
        block_np = dsa.WrapDataObject(
            input.GetBlock(i)
        )  # type paraview.vtk.numpy_interface.dataset_adapter.UnstructuredGrid
        # get volumes
        numTets = block.GetNumberOfCells()
        volumeArray = np.empty(numTets, dtype=np.float64)
        for j in range(numTets):
            cell = block.GetCell(j)
            p1 = block.GetPoint(cell.GetPointId(0))
            p2 = block.GetPoint(cell.GetPointId(1))
            p3 = block.GetPoint(cell.GetPointId(2))
            p4 = block.GetPoint(cell.GetPointId(3))
            volumeArray[j] = abs(vtk.vtkTetra.ComputeVolume(p1, p2, p3, p4))
Esempio n. 12
0
 def field_keys(self):
     vtk_object = sm.Fetch(self.filter)
     vtk_object = dsa.WrapDataObject(vtk_object)
     return vtk_object.FieldData.keys()
Esempio n. 13
0
 def point_keys(self):
     vtk_object = sm.Fetch(self.filter)
     vtk_object = dsa.WrapDataObject(vtk_object)
     return vtk_object.PointData.keys()
Esempio n. 14
0
 def cell_keys(self):
     vtk_object = sm.Fetch(self.filter)
     vtk_object = dsa.WrapDataObject(vtk_object)
     return vtk_object.CellData.keys()
Esempio n. 15
0
    zSlice.SliceOffsetValues = [0.0]

    zSlice.SliceType.Origin = [0.0, 0.0, spanwise_locations_m[i]]
    zSlice.SliceType.Normal = [0.0, 0.0, 1.0]

    UpdatePipeline()

    sortedLine = PlotOnSortedLines(Input=zSlice)
    UpdatePipeline()
    mergeBlocks2 = MergeBlocks(Input=sortedLine)
    UpdatePipeline()

    # stick data into useful array

    rawData = servermanager.Fetch(mergeBlocks2)
    data = dsa.WrapDataObject(rawData)

    results[i] = {}
    results[i]['spanwise_pctg'] = spanwise_locations_pctg[i]
    results[i]['spanwise_m'] = spanwise_locations_m[i]
    results[i]['p'] = data.PointData['p']
    results[i]['y'] = data.Points[:, 1]

    v_local = np.linalg.norm([omega * spanwise_locations_m[i], 15])
    print(v_local)

    results[i]['cp'] = np.zeros_like(results[i]['p'])
    results[i]['y/x'] = np.zeros_like(results[i]['y'])

    results[i]['cp'] = [(p - p_inf) / (0.5 * rho_inf * v_local ** 2) for p in results[i]['p']]