center = demReader.GetOutput().GetCenter() # Create a plane of onto which to map the elevation data plane = vtk.vtkPlaneSource() plane.SetResolution(res, res) plane.SetOrigin(bds[0], bds[2], bds[4]) plane.SetPoint1(bds[1], bds[2], bds[4]) plane.SetPoint2(bds[0], bds[3], bds[4]) plane.Update() # Gaussian kernel------------------------------------------------------- gaussianKernel = vtk.vtkGaussianKernel() gaussianKernel.SetSharpness(2) gaussianKernel.SetRadius(200) interp = vtk.vtkPointInterpolator2D() interp.SetInputConnection(plane.GetOutputPort()) interp.SetSourceConnection(demReader.GetOutputPort()) interp.SetKernel(gaussianKernel) interp.SetNullPointsStrategyToClosestPoint() interp.GetLocator().SetNumberOfPointsPerBucket(1) interp.InterpolateZOff() # Time execution timer = vtk.vtkTimerLog() timer.StartTimer() interp.Update() timer.StopTimer() time = timer.GetElapsedTime() print("Interpolate Terrain Points (Gaussian): {0}".format(time))
# Create a plane of onto which to map the elevation data plane = vtk.vtkPlaneSource() plane.SetResolution(res,res) plane.SetOrigin(bds[0],bds[2],bds[4]) plane.SetPoint1(bds[1],bds[2],bds[4]) plane.SetPoint2(bds[0],bds[3],bds[4]) plane.Update() # Gaussian kernel------------------------------------------------------- gaussianKernel = vtk.vtkGaussianKernel() gaussianKernel.SetSharpness(2) gaussianKernel.SetRadius(200) interp = vtk.vtkPointInterpolator2D() interp.SetInputConnection(plane.GetOutputPort()) interp.SetSourceConnection(demReader.GetOutputPort()) interp.SetKernel(gaussianKernel) interp.SetNullPointsStrategyToClosestPoint() interp.GetLocator().SetNumberOfPointsPerBucket(1) interp.InterpolateZOff() # Time execution timer = vtk.vtkTimerLog() timer.StartTimer() interp.Update() timer.StopTimer() time = timer.GetElapsedTime() print("Interpolate Terrain Points (Gaussian): {0}".format(time))
def npInterpolateVTK2D(npPoints, npValues, npTargetPoints, ParametreInterpolatorVTK=None): # Set SParameters if not define if ParametreInterpolatorVTK == None: ParametreInterpolatorVTK = { 'kernel': 'Gaussian', 'Radius': 20., 'Sharpness': 2. } print('[' + ParametreInterpolatorVTK['kernel'] + ' Interpolation - Radius =' + str(ParametreInterpolatorVTK['Radius']) + ' - Sharpness =' + str(ParametreInterpolatorVTK['Sharpness']) + '] processing... ') # Set Source Points UnGrid = vtk.vtkUnstructuredGrid() vtkP = vtk.vtkPoints() for [x, y] in npPoints: vtkP.InsertNextPoint(x, y, 0.) UnGrid.SetPoints(vtkP) # Set source Point Values l, c = npValues.shape for i in range(0, c): vtkFA = vtk.vtkFloatArray() vtkFA.SetName('Values' + str(i)) for v in npValues: vtkFA.InsertNextValue(v[i]) UnGrid.GetPointData().AddArray(vtkFA) # Set Target Points vtkTP = vtk.vtkPoints() for [x, y] in npTargetPoints: vtkTP.InsertNextPoint(x, y, 0.) vtkTargetPointsPolyData = vtk.vtkPolyData() vtkTargetPointsPolyData.SetPoints(vtkTP) if ParametreInterpolatorVTK['kernel'] == 'Gaussian': Kernel = vtk.vtkGaussianKernel() Kernel.SetSharpness(ParametreInterpolatorVTK['Sharpness']) Kernel.SetRadius(ParametreInterpolatorVTK['Radius']) if ParametreInterpolatorVTK['kernel'] == 'Voronoi': Kernel = vtk.vtkVoronoiKernel() if ParametreInterpolatorVTK['kernel'] == 'Shepard': Kernel = vtk.vtkShepardKernel() Kernel.SetRadius(ParametreInterpolatorVTK['Radius']) interp = vtk.vtkPointInterpolator2D() interp.SetInputData(vtkTargetPointsPolyData) interp.SetSourceData(UnGrid) interp.SetKernel(Kernel) # interp.GetLocator().SetNumberOfPointsPerBucket(1) interp.InterpolateZOff() interp.SetNullPointsStrategyToMaskPoints() interp.Update() outputInterp = interp.GetOutput() pointsArr = outputInterp.GetPoints().GetData() nppointsArr = vtk_to_numpy(pointsArr) pdata = outputInterp.GetPointData() # Convert volocities into Numpy Array npOutputValues = np.zeros((len(npTargetPoints), c)) for i in range(0, c): vtkOutputValues = pdata.GetArray('Values' + str(i)) npOutputValues[:, i] = vtk_to_numpy(vtkOutputValues) return npOutputValues