def cellContainsPoint(inputs, locations): array = vtk.vtkDoubleArray() array.SetNumberOfComponents(3) array.SetNumberOfTuples(len(locations)) for i in range(len(locations)): array.SetTuple(i, locations[i]) node = vtk.vtkSelectionNode() node.SetFieldType(vtk.vtkSelectionNode.CELL) node.SetContentType(vtk.vtkSelectionNode.LOCATIONS) node.SetSelectionList(array) selection = vtk.vtkSelection() selection.AddNode(node) from vtk.vtkFiltersExtraction import vtkExtractSelectedLocations cellsNear = vtkExtractSelectedLocations() cellsNear.SetInputData(0, inputs[0].VTKObject) cellsNear.SetInputData(1, selection) cellsNear.Update() extractedCells = cellsNear.GetOutput() numCells = inputs[0].GetNumberOfCells() result = np.zeros((numCells, ), dtype=np.int8) extracted = dsa.WrapDataObject(extractedCells) cellIds = extracted.CellData.GetArray('vtkOriginalCellIds') if isinstance(cellIds, dsa.VTKCompositeDataArray): for a in cellIds.GetArrays(): result[a] = 1 else: result[cellIds] = 1 import vtk.util.numpy_support as np_s vtkarray = np_s.numpy_to_vtk(result, deep=True) return dsa.vtkDataArrayToVTKArray(vtkarray)
def pointIsNear(locations, distance, inputs): array = vtkDoubleArray() array.SetNumberOfComponents(3) array.SetNumberOfTuples(len(locations)) for i in range(len(locations)): array.SetTuple(i, locations[i]) node = vtkSelectionNode() node.SetFieldType(vtkSelectionNode.POINT) node.SetContentType(vtkSelectionNode.LOCATIONS) node.GetProperties().Set(vtkSelectionNode.EPSILON(), distance) node.SetSelectionList(array) from paraview.vtk.vtkFiltersExtraction import vtkLocationSelector selector = vtkLocationSelector() selector.SetInsidednessArrayName("vtkInsidedness") selector.Initialize(node) inputDO = inputs[0].VTKObject outputDO = inputDO.NewInstance() outputDO.CopyStructure(inputDO) output = dsa.WrapDataObject(outputDO) if outputDO.IsA('vtkCompositeDataSet'): it = inputDO.NewIterator() it.InitTraversal() while not it.IsDoneWithTraversal(): outputDO.SetDataSet(it, inputDO.GetDataSet(it).NewInstance()) it.GoToNextItem() selector.Execute(inputDO, outputDO) return output.PointData.GetArray('vtkInsidedness')
def cellContainsPoint(inputs, locations): array = vtkDoubleArray() array.SetNumberOfComponents(3) array.SetNumberOfTuples(len(locations)) for i in range(len(locations)): array.SetTuple(i, locations[i]) node = vtkSelectionNode() node.SetFieldType(vtkSelectionNode.CELL) node.SetContentType(vtkSelectionNode.LOCATIONS) node.SetSelectionList(array) selection = vtkSelection() selection.AddNode(node) from vtkmodules.vtkFiltersExtraction import vtkExtractSelectedLocations cellsNear = vtkExtractSelectedLocations() cellsNear.SetInputData(0, inputs[0].VTKObject) cellsNear.SetInputData(1, selection) cellsNear.Update() extractedCells = cellsNear.GetOutput() numCells = inputs[0].GetNumberOfCells() result = np.zeros((numCells,), dtype = np.int8) extracted = dsa.WrapDataObject(extractedCells) cellIds = extracted.CellData.GetArray('vtkOriginalCellIds') if isinstance(cellIds, dsa.VTKCompositeDataArray): for a in cellIds.GetArrays(): result[a] = 1 else: result[cellIds] = 1 import vtkmodules.util.numpy_support as np_s vtkarray = np_s.numpy_to_vtk(result, deep=True) return dsa.vtkDataArrayToVTKArray(vtkarray)
def pointIsNear(locations, distance, inputs): array = vtk.vtkDoubleArray() array.SetNumberOfComponents(3) array.SetNumberOfTuples(len(locations)) for i in range(len(locations)): array.SetTuple(i, locations[i]) node = vtk.vtkSelectionNode() node.SetFieldType(vtk.vtkSelectionNode.POINT) node.SetContentType(vtk.vtkSelectionNode.LOCATIONS) node.GetProperties().Set(vtk.vtkSelectionNode.EPSILON(), distance) node.SetSelectionList(array) selection = vtk.vtkSelection() selection.AddNode(node) from vtk.vtkFiltersExtraction import vtkExtractSelectedLocations pointsNear = vtkExtractSelectedLocations() pointsNear.SetInputData(0, inputs[0].VTKObject) pointsNear.SetInputData(1, selection) pointsNear.Update() extractedPoints = pointsNear.GetOutput() numPoints = inputs[0].GetNumberOfPoints() result = np.zeros((numPoints, ), dtype=np.int8) extracted = dsa.WrapDataObject(extractedPoints) pointIds = extracted.PointData.GetArray('vtkOriginalPointIds') result[pointIds] = 1 import vtk.util.numpy_support as np_s vtkarray = np_s.numpy_to_vtk(result, deep=True) return dsa.vtkDataArrayToVTKArray(vtkarray)
def pointIsNear(locations, distance, inputs): array = vtkDoubleArray() array.SetNumberOfComponents(3) array.SetNumberOfTuples(len(locations)) for i in range(len(locations)): array.SetTuple(i, locations[i]) node = vtkSelectionNode() node.SetFieldType(vtkSelectionNode.POINT) node.SetContentType(vtkSelectionNode.LOCATIONS) node.GetProperties().Set(vtkSelectionNode.EPSILON(), distance) node.SetSelectionList(array) from paraview.vtk.vtkFiltersExtraction import vtkLocationSelector selector = vtkLocationSelector() selector.Initialize(node, "vtkInsidedness") inputDO = inputs[0].VTKObject outputDO = inputDO.NewInstance() outputDO.CopyStructure(inputDO) output = dsa.WrapDataObject(outputDO) if outputDO.IsA('vtkCompositeDataSet'): it = inputDO.NewIterator() it.InitTraversal() while not it.IsDoneWithTraversal(): outputDO.SetDataSet(it, inputDO.GetDataSet(it).NewInstance()) it.GoToNextItem() selector.ComputeSelectedElements(inputDO, outputDO) return output.PointData.GetArray('vtkInsidedness')
def cellContainsPoint(inputs, locations): array = vtkDoubleArray() array.SetNumberOfComponents(3) array.SetNumberOfTuples(len(locations)) for i in range(len(locations)): array.SetTuple(i, locations[i]) node = vtkSelectionNode() node.SetFieldType(vtkSelectionNode.CELL) node.SetContentType(vtkSelectionNode.LOCATIONS) node.SetSelectionList(array) from paraview.vtk.vtkFiltersExtraction import vtkLocationSelector selector = vtkLocationSelector() selector.Initialize(node, "vtkInsidedness") inputDO = inputs[0].VTKObject outputDO = inputDO.NewInstance() outputDO.CopyStructure(inputDO) output = dsa.WrapDataObject(outputDO) if outputDO.IsA('vtkCompositeDataSet'): it = inputDO.NewIterator() it.InitTraversal() while not it.IsDoneWithTraversal(): outputDO.SetDataSet(it, inputDO.GetDataSet(it).NewInstance()) it.GoToNextItem() selector.ComputeSelectedElements(inputDO, outputDO) return output.CellData.GetArray('vtkInsidedness')
def pointIsNear(locations, distance, inputs): array = vtkDoubleArray() array.SetNumberOfComponents(3) array.SetNumberOfTuples(len(locations)) for i in range(len(locations)): array.SetTuple(i, locations[i]) node = vtkSelectionNode() node.SetFieldType(vtkSelectionNode.POINT) node.SetContentType(vtkSelectionNode.LOCATIONS) node.GetProperties().Set(vtkSelectionNode.EPSILON(), distance) node.SetSelectionList(array) selection = vtkSelection() selection.AddNode(node) from vtkmodules.vtkFiltersExtraction import vtkExtractSelectedLocations pointsNear = vtkExtractSelectedLocations() pointsNear.SetInputData(0, inputs[0].VTKObject) pointsNear.SetInputData(1, selection) pointsNear.Update() extractedPoints = pointsNear.GetOutput() numPoints = inputs[0].GetNumberOfPoints() result = np.zeros((numPoints,), dtype = np.int8) extracted = dsa.WrapDataObject(extractedPoints) pointIds = extracted.PointData.GetArray('vtkOriginalPointIds') if isinstance(pointIds, dsa.VTKCompositeDataArray): for a in pointIds.GetArrays(): result[a] = 1 else: result[pointIds] = 1 import vtkmodules.util.numpy_support as np_s vtkarray = np_s.numpy_to_vtk(result, deep=True) return dsa.vtkDataArrayToVTKArray(vtkarray)