def create_glyph(self,plane_mapper): #in here we do the arrows arrows = vtk.vtkArrowSource() ptMask = vtk.vtkMaskPoints() ptMask.SetInputConnection(plane_mapper.GetOutputPort()) ptMask.SetOnRatio(10) ptMask.RandomModeOn() #in here we do the glyohs glyph = vtk.vtkGlyph3D() glyph.SetSourceConnection(arrows.GetOutputPort()) glyph.SetInputConnection(ptMask.GetOutputPort()) glyph.SetColorModeToColorByVector() glyph.SetScaleFactor(20) #Glyph mapper gly_mapper = vtk.vtkPolyDataMapper() gly_mapper.SetInputConnection(glyph.GetOutputPort()) gly_mapper.SetLookupTable(self.arrowColor) #glyph actor gly_actor = vtk.vtkActor() gly_actor.SetMapper(gly_mapper) return gly_actor
def __init__(self, points: np.ndarray = None, colors: np.ndarray = None): assert (points is None and colors is None) or (points is not None and colors is not None) self.num_points = 0 # VTK geometry representation self._points = vtk.vtkPoints() # VTK color representation self._colors = vtk.vtkUnsignedCharArray() self._colors.SetName("Colors") self._colors.SetNumberOfComponents(3) # Visualization pipeline # - Data source point_data = vtk.vtkPolyData() point_data.SetPoints(self._points) point_data.GetPointData().SetScalars(self._colors) # - Automatically generate topology cells from points mask_points = vtk.vtkMaskPoints() mask_points.SetInputData(point_data) mask_points.GenerateVerticesOn() mask_points.SingleVertexPerCellOn() mask_points.Update() # - Map the data representation to graphics primitives mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(mask_points.GetOutputPort()) super().__init__(mapper) self.add_points(points, colors)
def MakeGlyphs(src, normal_reverse, normal_arrowAtPoint): reverse = vtk.vtkReverseSense() maskPts = vtk.vtkMaskPoints() maskPts.SetOnRatio(1) if normal_reverse: reverse.SetInputData(src) reverse.ReverseCellsOn() reverse.ReverseNormalsOn() maskPts.SetInputConnection(reverse.GetOutputPort()) else: maskPts.SetInputData(src) arrow = vtk.vtkArrowSource() if normal_arrowAtPoint: arrow.SetInvert(1) else: arrow.SetInvert(0) arrow.SetTipResolution(16) arrow.SetTipLength(normal_length) arrow.SetTipRadius(normal_tip_radius) glyph = vtk.vtkGlyph3D() glyph.SetSourceConnection(arrow.GetOutputPort()) glyph.SetInputConnection(maskPts.GetOutputPort()) glyph.SetVectorModeToUseNormal() glyph.SetScaleFactor(normal_scale) if normal_scaleByPointScalar: glyph.SetScaleModeToScaleByScalar() else: glyph.SetScaleModeToScaleByVector() glyph.SetColorModeToColorByScalar() glyph.OrientOn() return glyph
def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__( self, module_manager, vtk.vtkMaskPoints(), 'Processing.', ('vtkDataSet',), ('vtkPolyData',), replaceDoc=True, inputFunctions=None, outputFunctions=None)
def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__(self, module_manager, vtk.vtkMaskPoints(), 'Processing.', ('vtkDataSet', ), ('vtkPolyData', ), replaceDoc=True, inputFunctions=None, outputFunctions=None)
def __init__(self, module_manager): ModuleBase.__init__(self, module_manager) InputArrayChoiceMixin.__init__(self) self._config.scaling = True self._config.scaleFactor = 1 self._config.scaleMode = glyphScaleMode.index('SCALE_BY_VECTOR') self._config.colourMode = glyphColourMode.index('COLOUR_BY_VECTOR') self._config.vectorMode = glyphVectorMode.index('USE_VECTOR') self._config.mask_on_ratio = 5 self._config.mask_random = True configList = [ ('Scale glyphs:', 'scaling', 'base:bool', 'checkbox', 'Should the size of the glyphs be scaled?'), ('Scale factor:', 'scaleFactor', 'base:float', 'text', 'By how much should the glyph size be scaled if scaling is ' 'active?'), ('Scale mode:', 'scaleMode', 'base:int', 'choice', 'Should scaling be performed by vector, scalar or only factor?', glyphScaleModeTexts), ('Colour mode:', 'colourMode', 'base:int', 'choice', 'Colour is determined based on scalar or vector magnitude.', glyphColourModeTexts), ('Vector mode:', 'vectorMode', 'base:int', 'choice', 'Should vectors or normals be used for scaling and orientation?', glyphVectorModeTexts), ('Vectors selection:', 'vectorsSelection', 'base:str', 'choice', 'The attribute that will be used as vectors for the warping.', (input_array_choice_mixin.DEFAULT_SELECTION_STRING,)), ('Mask on ratio:', 'mask_on_ratio', 'base:int', 'text', 'Every Nth point will be glyphed.'), ('Random masking:', 'mask_random', 'base:bool', 'checkbox', 'Pick random distribution of Nth points.')] self._mask_points = vtk.vtkMaskPoints() module_utils.setup_vtk_object_progress(self, self._mask_points, 'Masking points.') self._glyphFilter = vtk.vtkGlyph3D() asrc = vtk.vtkArrowSource() self._glyphFilter.SetSource(0, asrc.GetOutput()) self._glyphFilter.SetInput(self._mask_points.GetOutput()) module_utils.setup_vtk_object_progress(self, self._glyphFilter, 'Creating glyphs.') ScriptedConfigModuleMixin.__init__( self, configList, {'Module (self)' : self, 'vtkGlyph3D' : self._glyphFilter}) self.sync_module_logic_with_config()
def MakeGlyphs(src, reverseNormals): ''' Glyph the normals on the surface. You may need to adjust the parameters for maskPts, arrow and glyph for a nice appearance. :param: src - the surface to glyph. :param: reverseNormals - if True the normals on the surface are reversed. :return: The glyph object. ''' # Sometimes the contouring algorithm can create a volume whose gradient # vector and ordering of polygon (using the right hand rule) are # inconsistent. vtkReverseSense cures this problem. reverse = vtk.vtkReverseSense() # Choose a random subset of points. maskPts = vtk.vtkMaskPoints() maskPts.SetOnRatio(5) maskPts.RandomModeOn() if reverseNormals: reverse.SetInputData(src) reverse.ReverseCellsOn() reverse.ReverseNormalsOn() maskPts.SetInputConnection(reverse.GetOutputPort()) else: maskPts.SetInputData(src) # Source for the glyph filter arrow = vtk.vtkArrowSource() arrow.SetTipResolution(16) arrow.SetTipLength(0.3) arrow.SetTipRadius(0.1) glyph = vtk.vtkGlyph3D() glyph.SetSourceConnection(arrow.GetOutputPort()) glyph.SetInputConnection(maskPts.GetOutputPort()) glyph.SetVectorModeToUseNormal() glyph.SetScaleFactor(1) glyph.SetColorModeToColorByVector() glyph.SetScaleModeToScaleByVector() glyph.OrientOn() glyph.Update() return glyph
def normals(actor, ratio=5, c=(0.6, 0.6, 0.6), alpha=0.8, legend=None): ''' Build a vtkActor made of the normals at vertices shown as arrows [**Example1**](https://github.com/marcomusy/vtkplotter/blob/master/examples/tutorial.py) [**Example2**](https://github.com/marcomusy/vtkplotter/blob/master/examples/advanced/fatlimb.py) ''' maskPts = vtk.vtkMaskPoints() maskPts.SetOnRatio(ratio) maskPts.RandomModeOff() src = actor.polydata() maskPts.SetInputData(src) arrow = vtk.vtkLineSource() arrow.SetPoint1(0,0,0) arrow.SetPoint2(.75,0,0) glyph = vtk.vtkGlyph3D() glyph.SetSourceConnection(arrow.GetOutputPort()) glyph.SetInputConnection(maskPts.GetOutputPort()) glyph.SetVectorModeToUseNormal() b = src.GetBounds() sc = max([b[1]-b[0], b[3]-b[2], b[5]-b[4]])/20. glyph.SetScaleFactor(sc) glyph.SetColorModeToColorByVector() glyph.SetScaleModeToScaleByVector() glyph.OrientOn() glyph.Update() glyphMapper = vtk.vtkPolyDataMapper() glyphMapper.SetInputConnection(glyph.GetOutputPort()) glyphMapper.SetScalarModeToUsePointFieldData() glyphMapper.SetColorModeToMapScalars() glyphMapper.ScalarVisibilityOn() glyphMapper.SelectColorArray("Elevation") glyphActor = vtk.vtkActor() glyphActor.SetMapper(glyphMapper) glyphActor.GetProperty().EdgeVisibilityOff() glyphActor.GetProperty().SetColor(vc.getColor(c)) # check if color string contains a float, in this case ignore alpha al = vc.getAlpha(c) if al: alpha = al glyphActor.GetProperty().SetOpacity(alpha) glyphActor.PickableOff() aactor = Assembly([actor, glyphActor], legend=legend) return aactor
def createsuperquadrics(self, inputdata): mask = vtk.vtkMaskPoints() mask.SetInputConnection(inputdata) mask.RandomModeOn() mask.SetRandomModeType(2) mask.SetMaximumNumberOfPoints(10000) self.superquad.SetThetaResolution(self.tres) self.superquad.SetPhiResolution(self.phires) self.superquad.SetPhiRoundness(self.phiround) self.superquad.SetThetaRoundness(self.tround) self.superquad.ToroidalOff() self.tensorEllipsoids.SetInputConnection(mask.GetOutputPort()) self.tensorEllipsoids.SetSourceConnection( self.superquad.GetOutputPort()) self.tensorEllipsoids.ExtractEigenvaluesOn() self.tensorEllipsoids.ClampScalingOn() self.tensorEllipsoids.SetMaxScaleFactor(2) self.tensorEllipsoids.SetColorModeToEigenvalues() self.datacutmapper.SetInputConnection( self.tensorEllipsoids.GetOutputPort()) return self.dataCutActor.SetMapper(self.datacutmapper)
def GlyphActor(source, glyphPoints, scalarRange, scaleFactor, lut): """ Create the actor for glyphing the normals. :param: source: the surface. :param: glyphPoints: The number of points used by the mask filter. :param: scalarRange: The range in terms of scalar minimum and maximum. :param: scaleFactor: The scaling factor for the glyph. :param: lut: The lookup table to use. :return: The glyph actor. """ arrowSource = vtk.vtkArrowSource() # Subsample the dataset. maskPts = vtk.vtkMaskPoints() maskPts.SetInputConnection(source.GetOutputPort()) maskPts.SetOnRatio(source.GetOutput().GetNumberOfPoints() // glyphPoints) maskPts.SetRandomMode(1) arrowGlyph = vtk.vtkGlyph3D() arrowGlyph.SetScaleFactor(scaleFactor) arrowGlyph.SetVectorModeToUseNormal() arrowGlyph.SetColorModeToColorByScalar() arrowGlyph.SetScaleModeToScaleByVector() arrowGlyph.OrientOn() arrowGlyph.SetSourceConnection(arrowSource.GetOutputPort()) arrowGlyph.SetInputConnection(maskPts.GetOutputPort()) arrowGlyph.Update() arrowGlyphMapper = vtk.vtkDataSetMapper() # Colour by scalars. arrowGlyphMapper.SetScalarRange(scalarRange) arrowGlyphMapper.SetColorModeToMapScalars() arrowGlyphMapper.ScalarVisibilityOn() arrowGlyphMapper.SetLookupTable(lut) arrowGlyphMapper.SetInputConnection(arrowGlyph.GetOutputPort()) glyphActor = vtk.vtkActor() glyphActor.SetMapper(arrowGlyphMapper) return glyphActor
def onDraw(self, evt): """ Draw some random points on the screen. """ # Some random points as numpy array self.xyz = N.random.random((1000000, 3)) # Convert numpy array to a VTK array self.xyzVTK = numpy2vtk(self.xyz) # Create points points = vtk.vtkPoints() points.SetData(self.xyzVTK) # Make polydata from points pd = vtk.vtkPolyData() pd.SetPoints(points) # Point must be transformed to cells to be plotted. vtkMaskPoints can do it for us mask = vtk.vtkMaskPoints() mask.SetInput(pd) mask.GenerateVerticesOn() mask.SetOnRatio(1) # Define a mapper m = vtk.vtkPolyDataMapper() m.SetInput(mask.GetOutput()) # Define an actor actor = vtk.vtkActor() actor.SetMapper(m) # Add the actor to the vtkRenderer self.ren.AddActor(actor) # Reset the camera to view the dataset self.ren.ResetCamera() # Render the scene self.widget.Render()
def create_glyph(self,plane_mapper): ptMask = vtk.vtkMaskPoints() ptMask.SetInputConnection(plane_mapper.GetOutputPort()) ptMask.SetOnRatio(10) ptMask.RandomModeOn() arrows = vtk.vtkSphereSource() arrows.SetRadius(150) arrows.SetThetaResolution(35) arrows.SetPhiResolution(35) #in here we do the glyohs glyph = vtk.vtkTensorGlyph() glyph.SetSourceConnection(arrows.GetOutputPort()) glyph.SetInputConnection(ptMask.GetOutputPort()) glyph.SetScaleFactor(10) glyph.ColorGlyphsOn() glyph.SetColorModeToEigenvector() normals = vtk.vtkPolyDataNormals() normals.SetInputConnection(glyph.GetOutputPort()) #Glyph mapper gly_mapper = vtk.vtkPolyDataMapper() gly_mapper.SetInputConnection(normals.GetOutputPort()) gly_mapper.SetLookupTable(self.arrowColor) #glyph actor gly_actor = vtk.vtkActor() gly_actor.SetMapper(gly_mapper) return gly_actor
def __init__(self, dataset=None, name=None, image=None, gui_image=None): #################### # Public interface # #################### self.name = name ##################### # Private interface # ##################### self._dataset = None self._actor = vtkLODActor() self._image = None self._gui_image = None self._point_locator = vtkPointLocator() self._cell_locator = vtkCellLocator() self._point_locator_dirty = True self._cell_locator_dirty = True self._mapper = vtkPolyDataMapper() self._clipping_mapper = vtkPolyDataMapper() self._inside_out = True self._clipping_functions = None self._clippers = [] self._mask_filter = vtkMaskPoints() ################## # Initialization # ################## self._mask_filter.SetOnRatio(1) self._mask_filter.SetOffset(0) self._mask_filter.GenerateVerticesOn() self._actor.SetMapper(self._mapper) self._set_dataset(dataset) self.color_by_material() self._set_image(image) self._set_gui_image(image)
def normals(actor, ratio=5, c=(0.6, 0.6, 0.6), alpha=0.8, legend=None): ''' Build a vtkActor made of the normals at vertices shown as arrows ''' maskPts = vtk.vtkMaskPoints() maskPts.SetOnRatio(ratio) maskPts.RandomModeOff() src = vu.polydata(actor) vu.setInput(maskPts, src) arrow = vtk.vtkArrowSource() arrow.SetTipRadius(0.075) glyph = vtk.vtkGlyph3D() glyph.SetSourceConnection(arrow.GetOutputPort()) glyph.SetInputConnection(maskPts.GetOutputPort()) glyph.SetVectorModeToUseNormal() b = src.GetBounds() sc = max([b[1] - b[0], b[3] - b[2], b[5] - b[4]]) / 20. glyph.SetScaleFactor(sc) glyph.SetColorModeToColorByVector() glyph.SetScaleModeToScaleByVector() glyph.OrientOn() glyph.Update() glyphMapper = vtk.vtkPolyDataMapper() glyphMapper.SetInputConnection(glyph.GetOutputPort()) glyphMapper.SetScalarModeToUsePointFieldData() glyphMapper.SetColorModeToMapScalars() glyphMapper.ScalarVisibilityOn() glyphMapper.SelectColorArray("Elevation") glyphActor = vtk.vtkActor() glyphActor.SetMapper(glyphMapper) glyphActor.GetProperty().EdgeVisibilityOff() glyphActor.GetProperty().SetColor(vc.getColor(c)) # check if color string contains a float, in this case ignore alpha al = vc.getAlpha(c) if al: alpha = al glyphActor.GetProperty().SetOpacity(alpha) aactor = vu.makeAssembly([actor, glyphActor], legend=legend) return aactor
def main(): grid = vtk.vtkUnstructuredGrid() grid_mapper = vtk.vtkDataSetMapper() grid_mapper.SetInputData(grid) #grid_mapper.SetInputData(grid) nodes = np.array([ [0., 0., 0.], [1., 0., 0.], [1., 1., 0.], [0., 2., 1.], ], dtype='float32') points = vtk.vtkPoints() points.SetNumberOfPoints(4) points_array = numpy_to_vtk( num_array=nodes, deep=True, array_type=vtk.VTK_FLOAT, ) nelements = 1 grid.Allocate(nelements, 1000) grid.SetPoints(points) elem = vtk.vtkQuad() pts = elem.GetPointIds() pts.SetId(0, 0) pts.SetId(1, 1) pts.SetId(2, 2) pts.SetId(3, 3) grid.InsertNextCell(elem.GetCellType(), pts) grid.Modified() forces = np.array([ [0., 0.1, 0.], [0., 0., 0.], [0., 0., 0.], [0., 0., .3], ], dtype='float32') rend = vtk.vtkRenderer() if 1: maskPts = vtk.vtkMaskPoints() maskPts.SetInputData(grid) arrow = vtk.vtkArrowSource() arrow.SetTipResolution(16) arrow.SetTipLength(0.3) arrow.SetTipRadius(0.1) glyph = vtk.vtkGlyph3D() glyph.SetSourceConnection(arrow.GetOutputPort()) glyph.SetInputConnection(maskPts.GetOutputPort()) glyph.SetVectorModeToUseNormal() glyph.SetScaleFactor(1) glyph.SetColorModeToColorByVector() glyph.SetScaleModeToScaleByVector() glyph.OrientOn() glyph.Update() glyph_mapper = vtk.vtkPolyDataMapper() glyph_mapper.SetInputConnection(glyph.GetOutputPort()) glyph_mapper.SetScalarModeToUsePointFieldData() glyph_mapper.SetColorModeToMapScalars() glyph_mapper.ScalarVisibilityOn() glyph_mapper.SelectColorArray('Elevation') # Colour by scalars. #glyph_mapper.SetScalarRange(scalarRangeElevation) glyph_actor = vtk.vtkActor() glyph_actor.SetMapper(glyph_mapper) glyph_actor.RotateX(-45) glyph_actor.RotateZ(45) rend.AddViewProp(glyph_actor) #rend.AddActor(glyph_actor) geom_actor = vtk.vtkActor() geom_actor.SetMapper(grid_mapper) # ------------------------------------------------------------ # Create the RenderWindow, Renderer and Interactor # ------------------------------------------------------------ renWin = vtk.vtkRenderWindow() iren = vtk.vtkRenderWindowInteractor() renWin.AddRenderer(rend) iren.SetRenderWindow(renWin) # add actors #rend.AddViewProp(geom_actor) #rend.AddViewProp(edgeActor) rend.AddActor(geom_actor) #rend.AddViewProp(glyph_actor) #rend.AddActor2D(scalarBar) rend.SetBackground(0.7, 0.8, 1.0) renWin.SetSize(800, 800) renWin.Render() iren.Start()
def initialize (self): debug ("In MaskPoints::__init__ ()") self.fil = vtk.vtkMaskPoints () self.fil.SetInput (self.prev_fil.GetOutput ()) self.fil.Update ()
cut.Update() CG = timer.GetElapsedWallClockTime() print ("Cut and interpolate volume:", CG) cutMapper = vtk.vtkPolyDataMapper() cutMapper.SetInputConnection(cut.GetOutputPort()) cutMapper.SetScalarModeToUsePointFieldData() cutMapper.SelectColorArray("Implicit scalars") cutActor = vtk.vtkActor() cutActor.SetMapper(cutMapper) cutActor.GetProperty().SetColor(1,1,1) cutActor.GetProperty().SetOpacity(1) # Look at the vectors ranPts = vtk.vtkMaskPoints() ranPts.SetOnRatio(25) ranPts.SetInputConnection(cut.GetOutputPort()) hhog = vtk.vtkHedgeHog() hhog.SetInputConnection(ranPts.GetOutputPort()) hhog.SetVectorModeToUseVector() hhog.SetScaleFactor(0.05) hhogMapper = vtk.vtkPolyDataMapper() hhogMapper.SetInputConnection(hhog.GetOutputPort()) hhogActor = vtk.vtkActor() hhogActor.SetMapper(hhogMapper) hhogActor.GetProperty().SetColor(1,1,1) hhogActor.GetProperty().SetOpacity(1)
def main(): fileName = get_program_parameters() colors = vtk.vtkNamedColors() ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # Create the pipeline. # reader = vtk.vtkStructuredPointsReader() reader.SetFileName(fileName) threshold = vtk.vtkThresholdPoints() threshold.SetInputConnection(reader.GetOutputPort()) threshold.ThresholdByUpper(200) mask = vtk.vtkMaskPoints() mask.SetInputConnection(threshold.GetOutputPort()) mask.SetOnRatio(5) cone = vtk.vtkConeSource() cone.SetResolution(11) cone.SetHeight(1) cone.SetRadius(0.25) cones = vtk.vtkGlyph3D() cones.SetInputConnection(mask.GetOutputPort()) cones.SetSourceConnection(cone.GetOutputPort()) cones.SetScaleFactor(0.4) cones.SetScaleModeToScaleByVector() lut = vtk.vtkLookupTable() lut.SetHueRange(.667, 0.0) lut.Build() scalarRange = [0] * 2 cones.Update() scalarRange[0] = cones.GetOutput().GetPointData().GetScalars().GetRange( )[0] scalarRange[1] = cones.GetOutput().GetPointData().GetScalars().GetRange( )[1] print("range: ", scalarRange[0], ", ", scalarRange[1]) vectorMapper = vtk.vtkPolyDataMapper() vectorMapper.SetInputConnection(cones.GetOutputPort()) vectorMapper.SetScalarRange(scalarRange[0], scalarRange[1]) vectorMapper.SetLookupTable(lut) vectorActor = vtk.vtkActor() vectorActor.SetMapper(vectorMapper) # Speed contours. iso = vtk.vtkContourFilter() iso.SetInputConnection(reader.GetOutputPort()) iso.SetValue(0, 175) isoMapper = vtk.vtkPolyDataMapper() isoMapper.SetInputConnection(iso.GetOutputPort()) isoMapper.ScalarVisibilityOff() isoActor = vtk.vtkActor() isoActor.SetMapper(isoMapper) isoActor.GetProperty().SetRepresentationToWireframe() isoActor.GetProperty().SetOpacity(0.25) # Outline outline = vtk.vtkOutlineFilter() outline.SetInputConnection(reader.GetOutputPort()) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) outlineActor.GetProperty().SetColor(colors.GetColor3d("Black")) # Add the actors to the renderer, set the background and size. # ren1.AddActor(outlineActor) ren1.AddActor(vectorActor) ren1.AddActor(isoActor) ren1.SetBackground(colors.GetColor3d("Wheat")) renWin.SetSize(640, 480) renWin.SetWindowName('CarotidFlowGlyphs') cam1 = vtk.vtkCamera() cam1.SetClippingRange(17.4043, 870.216) cam1.SetFocalPoint(136.71, 104.025, 23) cam1.SetPosition(204.747, 258.939, 63.7925) cam1.SetViewUp(-0.102647, -0.210897, 0.972104) cam1.Zoom(1.2) ren1.SetActiveCamera(cam1) # Render the image. # renWin.Render() iren.Start()
time = timer.GetElapsedTime() print("Points processed: {0}".format(NPts)) print(" Time to generate normals: {0}".format(time)) #print(hBin) #print(hBin.GetOutput()) subMapper = vtk.vtkPointGaussianMapper() subMapper.SetInputConnection(norms.GetOutputPort()) subMapper.EmissiveOff() subMapper.SetScaleFactor(0.0) subActor = vtk.vtkActor() subActor.SetMapper(subMapper) # Draw the normals mask = vtk.vtkMaskPoints() mask.SetInputConnection(norms.GetOutputPort()) mask.SetRandomModeType(1) mask.SetMaximumNumberOfPoints(250) hhog = vtk.vtkHedgeHog() hhog.SetInputConnection(mask.GetOutputPort()) hhog.SetVectorModeToUseNormal() hhog.SetScaleFactor(0.25) hogMapper = vtk.vtkPolyDataMapper() hogMapper.SetInputConnection(hhog.GetOutputPort()) hogActor = vtk.vtkActor() hogActor.SetMapper(hogMapper)
def draw_vtk(nodes, elements, values=None, colors_count=256, contours_count=10, use_gray=False, title=None, background=(0.95, 0.95, 0.95), show_mesh=False, mesh_color=(0.25, 0.25, 0.25), use_cell_data=False, show_labels=False, show_axes=False): """ Function draws planar unstructured mesh using vtk :param show_axes: if it equals true than axes is drawn :param use_cell_data: if it equals true than cell data is used to colorize zones :param show_labels: if it equals true than labels are shown :param show_mesh: if it equals true than mesh lines are shown :param mesh_color: color of mesh lines (polygons edges) :param contours_count: Contour lines count :param title: Title of the scalar bar :param background: Background RGB-color value :param use_gray: if it equals true than gray-scale colormap is used :param colors_count: Colors count for values visualization :param nodes: nodes array [nodes_count; 2] :param elements: elements array [elements_count; element_nodes] :param values: values array (coloring rule) :return: nothing """ import vtk points = vtk.vtkPoints() for n in nodes: if len(n) == 2: points.InsertNextPoint([n[0], n[1], 0.0]) elif len(n) == 3: points.InsertNextPoint([n[0], n[1], n[2]]) cells_array = vtk.vtkCellArray() for el in elements: polygon = vtk.vtkPolygon() polygon.GetPointIds().SetNumberOfIds(len(el)) for i in range(len(el)): polygon.GetPointIds().SetId(i, el[i]) cells_array.InsertNextCell(polygon) lut = vtk.vtkLookupTable() lut.SetNumberOfTableValues(colors_count) lut.SetHueRange(0.66667, 0.0) if use_gray: lut.SetValueRange(1.0, 0.0) lut.SetSaturationRange(0.0, 0.0) # no color saturation lut.SetRampToLinear() lut.Build() renderer = vtk.vtkRenderer() renderer.SetBackground(background) render_window = vtk.vtkRenderWindow() render_window.AddRenderer(renderer) render_window_interactor = vtk.vtkRenderWindowInteractor() render_window_interactor.SetRenderWindow(render_window) bcf_actor = vtk.vtkActor() bcf_mapper = vtk.vtkPolyDataMapper() poly_data = vtk.vtkPolyData() poly_data.SetPoints(points) poly_data.SetPolys(cells_array) if values is not None: scalars = vtk.vtkFloatArray() for v in values: scalars.InsertNextValue(v) poly_data.GetPointData().SetScalars(scalars) bcf = vtk.vtkBandedPolyDataContourFilter() if vtk.VTK_MAJOR_VERSION <= 5: bcf.SetInput(poly_data) else: bcf.SetInputData(poly_data) if contours_count > 0: bcf.SetNumberOfContours(contours_count) bcf.GenerateValues(contours_count, [values.min(), values.max()]) bcf.SetNumberOfContours(contours_count + 1) bcf.GenerateContourEdgesOn() bcf.Update() bcf_mapper.ImmediateModeRenderingOn() if vtk.VTK_MAJOR_VERSION <= 5: bcf_mapper.SetInput(bcf.GetOutput()) else: bcf_mapper.SetInputData(bcf.GetOutput()) bcf_mapper.SetScalarRange(values.min(), values.max()) bcf_mapper.SetLookupTable(lut) bcf_mapper.ScalarVisibilityOn() if use_cell_data: bcf_mapper.SetScalarModeToUseCellData() bcf_actor.SetMapper(bcf_mapper) renderer.AddActor(bcf_actor) edge_mapper = vtk.vtkPolyDataMapper() if vtk.VTK_MAJOR_VERSION <= 5: edge_mapper.SetInput(bcf.GetContourEdgesOutput()) else: edge_mapper.SetInputData(bcf.GetContourEdgesOutput()) edge_mapper.SetResolveCoincidentTopologyToPolygonOffset() edge_actor = vtk.vtkActor() edge_actor.SetMapper(edge_mapper) if use_gray: edge_actor.GetProperty().SetColor(0.0, 1.0, 0.0) else: edge_actor.GetProperty().SetColor(0.0, 0.0, 0.0) renderer.AddActor(edge_actor) if show_labels: mask = vtk.vtkMaskPoints() if vtk.VTK_MAJOR_VERSION <= 5: mask.SetInput(bcf.GetOutput()) else: mask.SetInputData(bcf.GetOutput()) mask.SetOnRatio(bcf.GetOutput().GetNumberOfPoints() / 20) mask.SetMaximumNumberOfPoints(20) # Create labels for points - only show visible points visible_points = vtk.vtkSelectVisiblePoints() visible_points.SetInputConnection(mask.GetOutputPort()) visible_points.SetRenderer(renderer) ldm = vtk.vtkLabeledDataMapper() ldm.SetInputConnection(mask.GetOutputPort()) ldm.SetLabelFormat("%.2E") ldm.SetLabelModeToLabelScalars() text_property = ldm.GetLabelTextProperty() text_property.SetFontFamilyToArial() text_property.SetFontSize(10) if use_gray: text_property.SetColor(0.0, 1.0, 0.0) else: text_property.SetColor(0.0, 0.0, 0.0) text_property.ShadowOff() text_property.BoldOff() contour_labels = vtk.vtkActor2D() contour_labels.SetMapper(ldm) renderer.AddActor(contour_labels) scalar_bar = vtk.vtkScalarBarActor() scalar_bar.SetOrientationToHorizontal() scalar_bar.SetLookupTable(lut) if title is not None: scalar_bar.SetTitle(title) scalar_bar_widget = vtk.vtkScalarBarWidget() scalar_bar_widget.SetInteractor(render_window_interactor) scalar_bar_widget.SetScalarBarActor(scalar_bar) scalar_bar_widget.On() else: if vtk.VTK_MAJOR_VERSION <= 5: bcf_mapper.SetInput(poly_data) else: bcf_mapper.SetInputData(poly_data) bcf_actor.GetProperty().SetColor(0.0, 1.0, 0.0) if show_mesh: bcf_actor.GetProperty().EdgeVisibilityOn() bcf_actor.GetProperty().SetEdgeColor(mesh_color) bcf_actor.SetMapper(bcf_mapper) renderer.AddActor(bcf_actor) if show_axes: axes = vtk.vtkAxesActor() renderer.AddActor(axes) render_window.Render() render_window_interactor.Start()
cut.Update() CG = timer.GetElapsedWallClockTime() print("Cut and interpolate volume:", CG) cutMapper = vtk.vtkPolyDataMapper() cutMapper.SetInputConnection(cut.GetOutputPort()) cutMapper.SetScalarModeToUsePointFieldData() cutMapper.SelectColorArray("Implicit scalars") cutActor = vtk.vtkActor() cutActor.SetMapper(cutMapper) cutActor.GetProperty().SetColor(1, 1, 1) cutActor.GetProperty().SetOpacity(1) # Look at the vectors ranPts = vtk.vtkMaskPoints() ranPts.SetOnRatio(25) ranPts.SetInputConnection(cut.GetOutputPort()) hhog = vtk.vtkHedgeHog() hhog.SetInputConnection(ranPts.GetOutputPort()) hhog.SetVectorModeToUseVector() hhog.SetScaleFactor(0.05) hhogMapper = vtk.vtkPolyDataMapper() hhogMapper.SetInputConnection(hhog.GetOutputPort()) hhogActor = vtk.vtkActor() hhogActor.SetMapper(hhogMapper) hhogActor.GetProperty().SetColor(1, 1, 1) hhogActor.GetProperty().SetOpacity(1)
def draw_vtk(nodes, elements, values=None, colors_count=256, contours_count=10, use_gray=False, title=None, background=(0.95, 0.95, 0.95), show_mesh=False, mesh_color=(0.25, 0.25, 0.25), use_cell_data=False, show_labels=False, show_axes=False): """ Function draws planar unstructured mesh using vtk :param show_axes: if it equals true than axes is drawn :param use_cell_data: if it equals true than cell data is used to colorize zones :param show_labels: if it equals true than labels are shown :param show_mesh: if it equals true than mesh lines are shown :param mesh_color: color of mesh lines (polygons edges) :param contours_count: Contour lines count :param title: Title of the scalar bar :param background: Background RGB-color value :param use_gray: if it equals true than gray-scale colormap is used :param colors_count: Colors count for values visualization :param nodes: nodes array [nodes_count; 2] :param elements: elements array [elements_count; element_nodes] :param values: values array (coloring rule) :return: nothing """ import vtk points = vtk.vtkPoints() for n in nodes: points.InsertNextPoint([n[0], n[1], 0.0]) cells_array = vtk.vtkCellArray() for el in elements: polygon = vtk.vtkPolygon() polygon.GetPointIds().SetNumberOfIds(len(el)) for i in range(len(el)): polygon.GetPointIds().SetId(i, el[i]) cells_array.InsertNextCell(polygon) lut = vtk.vtkLookupTable() lut.SetNumberOfTableValues(colors_count) lut.SetHueRange(0.66667, 0.0) if use_gray: lut.SetValueRange(1.0, 0.0) lut.SetSaturationRange(0.0, 0.0) # no color saturation lut.SetRampToLinear() lut.Build() renderer = vtk.vtkRenderer() renderer.SetBackground(background) render_window = vtk.vtkRenderWindow() render_window.AddRenderer(renderer) render_window_interactor = vtk.vtkRenderWindowInteractor() render_window_interactor.SetRenderWindow(render_window) bcf_actor = vtk.vtkActor() bcf_mapper = vtk.vtkPolyDataMapper() poly_data = vtk.vtkPolyData() poly_data.SetPoints(points) poly_data.SetPolys(cells_array) if values is not None: scalars = vtk.vtkFloatArray() for v in values: scalars.InsertNextValue(v) poly_data.GetPointData().SetScalars(scalars) bcf = vtk.vtkBandedPolyDataContourFilter() if vtk.VTK_MAJOR_VERSION <= 5: bcf.SetInput(poly_data) else: bcf.SetInputData(poly_data) bcf.SetNumberOfContours(contours_count) bcf.GenerateValues(contours_count, [values.min(), values.max()]) bcf.SetNumberOfContours(contours_count + 1) bcf.SetScalarModeToValue() bcf.GenerateContourEdgesOn() bcf.Update() bcf_mapper.ImmediateModeRenderingOn() if vtk.VTK_MAJOR_VERSION <= 5: bcf_mapper.SetInput(bcf.GetOutput()) else: bcf_mapper.SetInputData(bcf.GetOutput()) bcf_mapper.SetScalarRange(values.min(), values.max()) bcf_mapper.SetLookupTable(lut) bcf_mapper.ScalarVisibilityOn() if use_cell_data: bcf_mapper.SetScalarModeToUseCellData() bcf_actor.SetMapper(bcf_mapper) renderer.AddActor(bcf_actor) edge_mapper = vtk.vtkPolyDataMapper() if vtk.VTK_MAJOR_VERSION <= 5: edge_mapper.SetInput(bcf.GetContourEdgesOutput()) else: edge_mapper.SetInputData(bcf.GetContourEdgesOutput()) edge_mapper.SetResolveCoincidentTopologyToPolygonOffset() edge_actor = vtk.vtkActor() edge_actor.SetMapper(edge_mapper) if use_gray: edge_actor.GetProperty().SetColor(0.0, 1.0, 0.0) else: edge_actor.GetProperty().SetColor(0.0, 0.0, 0.0) renderer.AddActor(edge_actor) if show_labels: mask = vtk.vtkMaskPoints() if vtk.VTK_MAJOR_VERSION <= 5: mask.SetInput(bcf.GetOutput()) else: mask.SetInputData(bcf.GetOutput()) mask.SetOnRatio(bcf.GetOutput().GetNumberOfPoints() / 20) mask.SetMaximumNumberOfPoints(20) # Create labels for points - only show visible points visible_points = vtk.vtkSelectVisiblePoints() visible_points.SetInputConnection(mask.GetOutputPort()) visible_points.SetRenderer(renderer) ldm = vtk.vtkLabeledDataMapper() ldm.SetInputConnection(mask.GetOutputPort()) ldm.SetLabelFormat("%.2E") ldm.SetLabelModeToLabelScalars() text_property = ldm.GetLabelTextProperty() text_property.SetFontFamilyToArial() text_property.SetFontSize(10) if use_gray: text_property.SetColor(0.0, 1.0, 0.0) else: text_property.SetColor(0.0, 0.0, 0.0) text_property.ShadowOff() text_property.BoldOff() contour_labels = vtk.vtkActor2D() contour_labels.SetMapper(ldm) renderer.AddActor(contour_labels) scalar_bar = vtk.vtkScalarBarActor() scalar_bar.SetOrientationToHorizontal() scalar_bar.SetLookupTable(lut) if title is not None: scalar_bar.SetTitle(title) scalar_bar_widget = vtk.vtkScalarBarWidget() scalar_bar_widget.SetInteractor(render_window_interactor) scalar_bar_widget.SetScalarBarActor(scalar_bar) scalar_bar_widget.On() else: if vtk.VTK_MAJOR_VERSION <= 5: bcf_mapper.SetInput(poly_data) else: bcf_mapper.SetInputData(poly_data) bcf_actor.GetProperty().SetColor(0.0, 1.0, 0.0) if show_mesh: bcf_actor.GetProperty().EdgeVisibilityOn() bcf_actor.GetProperty().SetEdgeColor(mesh_color) bcf_actor.SetMapper(bcf_mapper) renderer.AddActor(bcf_actor) if show_axes: axes = vtk.vtkAxesActor() renderer.AddActor(axes) render_window.Render() render_window_interactor.Start()
plane2.SetNormal(0, 0, 1) #Interesting Cut down the center, shows brain stem plane3.SetOrigin([125., centery, centerz]) plane3.SetNormal(1, 0, 0) plane4.SetOrigin([centerx, centery, centerz]) plane4.SetNormal(0, 1, 0) plane1Cut = vtk.vtkCutter() plane1Cut.SetInputConnection(reader.GetOutputPort()) plane1Cut.SetCutFunction(plane1) onratio = 5 downsampled1 = vtk.vtkMaskPoints() downsampled1.SetInputConnection(plane1Cut.GetOutputPort()) downsampled1.SetOnRatio(onratio) downsampled1.RandomModeOff() plane2Cut = vtk.vtkCutter() plane2Cut.SetInputConnection(reader.GetOutputPort()) plane2Cut.SetCutFunction(plane2) downsampled2 = vtk.vtkMaskPoints() downsampled2.SetInputConnection(plane2Cut.GetOutputPort()) downsampled2.SetOnRatio(onratio) downsampled2.RandomModeOff() plane3Cut = vtk.vtkCutter() plane3Cut.SetInputConnection(reader.GetOutputPort())
def main(): fileName = r"carotid.vtk" colors = vtk.vtkNamedColors() ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # Create the pipeline. reader = vtk.vtkStructuredPointsReader() reader.SetFileName(fileName) threshold = vtk.vtkThresholdPoints() threshold.SetInputConnection(reader.GetOutputPort()) threshold.ThresholdByUpper(200) mask = vtk.vtkMaskPoints() mask.SetInputConnection(threshold.GetOutputPort()) mask.SetOnRatio(5) cone = vtk.vtkConeSource() cone.SetResolution(11) cone.SetHeight(1) cone.SetRadius(0.25) cones = vtk.vtkGlyph3D() cones.SetInputConnection(mask.GetOutputPort()) cones.SetSourceConnection(cone.GetOutputPort()) cones.SetScaleFactor(0.4) cones.SetScaleModeToScaleByVector() lut = vtk.vtkLookupTable() lut.SetHueRange(.667, 0.0) lut.Build() scalarRange = [0] * 2 cones.Update() scalarRange[0] = cones.GetOutput().GetPointData().GetScalars().GetRange( )[0] scalarRange[1] = cones.GetOutput().GetPointData().GetScalars().GetRange( )[1] vectorMapper = vtk.vtkPolyDataMapper() vectorMapper.SetInputConnection(cones.GetOutputPort()) vectorMapper.SetScalarRange(scalarRange[0], scalarRange[1]) vectorMapper.SetLookupTable(lut) vectorActor = vtk.vtkActor() vectorActor.SetMapper(vectorMapper) # Speed contours. iso = vtk.vtkContourFilter() iso.SetInputConnection(reader.GetOutputPort()) iso.SetValue(0, 175) isoMapper = vtk.vtkPolyDataMapper() isoMapper.SetInputConnection(iso.GetOutputPort()) isoMapper.ScalarVisibilityOff() isoActor = vtk.vtkActor() isoActor.SetMapper(isoMapper) isoActor.GetProperty().SetRepresentationToWireframe() isoActor.GetProperty().SetOpacity(0.25) # Outline outline = vtk.vtkOutlineFilter() outline.SetInputConnection(reader.GetOutputPort()) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) outlineActor.GetProperty().SetColor(0., 0., 0.) # Add the actors to the renderer, set the background and size. ren1.AddActor(outlineActor) ren1.AddActor(vectorActor) ren1.AddActor(isoActor) ren1.SetBackground(1., 1., 1.) renWin.SetSize(640, 480) ren1.ResetCamera() ren1.ResetCameraClippingRange() # Render the image. renWin.Render() iren.Start()
def main(vector_file, magnitude_file): num_critical_points = 6 CriticalPoints = vtk.vtkPoints() CriticalPoints.InsertNextPoint(35, 14, 20) CriticalPoints.InsertNextPoint(55, 15, 20) CriticalPoints.InsertNextPoint(65, 45, 19) CriticalPoints.InsertNextPoint(45, 44.8, 20) CriticalPoints.InsertNextPoint(20, 29.7, 19.8) CriticalPoints.InsertNextPoint(10, 32.2, 16.1) ColorRange = vtk.vtkLookupTable() ColorRange.SetTableRange(0, 1) ColorRange.SetHueRange(0, 1) ColorRange.SetSaturationRange(1, 1) ColorRange.SetAlphaRange(0.3, 0.5) ColorRange.Build() reader = vtk.vtkStructuredPointsReader() reader.SetFileName(vector_file) reader.Update() mags = reader.GetOutput() range1 = mags.GetScalarRange() v0 = range1[0] v1 = range1[1] reader_magnitude = vtk.vtkStructuredPointsReader() reader_magnitude.SetFileName(magnitude_file) reader_magnitude.Update() # All entities initialized equal to number of critical points sphere1, stream1, scalarSurface1, tube1, dataMapper1, dataActor1, criticalMarker1, criticalMapper1, criticalActor1, probe1, mask1, glyph1, glyphMapper1, glyphActor1, plane1 = ( [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], ) for i in range(0, num_critical_points): sphere1.append(vtk.vtkSphereSource()) stream1.append(vtk.vtkStreamLine()) scalarSurface1.append(vtk.vtkRuledSurfaceFilter()) tube1.append(vtk.vtkTubeFilter()) dataMapper1.append(vtk.vtkPolyDataMapper()) dataActor1.append(vtk.vtkActor()) criticalMarker1.append(vtk.vtkSphereSource()) criticalMapper1.append(vtk.vtkPolyDataMapper()) criticalActor1.append(vtk.vtkActor()) probe1.append(vtk.vtkProbeFilter()) mask1.append(vtk.vtkMaskPoints()) glyph1.append(vtk.vtkGlyph3D()) glyphMapper1.append(vtk.vtkPolyDataMapper()) glyphActor1.append(vtk.vtkActor()) plane1.append(vtk.vtkPlaneSource()) integ = vtk.vtkRungeKutta4() cone = vtk.vtkConeSource() cone.SetResolution(8) cone.SetHeight(1.0) cone.SetRadius(0.2) transform = vtk.vtkTransform() transform.Translate(0, 0, 0) transformFilter = vtk.vtkTransformPolyDataFilter() transformFilter.SetInput(cone.GetOutput()) transformFilter.SetTransform(transform) outline = vtk.vtkOutlineFilter() outline.SetInput(reader.GetOutput()) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInput(outline.GetOutput()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) outlineActor.GetProperty().SetColor(1, 1, 1) bar = vtk.vtkScalarBarActor() bar.SetLookupTable(ColorRange) renderer = vtk.vtkRenderer() for i in range(0, num_critical_points): sphere1[i].SetRadius(2) sphere1[i].SetCenter( CriticalPoints.GetPoint(i)[0], CriticalPoints.GetPoint(i)[1], CriticalPoints.GetPoint(i)[2] ) sphere1[i].SetThetaResolution(1) stream1[i].SetInput(reader.GetOutput()) stream1[i].SetSource(sphere1[i].GetOutput()) stream1[i].SetIntegrator(integ) stream1[i].SetMaximumPropagationTime(500) stream1[i].SetIntegrationStepLength(0.1) stream1[i].SetIntegrationDirectionToIntegrateBothDirections() stream1[i].SetStepLength(0.1) scalarSurface1[i].SetInput(stream1[i].GetOutput()) scalarSurface1[i].SetOffset(0) scalarSurface1[i].SetOnRatio(2) scalarSurface1[i].PassLinesOn() scalarSurface1[i].SetRuledModeToPointWalk() scalarSurface1[i].SetDistanceFactor(50) tube1[i].SetInput(scalarSurface1[i].GetOutput()) tube1[i].SetRadius(0.1) tube1[i].SetNumberOfSides(6) dataMapper1[i].SetInput(tube1[i].GetOutput()) dataMapper1[i].SetScalarRange(v0, v1) dataMapper1[i].SetLookupTable(ColorRange) dataActor1[i].SetMapper(dataMapper1[i]) # renderer.AddActor(dataActor1[i]) criticalMarker1[i].SetRadius(1.0) criticalMarker1[i].SetCenter( CriticalPoints.GetPoint(i)[0], CriticalPoints.GetPoint(i)[1], CriticalPoints.GetPoint(i)[2] ) criticalMarker1[i].SetThetaResolution(10) criticalMapper1[i].SetInput(criticalMarker1[i].GetOutput()) criticalActor1[i].SetMapper(criticalMapper1[i]) criticalActor1[i].GetProperty().SetColor(1, 1, 0) criticalActor1[i].GetProperty().SetOpacity(0.5) # renderer.AddActor(criticalActor1[i]) probe1[i].SetInput(stream1[i].GetOutput()) probe1[i].SetSource(reader.GetOutput()) mask1[i].SetInput(probe1[i].GetOutput()) mask1[i].SetOnRatio(60) mask1[i].RandomModeOn() glyph1[i].SetInput(mask1[i].GetOutput()) glyph1[i].SetSource(transformFilter.GetOutput()) glyph1[i].SetScaleModeToScaleByVector() glyph1[i].SetScaleFactor(2) glyph1[i].SetVectorModeToUseVector() glyph1[i].SetColorModeToColorByVector() glyphMapper1[i].SetInput(glyph1[i].GetOutput()) glyphMapper1[i].SetLookupTable(ColorRange) glyphActor1[i].SetMapper(glyphMapper1[i]) # renderer.AddActor(glyphActor1[i]) # removeActors1(renderer, dataActor, criticalActor, glyphActor, dataActor1, criticalActor1, glyphActor1) mags = reader.GetOutput() bounds = mags.GetBounds() x0 = bounds[0] x1 = bounds[1] y0 = bounds[2] y1 = bounds[3] z0 = bounds[4] z1 = bounds[5] range1 = mags.GetScalarRange() v0 = range1[0] v1 = range1[1] plane1[0].SetOrigin(x0, y0, z0) plane1[0].SetPoint1(x0, y1, z0) plane1[0].SetPoint2(x0, y0, z1) plane1[1].SetOrigin(x0, y0, z0) plane1[1].SetPoint1(x0, y1, z0) plane1[1].SetPoint2(x1, y0, z0) plane1[2].SetOrigin(x0, y0, z0) plane1[2].SetPoint1(x0, y0, z1) plane1[2].SetPoint2(x1, y0, z0) plane1[3].SetOrigin(x1, y1, z1) plane1[3].SetPoint1(x1, y1, z0) plane1[3].SetPoint2(x1, y0, z1) plane1[4].SetOrigin(x1, y1, z1) plane1[4].SetPoint1(x0, y1, z1) plane1[4].SetPoint2(x1, y1, z0) plane1[5].SetOrigin(x1, y1, z1) plane1[5].SetPoint1(x0, y1, z1) plane1[5].SetPoint2(x1, y1, z0) for i in range(0, num_critical_points): plane1[i].SetResolution(5, 5) stream1[i].SetSource(plane1[i].GetOutput()) renderer.AddActor(dataActor1[i]) renderer.AddActor(glyphActor1[i]) glyph1[i].SetScaleFactor(4) renderer.AddActor(bar) renderer.AddActor(outlineActor) for i in range(0, num_critical_points): renderer.AddActor(criticalActor1[i]) renderer_window = vtk.vtkRenderWindow() renderer_window.AddRenderer(renderer) renderer_window.SetSize(512, 512) interactor = vtk.vtkRenderWindowInteractor() interactor.SetRenderWindow(renderer_window) style = vtk.vtkInteractorStyleTrackballCamera() interactor.SetInteractorStyle(style) renderer.AddActor(bar) renderer.AddActor(outlineActor) renderer_window.Render() interactor.Start()
def __init__ (self, mod_m, module=None, n_points=25, vis_points=0): """Input arguments: mod_m -- Module manager that manages this module. module -- Module to label. Can be given a module name (the same name as listed in the Modules GUI) or an index of the module (starting from 0) in the current module manager. If the value is -1, then the filtered data from the module manager is used. The value defaults to None where the user is asked to specify the module to label. n_points -- Number of points to label. Defaults to 25. vis_points -- If 1 turns on the vtkSelectVisiblePoints filter. Defaults to 0. """ debug ("In Labels::__init__ ()") Base.Objects.Module.__init__ (self, mod_m) self.act = None self.input = None self.mod_num = -1 if module is not None: self._set_input(module) if not self.input: res = self._get_input_gui() self._set_input(res) if not self.input: msg = "Sorry, you need to choose a valid module in order to "\ "use this module." raise Base.Objects.ModuleException, msg input = self.input Common.state.busy () self.n_points = n_points self.vis_points = vis_points self.mask = vtk.vtkMaskPoints () n = input.GetNumberOfPoints () self.mask.SetInput (input) self.mask.SetOnRatio (max(n/n_points, 1)) self.mask.GenerateVerticesOn() self.mask.RandomModeOn () self.vis_pnts = vtk.vtkSelectVisiblePoints () self.vis_pnts.SetRenderer(self.renwin.get_renderer()) self.mapper = self.map = vtk.vtkLabeledDataMapper () self.mapper.SetLabelModeToLabelScalars() self.tprop = None if hasattr(self.mapper, "GetLabelTextProperty"): self.tprop = self.mapper.GetLabelTextProperty() self.tprop.SetColor (*Common.config.fg_color) self.tprop.SetOpacity(1.0) if vis_points: self.vis_pnts.SetInput (self.mask.GetOutput ()) self.mapper.SetInput (self.vis_pnts.GetOutput ()) else: self.mapper.SetInput (self.mask.GetOutput ()) self.actor = self.act = vtk.vtkActor2D () self.actor.SetMapper (self.mapper) self.vis_pnt_gui = None self.act.GetProperty ().SetColor (*Common.config.fg_color) self.renwin.add_actors (self.act) # used for the pipeline browser self.pipe_objs = self.act self.renwin.Render () Common.state.idle ()
def extract_profiles_vtk(name): gridreader = vtk.vtkXMLStructuredGridReader() gridreader.SetFileName(name) gridreader.Update() grid = gridreader.GetOutput() data = grid.GetPointData() points = grid.GetPoints() dims = grid.GetDimensions() velocity = data.GetArray("Velocity") phase = data.GetArray("Phase") #data.SetActiveScalars("Phase") phase_image = vtk.vtkImageData() phase_image.SetSpacing(1.0, 1.0, 1.0) phase_image.SetOrigin(0.0, 0.0, 0.0) phase_image.SetDimensions(dims[0], dims[1], dims[2]) phase_image.GetPointData().SetScalars(phase) phase_image.GetPointData().SetVectors(velocity) extract = vtk.vtkExtractVOI() extract.SetInput(phase_image) extract.SetVOI(0, 0, 0, dims[1] - 1, 0, dims[2] - 1) extract.Update() #Create a contour #contour=vtk.vtkOutlineFilter() contour = vtk.vtkContourFilter() contour.SetInputConnection(extract.GetOutputPort()) #contour.SetInput(phase_image) contour.SetValue(0, 0.0) contour.Update() #cont_points=contour.GetOutput().GetPoints() probe = vtk.vtkProbeFilter() probe.SetInputConnection(contour.GetOutputPort()) probe.SetSource(extract.GetOutput()) probe.Update() filt_points = vtk.vtkMaskPoints() filt_points.SetInputConnection(probe.GetOutputPort()) #filt_points.SetMaximumNumberOfPoints(200) #filt_points.SetRandomMode(1) filt_points.SetOnRatio(10) arrow = vtk.vtkArrowSource() glyph = vtk.vtkGlyph3D() glyph.SetInputConnection(filt_points.GetOutputPort()) glyph.SetSourceConnection(arrow.GetOutputPort()) glyph.SetVectorModeToUseVector() glyph.SetScaleModeToScaleByVector() glyph.SetScaleFactor(400.0) glyphMapper = vtk.vtkPolyDataMapper() glyphMapper.SetInputConnection(glyph.GetOutputPort()) glyphActor = vtk.vtkActor() glyphActor.SetMapper(glyphMapper) glyphActor.GetProperty().SetColor(0.1, 0.5, 0.2) print glyphActor.GetProperty().GetColor() #print "Probe=", probe.GetOutput() calc = vtk.vtkArrayCalculator() calc.SetInput(probe.GetOutput()) #calc.AddVectorArrayName("Velocity",1,1,1) calc.AddScalarVariable("Vz", "Velocity", 2) calc.SetResultArrayName("Velocity comp 2") calc.SetFunction("Vz") #calc.SetResultArrayName("Velocity Magnitude") #calc.SetFunction("mag(Velocity)") calc.Update() print calc.GetOutput() xyplot = vtk.vtkXYPlotActor() vel = probe.GetOutput().GetPointData().GetArray("Velocity") #exam=vtk.vtkDoubleArray() #vel.GetData(0,vel.GetNumberOfTuples()-1,2,2,exam) xyplot.AddInput(calc.GetOutput()) #xyplot.GetPositionCoordinate().SetValue(0.0, 0.67, 0) #xyplot.GetPosition2Coordinate().SetValue(1.0, 0.33, 0) #relative to Position xyplot.SetXValuesToArcLength() #xyplot.SetNumberOfXLabels(6) #xyplot.SetTitle("Pressure vs. Arc Length (Zoomed View)") #xyplot.SetXTitle("") #xyplot.SetYTitle("P") #xyplot.SetXRange(.1, .35) #xyplot.SetYRange(.2, .4) xyplot.GetProperty().SetColor(0, 0, 0) xyplot.GetProperty().SetLineWidth(2) # Set text prop color (same color for backward compat with test) # Assign same object to all text props tprop = xyplot.GetTitleTextProperty() tprop.SetColor(xyplot.GetProperty().GetColor()) xyplot.SetAxisTitleTextProperty(tprop) xyplot.SetAxisLabelTextProperty(tprop) #glyph=vtk.vtkGlyph3D() #glyph.SetInput(contour.GetOutput()) contourMapper = vtk.vtkPolyDataMapper() #contourMapper.SetScalarRange(phase.GetRange()) contourMapper.SetInputConnection(contour.GetOutputPort()) sliceMapper = vtk.vtkImageMapper() #sliceMapper = vtk.vtkDataSetMapper() sliceMapper.SetInput(extract.GetOutput()) sliceMapper.SetColorLevel(1000) sliceMapper.SetColorWindow(2000) #sliceMapper.SetColorModeToMapScalars() #print polydata.GetClassName() contourActor = vtk.vtkActor() contourActor.SetMapper(contourMapper) sliceActor = vtk.vtkActor2D() sliceActor.SetMapper(sliceMapper) ren = vtk.vtkRenderer() #ren.AddActor(contourActor) ren.AddActor2D(sliceActor) #ren.AddActor(glyphActor) ren.SetBackground(0.1, 0.2, 0.4) #ren.SetColor(0.1,0.5,0.2) #ren.SetViewport(0, 0, .3, 1) ren2 = vtk.vtkRenderer() ren2.SetBackground(1, 1, 1) ren2.SetViewport(0.3, 0.0, 1.0, 1.0) ren2.AddActor2D(xyplot) renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) #renWin.AddRenderer(ren2) renWin.SetSize(500, 500) #win=vtk.vtkWindowToImageFilter() #win.SetInput(renWin) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) iren.Initialize() renWin.Render() iren.Start()
def main(): colors = vtk.vtkNamedColors() fileName = get_program_parameters() # Create the RenderWindow, Renderer and Interactor. # ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # Read cyberware file. # cyber = vtk.vtkPolyDataReader() cyber.SetFileName(fileName) normals = vtk.vtkPolyDataNormals() normals.SetInputConnection(cyber.GetOutputPort()) mask = vtk.vtkMaskPoints() mask.SetInputConnection(normals.GetOutputPort()) mask.SetOnRatio(8) # mask.RandomModeOn() splatter = vtk.vtkGaussianSplatter() splatter.SetInputConnection(mask.GetOutputPort()) splatter.SetSampleDimensions(100, 100, 100) splatter.SetEccentricity(2.5) splatter.NormalWarpingOn() splatter.SetScaleFactor(1.0) splatter.SetRadius(0.025) contour = vtk.vtkContourFilter() contour.SetInputConnection(splatter.GetOutputPort()) contour.SetValue(0, 0.25) splatMapper = vtk.vtkPolyDataMapper() splatMapper.SetInputConnection(contour.GetOutputPort()) splatMapper.ScalarVisibilityOff() splatActor = vtk.vtkActor() splatActor.SetMapper(splatMapper) splatActor.GetProperty().SetColor(colors.GetColor3d("Flesh")) cyberMapper = vtk.vtkPolyDataMapper() cyberMapper.SetInputConnection(cyber.GetOutputPort()) cyberMapper.ScalarVisibilityOff() cyberActor = vtk.vtkActor() cyberActor.SetMapper(cyberMapper) cyberActor.GetProperty().SetRepresentationToWireframe() cyberActor.GetProperty().SetColor(colors.GetColor3d("Turquoise")) # Add the actors to the renderer, set the background and size. # ren1.AddActor(cyberActor) ren1.AddActor(splatActor) ren1.SetBackground(colors.GetColor3d("Wheat")) renWin.SetSize(640, 480) camera = vtk.vtkCamera() camera.SetClippingRange(0.0332682, 1.66341) camera.SetFocalPoint(0.0511519, -0.127555, -0.0554379) camera.SetPosition(0.516567, -0.124763, -0.349538) camera.SetViewAngle(18.1279) camera.SetViewUp(-0.013125, 0.99985, -0.0112779) ren1.SetActiveCamera(camera) # Render the image. # renWin.Render() iren.Start()
def main(vector_file, magnitude_file): ColorRange = vtk.vtkLookupTable() ColorRange.SetTableRange(0, 1) ColorRange.SetHueRange(0, 1) ColorRange.SetSaturationRange(1, 1) ColorRange.SetAlphaRange(0.3, 0.5) ColorRange.Build() reader = vtk.vtkStructuredPointsReader() reader.SetFileName(vector_file) reader.Update() data = reader.GetOutput() range1 = data.GetScalarRange() v0 = range1[0] v1 = range1[1] reader_magnitude = vtk.vtkStructuredPointsReader() reader_magnitude.SetFileName(magnitude_file) reader_magnitude.Update() contour = vtk.vtkContourFilter() contour.SetInput(reader_magnitude.GetOutput()) contour.SetValue(0, 1) normals = vtk.vtkPolyDataNormals() normals.SetInput(contour.GetOutput()) normals.SetFeatureAngle(60) normals.ConsistencyOff() normals.SplittingOff() mapper_magnitude = vtk.vtkPolyDataMapper() mapper_magnitude.SetInput(normals.GetOutput()) mapper_magnitude.SetLookupTable(ColorRange) mapper_magnitude.SetColorModeToMapScalars() mapper_magnitude.SetScalarRange(v0, v1) actor_magnitude = vtk.vtkActor() actor_magnitude.SetMapper(mapper_magnitude) sphere = vtk.vtkSphereSource() sphere.SetRadius(2) sphere.SetCenter(15, 15, 15) # Critical point for all 3 test datasets sphere.SetThetaResolution(10) integrator = vtk.vtkRungeKutta4() stream = vtk.vtkStreamLine() stream.SetInput(reader.GetOutput()) stream.SetSource(sphere.GetOutput()) stream.SetIntegrator(integrator) stream.SetMaximumPropagationTime(500) stream.SetIntegrationStepLength(0.1) stream.SetIntegrationDirectionToIntegrateBothDirections() stream.SetStepLength(0.1) scalarSurface = vtk.vtkRuledSurfaceFilter() scalarSurface.SetInput(stream.GetOutput()) scalarSurface.SetOffset(0) scalarSurface.SetOnRatio(2) scalarSurface.PassLinesOn() scalarSurface.SetRuledModeToPointWalk() scalarSurface.SetDistanceFactor(50) tube = vtk.vtkTubeFilter() tube.SetInput(scalarSurface.GetOutput()) tube.SetRadius(0.1) tube.SetNumberOfSides(6) dataMapper = vtk.vtkPolyDataMapper() dataMapper.SetInput(tube.GetOutput()) dataMapper.SetScalarRange(v0, v1) dataMapper.SetLookupTable(ColorRange) dataActor = vtk.vtkActor() dataActor.SetMapper(dataMapper) probe = vtk.vtkProbeFilter() probe.SetInput(stream.GetOutput()) probe.SetSource(reader.GetOutput()) mask = vtk.vtkMaskPoints() mask.SetInput(probe.GetOutput()) mask.SetOnRatio(60) mask.RandomModeOn() cone = vtk.vtkConeSource() cone.SetResolution(8) cone.SetHeight(1.0) cone.SetRadius(0.2) transform = vtk.vtkTransform() transform.Translate(0, 0, 0) transformFilter = vtk.vtkTransformPolyDataFilter() transformFilter.SetInput(cone.GetOutput()) transformFilter.SetTransform(transform) glyph = vtk.vtkGlyph3D() glyph.SetInput(mask.GetOutput()) glyph.SetSource(transformFilter.GetOutput()) glyph.SetScaleModeToScaleByVector() glyph.SetScaleFactor(1.5) glyph.SetVectorModeToUseVector() glyph.SetColorModeToColorByVector() glyphMapper = vtk.vtkPolyDataMapper() glyphMapper.SetInput(glyph.GetOutput()) glyphMapper.SetLookupTable(ColorRange) glyphActor = vtk.vtkActor() glyphActor.SetMapper(glyphMapper) outline = vtk.vtkOutlineFilter() outline.SetInput(reader.GetOutput()) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInput(outline.GetOutput()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) outlineActor.GetProperty().SetColor(1, 1, 1) criticalMarker = vtk.vtkSphereSource() criticalMarker.SetRadius(1.0) criticalMarker.SetCenter(15, 15, 15) criticalMarker.SetThetaResolution(10) criticalMapper = vtk.vtkPolyDataMapper() criticalMapper.SetInput(criticalMarker.GetOutput()) criticalActor = vtk.vtkActor() criticalActor.SetMapper(criticalMapper) criticalActor.GetProperty().SetColor(1, 1, 0) criticalActor.GetProperty().SetOpacity(0.5) colorActor = vtk.vtkScalarBarActor() colorActor.SetLookupTable(ColorRange) renderer = vtk.vtkRenderer() renderer_window = vtk.vtkRenderWindow() renderer_window.AddRenderer(renderer) renderer_window.SetSize(512, 512) interactor = vtk.vtkRenderWindowInteractor() interactor.SetRenderWindow(renderer_window) renderer.AddActor(actor_magnitude) renderer.AddActor(outlineActor) renderer.AddActor(criticalActor) renderer.AddActor(colorActor) renderer.AddActor(dataActor) renderer.AddActor(glyphActor) renderer.ResetCamera() style = vtk.vtkInteractorStyleTrackballCamera() # style = vtk.vtkInteractorStyleRubberBandZoom() # style = vtk.vtkInteractorStyleTerrain() interactor.SetInteractorStyle(style) renderer_window.Render() interactor.Start()
def main(): fileName = get_program_parameters() colors = vtk.vtkNamedColors() fran = vtk.vtkPolyDataReader() fran.SetFileName(fileName) normals = vtk.vtkPolyDataNormals() normals.SetInputConnection(fran.GetOutputPort()) normals.FlipNormalsOn() franMapper = vtk.vtkPolyDataMapper() franMapper.SetInputConnection(normals.GetOutputPort()) franActor = vtk.vtkActor() franActor.SetMapper(franMapper) franActor.GetProperty().SetColor(colors.GetColor3d("Flesh")) # We subsample the dataset because we want to glyph just a subset of # the points. Otherwise the display is cluttered and cannot be easily # read. The RandomModeOn and SetOnRatio combine to random select one out # of every 10 points in the dataset. # ptMask = vtk.vtkMaskPoints() ptMask.SetInputConnection(normals.GetOutputPort()) ptMask.SetOnRatio(10) ptMask.RandomModeOn() # In this case we are using a cone as a glyph. We transform the cone so # its base is at 0,0,0. This is the point where glyph rotation occurs. cone = vtk.vtkConeSource() cone.SetResolution(6) transform = vtk.vtkTransform() transform.Translate(0.5, 0.0, 0.0) transformF = vtk.vtkTransformPolyDataFilter() transformF.SetInputConnection(cone.GetOutputPort()) transformF.SetTransform(transform) # vtkGlyph3D takes two inputs: the input point set (SetInputConnection) # which can be any vtkDataSet and the glyph (SetSourceConnection) which # must be a vtkPolyData. We are interested in orienting the glyphs by the # surface normals that we previously generated. glyph = vtk.vtkGlyph3D() glyph.SetInputConnection(ptMask.GetOutputPort()) glyph.SetSourceConnection(transformF.GetOutputPort()) glyph.SetVectorModeToUseNormal() glyph.SetScaleModeToScaleByVector() glyph.SetScaleFactor(0.004) spikeMapper = vtk.vtkPolyDataMapper() spikeMapper.SetInputConnection(glyph.GetOutputPort()) spikeActor = vtk.vtkActor() spikeActor.SetMapper(spikeMapper) spikeActor.GetProperty().SetColor(colors.GetColor3d("Emerald_Green")) # Create the RenderWindow, Renderer and Interactor. # ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # Add the actors to the renderer, set the background and size. # ren1.AddActor(franActor) ren1.AddActor(spikeActor) renWin.SetSize(640, 480) ren1.SetBackground(colors.GetColor3d("SlateGray")) # Render the image. # renWin.Render() ren1.GetActiveCamera().Zoom(1.4) ren1.GetActiveCamera().Azimuth(110) renWin.Render() iren.Start()
grid = magnitudeCalcFilter.GetOutput() grid.GetPoints(points) scalars = grid.GetPointData().GetArray('magnitude') #Create an unstructured grid that will contain the points and scalars data ugrid = vtk.vtkUnstructuredGrid() ugrid.SetPoints(points) ugrid.GetPointData().SetScalars(scalars) #Populate the cells in the unstructured grid using the output of the vtkCalculator for i in range(0, grid.GetNumberOfCells()): cell = grid.GetCell(i) ugrid.InsertNextCell(cell.GetCellType(), cell.GetPointIds()) # There are too many points, let's filter the points subset = vtk.vtkMaskPoints() subset.SetOnRatio(50) subset.SetRandomModeType(1) subset.SetInputData(ugrid) # Make a vtkPolyData with a vertex on each point. pointsGlyph = vtk.vtkVertexGlyphFilter() pointsGlyph.SetInputConnection(subset.GetOutputPort()) # pointsGlyph.SetInputData(ugrid) pointsGlyph.Update() pointsMapper = vtk.vtkPolyDataMapper() pointsMapper.SetInputConnection(pointsGlyph.GetOutputPort()) pointsMapper.SetScalarModeToUsePointData() pointsActor = vtk.vtkActor()
def main(): back_face, normals, surface_name, write_out_image = get_program_parameters( ) colors = vtk.vtkNamedColors() if surface_name: rendererSize = 800 gridColumnDimensions = 1 gridRowDimensions = 1 else: rendererSize = 200 gridColumnDimensions = 5 gridRowDimensions = 5 # Create one text property for all textProperty = vtk.vtkTextProperty() textProperty.SetJustificationToCentered() textProperty.SetFontSize(int(rendererSize / 12)) textProperty.SetColor(colors.GetColor3d("LavenderBlush")) # Create a parametric function source, renderer, mapper, and actor # for each object pfnSrcs = [] renderers = [] mappers = [] actors = [] textmappers = [] textactors = [] # Glyph the normals maskPts = [] arrow = [] glyph = [] glyphMapper = [] glyphActor = [] backProperty = vtk.vtkProperty() if back_face: backProperty.SetColor(colors.GetColor3d("Peru")) boundingBox = [] # Get the parametric functions and build the pipeline pfn = get_parametric_functions() if surface_name: # is the surface in the map? surface_exists = list() for t in pfn.keys(): for obj in pfn[t].keys(): if surface_name == obj: surface_exists.append(True) else: surface_exists.append(False) if not any(surface_exists): print('Nonexistent object:', surface_name) return single_surface = list() obj_count = 0 sorted_names = list() for t in sorted(pfn.keys()): for obj in sorted(pfn[t].keys()): sorted_names.append(obj) if surface_name: if obj == surface_name: single_surface = [surface_name, obj_count] pfnSrcs.append(vtk.vtkParametricFunctionSource()) pfnSrcs[obj_count].SetParametricFunction(pfn[t][obj]) pfnSrcs[obj_count].SetUResolution(51) pfnSrcs[obj_count].SetVResolution(51) pfnSrcs[obj_count].SetWResolution(51) pfnSrcs[obj_count].Update() mappers.append(vtk.vtkPolyDataMapper()) mappers[obj_count].SetInputConnection( pfnSrcs[obj_count].GetOutputPort()) actors.append(vtk.vtkActor()) actors[obj_count].SetMapper(mappers[obj_count]) actors[obj_count].GetProperty().SetColor( colors.GetColor3d("NavajoWhite")) if back_face: actors[obj_count].SetBackfaceProperty(backProperty) textmappers.append(vtk.vtkTextMapper()) textmappers[obj_count].SetInput(obj) textmappers[obj_count].SetTextProperty(textProperty) textactors.append(vtk.vtkActor2D()) textactors[obj_count].SetMapper(textmappers[obj_count]) textactors[obj_count].SetPosition(rendererSize / 2.0, 8) renderers.append(vtk.vtkRenderer()) bounds = pfnSrcs[obj_count].GetOutput().GetBounds() boundingBox.append(bounds) # display_bounding_box_and_center(obj, obj_count, bounds) if normals: # Glyphing maskPts.append(vtk.vtkMaskPoints()) maskPts[obj_count].RandomModeOn() maskPts[obj_count].SetMaximumNumberOfPoints(150) maskPts[obj_count].SetInputConnection( pfnSrcs[obj_count].GetOutputPort()) arrow.append(vtk.vtkArrowSource()) arrow[obj_count].SetTipResolution(16) arrow[obj_count].SetTipLength(0.3) arrow[obj_count].SetTipRadius(0.1) glyphScale = get_maximum_length(boundingBox[obj_count]) glyph.append(vtk.vtkGlyph3D()) glyph[obj_count].SetSourceConnection( arrow[obj_count].GetOutputPort()) glyph[obj_count].SetInputConnection( maskPts[obj_count].GetOutputPort()) glyph[obj_count].SetVectorModeToUseNormal() glyph[obj_count].SetScaleFactor(glyphScale / 10.0) glyph[obj_count].OrientOn() glyph[obj_count].Update() glyphMapper.append(vtk.vtkPolyDataMapper()) glyphMapper[obj_count].SetInputConnection( glyph[obj_count].GetOutputPort()) glyphActor.append(vtk.vtkActor()) glyphActor[obj_count].SetMapper(glyphMapper[obj_count]) glyphActor[obj_count].GetProperty().SetColor( colors.GetColor3d("GreenYellow")) obj_count += 1 # Need a renderer even if there is no actor for i in range(obj_count, gridColumnDimensions * gridRowDimensions): renderers.append(vtk.vtkRenderer()) renderers[i].SetBackground(colors.GetColor3d("MidnightBlue")) sorted_names.append(None) renderWindow = vtk.vtkRenderWindow() renderWindow.SetSize(rendererSize * gridColumnDimensions, rendererSize * gridRowDimensions) for row in range(0, gridRowDimensions): for col in range(0, gridColumnDimensions): # (xmin, ymin, xmax, ymax) viewport = [ float(col) * rendererSize / (gridColumnDimensions * rendererSize), float(gridRowDimensions - (row + 1)) * rendererSize / (gridRowDimensions * rendererSize), float(col + 1) * rendererSize / (gridColumnDimensions * rendererSize), float(gridRowDimensions - row) * rendererSize / (gridRowDimensions * rendererSize) ] if not surface_name: index = row * gridColumnDimensions + col renderWindow.AddRenderer(renderers[index]) renderers[index].SetViewport(viewport) if index > obj_count - 1: continue renderers[index].AddActor(actors[index]) # Normals can only be computed for polygons and triangle strips. # The Spline is a line. if normals and sorted_names[index] != 'Spline': renderers[index].AddActor(glyphActor[index]) renderers[index].AddActor(textactors[index]) renderers[index].SetBackground( colors.GetColor3d("MidnightBlue")) renderers[index].ResetCamera() renderers[index].GetActiveCamera().Azimuth(30) renderers[index].GetActiveCamera().Elevation(-30) renderers[index].GetActiveCamera().Zoom(0.9) renderers[index].ResetCameraClippingRange() else: index = single_surface[1] if index != -1: renderWindow.AddRenderer(renderers[index]) renderers[index].SetViewport(viewport) renderers[index].AddActor(actors[index]) # Normals can only be computed for polygons and triangle strips. # The Spline is a line. if normals and sorted_names[index] != 'Spline': renderers[index].AddActor(glyphActor[index]) renderers[index].AddActor(textactors[index]) renderers[index].SetBackground( colors.GetColor3d("MidnightBlue")) renderers[index].ResetCamera() renderers[index].GetActiveCamera().Azimuth(30) renderers[index].GetActiveCamera().Elevation(-30) renderers[index].GetActiveCamera().Zoom(0.9) renderers[index].ResetCameraClippingRange() interactor = vtk.vtkRenderWindowInteractor() interactor.SetRenderWindow(renderWindow) renderWindow.Render() if surface_name: renderWindow.SetWindowName(single_surface[0]) else: renderWindow.SetWindowName("ParametricObjectsDemo") renderWindow.Render() if write_out_image: # ------------------------------- # Save the image # ------------------------------- if surface_name: write_image(single_surface[0], renderWindow, rgba=False) else: write_image('ParametricObjectsDemo', renderWindow, rgba=False) interactor.Start()