def PlotBoundaries(mesh): """ Plots boundaries of a mesh """ featureEdges = vtk.vtkFeatureEdges() vtkInterface.SetVTKInput(featureEdges, mesh) featureEdges.FeatureEdgesOff() featureEdges.BoundaryEdgesOn() featureEdges.NonManifoldEdgesOn() featureEdges.ManifoldEdgesOff() edgeMapper = vtk.vtkPolyDataMapper(); edgeMapper.SetInputConnection(featureEdges.GetOutputPort()); edgeActor = vtk.vtkActor(); edgeActor.GetProperty().SetLineWidth(5); edgeActor.SetMapper(edgeMapper) mapper = vtk.vtkDataSetMapper() vtkInterface.SetVTKInput(mapper, mesh) # Actor actor = vtk.vtkActor() actor.SetMapper(mapper) actor.GetProperty().LightingOff() # Render pobj = PlotClass() pobj.AddActor(actor) pobj.AddActor(edgeActor) pobj.Plot(); del pobj
def AddLines(self, lines, color=[1, 1, 1], width=5): """ Adds an actor to the renderwindow """ if type(lines) is np.ndarray: lines = vtkInterface.MakeLine(lines) # Create mapper and add lines mapper = vtk.vtkDataSetMapper() vtkInterface.SetVTKInput(mapper, lines) # Create Actor actor = vtk.vtkActor() actor.SetMapper(mapper) actor.GetProperty().SetLineWidth(width); actor.GetProperty().EdgeVisibilityOn() actor.GetProperty().SetEdgeColor(color) actor.GetProperty().SetColor(ParseColor(color)) actor.GetProperty().LightingOff() # Add to renderer self.ren.AddActor(actor)
def AddPoints(self, points, color=None, psize=5, scalars=None, rng=None, name='', opacity=1, stitle='', flipscalars=False): """ Adds a point actor or numpy points array to plotting object """ # select color if color is None: color = [1, 1, 1] elif type(color) is str or type(color) is unicode: color = vtkInterface.StringToRGB(color) # Convert to vtk points object if "points" is a numpy array if type(points) == np.ndarray: self.points = MakeVTKPointsMesh(points) else: self.points = points # Create mapper and add lines mapper = vtk.vtkDataSetMapper() vtkInterface.SetVTKInput(mapper, self.points) if np.any(scalars): vtkInterface.AddPointScalars(self.points, scalars, name, True) mapper.SetScalarModeToUsePointData() if not rng: rng = [np.min(scalars), np.max(scalars)] if np.any(rng): mapper.SetScalarRange(rng[0], rng[1]) # Flip if requested if flipscalars: mapper.GetLookupTable().SetHueRange(0.66667, 0.0) # Create Actor actor = vtk.vtkActor() actor.SetMapper(mapper) actor.GetProperty().SetPointSize(psize); actor.GetProperty().SetColor(color) actor.GetProperty().LightingOff() actor.GetProperty().SetOpacity(opacity) self.ren.AddActor(actor) # Add scalar bar if stitle: self.scalarBar = vtk.vtkScalarBarActor() self.scalarBar.SetLookupTable(mapper.GetLookupTable()) self.scalarBar.GetTitleTextProperty().SetFontFamilyToCourier() self.scalarBar.GetTitleTextProperty().ItalicOff() self.scalarBar.GetTitleTextProperty().BoldOn() self.scalarBar.GetLabelTextProperty().SetFontFamilyToCourier() self.scalarBar.GetLabelTextProperty().ItalicOff() self.scalarBar.GetLabelTextProperty().BoldOn() self.scalarBar.SetTitle(stitle) self.scalarBar.SetNumberOfLabels(5) self.ren.AddActor(self.scalarBar)