vtkfilters - VTK Filtering and Processing
@author Fraser Callaghan
- ngawari.vtkfilters.getArrayNames(data: vtkDataObject, pointData: bool = True) List[str][source]
Get the list of array names from a VTK data object.
- Parameters:
data (vtk.vtkDataObject) – The VTK data object.
pointData (bool) – Whether to get point data arrays.
- Returns:
The list of array names.
- Return type:
List[str]
- ngawari.vtkfilters.getArray(data: vtkDataObject, arrayName: str, pointData: bool = True) vtkAbstractArray[source]
Get an array from a VTK data object.
- Parameters:
data (vtk.vtkDataObject) – The VTK data object.
arrayName (str) – The name of the array to get.
pointData (bool) – Whether to get point data arrays.
- Returns:
The array.
- Return type:
vtk.vtkAbstractArray
- ngawari.vtkfilters.getScalarsArrayName(data: vtkDataObject, pointData: bool = True) str | None[source]
Get the name of the scalars array from a VTK data object.
- Parameters:
data (vtk.vtkDataObject) – The VTK data object.
pointData (bool) – Whether to get point data arrays [default: True].
- Returns:
The name of the scalars array (None if none found)
- Return type:
str
- ngawari.vtkfilters.getVectorsArrayName(data: vtkDataObject, pointData: bool = True) str | None[source]
- ngawari.vtkfilters.getArrayId(data: vtkDataObject, arrayName: str, pointData: bool = True) int | None[source]
Get the index of an array in a VTK data object.
- Parameters:
data (vtk.vtkDataObject) – The VTK data object.
arrayName (str) – The name of the array to get.
pointData (bool) – Whether to get point data arrays.
- Returns:
The index of the array.
- Return type:
Optional[int]
- ngawari.vtkfilters.renameArray(data: vtkDataObject, arrayNameOld: str, arrayNameNew: str, pointData: bool = True) None[source]
Rename an array in a VTK data object.
- Parameters:
data (vtk.vtkDataObject) – The VTK data object.
arrayNameOld (str) – The old name of the array.
arrayNameNew (str) – The new name of the array.
pointData (bool) – Whether to rename point (or cell)data arrays [default: True].
- ngawari.vtkfilters.getArrayAsNumpy(data: vtkDataObject, arrayName: str, RETURN_3D: bool = False, pointData: bool = True) ndarray[source]
Get an array from a VTK data object as a numpy array.
- Parameters:
data (vtk.vtkDataObject) – The VTK data object.
arrayName (str) – The name of the array.
RETURN_3D (bool) – Whether to return a 3D array [default: False].
pointData (bool) – Whether to get point data arrays [default: True].
- Returns:
The array.
- Return type:
np.ndarray
- ngawari.vtkfilters.getScalarsAsNumpy(data: vtkDataObject, RETURN_3D: bool = False, pointData: bool = True) ndarray[source]
Get the scalars as a numpy array.
- Parameters:
data (vtk.vtkDataObject) – The VTK data object.
RETURN_3D (bool) – Whether to return a 3D array [default: False].
pointData (bool) – Whether to get point (or cell) data scalars [default: True].
- Returns:
The scalars.
- Return type:
np.ndarray
- ngawari.vtkfilters.setArrayFromNumpy(data: vtkDataObject, npArray: ndarray, arrayName: str, SET_SCALAR: bool = False, SET_VECTOR: bool = False, IS_3D: bool = False, pointData: bool = True) None[source]
Add a numpy array to a VTK data object.
- Parameters:
data (vtk.vtkDataObject) – The VTK data object.
npArray (np.ndarray) – The numpy array.
arrayName (str) – The name of the array.
SET_SCALAR (bool) – Whether to set the array as scalars.
SET_VECTOR (bool) – Whether to set the array as vectors.
IS_3D (bool) – Whether the array is 3D.
pointData (bool) – Whether to add point data arrays [default: True].
- ngawari.vtkfilters.addNpArray(data: vtkDataObject, npArray: ndarray, arrayName: str, SET_SCALAR: bool = False, SET_VECTOR: bool = False, IS_3D: bool = False, pointData: bool = True) None[source]
Add a numpy array to a VTK data object. TO DEPRECIATE - RENAMED AS setArrayFromNumpy
- Parameters:
data (vtk.vtkDataObject) – The VTK data object.
npArray (np.ndarray) – The numpy array.
arrayName (str) – The name of the array.
SET_SCALAR (bool) – Whether to set the array as scalars.
SET_VECTOR (bool) – Whether to set the array as vectors.
IS_3D (bool) – Whether the array is 3D.
pointData (bool) – Whether to add point data arrays [default: True].
- ngawari.vtkfilters.setArrayDtype(data: vtkDataObject, arrayName: str, dtype: dtype, SET_SCALAR: bool = False, pointData: bool = True) None[source]
- ngawari.vtkfilters.setArrayAsScalars(data: vtkDataObject, arrayName: str, pointData: bool = True) None[source]
Set an array as scalars. Note: array must already be in data and if a scalars array already exists then it will be overwritten.
- Parameters:
data (vtk.vtkDataObject) – The VTK data object.
arrayName (str) – The name of the array (already in data).
pointData (bool) – Whether to set point data scalars [default: True].
- ngawari.vtkfilters.setArrayAsVectors(data: vtkDataObject, arrayName: str, pointData: bool = True) None[source]
Set an array as vectors. Note: array must already be in data and if a vectors array already exists then it will be overwritten.
- Parameters:
data (vtk.vtkDataObject) – The VTK data object.
arrayName (str) – The name of the array (already in data).
pointData (bool) – Whether to set point data vectors [default: True].
- ngawari.vtkfilters.ensureScalarsSet(data: vtkDataObject, possibleName: str | None = None, pointData: bool = True) str[source]
Ensure that scalars are set for a VTK data object. Necessary for some VTK filters. If no name given then first in list taken.
- Parameters:
data (vtk.vtkDataObject) – The VTK data object.
possibleName (Optional[str]) – The name of the array to set as scalars.
pointData (bool) – Whether to set point data scalars [default: True].
- Returns:
The name of the scalars array.
- Return type:
str
- ngawari.vtkfilters.delArray(data: vtkDataObject, arrayName: str, pointData: bool = True) None[source]
Delete an array from a VTK data object.
- Parameters:
data (vtk.vtkDataObject) – The VTK data object.
arrayName (str) – The name of the array to delete.
pointData (bool) – Whether to delete point data arrays [default: True].
- ngawari.vtkfilters.delArraysExcept(data: vtkDataObject, arrayNamesToKeep_list: List[str], pointData: bool = True) vtkDataObject[source]
Delete all arrays except the specified ones.
- Parameters:
data (vtk.vtkDataObject) – The VTK data object.
arrayNamesToKeep_list (List[str]) – The list of array names to keep.
pointData (bool) – Whether to delete point data arrays [default: True].
- Returns:
The data object with the specified arrays kept.
- Return type:
vtk.vtkDataObject
- ngawari.vtkfilters.getFieldDataDict(data: vtkDataObject) Dict[str, ndarray][source]
Get the field data as a dictionary. Note: will skip strings.
- Parameters:
data (vtk.vtkDataObject) – The VTK data object.
- Returns:
The field data.
- Return type:
Dict[str, np.ndarray]
- ngawari.vtkfilters.getFieldDataNames(data: vtkDataObject) List[str][source]
Get the field data names from a VTK data object.
- Parameters:
data (vtk.vtkDataObject) – The VTK data object.
- Returns:
The field data names.
- Return type:
List[str]
- ngawari.vtkfilters.duplicateFieldData(srcData: vtkDataObject, destData: vtkDataObject) None[source]
Duplicate the field data from one VTK data object to another.
- Parameters:
srcData (vtk.vtkDataObject) – The source VTK data object.
destData (vtk.vtkDataObject) – The destination VTK data object.
- ngawari.vtkfilters.deleteFieldData(data: vtkDataObject) vtkDataObject[source]
Remove the field data from a VTK data object.
- Parameters:
data (vtk.vtkDataObject) – The VTK data object.
- Returns:
The data object with the field data removed.
- Return type:
vtk.vtkDataObject
- ngawari.vtkfilters.getVtkPointsAsNumpy(data)[source]
Get the points as a numpy array.
- Parameters:
data (vtk.vtkDataObject) – The VTK data object.
- Returns:
The points.
- Return type:
np.ndarray
- ngawari.vtkfilters.getPtsAsNumpy(data)[source]
Get the points as a numpy array.
- Parameters:
data (vtk.vtkDataObject) – The VTK data object.
- Returns:
The points.
- Return type:
np.ndarray
- ngawari.vtkfilters.buildImplicitSphere(centerPt, radius)[source]
returns vtkSphere - for implicit functions etc use buildSphereSource if want polydata
- ngawari.vtkfilters.buildCylinderSource(centerPt, radius, height, res=8, norm=None)[source]
returns sphere polydata
- ngawari.vtkfilters.buildImplicitBox(faceCP, norm, boxWidth, boxThick)[source]
Builds a box so that the face cp is given and then a thick in the norm direction :param faceCP: :param norm: :param boxWidth: :param boxThick: :return:
- ngawari.vtkfilters.buildPolyLineBetweenTwoPoints(ptStart, ptEnd, nPts)[source]
build a poly line between start and end points, with nPts
- ngawari.vtkfilters.buildPlaneCentredOnRoi(roiVTK, PLANE_SIZE=None, RESOLUTION=None, subDivide=100)[source]
- ngawari.vtkfilters.buildPlaneCentredOnSphere(sphereVTK, structVTK, vecArrayName='Velocity_m_per_s', PLANE_SIZE=0.07, RESOLUTION=0.001)[source]
- ngawari.vtkfilters.buildPlaneCentredOnO(O, pointInplane, norm, PLANE_SIZE=0.07, RESOLUTION=0.001)[source]
- ngawari.vtkfilters.buildPolyLineFromXYZ(xyz, LOOP=False)[source]
build a poly line - if LOOP - then close with extra lineseg between last and first points
- ngawari.vtkfilters.getPolyDataClippedByROI(data, roi, INSIDE=False, axialDisplacement=0.02, closestPt=None, refNorm=None, boxWidth=None, boxWidthFactor=3.0)[source]
If no closest point given will return largest. refNorm points into volume
- ngawari.vtkfilters.getPolyDataClippedByBox(data, cp, norm, boxWidth, boxThick, INSIDE=False, closestPt=None, RETURN_FULL=False)[source]
Note - norm moves the box opposite so if inside then flip norm If no closest point given will return largest If closestPt == ‘CP-NORM’ then will use cp and norm and boxThick to calc closest pt
- ngawari.vtkfilters.clipVolumeToEightPolydataBoxes(data, RETURN_ptIDs)[source]
Clips same ordering as outline filter 6-7 4-5 | | 2-3 0-1 :param data: :param RETURN_ptIDs: much faster for downstream operations :return: 8 polydata surfs
- ngawari.vtkfilters.clipPlaneToROI(fullPlane, ROI)[source]
- Parameters:
fullPlane – a plane covering ROI
ROI – the ROI
- Returns:
plane cliped to pixels within the ROI stencil (polydata)
- ngawari.vtkfilters.getVarValueAtI_ImageData(imData, X, arrayName)[source]
Useful to get the vel value at a location from imdata :param imData: :param X: :param arrayName: :return: tuple
- ngawari.vtkfilters.getImageX(data, pointID)[source]
Get X from image matching pointID. NOTE: opposite: iXID = imData.FindPoint(X) :param data: image data :param pointID: int :return: tuple - the point x,y,z
- ngawari.vtkfilters.imageX_ToStructuredCoords(imageData, xyz_list)[source]
Note - this is no good if extracted a VOI from image already in this :
id2 = ii.FindPoint(xyz) ijk = vtkfilters.imageIndex_ToStructuredCoords(ii, [id2])
- ngawari.vtkfilters.getNeighbours26_fromImageIndex(imageData, index, delta=1, RETURN_STRUCTCOORDS=False)[source]
Get the 26 neighbours from an image index :param imageData: image data :param index: int :param delta: int :param RETURN_STRUCTCOORDS: bool :return: list of ints
- ngawari.vtkfilters.imageStrucCoords_toIndex(imageData, strucCoords_list)[source]
Convert structured coordinates to image indices :param imageData: image data :param strucCoords_list: list of tuples :return: list of ints
- ngawari.vtkfilters.contourFilter(data: vtkDataObject, isoValue: float) vtkPolyData[source]
Find the triangles that lie along the ‘isoValue’ contour.
- Parameters:
data (vtk.vtkDataObject) – The VTK data object.
isoValue (float) – The iso value.
- Returns:
The filtered data.
- Return type:
vtk.vtkPolyData
- ngawari.vtkfilters.cleanData(data: vtkDataObject, tolerance: float = 0.0, DO_POINT_MERGING: bool = True) vtkPolyData[source]
Cleans PolyData - merge points, remove pts not in cell, remove cells with no points etc. 30.9.14: Set default tol=0.0, should be faster merging as no look up
of every pt. See class docs
- ngawari.vtkfilters.filterBoolean(dataA, dataB, booleanOperationType)[source]
Perform a boolean operation on two datasets. Ensure that the data is triangulated.
- Parameters:
dataA (vtk.vtkDataObject) – The first dataset.
dataB (vtk.vtkDataObject) – The second dataset.
booleanOperationType (str) – The type of boolean operation to perform. Can be ‘union’, ‘intersection’, or ‘difference’.
- Returns:
The result of the boolean operation.
- Return type:
vtk.vtkPolyData
- ngawari.vtkfilters.tubeFilter(data, radius, nSides=12, CAPS=True)[source]
Convert a polyline to a tube.
- Parameters:
data (vtk.vtkDataObject) – The VTK data object.
radius (float) – The radius of the tube. If None then will use scalar of polydata
nSides (int, optional) – The number of sides of the tube. Defaults to 12.
CAPS (bool, optional) – Whether to cap the ends of the tube. Defaults to True.
- Returns:
The filtered data.
- Return type:
vtk.vtkPolyData
- ngawari.vtkfilters.filterTransformPolyData(polyData, scale=[1.0, 1.0, 1.0], disp=[0.0, 0.0, 0.0], rotate=None, matrix=None, rotateXYZ=None)[source]
- ngawari.vtkfilters.transformPolydataA_to_B_ICP(sourcePoly, target_poly, maxMeanDist, RIGID=False, AFFINE=False, internalIterations=50, maxLandmarks=1000)[source]
- ngawari.vtkfilters.iterativeClosestPointsTransform(sourcePoly, target_poly, maxMeanDist, RIGID=False, AFFINE=False, internalIterations=50, maxLandmarks=1000)[source]
Iterative Closest Points Transform
- Parameters:
sourcePoly (vtk.vtkPolyData) – The source polydata.
target_poly (vtk.vtkPolyData) – The target polydata.
maxMeanDist (float) – The maximum mean distance.
RIGID (bool, optional) – Whether to use rigid transformation. Defaults to False. (default Similarity)
AFFINE (bool, optional) – Whether to use affine transformation. Defaults to False. (default Similarity)
internalIterations (int, optional) – The number of internal iterations. Defaults to 50.
maxLandmarks (int, optional) – The maximum number of landmarks. Defaults to 1000.
- ngawari.vtkfilters.extractSelection(data, vtkSelection)[source]
Data = vtu, vtkSelection made from vtkSelectionNode, vtkSelection
- ngawari.vtkfilters.delCellsByEdgeLength(data, edgeLength)[source]
Delete cells with edges greater than edgeLength Returns unstructuredGrid
- ngawari.vtkfilters.delCellsByID(data, IDsToDEL)[source]
Delete cells from list of IDs Returns unstructuredGrid
- ngawari.vtkfilters.shrinkWrapData(data, wrappingData=None, DEFAULT_WRAP_RES=100)[source]
- Parameters:
data
wrappingData – if None - then just make a sphere larger
- Returns:
wrapped data
- ngawari.vtkfilters.getPolyDataCenterPtNormal(data, refNorm=None)[source]
return 2x np array center point, normal for each tri in poly data
- ngawari.vtkfilters.addNormalVelocities(data, normal, vecArrayName, vecArrayNameOut)[source]
Will add scalar array of normal velocity magnitude output array: fDC.varNameVelocityNormal
- ngawari.vtkfilters.mergeSurfsByPointsInsideVti(surf1: vtkDataObject | list, surf2=None, res=0.001)[source]
An alternative “boolean union” method.
- Parameters:
surf1 (Union[vtk.vtkDataObject, list]) – surfA or list of surfaces to bool union
surf2 (vtk.vtkDataObject, optional) – surfB. Defaults to None if surfA is list.
res (float, optional) – resolution to perform merging. Defaults to 0.001.
- Returns:
merged surface as polydata.
- Return type:
vtk.vtkDataObject
- ngawari.vtkfilters.addNormalsToPolyData(data, REV=False, SPLITTING=True, MANIFOLD=True)[source]
Add normals to polydata. This is a wrapper around vtkPolyDataNormals. See the vtk documentation for more details.
- Parameters:
data – vtkPolyData
REV – bool - reverse normals
SPLITTING – bool - split normals
MANIFOLD – bool - manifold normals
- Returns:
vtkPolyData with normals
- ngawari.vtkfilters.getBoundaryEdges(data)[source]
Get boundary edges of polydata. This is a wrapper around vtkFeatureEdges. See the vtk documentation for more details.
- Parameters:
data – vtkPolyData
- Returns:
vtkPolyData with boundary edges
- ngawari.vtkfilters.extractStructuredSubGrid(data, ijkMinMax=None, sampleRate=(1, 1, 1), TO_INCLUDE_BOUNDARY=False)[source]
Extract a structured subgrid from a vtkDataObject. This is a wrapper around vtkExtractGrid. See the vtk documentation for more details.
- Parameters:
data – vtkDataObject
ijkMinMax – tuple of ints - min and max indices
sampleRate – tuple of ints - sample rate
TO_INCLUDE_BOUNDARY – bool - include boundary
- Returns:
vtkDataObject
- ngawari.vtkfilters.extractVOI(data, ijkMinMax=None, sampleRate=(1, 1, 1))[source]
Extract a volume of interest from a vtkImageData. This is a wrapper around vtkExtractVOI. See the vtk documentation for more details.
- Parameters:
data – vtkImageData
ijkMinMax – tuple of ints - min and max indices
sampleRate – tuple of ints - sample rate
- Returns:
vtkDataObject
- ngawari.vtkfilters.extractVOI_fromFov(data, fovData)[source]
Extract a volume of interest from a vtkImageData. This is a wrapper around vtkExtractVOI. See the vtk documentation for more details. Locally this runs extractVOI using the bounds of the fovData.
- Parameters:
data – vtkImageData
fovData – vtkDataObject - volume of interest
- Returns:
vtkImageData
- ngawari.vtkfilters.filterNullOutsideSurface(vtkObj, surfObj, arrayListToNull=None, tfArray=None)[source]
Null out arrays outside a surface. This uses filterGetPointsInsideSurface to get a mask and then nulls out arrays outside the surface. See the vtk documentation for more details.
- Parameters:
vtkObj – vtkImageData or similar - data to null
surfObj – vtkPolyData - surface
arrayListToNull – list of strings - arrays to null
tfArray – numpy array - mask
- Returns:
vtkPolyData
- ngawari.vtkfilters.filterNullInsideSurface(vtkObj, surfObj, arrayListToNull=None, nullVal=0.0)[source]
Null out arrays inside a surface. This uses filterGetPointsInsideSurface to get a mask and then nulls out arrays inside the surface. See the vtk documentation for more details.
- Parameters:
vtkObj – vtkImageData or similar - data to null
surfObj – vtkPolyData - surface
arrayListToNull – list of strings - arrays to null
nullVal – float - value to null
- Returns:
vtkPolyData
- ngawari.vtkfilters.filterResampleToDataset(src, destData, PASS_POINTS=False)[source]
Resample data from src onto destData This is a wrapper around vtkProbeFilter. See the vtk documentation for more details.
- Parameters:
src – source vtkObj
destData – destination vtkObj
PASS_POINTS – bool [False] set true to pass point data from ‘destData’ to output
- Returns:
destData with interpolated point data from src
- ngawari.vtkfilters.filterResampleToImage(vtsObj, dims=None, bounder=None)[source]
Resample a vtkStructuredGrid or similar to an image.
- Parameters:
vtsObj – vtkStructuredGrid or similar
dims – tuple of ints - dimensions of image. Default is to use the dimensions of the vtsObj.
bounder – vtkPolyData - bounding box. Default is to use the bounds of the vtsObj.
- Returns:
vtkImageData
- ngawari.vtkfilters.filterResampleToImage_BestAligned(vtsObj)[source]
Resample a vtkStructuredGrid or similar to an image. This will align the image to the best axis-aligned orientation of the vtsObj. :param vtsObj: vtkStructuredGrid or similar :return: vtkImageData
- ngawari.vtkfilters.getAxesDirectionCosinesForNormal(normalVector, guidingVector=None)[source]
A good option is to set guidingVec to None for first and then to u for all others :param normalVector: :param guidingVector: :return:
- ngawari.vtkfilters.filterResliceImage(vtiObj, X, normalVector, guidingVector=None, slabNumberOfSlices=1, LINEAR_INTERPOLATION=False, MIP=False, OUTPUT_DIM=2)[source]
- This returns a reslice
add .GetOutput() to get the slice as imagedata
Example
ii = vtkfilters.filterResliceImage(vtiObj, X, n, [0,0,1]) iI = ii.GetOutput() axT = ii.GetResliceAxes() c = contourFilter(iI, 450) c = filterTransformPolyData(c, matrix=axT)
- Parameters:
vtiObj – vtiObject to reslice
X – loaction of slice center
normalVector – normal vector defining slice
guidingVector – 3_tuple - inplane vector to define slice x-axis [default None - will choose]
slabNumberOfSlices – int - to make a thick slice [default=1]
LINEAR_INTERPOLATION – bool - set true to have linear interpolation [default cubic]
MIP – bool - set true for thick slice to show MIP [default mean]
OUTPUT_DIM – int - set 3 for volume [default 2]
- Returns:
vtk.vtkImageReslice object
- ngawari.vtkfilters.filterImageGradient(data, arrayNameToCalcGradient, outputArrayName=None)[source]
Calculate the gradient of an image array. (du/dx, du/dy, du/dz, dv/dx, dv/dy, dv/dz, dw/dx, dw/dy, dw/dz)
- Parameters:
data – vtkImageData
arrayNameToCalcGradient – string - name of array to calculate gradient
outputArrayName – string - name of output array (default is arrayNameToCalcGradient + ‘-Gradient’)
- Returns:
vtkImageData with gradient array
- ngawari.vtkfilters.filterAnisotropicDiffusion(vtiObj, diffusionThreshold=10, diffusionFactor=1.0, iterations=5)[source]
- ngawari.vtkfilters.filterMaskImageBySurface(vtiObj, surf3D, fill_value=1, arrayName='LabelMap')[source]
Create a binary mask from a VTK image and a closed surface. The mask is added as an array to the input image.
- Parameters:
image_data – vtkImageData - The reference image that defines the output dimensions and spacing
surface – vtkPolyData - The closed surface to create mask from
fill_value – Value to use for the mask (default=1)
arrayName – Name of the array to use for the mask (default=”LabelMap”)
- Returns:
vtkImageData with same dimensions as input but containing binary mask
- ngawari.vtkfilters.filterGetPointsInsideSurface(data, surfaceData)[source]
classify points as inside(t) or outside(f) :param data: vtkObj :param surfaceData: closed polydata :return: vtkPolyData of points inside surface
- ngawari.vtkfilters.filterGetEnclosedPts(vtkObj, surf3D, RETURNTYPE='POLYDATA', tol=1e-10)[source]
Get all pts from vtkObj enclosed by surface. :param vtkObj: A vtkObj :param surf3D: A closed polydata surface :param RETURNTYPE: string - Options: ‘POLYDATA’ | ‘tf’ | ‘ID’ | ‘UNSTRUCT’ :param tol: default [0.00001] :return: polydata of points | np.array of true/false | list of IDs
- ngawari.vtkfilters.getDataWithThreshold(data, thresholdArrayName, thresholdLower, thresholdUpper)[source]
Get data within a threshold. This is a wrapper around vtkThreshold. See the vtk documentation for more details.
- Parameters:
data – vtkImageData or similar
thresholdArrayName – string - name of array to threshold
thresholdLower – float - lower threshold
thresholdUpper – float - upper threshold
- Returns:
vtkUnstructuredGrid
- ngawari.vtkfilters.countPointsInVti(vtiObj, objWithPoints, npArray=None, countArrayName='count', weightingArray=None)[source]
Add cell array “count” to vti with count of points from objWithPoints per cell
- Parameters:
vtiObj – vtkImageData or similar
objWithPoints – vtkPolyData or similar
npArray – numpy array - array to add count points to. default None
countArrayName – string - name of array to add - default “count”
weightingArray – string - name of array to weight points by - default None
- Returns:
vtkImageData with count array
- ngawari.vtkfilters.getConnectedRegionLargest(data: vtkDataObject) vtkPolyData[source]
Get the largest connected region from a vtkDataObject.
- Parameters:
data – vtkDataObject
- Returns:
vtkPolyData
- ngawari.vtkfilters.getConnectedRegionContaining(data: vtkDataObject, vtkId: int) vtkPolyData[source]
Get the connected region containing a given vtkId.
- Parameters:
data – vtkDataObject
vtkId – int
- Returns:
vtkPolyData
- ngawari.vtkfilters.getConnectedRegionClosestToX(data: vtkDataObject, X: ndarray) vtkDataObject[source]
Get the connected region closest to a given point.
- Parameters:
data – vtkDataObject
X – numpy array - point coordinates
- Returns:
vtkDataObject - vtkPolyData or vtkUnstructuredGrid
- ngawari.vtkfilters.getConnectedRegionClosestToX_UnStruct(data: vtkDataObject, X: ndarray) vtkDataObject[source]
- ngawari.vtkfilters.getConnectedRegionAll(data: vtkDataObject, minPts: int | None = None) List[vtkPolyData][source]
- ngawari.vtkfilters.getConnectedRegionMinDistToX(data: vtkDataObject, X: ndarray, minNPts: int = 10) vtkPolyData[source]
Like closest to X - but min dist on pt by pt (rather than closest center point :param data: :param X: :param minNPts: default 10 :return:
Data Type Checkers
Array Operations
- ngawari.vtkfilters.getArrayNames(data: vtkDataObject, pointData: bool = True) List[str][source]
Get the list of array names from a VTK data object.
- Parameters:
data (vtk.vtkDataObject) – The VTK data object.
pointData (bool) – Whether to get point data arrays.
- Returns:
The list of array names.
- Return type:
List[str]
- ngawari.vtkfilters.getArray(data: vtkDataObject, arrayName: str, pointData: bool = True) vtkAbstractArray[source]
Get an array from a VTK data object.
- Parameters:
data (vtk.vtkDataObject) – The VTK data object.
arrayName (str) – The name of the array to get.
pointData (bool) – Whether to get point data arrays.
- Returns:
The array.
- Return type:
vtk.vtkAbstractArray
- ngawari.vtkfilters.getArrayAsNumpy(data: vtkDataObject, arrayName: str, RETURN_3D: bool = False, pointData: bool = True) ndarray[source]
Get an array from a VTK data object as a numpy array.
- Parameters:
data (vtk.vtkDataObject) – The VTK data object.
arrayName (str) – The name of the array.
RETURN_3D (bool) – Whether to return a 3D array [default: False].
pointData (bool) – Whether to get point data arrays [default: True].
- Returns:
The array.
- Return type:
np.ndarray
- ngawari.vtkfilters.setArrayFromNumpy(data: vtkDataObject, npArray: ndarray, arrayName: str, SET_SCALAR: bool = False, SET_VECTOR: bool = False, IS_3D: bool = False, pointData: bool = True) None[source]
Add a numpy array to a VTK data object.
- Parameters:
data (vtk.vtkDataObject) – The VTK data object.
npArray (np.ndarray) – The numpy array.
arrayName (str) – The name of the array.
SET_SCALAR (bool) – Whether to set the array as scalars.
SET_VECTOR (bool) – Whether to set the array as vectors.
IS_3D (bool) – Whether the array is 3D.
pointData (bool) – Whether to add point data arrays [default: True].
- ngawari.vtkfilters.delArray(data: vtkDataObject, arrayName: str, pointData: bool = True) None[source]
Delete an array from a VTK data object.
- Parameters:
data (vtk.vtkDataObject) – The VTK data object.
arrayName (str) – The name of the array to delete.
pointData (bool) – Whether to delete point data arrays [default: True].
- ngawari.vtkfilters.renameArray(data: vtkDataObject, arrayNameOld: str, arrayNameNew: str, pointData: bool = True) None[source]
Rename an array in a VTK data object.
- Parameters:
data (vtk.vtkDataObject) – The VTK data object.
arrayNameOld (str) – The old name of the array.
arrayNameNew (str) – The new name of the array.
pointData (bool) – Whether to rename point (or cell)data arrays [default: True].
Geometry Creation
- ngawari.vtkfilters.buildCylinderSource(centerPt, radius, height, res=8, norm=None)[source]
returns sphere polydata
Filtering Operations
- ngawari.vtkfilters.contourFilter(data: vtkDataObject, isoValue: float) vtkPolyData[source]
Find the triangles that lie along the ‘isoValue’ contour.
- Parameters:
data (vtk.vtkDataObject) – The VTK data object.
isoValue (float) – The iso value.
- Returns:
The filtered data.
- Return type:
vtk.vtkPolyData
- ngawari.vtkfilters.cleanData(data: vtkDataObject, tolerance: float = 0.0, DO_POINT_MERGING: bool = True) vtkPolyData[source]
Cleans PolyData - merge points, remove pts not in cell, remove cells with no points etc. 30.9.14: Set default tol=0.0, should be faster merging as no look up
of every pt. See class docs
- ngawari.vtkfilters.filterBoolean(dataA, dataB, booleanOperationType)[source]
Perform a boolean operation on two datasets. Ensure that the data is triangulated.
- Parameters:
dataA (vtk.vtkDataObject) – The first dataset.
dataB (vtk.vtkDataObject) – The second dataset.
booleanOperationType (str) – The type of boolean operation to perform. Can be ‘union’, ‘intersection’, or ‘difference’.
- Returns:
The result of the boolean operation.
- Return type:
vtk.vtkPolyData
- ngawari.vtkfilters.tubeFilter(data, radius, nSides=12, CAPS=True)[source]
Convert a polyline to a tube.
- Parameters:
data (vtk.vtkDataObject) – The VTK data object.
radius (float) – The radius of the tube. If None then will use scalar of polydata
nSides (int, optional) – The number of sides of the tube. Defaults to 12.
CAPS (bool, optional) – Whether to cap the ends of the tube. Defaults to True.
- Returns:
The filtered data.
- Return type:
vtk.vtkPolyData
Clipping and Cutting
- ngawari.vtkfilters.getPolyDataClippedByBox(data, cp, norm, boxWidth, boxThick, INSIDE=False, closestPt=None, RETURN_FULL=False)[source]
Note - norm moves the box opposite so if inside then flip norm If no closest point given will return largest If closestPt == ‘CP-NORM’ then will use cp and norm and boxThick to calc closest pt
Image Data Operations
- ngawari.vtkfilters.filterResampleToImage(vtsObj, dims=None, bounder=None)[source]
Resample a vtkStructuredGrid or similar to an image.
- Parameters:
vtsObj – vtkStructuredGrid or similar
dims – tuple of ints - dimensions of image. Default is to use the dimensions of the vtsObj.
bounder – vtkPolyData - bounding box. Default is to use the bounds of the vtsObj.
- Returns:
vtkImageData
- ngawari.vtkfilters.filterResliceImage(vtiObj, X, normalVector, guidingVector=None, slabNumberOfSlices=1, LINEAR_INTERPOLATION=False, MIP=False, OUTPUT_DIM=2)[source]
- This returns a reslice
add .GetOutput() to get the slice as imagedata
Example
ii = vtkfilters.filterResliceImage(vtiObj, X, n, [0,0,1]) iI = ii.GetOutput() axT = ii.GetResliceAxes() c = contourFilter(iI, 450) c = filterTransformPolyData(c, matrix=axT)
- Parameters:
vtiObj – vtiObject to reslice
X – loaction of slice center
normalVector – normal vector defining slice
guidingVector – 3_tuple - inplane vector to define slice x-axis [default None - will choose]
slabNumberOfSlices – int - to make a thick slice [default=1]
LINEAR_INTERPOLATION – bool - set true to have linear interpolation [default cubic]
MIP – bool - set true for thick slice to show MIP [default mean]
OUTPUT_DIM – int - set 3 for volume [default 2]
- Returns:
vtk.vtkImageReslice object
Surface Operations
- ngawari.vtkfilters.filterGetPointsInsideSurface(data, surfaceData)[source]
classify points as inside(t) or outside(f) :param data: vtkObj :param surfaceData: closed polydata :return: vtkPolyData of points inside surface
- ngawari.vtkfilters.filterGetEnclosedPts(vtkObj, surf3D, RETURNTYPE='POLYDATA', tol=1e-10)[source]
Get all pts from vtkObj enclosed by surface. :param vtkObj: A vtkObj :param surf3D: A closed polydata surface :param RETURNTYPE: string - Options: ‘POLYDATA’ | ‘tf’ | ‘ID’ | ‘UNSTRUCT’ :param tol: default [0.00001] :return: polydata of points | np.array of true/false | list of IDs
- ngawari.vtkfilters.filterMaskImageBySurface(vtiObj, surf3D, fill_value=1, arrayName='LabelMap')[source]
Create a binary mask from a VTK image and a closed surface. The mask is added as an array to the input image.
- Parameters:
image_data – vtkImageData - The reference image that defines the output dimensions and spacing
surface – vtkPolyData - The closed surface to create mask from
fill_value – Value to use for the mask (default=1)
arrayName – Name of the array to use for the mask (default=”LabelMap”)
- Returns:
vtkImageData with same dimensions as input but containing binary mask