def update_pipeline(self): """Override this method so that it *updates* the tvtk pipeline when data upstream is known to have changed. This method is invoked (automatically) when the input fires a `pipeline_changed` event. """ if len(self.inputs) == 0: return input = self.inputs[0].outputs[0] plane = None if input.is_a('vtkStructuredGrid'): plane = tvtk.StructuredGridGeometryFilter() elif input.is_a('vtkStructuredPoints') or input.is_a('vtkImageData'): plane = tvtk.ImageDataGeometryFilter () elif input.is_a('vtkRectilinearGrid'): plane = tvtk.RectilinearGridGeometryFilter () else: msg = "The GridPlane component does not support the %s dataset."\ %(input.class_name) error(msg) raise TypeError, msg plane.input = input self.plane = plane self.outputs = [plane.output] self._update_limits() self._update_extents() # If the data is 2D make sure that we default to the # appropriate axis. extents = list(_get_extent(input)) diff = [y-x for x, y in zip(extents[::2], extents[1::2])] if diff.count(0) > 0: self.axis = ['x', 'y', 'z'][diff.index(0)]
def update_pipeline(self): """Override this method so that it *updates* the tvtk pipeline when data upstream is known to have changed. This method is invoked (automatically) when the input fires a `pipeline_changed` event. """ if len(self.inputs) == 0: return input = self.inputs[0].get_output_dataset() plane = None if input.is_a('vtkStructuredGrid'): plane = tvtk.StructuredGridGeometryFilter() elif input.is_a('vtkStructuredPoints') or input.is_a('vtkImageData'): plane = tvtk.ImageDataGeometryFilter() elif input.is_a('vtkRectilinearGrid'): plane = tvtk.RectilinearGridGeometryFilter() else: msg = "The GridPlane component does not support the %s dataset."\ %(input.class_name) error(msg) raise TypeError(msg) self.configure_connection(plane, self.inputs[0]) self.plane = plane self._update_limits() self._update_voi() self.outputs = [plane]
def test_tuple_array_handling(self): """Test if methods can take any sequence rather than only tuples.""" sg = tvtk.StructuredGridGeometryFilter() # setting a bogus value triggers an error since VTK assumes # that we want the extent set in the passed object. If we use # an Array type instead of a Tuple then we can pass in # a list and it should work OK. sg.extent = [0, -1, 0, -1, 0, -1]
return plot3d if __name__ == "__main__": plot3d = read_data() grid = plot3d.output.get_block(0) # 创建颜色映射表 import pylab as pl lut = tvtk.LookupTable() lut.table = pl.cm.cool(np.arange(0, 256)) * 255 # 显示StructuredGrid中的一个网格面 plane = tvtk.StructuredGridGeometryFilter(extent=(0, 100, 0, 100, 6, 6)) plane.set_input_data(grid) plane_mapper = tvtk.PolyDataMapper(input_connection=plane.output_port, lookup_table=lut) plane_mapper.scalar_range = grid.scalar_range plane_actor = tvtk.Actor(mapper=plane_mapper) lut2 = tvtk.LookupTable() lut2.table = pl.cm.cool(np.arange(0, 256)) * 255 cut_plane = tvtk.Plane(origin=grid.center, normal=(-0.287, 0, 0.9579)) cut = tvtk.Cutter(cut_function=cut_plane) cut.set_input_data(grid) cut_mapper = tvtk.PolyDataMapper(lookup_table=lut2, input_connection=cut.output_port) cut_actor = tvtk.Actor(mapper=cut_mapper) outline_actor = make_outline(grid)