def showGrid(view, cellSize=0.5, numberOfCells=25, name='grid', parent='sensors', color=[1,1,1], alpha=0.05, gridTransform=None, viewBoundsFunction=None): grid = vtk.vtkGridSource() grid.SetScale(cellSize) grid.SetGridSize(numberOfCells) grid.SetSurfaceEnabled(True) grid.Update() gridObj = showPolyData(grid.GetOutput(), name, view=view, alpha=alpha, color=color, visible=True, parent=parent) gridObj.gridSource = grid gridObj.actor.GetProperty().LightingOff() gridObj.actor.SetPickable(False) gridTransform = gridTransform or vtk.vtkTransform() gridObj.actor.SetUserTransform(gridTransform) showFrame(gridTransform, name + ' frame', scale=0.2, visible=False, parent=gridObj, view=view) gridObj.setProperty('Surface Mode', 'Wireframe') viewBoundsFunction = viewBoundsFunction or computeViewBoundsNoGrid def onViewBoundsRequest(): if view not in gridObj.views or not gridObj.getProperty('Visible'): return bounds = viewBoundsFunction(view, gridObj) if vtk.vtkMath.AreBoundsInitialized(bounds): view.addCustomBounds(bounds) else: view.addCustomBounds([-1, 1, -1, 1, -1, 1]) view.connect('computeBoundsRequest(ddQVTKWidgetView*)', onViewBoundsRequest) return gridObj
from director import visualization as vis from director import vtkAll as vtk from director import applogic from director import vtkNumpy as vnp from director.shallowCopy import shallowCopy import numpy as np app = consoleapp.ConsoleApp() view = app.createView(useGrid=False) cellSize = 0.5 numberOfCells = 10 grid = vtk.vtkGridSource() grid.SetScale(cellSize) grid.SetGridSize(numberOfCells) grid.SetSurfaceEnabled(True) grid.Update() grid = grid.GetOutput() pts = vnp.getNumpyFromVtk(grid, 'Points') print "pts ", np.shape(pts) print "pts is this ", pts #print "grid is this ", grid def evalXYpoly(x,y): return x**2 + 3*y**2 + x - y
from director import consoleapp from director import objectmodel as om from director import visualization as vis from director import vtkAll as vtk from director import applogic from director import vtkNumpy as vnp import numpy as np app = consoleapp.ConsoleApp() view = app.createView() cellSize = 0.5 numberOfCells = 20 grid = vtk.vtkGridSource() grid.SetScale(cellSize) grid.SetGridSize(numberOfCells) grid.SetSurfaceEnabled(True) grid.Update() grid = grid.GetOutput() pts = vnp.getNumpyFromVtk(grid, 'Points') heatMap = np.random.randn(len(pts)) vnp.addNumpyToVtk(grid, heatMap, 'heat_map') gridObj = vis.showPolyData(grid, 'heat map', colorByName='heat_map', parent='scene')