def build_vtk_renderer(self): # offscreen rendering if (vtk.vtkVersion().GetVTKMajorVersion() == 5.0): graphics_factory = vtk.vtkGraphicsFactory() graphics_factory.SetOffScreenOnlyMode( 1); graphics_factory.SetUseMesaClasses( 1 ); imaging_factory = vtk.vtkImagingFactory() imaging_factory.SetUseMesaClasses( 1 ); self.renderer = vtk.vtkRenderer() self.renderer.SetBackground(1, 1, 1) self.render_window = vtk.vtkRenderWindow() # offscreen rendering self.render_window.SetOffScreenRendering(1) self.render_window.AddRenderer(self.renderer) # create a renderwindowinteractor #if self.interact: #self.iren = vtk.vtkRenderWindowInteractor() #self.iren.SetRenderWindow(self.render_window) # scalar bar self.scalarbar = vtk.vtkScalarBarActor() # To avoid uninitialized warning in VTK 6 self.scalarbar.SetTitle("") # black text since background is white for printing self.scalarbar.GetLabelTextProperty().SetColor(0, 0, 0) self.scalarbar.GetTitleTextProperty().SetColor(0, 0, 0)
def __init__(self, point_cloud): # set renderer renderer = vtk.vtkRenderer() renderer.AddActor(point_cloud.vtkActor) renderer.SetBackground(.1, .2, .4) renderer.ResetCamera() # set the window renderWindow = vtk.vtkRenderWindow() renderWindow.AddRenderer(renderer) # set interactor renderWindowInteractor = vtk.vtkRenderWindowInteractor() renderWindowInteractor.SetRenderWindow(renderWindow) # create scalar bar scalar_bar = vtk.vtkScalarBarActor() scalar_bar.SetOrientationToHorizontal() scalar_bar.SetLookupTable(point_cloud.lut) scalar_bar_widget = vtk.vtkScalarBarWidget() scalar_bar_widget.SetInteractor(renderWindowInteractor) scalar_bar_widget.SetScalarBarActor(scalar_bar) scalar_bar_widget.On() # start interactor renderWindow.Render() renderWindow.SetWindowName("CrackVis:" + point_cloud.filename) renderWindowInteractor.Start()
def create_scalar_bar(lut, grid=None, p_name=""): """ creates a vtkScalarBarActor, for a vtkLookupTable, sets hte active scalar to p_name @param lut vtkLookupTable @param grid the grid the scalar bar will be used on (to automatically determine the scalar range) @param p_name name of the cell data or point data, from which the range is determined @return a vtkScalarBarActor """ if grid != None and p_name != "": range = [0, 1] a = grid.GetCellData().GetAbstractArray(p_name) if a: range = a.GetRange() grid.GetCellData().SetActiveScalars(p_name) else: a = grid.GetPointData().GetAbstractArray(p_name) grid.GetPointData().SetActiveScalars(p_name) if a: range = a.GetRange() lut.SetTableRange(range) scalarBar = vtk.vtkScalarBarActor() scalarBar.SetLookupTable(lut) scalarBar.SetTitle(p_name) scalarBar.SetDrawAnnotations(False) textProperty = vtk.vtkTextProperty() textProperty.SetFontSize(30) scalarBar.SetAnnotationTextProperty(textProperty) scalarBar.SetTitleTextProperty(textProperty) scalarBar.SetLabelTextProperty(textProperty) scalarBar.AnnotationTextScalingOff() scalarBar.SetUnconstrainedFontSize(True) return scalarBar
def creaColorScaleBar(self,orientation='H'): '''Creates the scalar bar that indicates to the viewer the correspondence between color values and data values :param orientation: 'H' for horizontal bar, 'V' for vertical bar (defaults to 'H') ''' self.scalarBar= vtk.vtkScalarBarActor() pos= self.scalarBar.GetPositionCoordinate() pos.SetCoordinateSystemToNormalizedViewport() if orientation=='H': pos.SetValue(0.1,0.1) self.scalarBar.SetOrientationToHorizontal() self.scalarBar.SetWidth(0.8) self.scalarBar.SetHeight(0.06) else: pos.SetValue(0.85,0.25) self.scalarBar.SetOrientationToVertical() self.scalarBar.SetWidth(0.1) self.scalarBar.SetHeight(0.7) self.scalarBar.SetLookupTable(self.lookUpTable) self.scalarBar.Modified() #self.scalarBar.SetLabelFormat("%.2f") labelTextProperty= self.scalarBar.GetLabelTextProperty() labelTextProperty.ItalicOff() return self.scalarBar
def get_scalarbar(self) -> vtk.vtkScalarBarActor: """Get a vtk scalar bar (legend).""" color_range = self.get_lookuptable() scalar_bar = vtk.vtkScalarBarActor() scalar_bar.SetLookupTable(color_range) scalar_bar.SetTitle(self._name) scalar_bar.SetPosition(self._position) scalar_bar.SetWidth(self._width) scalar_bar.SetHeight(self._height) # The following allows the change in font size for the text labels on the legend scalar_bar.SetUnconstrainedFontSize(True) if self._orientation == Orientation.horizontal: scalar_bar.SetOrientationToHorizontal() else: scalar_bar.SetOrientationToVertical() if self._number_of_colors: scalar_bar.SetMaximumNumberOfColors(self._number_of_colors) if self._number_of_labels: scalar_bar.SetNumberOfLabels(self._number_of_labels) # setting the type of labels. Such as integers, decimals, etc. scalar_bar.SetLabelFormat(self._label_format.value) # Setting whether the labels and title should precede the legend scalar_bar.SetTextPosition(self._label_position) scalar_bar.SetLabelTextProperty(self._label_font.to_vtk()) scalar_bar.SetTitleTextProperty(self._title_font.to_vtk()) return scalar_bar
def add_widgets(self): # axes axes = vtk.vtkAxesActor() self.marker_widget = vtk.vtkOrientationMarkerWidget() self.marker_widget.SetInteractor(self.iren) self.marker_widget.SetOrientationMarker(axes) self.marker_widget.SetViewport(0.0, 0.0, 0.25, 0.25) # scalar bar self.scalarbar_actor = vtk.vtkScalarBarActor() self.scalarbar_actor.SetLookupTable(self.lut) self.scalarbar_widget = vtk.vtkScalarBarWidget() self.scalarbar_widget.SetInteractor(self.iren) self.scalarbar_widget.SetScalarBarActor(self.scalarbar_actor) # contour slider self.slider_rep = vtk.vtkSliderRepresentation2D() self.slider_rep.SetTitleText("contour") self.slider_rep.GetPoint1Coordinate( ).SetCoordinateSystemToNormalizedViewport() self.slider_rep.GetPoint1Coordinate().SetValue(0.65, 0.1) self.slider_rep.GetPoint2Coordinate( ).SetCoordinateSystemToNormalizedViewport() self.slider_rep.GetPoint2Coordinate().SetValue(0.95, 0.1) self.slider_widget = vtk.vtkSliderWidget() self.slider_widget.SetInteractor(self.iren) self.slider_widget.SetRepresentation(self.slider_rep) self.slider_widget.SetAnimationModeToAnimate() self.slider_widget.AddObserver(vtk.vtkCommand.InteractionEvent, self.update_contour)
def scalar_bar(lookup_table=None, title=" "): """ Default scalar bar actor for a given colormap (colorbar) Parameters ---------- lookup_table : vtkLookupTable or None If None then ``colormap_lookup_table`` is called with default options. title : str Returns ------- scalar_bar : vtkScalarBarActor See Also -------- :func:`fury.actor.colormap_lookup_table` """ lookup_table_copy = vtk.vtkLookupTable() if lookup_table is None: lookup_table = colormap_lookup_table() # Deepcopy the lookup_table because sometimes vtkPolyDataMapper deletes it lookup_table_copy.DeepCopy(lookup_table) scalar_bar = vtk.vtkScalarBarActor() scalar_bar.SetTitle(title) scalar_bar.SetLookupTable(lookup_table_copy) scalar_bar.SetNumberOfLabels(6) return scalar_bar
def createActor(self, **args): if self.colorBarActor == None: pos = args.get('pos', [0.9, 0.2]) title = args.get('title', '') self.colorBarActor = vtk.vtkScalarBarActor() self.colorBarActor.SetMaximumWidthInPixels(50) self.colorBarActor.SetNumberOfLabels(9) labelFormat = vtk.vtkTextProperty() labelFormat.SetFontSize(160) labelFormat.SetColor(VTK_FOREGROUND_COLOR[0], VTK_FOREGROUND_COLOR[1], VTK_FOREGROUND_COLOR[2]) titleFormat = vtk.vtkTextProperty() titleFormat.SetFontSize(160) titleFormat.SetColor(VTK_FOREGROUND_COLOR[0], VTK_FOREGROUND_COLOR[1], VTK_FOREGROUND_COLOR[2]) # titleFormat.SetVerticalJustificationToTop () # titleFormat.BoldOn() self.colorBarActor.SetPosition(pos[0], pos[1]) self.colorBarActor.SetLabelTextProperty(labelFormat) self.colorBarActor.SetTitleTextProperty(titleFormat) self.colorBarActor.SetTitle(title) self.colorBarActor.SetLookupTable(self.getDisplayLookupTable()) self.colorBarActor.SetVisibility(0) else: self.colorBarActor.SetLookupTable(self.getDisplayLookupTable()) self.colorBarActor.Modified() return self.colorBarActor
def createActor( self, **args ): if self.colorBarActor == None: pos = args.get( 'pos', [ 0.9, 0.2 ] ) title = args.get( 'title', '' ) self.colorBarActor = vtk.vtkScalarBarActor() # self.colorBarActor.SetMaximumWidthInPixels( 50 ) self.colorBarActor.SetNumberOfLabels(9) labelFormat = vtk.vtkTextProperty() labelFormat.SetFontSize( 160 ) labelFormat.SetColor( VTK_FOREGROUND_COLOR[0], VTK_FOREGROUND_COLOR[1], VTK_FOREGROUND_COLOR[2] ) titleFormat = vtk.vtkTextProperty() titleFormat.SetFontSize( 160 ) titleFormat.SetColor( VTK_FOREGROUND_COLOR[0], VTK_FOREGROUND_COLOR[1], VTK_FOREGROUND_COLOR[2] ) # titleFormat.SetVerticalJustificationToTop () # titleFormat.BoldOn() self.colorBarActor.SetPosition( pos[0], pos[1] ) self.colorBarActor.SetLabelTextProperty( labelFormat ) self.colorBarActor.SetTitleTextProperty( titleFormat ) self.colorBarActor.SetTitle( title ) self.colorBarActor.SetLookupTable( self.getDisplayLookupTable() ) self.colorBarActor.SetVisibility(0) self.colorBarActor.SetMaximumWidthInPixels(75) else: self.colorBarActor.SetLookupTable( self.getDisplayLookupTable() ) self.colorBarActor.Modified() return self.colorBarActor
def __init__(self, _drawModel): self.legendActor = vtk.vtkScalarBarActor() self.legendActor.SetNumberOfLabels(8) (self.minCon, self.maxCon) = (0, 0) self.plane = 'XY' self.planePos = 0 self.ren = None dM = ref(_drawModel) self.drawModel = dM() self.currentDrawingFunction = None self.currentActors = {} # dictionary of current actors self.drawingFcnName = "" # holds a string describing name of the drawing fcn . Used to determine if current actors need to be removed before next drawing self.drawingFcnHasChanged = True self.fieldTypes = None self.currentDrawingParameters = DrawingParameters() # self.currentFieldType = ("Cell_Field", FIELD_TYPES[0]) self.currentFieldType = ("Cell_Field", 'CellField') self.__initDist = 0 # initial camera distance - used in zoom functions self.min_max_text_actor = vtk.vtkTextActor() # CUSTOM ACTORS self.customActors = {} # {visName: CustomActorsStorage() } self.currentCustomVisName = '' # stores name of the current custom visualization self.currentVisName = '' # stores name of the current visualization self.cameraSettingsDict = {} # {fieldName:CameraSettings()}
def creaColorScaleBar(self,orientation=1,title=None): '''Creates the scalar bar that indicates to the viewer the correspondence between color values and data values :param orientation: 1 for horizontal bar, 2 for left-vertical bar 3 for right-vertical bar(defaults to horizontal) ''' self.scalarBar= vtk.vtkScalarBarActor() pos= self.scalarBar.GetPositionCoordinate() pos.SetCoordinateSystemToNormalizedViewport() if orientation>1: #vertical self.scalarBar.SetOrientationToVertical() self.scalarBar.SetWidth(0.075) self.scalarBar.SetHeight(0.7) pos.SetValue(0.04,0.20) if orientation==2 else pos.SetValue(0.87,0.20) if title: title=title.replace(' ',' \n ') self.scalarBar.SetTitle(title) else: #horizontal self.scalarBar.SetOrientationToHorizontal() self.scalarBar.SetWidth(0.8) self.scalarBar.SetHeight(0.055) pos.SetValue(0.1,0.07) if title: self.scalarBar.SetHeight(0.09) self.scalarBar.SetTitle(title) self.scalarBar.SetLookupTable(self.lookUpTable) self.scalarBar.Modified() #self.scalarBar.SetLabelFormat("%.2f") labelTextProperty= self.scalarBar.GetLabelTextProperty() labelTextProperty.ItalicOff() return self.scalarBar
def __init__(self, lookupTable, pos=(0.8, 0.2), size=14): self.lut = lookupTable self.actor = vtk.vtkScalarBarActor() self.actor.SetLookupTable(lookupTable) self.actor.SetPosition(pos) self.actor.GetLabelTextProperty().SetFontSize(size)
def __init__(self, _drawModel , graphicsFrameWidget, parent=None): self.legendActor = vtk.vtkScalarBarActor() self.legendActor.SetNumberOfLabels(8) (self.minCon, self.maxCon) = (0, 0) # print MODULENAME,"graphicsFrameWidget=",graphicsFrameWidget # print MODULENAME,"parent=",parent self.plane = 'XY' self.planePos = 0 # # # self.drawModel = _drawModel self.parentWidget = parent # print MODULENAME,' __init__: parentWidget=',self.parentWidget # from weakref import ref # self.graphicsFrameWidget = ref(graphicsFrameWidget) # gfw=self.graphicsFrameWidget() # self.qvtkWidget = self.graphicsFrameWidget.qvtkWidget from weakref import ref dM = ref(_drawModel) self.drawModel=dM() gfw=ref(graphicsFrameWidget) self.graphicsFrameWidget = gfw() # qvtk=ref(self.graphicsFrameWidget.qvtkWidget) # self.qvtkWidget = qvtk() self.qvtkWidget = ref(self.graphicsFrameWidget.qvtkWidget) # # # self.graphicsFrameWidget = graphicsFrameWidget # # # self.qvtkWidget = self.graphicsFrameWidget.qvtkWidget self.currentDrawingFunction = None self.currentActors = {} # dictionary of current actors self.drawingFcnName = "" # holds a string describing name of the drawing fcn . Used to determine if current actors need to be removed before next drawing self.drawingFcnHasChanged = True self.fieldTypes = None self.currentDrawingParameters = DrawingParameters() self.currentFieldType = ("Cell_Field", FIELD_TYPES[0]) self.__initDist = 0 # initial camera distance - used in zoom functions #CUSTOM ACTORS self.customActors = {} #{visName: CustomActorsStorage() } self.currentCustomVisName = '' #stores name of the current custom visualization self.currentVisName = '' #stores name of the current visualization self.cameraSettingsDict = {} # {fieldName:CameraSettings()}
def Execute(self): if not self.Centerlines: self.PrintError('Error: No input centerlines.') return if not self.vmtkRenderer: self.vmtkRenderer = vmtkrenderer.vmtkRenderer() self.vmtkRenderer.Initialize() self.OwnRenderer = 1 self.vmtkRenderer.RegisterScript(self) if self.CellDataArrayName: cellCenters = vtk.vtkCellCenters() cellCenters.SetInput(self.Centerlines) cellCenters.Update() cellCenters.GetOutput().GetPointData().SetActiveScalars(self.CellDataArrayName) labelsMapper = vtk.vtkLabeledDataMapper(); labelsMapper.SetInput(cellCenters.GetOutput()) labelsMapper.SetLabelModeToLabelScalars() labelsActor = vtk.vtkActor2D() labelsActor.SetMapper(labelsMapper) self.vmtkRenderer.Renderer.AddActor(labelsActor) centerlineMapper = vtk.vtkPolyDataMapper() centerlineMapper.SetInput(self.Centerlines) if self.CellDataArrayName and not self.PointDataArrayName: centerlineMapper.ScalarVisibilityOn() centerlineMapper.SetScalarModeToUseCellData() self.Centerlines.GetCellData().SetActiveScalars(self.CellDataArrayName) centerlineMapper.SetScalarRange(self.Centerlines.GetCellData().GetScalars().GetRange(0)) elif self.PointDataArrayName: centerlineMapper.ScalarVisibilityOn() centerlineMapper.SetScalarModeToUsePointData() self.Centerlines.GetPointData().SetActiveScalars(self.PointDataArrayName) centerlineMapper.SetScalarRange(self.Centerlines.GetPointData().GetScalars().GetRange(0)) else: centerlineMapper.ScalarVisibilityOff() centerlineActor = vtk.vtkActor() centerlineActor.SetMapper(centerlineMapper) self.vmtkRenderer.Renderer.AddActor(centerlineActor) scalarBarActor = None if self.Legend and centerlineActor and self.PointDataArrayName: scalarBarActor = vtk.vtkScalarBarActor() scalarBarActor.SetLookupTable(centerlineActor.GetMapper().GetLookupTable()) scalarBarActor.GetLabelTextProperty().ItalicOff() scalarBarActor.GetLabelTextProperty().BoldOff() scalarBarActor.GetLabelTextProperty().ShadowOff() scalarBarActor.SetLabelFormat('%.2f') scalarBarActor.SetTitle(self.PointDataArrayName) self.vmtkRenderer.Renderer.AddActor(scalarBarActor) if self.Display: self.vmtkRenderer.Render() if self.OwnRenderer: self.vmtkRenderer.Deallocate()
def __init__(self): ''' Constructor ''' self.__OrientationMatrix = vtk.vtkMatrix4x4() self.__CornerAnnotation = vtk.vtkCornerAnnotation() self.__TextProperty = vtk.vtkTextProperty() self.__LookupTable = vtk.vtkLookupTable() self.__ScalarBarActor = vtk.vtkScalarBarActor() self.__Prop3DCollection = vtk.vtkProp3DCollection() self.__DataSetCollection = vtk.vtkDataSetCollection() self.__OrientationTransform = vtk.vtkMatrixToLinearTransform() self.__OrientationMatrix.Identity() self.__CornerAnnotation.SetNonlinearFontScaleFactor(0.30) self.__CornerAnnotation.SetText(0, "Jolly - (c) summit 2009 ref vtkINRIA3D") self.__CornerAnnotation.SetMaximumFontSize(46) self.__ScalarBarActor.SetLabelTextProperty(self.__TextProperty) self.__ScalarBarActor.GetLabelTextProperty().BoldOff() self.__ScalarBarActor.GetLabelTextProperty().ItalicOff() self.__ScalarBarActor.SetNumberOfLabels(3) self.__ScalarBarActor.SetWidth(0.1) self.__ScalarBarActor.SetHeight(0.5) self.__ScalarBarActor.SetPosition(0.9, 0.3) self.__LookupTable.SetTableRange(0, 1) self.__LookupTable.SetSaturationRange(0, 0) self.__LookupTable.SetHueRange(0, 0) self.__LookupTable.SetValueRange(0, 1) self.__LookupTable.Build() self.__ShowAnnotations = True self.__ShowScalarBar = True self.__OrientationTransform.SetInput(self.__OrientationMatrix) self.__WindowLevel = self.GetWindowLevel() self.__WindowLevel.SetLookupTable( self.__LookupTable ) self.__ScalarBarActor.SetLookupTable(self.__LookupTable) self.__Renderer = self.GetRenderer() self.__Renderer.AddViewProp(self.__CornerAnnotation) self.__Renderer.AddViewProp(self.__ScalarBarActor) self.__ImageActor = self.GetImageActor() self.__RenderWindow = self.GetRenderWindow () self.__InteractorStyle = self.GetInteractorStyle() self.__Interactor = None self.__CornerAnnotation.SetWindowLevel(self.__WindowLevel) self.__CornerAnnotation.SetImageActor(self.__ImageActor) self.__CornerAnnotation.ShowSliceAndImageOn() # Sometime we would want to set the default window/level value instead # of the ImageData's ScalarRange self.__RefWindow = None self.__RefLevel = None
def main(): colors = vtk.vtkNamedColors() # colors.SetColor('bkg', [0.1, 0.2, 0.4, 1.0]) # The source file file_name = get_program_parameters() # Create a custom lut. The lut is used for both at the mapper and at the # scalar_bar lut = vtk.vtkLookupTable() lut.Build() # Read the source file. reader = vtk.vtkUnstructuredGridReader() reader.SetFileName(file_name) reader.Update() # Needed because of GetScalarRange output = reader.GetOutput() scalar_range = output.GetScalarRange() mapper = vtk.vtkDataSetMapper() mapper.SetInputData(output) mapper.SetScalarRange(scalar_range) mapper.SetLookupTable(lut) actor = vtk.vtkActor() actor.SetMapper(mapper) renderer = vtk.vtkRenderer() renderer.AddActor(actor) renderer.SetBackground(colors.GetColor3d('MidnightBLue')) render_window = vtk.vtkRenderWindow() render_window.AddRenderer(renderer) render_window.SetSize(300, 300) render_window.SetWindowName("ScalarBarWidget") interactor = vtk.vtkRenderWindowInteractor() interactor.SetRenderWindow(render_window) # create the scalar_bar scalar_bar = vtk.vtkScalarBarActor() scalar_bar.SetOrientationToHorizontal() scalar_bar.SetLookupTable(lut) # create the scalar_bar_widget scalar_bar_widget = vtk.vtkScalarBarWidget() scalar_bar_widget.SetInteractor(interactor) scalar_bar_widget.SetScalarBarActor(scalar_bar) scalar_bar_widget.On() interactor.Initialize() render_window.Render() renderer.GetActiveCamera().SetPosition(-6.4, 10.3, 1.4) renderer.GetActiveCamera().SetFocalPoint(1.0, 0.5, 3.0) renderer.GetActiveCamera().SetViewUp(0.6, 0.4, -0.7) render_window.Render() interactor.Start()
def ShowPolyData(in_polydata, caption=""): """Visualize the in_polydata surface which has scalar values which will be colour-coded. """ if True: color_series = vtk.vtkColorSeries() color_series.SetColorScheme( color_series.BREWER_DIVERGING_SPECTRAL_10) #set the color theme lut = vtk.vtkColorTransferFunction() lut.SetColorSpaceToHSV() num_colors = color_series.GetNumberOfColors() d_color = [0.0, 0.0, 0.0] scalar_range = [0.0, 0.0] #[-0.002,0.001] # in_polydata.GetPointData().GetScalars().GetRange(scalar_range) # for i in range(num_colors): # color = color_series.GetColor(i) # d_color[0] = color[0] / 255.0 # d_color[1] = color[1] / 255.0 # d_color[2] = color[2] / 255.0 # t= scalar_range[0] + (scalar_range[1] - scalar_range[0]) * i / (num_colors - 1) # lut.AddRGBPoint(t, d_color[0], d_color[1], d_color[2]); ##Create a mapper and actor mapper = vtk.vtkPolyDataMapper() # mapper.UseLookupTableScalarRangeOn() mapper.SetInputData( in_polydata) #SetInputConnection() is for algorithm not polydata # mapper.SetLookupTable(lut) # mapper.SetScalarRange(scalar_range) actor = vtk.vtkActor() actor.SetMapper(mapper) ##Create a scalar bar actor scalarBar = vtk.vtkScalarBarActor() scalarBar.SetLookupTable(mapper.GetLookupTable()) scalarBar.SetNumberOfLabels(5) ##Create text actor text_actor = vtk.vtkTextActor() text_actor.SetInput(caption) text_actor.GetTextProperty().SetFontSize(20) text_actor.GetTextProperty().SetColor(0.5, 0.5, 0.5) text_actor.SetPosition(100, 16) renderer = vtk.vtkRenderer() renderer.SetBackground([0.5, 0.5, 0.5]) renderer.AddActor(actor) renderer.AddActor2D(scalarBar) renderer.AddActor2D(text_actor) #### window = vtk.vtkRenderWindow() interactor = vtk.vtkRenderWindowInteractor() interactor.SetInteractorStyle(molar.pdb_viewer.PdbInteractorStyle()) interactor.SetRenderWindow(window) window.SetSize(1800, 1200) window.AddRenderer(renderer) window.Render() interactor.Start()
def init_plane_widget(self): self.scalar_bar = vtk.vtkScalarBarActor() # Must add this to avoid vtkTextActor error self.scalar_bar.SetTitle("Number of counts") self.scalar_bar.SetWidth(0.1) self.scalar_bar.SetHeight(0.9) self.scalar_bar.SetLookupTable(self.lut) # The image plane widget are used to probe the dataset. self.plane_widget = vtk.vtkPlaneWidget() if vtk.vtkVersion.GetVTKMajorVersion() < 6: self.plane_widget.SetInput(self.data) else: self.plane_widget.SetInputData(self.data) #VTK6 self.plane_widget.NormalToXAxisOn() #TODO self.plane_widget.SetRepresentationToOutline() self.plane_widget.PlaceWidget() self.plane_widget.SetResolution(350) #TODO self.plane = vtk.vtkPolyData() self.plane_widget.GetPolyData(self.plane) self.implicit_plane = vtk.vtkPlane() self.plane_widget.GetPlane(self.implicit_plane) self.probe = vtk.vtkProbeFilter() if vtk.vtkVersion.GetVTKMajorVersion() < 6: self.probe.SetInput(self.plane) self.probe.SetSource(self.data) else: self.probe.SetInputData(self.plane) #VTK6 self.probe.SetSourceData(self.data) self.probe.Update() contour_mapper = vtk.vtkPolyDataMapper() contour_mapper.SetInputConnection(self.probe.GetOutputPort()) contour_mapper.SetScalarRange(self.mi, self.ma) contour_mapper.SetLookupTable(self.lut) self.contour_actor = vtk.vtkActor() self.contour_actor.SetMapper(contour_mapper) self.contour_actor.GetProperty().ShadingOff() self.contour_actor.GetProperty().SetAmbient(0.6) self.contour_actor.GetProperty().SetDiffuse(0.4) self.plane_widget.AddObserver('InteractionEvent', self.update_interactive_plane_widget) self.plane_widget.AddObserver('StartInteractionEvent', self.on_pick) # Associate the widget with the interactor self.plane_widget.SetInteractor(self.iren) self.plane_widget.SetEnabled(1) self.disablation_mode = True self.renderer.AddActor(self.contour_actor) self.renderer.AddActor2D(self.scalar_bar) #TODO self.renwin.Render()
def color_bar(ctf, title=None, num_lbl=10, label_fmt=None, text_color='k', bgcolor='0.9', bg_opacity=1.0, frame_color='r', barw=0.08, barh=0.8, barx=0.9, bary=0.1, renderer=None): require_isinstance(ctf, vtk.vtkScalarsToColors) abar = vtk.vtkScalarBarActor() abar.SetLookupTable(ctf) if isinstance(ctf, vtk.vtkLookupTable): abar.SetMaximumNumberOfColors(ctf.GetNumberOfColors()) abar.UseOpacityOn() # tcolor = colors.to_rgb(text_color) lp = abar.GetLabelTextProperty() lp.SetColor(tcolor) lp.ShadowOff() lp.BoldOff() lp.ItalicOff() if title is not None: abar.SetTitle(title) tp = abar.GetTitleTextProperty() tp.SetColor(tcolor) #tp.SetOrientation(90.0) tp.ShadowOff() tp.BoldOff() tp.ItalicOff() # if bgcolor is not None: abar.DrawBackgroundOn() bp = abar.GetBackgroundProperty() bp.SetColor(colors.to_rgb(bgcolor)) bp.SetOpacity(bg_opacity) # if frame_color is not None: abar.DrawFrameOn() abar.GetFrameProperty().SetColor(colors.to_rgb(frame_color)) # abar.SetNumberOfLabels(int(num_lbl)) abar.SetPosition(barx, bary) abar.SetWidth(barw) abar.SetHeight(barh) if label_fmt is not None: abar.SetLabelFormat(label_fmt) # if renderer is not None: renderer.AddActor2D(abar) # return abar
def __init__(self, ws, parent=None): super().__init__(parent) self.vtkWidget = QVTKRenderWindowInteractor(self) vti = self.md_to_vti(ws) self.mapper = vtk.vtkDataSetMapper() self.mapper.SetInputData(vti) self.mapper.ScalarVisibilityOn() self.mapper.SetScalarModeToUseCellData() self.mapper.SetColorModeToMapScalars() self.actor = vtk.vtkActor() self.actor.SetMapper(self.mapper) scalarBar = vtk.vtkScalarBarActor() scalarBar.SetLookupTable(self.mapper.GetLookupTable()) scalarBar.SetNumberOfLabels(4) srange = vti.GetScalarRange() self.lut = vtk.vtkLookupTable() self.lut.SetTableRange(srange) self.lut.Build() self.mapper.UseLookupTableScalarRangeOn() self.mapper.SetLookupTable(self.lut) scalarBar.SetLookupTable(self.lut) self.renderer = vtk.vtkRenderer() self.renderer.GradientBackgroundOn() self.renderer.SetBackground(0.8, 0.8, 0.8) self.renderer.SetBackground2(0, 0, 0) axes = vtk.vtkCubeAxesActor() axes.SetUseTextActor3D(1) axes.SetBounds(vti.GetBounds()) axes.SetCamera(self.renderer.GetActiveCamera()) axes.DrawXGridlinesOn() axes.DrawYGridlinesOn() axes.DrawZGridlinesOn() axes.SetFlyModeToOuterEdges() self.renderer.AddActor(self.actor) self.renderer.AddActor(axes) self.renderer.AddActor2D(scalarBar) self.renderer.ResetCamera() self.vtkWidget.GetRenderWindow().AddRenderer(self.renderer) self.iren = self.vtkWidget.GetRenderWindow().GetInteractor() layout = QVBoxLayout() layout.addWidget(self.vtkWidget) self.setLayout(layout) self.iren.Initialize()
def _addScalarBar(self, val): if len(val.shape) > 1: val = norm(val, axis=1) self._setupColorFunction(val.min(), val.max()) self._scalarBar = vtk.vtkScalarBarActor() self._scalarBar.SetLookupTable(self._colorTransferFunction) self._scalarBar.SetTitle("Velocities (m/s)") self._ren.AddActor2D(self._scalarBar)
def PlotQualFace(mesh, qual, rng, scbar=False): """ Plot score """ # Add score to mesh vtkfloat = VN.numpy_to_vtk(np.ascontiguousarray(qual), deep=True) vtkfloat.SetName('Score') mesh.GetCellData().AddArray(vtkfloat) mesh.GetCellData().SetActiveScalars('Score') mapper = vtk.vtkDataSetMapper() if vtk.vtkVersion().GetVTKMajorVersion() >5: mapper.SetInputData(mesh) else: mapper.SetInput(mesh) mapper.SetScalarRange(rng[0], rng[1]) mapper.SetScalarModeToUseCellData() # Create Actor actor = vtk.vtkActor() actor.SetMapper(mapper) actor.GetProperty().SetRepresentationToSurface() actor.GetProperty().EdgeVisibilityOn() actor.GetProperty().SetColor(1, 1, 1) actor.GetProperty().LightingOff() # Add FEM Actor to renderer window ren = vtk.vtkRenderer() ren.SetBackground(0.3, 0.3, 0.3) renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # Allow user to interact istyle = vtk.vtkInteractorStyleTrackballCamera() iren.SetInteractorStyle(istyle) # Add actor ren.AddActor(actor) if scbar: scalarBar = vtk.vtkScalarBarActor() scalarBar.SetLookupTable(mapper.GetLookupTable()) # scalarBar.SetTitle('Quality') scalarBar.SetNumberOfLabels(5) ren.AddActor(scalarBar) # Render iren.Initialize() renWin.Render() iren.Start()
def add_color_bar(self): colorbar=vtk.vtkScalarBarActor() colorbar.SetMaximumNumberOfColors(400) colorbar.SetLookupTable(self.mapper_list[0].GetLookupTable()) colorbar.SetWidth(0.09) colorbar.SetPosition(0.91,0.1) colorbar.SetLabelFormat("%.3g mm") colorbar.VisibilityOn() if len(self.color_list) == 0: self.ren.AddActor(colorbar)
def BuildView(self): if not self.vmtkRenderer: self.vmtkRenderer = vmtkrenderer.vmtkRenderer() self.vmtkRenderer.Initialize() self.OwnRenderer = 1 self.vmtkRenderer.RegisterScript(self) if self.Actor != None: self.vmtkRenderer.Renderer.RemoveActor(self.Actor) if self.ScalarBarActor != None: self.vmtkRenderer.Renderer.RemoveActor(self.ScalarBarActor) if self.Mesh != None: mapper = vtk.vtkDataSetMapper() mapper.SetInput(self.Mesh) if (self.ArrayName != ''): self.Mesh.GetPointData().SetActiveScalars(self.ArrayName) if (self.Mesh.GetPointData().GetScalars() != None): array = self.Mesh.GetPointData().GetScalars() if (self.ScalarRange[1] > self.ScalarRange[0]): mapper.SetScalarRange(self.ScalarRange) else: mapper.SetScalarRange(array.GetRange(0)) if (self.Grayscale == 1): lut = vtk.vtkLookupTable() lut.SetValueRange(0.0, 1.0) lut.SetSaturationRange(0.0, 0.0) mapper.SetLookupTable(lut) self.Actor = vtk.vtkActor() self.Actor.SetMapper(mapper) if (self.FlatInterpolation == 1): self.Actor.GetProperty().SetInterpolationToFlat() self.Actor.GetProperty().SetOpacity(self.Opacity) self.vmtkRenderer.Renderer.AddActor(self.Actor) if (self.Legend == 1) & (self.Actor != None): self.ScalarBarActor = vtk.vtkScalarBarActor() self.ScalarBarActor.SetLookupTable( self.Actor.GetMapper().GetLookupTable()) self.ScalarBarActor.GetLabelTextProperty().ItalicOff() self.ScalarBarActor.GetLabelTextProperty().BoldOff() self.ScalarBarActor.GetLabelTextProperty().ShadowOff() ## self.ScalarBarActor.GetLabelTextProperty().SetColor(0.0,0.0,0.0) self.ScalarBarActor.SetLabelFormat('%.2f') self.vmtkRenderer.Renderer.AddActor(self.ScalarBarActor) if (self.Display == 1): self.vmtkRenderer.Render() if self.OwnRenderer: self.vmtkRenderer.Deallocate()
def __init__(self, project, opv): super().__init__(vtkInteractorStyleClicker(self)) self.project = project self.opv = opv self.textActorUnit = vtk.vtkTextActor() self.colorbar = vtk.vtkScalarBarActor() self.setUsePicker(False) self.frequencyIndice = -1 self.sliderFactor = 1 self.valueFactor = -1
def BuildView(self): if not self.vmtkRenderer: self.vmtkRenderer = vmtkrenderer.vmtkRenderer() self.vmtkRenderer.Initialize() self.OwnRenderer = 1 self.vmtkRenderer.RegisterScript(self) if self.Actor != None: self.vmtkRenderer.Renderer.RemoveActor(self.Actor) if self.ScalarBarActor != None: self.vmtkRenderer.Renderer.RemoveActor(self.ScalarBarActor) if self.Mesh != None: mapper = vtk.vtkDataSetMapper() mapper.SetInput(self.Mesh) if (self.ArrayName != ''): self.Mesh.GetPointData().SetActiveScalars(self.ArrayName) if (self.Mesh.GetPointData().GetScalars() != None): array = self.Mesh.GetPointData().GetScalars() if (self.ScalarRange[1] > self.ScalarRange[0]): mapper.SetScalarRange(self.ScalarRange) else: mapper.SetScalarRange(array.GetRange(0)) if (self.Grayscale == 1): lut = vtk.vtkLookupTable() lut.SetValueRange(0.0,1.0) lut.SetSaturationRange(0.0,0.0) mapper.SetLookupTable(lut) self.Actor = vtk.vtkActor() self.Actor.SetMapper(mapper) if (self.FlatInterpolation == 1): self.Actor.GetProperty().SetInterpolationToFlat() self.Actor.GetProperty().SetOpacity(self.Opacity) self.vmtkRenderer.Renderer.AddActor(self.Actor) if (self.Legend == 1) & (self.Actor != None): self.ScalarBarActor = vtk.vtkScalarBarActor() self.ScalarBarActor.SetLookupTable(self.Actor.GetMapper().GetLookupTable()) self.ScalarBarActor.GetLabelTextProperty().ItalicOff() self.ScalarBarActor.GetLabelTextProperty().BoldOff() self.ScalarBarActor.GetLabelTextProperty().ShadowOff() ## self.ScalarBarActor.GetLabelTextProperty().SetColor(0.0,0.0,0.0) self.ScalarBarActor.SetLabelFormat('%.2f') self.vmtkRenderer.Renderer.AddActor(self.ScalarBarActor) if (self.Display == 1): self.vmtkRenderer.Render() if self.OwnRenderer: self.vmtkRenderer.Deallocate()
def PlotQualFace(mesh, qual, rng, scbar=False): """ Plot score """ # Add score to mesh vtkfloat = VN.numpy_to_vtk(np.ascontiguousarray(qual), deep=True) vtkfloat.SetName('Score') mesh.GetCellData().AddArray(vtkfloat) mesh.GetCellData().SetActiveScalars('Score') mapper = vtk.vtkDataSetMapper() if vtk.vtkVersion().GetVTKMajorVersion() > 5: mapper.SetInputData(mesh) else: mapper.SetInput(mesh) mapper.SetScalarRange(rng[0], rng[1]) mapper.SetScalarModeToUseCellData() # Create Actor actor = vtk.vtkActor() actor.SetMapper(mapper) actor.GetProperty().SetRepresentationToSurface() actor.GetProperty().EdgeVisibilityOn() actor.GetProperty().SetColor(1, 1, 1) actor.GetProperty().LightingOff() # Add FEM Actor to renderer window ren = vtk.vtkRenderer() ren.SetBackground(0.3, 0.3, 0.3) renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # Allow user to interact istyle = vtk.vtkInteractorStyleTrackballCamera() iren.SetInteractorStyle(istyle) # Add actor ren.AddActor(actor) if scbar: scalarBar = vtk.vtkScalarBarActor() scalarBar.SetLookupTable(mapper.GetLookupTable()) # scalarBar.SetTitle('Quality') scalarBar.SetNumberOfLabels(5) ren.AddActor(scalarBar) # Render iren.Initialize() renWin.Render() iren.Start()
def __init__(self, lut=None, **kwargs): self.actor = vtk.vtkScalarBarActor() self.actor.SetMaximumNumberOfColors(400) if lut is None: lut = get_jet_lut() self.lut = lut self.actor.SetLookupTable(lut) self.actor.SetWidth(0.05) self.actor.SetPosition(0.95, 0.1) self.actor.SetLabelFormat("%.3g") self.actor.VisibilityOn()
def show(self): actors = [] gridMapper = vtk.vtkDataSetMapper() gridMapper.SetInputData(self.grid) data = self.grid.GetCellData().GetScalars() if data: lut = vtk.vtkLookupTable() lut.SetHueRange(0., 0.666) dmin, dmax = data.GetRange() # reset the colour scale min to map to area 0 dmin = 0.0 lut.SetTableRange(dmin, dmax) lut.Build() cbar = vtk.vtkScalarBarActor() cbar.SetLookupTable(lut) #actors.append(cbar) gridMapper.SetLookupTable(lut) gridMapper.SetUseLookupTableScalarRange(1) gridActor = vtk.vtkActor() gridActor.SetMapper(gridMapper) #gridActor.GetProperty().SetColor(93./255., 173./255., 226./255.) actors.append(gridActor) light = vtk.vtkLight() light.SetFocalPoint(0., 0., 0) light.SetPosition(1., 1., 0.) #light.SetSpecularColor(0.8, 0.2, 0.0) #light.SetDiffuseColor(0., 0.2, 0.8) light.SetConeAngle(0.2) light.SetIntensity(1.0) ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # add the actors to the renderer, set the background and size for a in actors: ren.AddActor(a) #ren.AddLight(light) ren.SetBackground(1, 1, 1) renWin.SetSize(640, 640) iren.Initialize() renWin.Render() iren.Start()
def makeScalarbar(self, lut): """Create color bar.""" scalarbar = vtk.vtkScalarBarActor() scalarbar.SetLookupTable(lut) scalarbar.GetPositionCoordinate( ).SetCoordinateSystemToNormalizedViewport() scalarbar.GetPositionCoordinate().SetValue(0.1, 0.01) scalarbar.SetOrientationToHorizontal() scalarbar.SetWidth(0.8) scalarbar.SetHeight(0.14) scalarbar.VisibilityOff() scalarbar.GetTitleTextProperty().SetColor(0, 0, 0) scalarbar.GetLabelTextProperty().SetColor(0, 0, 0) return scalarbar
def plot_roots(pd, p_name, render=True, axis='side_view'): """ renders the root system in an interactive window @param pd the polydata representing the root system @param p_name parameter name of the data to be visualized @param render render in a new interactive window (default = True) @param axis inital view: 'side_view' (default, xz), 'top_view' (xy),'oblique' (nice) @return The vtkActor object """ if isinstance(pd, pb.RootSystem): pd = segs_to_polydata(pd, 1.) if isinstance(pd, pb.SegmentAnalyser): pd = segs_to_polydata(pd, 1.) pd.GetPointData().SetActiveScalars("radius") # for the the filter tubeFilter = vtk.vtkTubeFilter() tubeFilter.SetInputData(pd) tubeFilter.SetNumberOfSides(9) tubeFilter.SetVaryRadiusToVaryRadiusByAbsoluteScalar() tubeFilter.Update() mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(tubeFilter.GetOutputPort()) mapper.Update() mapper.ScalarVisibilityOn() mapper.SetScalarModeToUseCellFieldData() # Cell is not working mapper.SetArrayName(p_name) mapper.SelectColorArray(p_name) mapper.UseLookupTableScalarRangeOn() plantActor = vtk.vtkActor() plantActor.SetMapper(mapper) lut = get_lookup_table(24) # 24= Brewer Diverging Brown-Blue-Green (11) lut.SetTableRange(pd.GetPointData().GetScalars(p_name).GetRange()) mapper.SetLookupTable(lut) scalarBar = vtk.vtkScalarBarActor() scalarBar.SetLookupTable(lut) scalarBar.SetTitle(p_name) textProperty = vtk.vtkTextProperty() textProperty.SetFontSize(1) scalarBar.SetTitleTextProperty(textProperty) scalarBar.SetLabelTextProperty(textProperty) # scalarBar.SetAnnotationTextProperty(textProperty) if render: render_window(plantActor, p_name, scalarBar, axis).Start() return plantActor, scalarBar
def initVtkBar(self) : '''Initialize the scalar bar for color levels''' aSBar = vtk.vtkScalarBarActor() aSBar.SetOrientationToVertical() aSBar.SetLookupTable(self._lut) aSBar.SetTitle("Residue score") aSBar.GetLabelTextProperty().SetColor(0.8, 0.8, 0.8) aSBar.GetTitleTextProperty().SetColor(0.8, 0.8, 0.8) aSBar.SetWidth(0.1) aSBar.SetHeight(0.9) spc = aSBar.GetPositionCoordinate() spc.SetCoordinateSystemToNormalizedViewport() spc.SetValue(0.05, 0.05) return aSBar
def create_colourbar(lut, title=None): colourbar = vtk.vtkScalarBarActor() colourbar.SetBarRatio(0.2) colourbar.SetWidth(0.15) colourbar.SetHeight(0.8) colourbar.SetNumberOfLabels(2) colourbar.SetTextPositionToPrecedeScalarBar() colourbar.SetTextPad(5) colourbar.SetLabelFormat('%.2f') colourbar.GetLabelTextProperty().ItalicOff() colourbar.SetLookupTable(lut) colourbar.SetMaximumNumberOfColors(lut.GetNumberOfTableValues()) colourbar.SetTitle(title if title else '') colourbar.GetTitleTextProperty().ItalicOff() return colourbar
def AddDistance(renderer,renderWindowInteractor,distance,actor): # Create the color map minD=min(distance) print("Distance min : "+str(minD)) maxD=max(distance) print("Distance max : "+str(maxD)) colorLookupTable = vtk.vtkLookupTable() colorLookupTable.SetTableRange(minD, maxD) colorLookupTable.SetHueRange(0.667, 0.0) colorLookupTable.Build() # Get Points pointPolyData=actor.GetMapper().GetInput() # Generate colors for each points colors = vtk.vtkUnsignedCharArray() colors.SetNumberOfComponents(3) colors.SetName("Colors") for i in range (pointPolyData.GetNumberOfPoints()): p= 3*[0.0] pointPolyData.GetPoint(i,p) dcolor = 3*[0.0] colorLookupTable.GetColor(distance[i], dcolor) color=3*[0.0] for j in range(0,3): color[j] = int(255.0 * dcolor[j]) colors.InsertNextTypedTuple(color) pointPolyData.GetPointData().SetScalars(colors) # create the scalar_bar scalar_bar = vtk.vtkScalarBarActor() scalar_bar.SetMaximumWidthInPixels(50) scalar_bar.SetOrientationToHorizontal() scalar_bar.SetLookupTable(colorLookupTable) scalar_bar.SetTitle("Distance") # create the scalar_bar_widget scalar_bar_widget = vtk.vtkScalarBarWidget() scalar_bar_widget.SetInteractor(renderWindowInteractor) scalar_bar_widget.SetScalarBarActor(scalar_bar) scalar_bar_widget.On() # Add the actor to the scene renderWindowInteractor.Start() renderWindowInteractor.Disable() #start required or no bar actor show
def creaVertColorScaleBar(self): '''Creates the scalar bar that indicates to the viewer the correspondence between color values and data values ''' self.scalarBar= vtk.vtkScalarBarActor() pos= self.scalarBar.GetPositionCoordinate() pos.SetCoordinateSystemToNormalizedViewport() pos.SetValue(0.85,0.25) self.scalarBar.SetOrientationToVertical() self.scalarBar.SetWidth(0.1) self.scalarBar.SetHeight(0.7) self.scalarBar.SetLookupTable(self.lookUpTable) self.scalarBar.Modified() return self.scalarBar
def createScalarBar(self, sliceViewName): if self.hasVTKPVScalarBarActor: scalarBar = slicer.vtkPVScalarBarActor() else: scalarBar = vtk.vtkScalarBarActor() scalarBar.SetTitle(" ") # adjust text property if self.hasVTKPVScalarBarActor: scalarBar.SetRangeLabelFormat(self.rangeLabelFormat) lookupTable = vtk.vtkLookupTable() scalarBar.SetLookupTable(lookupTable) ''' scalarBarWidget = vtk.vtkScalarBarWidget() scalarBarWidget.SetScalarBarActor(scalarBar) self.scalarBarWidgets[sliceViewName] = scalarBarWidget ''' return scalarBar
def buildVTK(self, infile_name, dirname=None): self.infile_name = infile_name self.rend = vtk.vtkRenderer() self.scalarBar = vtk.vtkScalarBarActor() self.load_nastran_geometry(self.infile_name, dirname) self.main() #self.renWin = vtk.vtkRenderWindow() #renWin = window cam = self.rend.GetActiveCamera() mouseArgs = {'pipeline': self, 'camera': cam} xSize = 800 ySize = 600 (x, y) = getScreenCorner(xSize, ySize)
def setScalarBar(self, actor, viewport=0, title=''): r""" Set the scalar bar within the window based upon a look-up table defined within an actor Parameters --------- actor: ampActor The actor from which the lut is read from, the actor must have the attribute actor.lut viewport: int, default 0 The viewport index to render the scalar bar within title: str The accompanying title for the scalar bar Returns ------- scalar_bar A vtkScalarBarActor attribute to the vtkRenWin """ if self.scalar_bar is not None: self.rens[0].RemoveActor(self.scalar_bar) self.scalar_bar = vtk.vtkScalarBarActor() # self.scalar_bar.AnnotationTextScalingOff() # self.scalar_bar.SetTitle('Interfacial Pressure, kPa') self.scalar_bar.SetLookupTable(actor.lut) self.scalar_bar.UnconstrainedFontSizeOn() self.scalar_bar.SetOrientationToVertical() self.scalar_bar.SetPosition(0.8, 0.15) self.scalar_bar.SetPosition2(0.1, 0.7) self.scalar_bar.SetLabelFormat('%-#3.1f') self.scalar_bar.GetLabelTextProperty().SetFontFamilyToArial() self.scalar_bar.GetLabelTextProperty().BoldOff() self.scalar_bar.GetLabelTextProperty().ShadowOff() self.scalar_bar.GetLabelTextProperty().SetColor(0, 0, 0) self.scalar_bar.GetLabelTextProperty().SetFontSize(18) self.scalar_bar.GetLabelTextProperty().ItalicOff() self.scalar_bar.SetTitle(title) self.scalar_bar.GetTitleTextProperty().SetFontFamilyToArial() self.scalar_bar.GetTitleTextProperty().BoldOff() self.scalar_bar.GetTitleTextProperty().ShadowOff() self.scalar_bar.GetTitleTextProperty().SetColor(0, 0, 0) self.scalar_bar.GetTitleTextProperty().SetFontSize(20) self.scalar_bar.GetTitleTextProperty().ItalicOff() self.rens[viewport].AddActor(self.scalar_bar)
def addLegend(self, lut): """Add a color bar and a color legend""" tprop = self.textProperty(fontsize = self.opt.legend_fontsize) legend = vtk.vtkScalarBarActor() legend.SetLookupTable(lut) legend.SetLabelTextProperty(tprop) legend.GetLabelTextProperty().BoldOff() legend.SetLabelFormat(self.opt.legend_format) legend.SetNumberOfLabels(self.opt.color_levels) legend.GetPositionCoordinate().SetCoordinateSystemToNormalizedDisplay() if self.opt.legend: legend.SetTitle(self.opt.legend) legend.SetTitleTextProperty(tprop) legend.GetTitleTextProperty().BoldOff() if self.opt.color_position in ('South', 'North'): legend.SetOrientationToHorizontal() else: legend.SetOrientationToVertical() __locations = {'North': (0.1, 0.9 , 0.8, 0.1), 'South': (0.1, 0.01, 0.8, 0.1), 'West': (0.01, 0.1, 0.1, 0.8), 'East': (0.9, 0.09, 0.1, 0.8)} cbloc = __locations[self.opt.color_position] if not self.opt.color_width: legend.SetWidth(cbloc[2]) else: legend.SetWidth(self.opt.color_width) if not self.opt.color_height: legend.SetHeight(cbloc[3]) else: legend.SetHeight(self.opt.color_height) if not self.opt.color_coord: legend.GetPositionCoordinate().SetValue(cbloc[0], cbloc[1]) else: legend.GetPositionCoordinate().SetValue(self.opt.color_coord[0], self.opt.color_coord[1]) return legend
def Save_VTK_data_to_picture_file(inputFileName, field_name, node_or_cell, outputFileName ): reader = vtk.vtkXMLUnstructuredGridReader() reader.SetFileName(inputFileName) reader.Update() if node_or_cell== 'CELLS': reader.CellArrayStatus = [field_name] reader.GetOutput().GetCellData().SetActiveScalars(field_name) elif node_or_cell== 'NODES': reader.PointArrayStatus = [field_name] reader.GetOutput().GetPointData().SetActiveScalars(field_name) else: raise ValueError("unknown type : should be CELLS or NODES") #------------------------------------------------------------------------------- mapper = vtk.vtkDataSetMapper() mapper.SetInputConnection(reader.GetOutputPort()) actor = vtk.vtkActor() actor.SetMapper(mapper) scalarBar=vtk.vtkScalarBarActor() scalarBar.SetLookupTable(mapper.GetLookupTable()) scalarBar.SetTitle(field_name) mapper.SetScalarRange(reader.GetOutput().GetScalarRange()) ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) ren.AddViewProp(actor) ren.AddActor2D(scalarBar); renWin.Render() image = vtk.vtkWindowToImageFilter() image.SetInput(renWin) image.ReadFrontBufferOff() image.Update() writer = vtk.vtkPNGWriter() writer.SetFileName(outputFileName+".png") writer.SetInputConnection(image.GetOutputPort()) writer.Write()
def buildVTK(self, bdfFileName=None, dirname=None): self.bdfFileName = bdfFileName self.rend = vtk.vtkRenderer() self.scalarBar = vtk.vtkScalarBarActor() self.loadNastranGeometry(self.bdfFileName, dirname, self.isNodal, self.isCentroidal) self.main() #self.renWin = vtk.vtkRenderWindow() #renWin = window cam = self.rend.GetActiveCamera() mouseArgs = {'pipeline': self, 'camera': cam} xSize = 800 ySize = 600 (x, y) = getScreenCorner(xSize, ySize)
def __init__(self, min=0, max=1, nColors=80, title='Scale', reverse=False): self.cTable = vtk.vtkLookupTable() self.cTable.SetNumberOfColors(nColors) self.cTable.SetRange((min, max)) self.cTable.Build() if reverse: c = map(self.cTable.GetTableValue, range(nColors)) c.reverse() map(self.cTable.SetTableValue, range(nColors), c) self._actor = vtk.vtkScalarBarActor() self._actor.SetLookupTable(self.cTable) self._actor.SetTitle(title) #self._actor.ShadowOn() self._actor.GetPositionCoordinate().SetCoordinateSystemToNormalizedViewport() self._actor.GetPositionCoordinate().SetValue(0.1,0.1) self._actor.SetOrientationToHorizontal() self._actor.SetWidth(0.8) self._actor.SetHeight(0.17)
def __init__(self, datafilename, posfilename): self.datahandler = TraubDataHandler(datafilename, posfilename) self.glyph_source_map = {} self.scalarbar = None self.renderer = vtk.vtkRenderer() self.renwin = vtk.vtkRenderWindow() self.renwin.SetSize(1280, 900) # self.renwin.SetStereoRender(True) # self.renwin.StereoCapableWindowOn() # self.renwin.SetStereoTypeToCrystalEyes() # self.renwin.StereoRenderOn() self.renwin.AddRenderer(self.renderer) self.colorfn = vtk.vtkColorTransferFunction() colormap_matrix = numpy.loadtxt('cool.cmp') index = 0 for value in numpy.linspace(-120e-3, 40e-3, len(colormap_matrix)): self.colorfn.AddRGBPoint(value, colormap_matrix[index, 0], colormap_matrix[index, 1], colormap_matrix[index, 2]) index += 1 pyramidal_pos = self.datahandler.position_array[self.datahandler.pyramidal_indices] self.pyramidal_pipeline = self.__create_cells(pyramidal_pos, 'cone') nonpyramidal_pos = self.datahandler.position_array[self.datahandler.nonpyramidal_indices] self.nonpyramidal_pipeline = self.__create_cells(nonpyramidal_pos, 'sphere') # Create colour mapping for Vm values self.renderer.AddActor(self.pyramidal_pipeline['actor']) self.renderer.AddActor(self.nonpyramidal_pipeline['actor']) # Set up color-bar scalarbar = vtk.vtkScalarBarActor() scalarbar.SetLookupTable(self.colorfn) scalarbar.SetPosition(0.95, 0.1) scalarbar.SetHeight(0.80) scalarbar.SetWidth(0.05) scalarbar.SetOrientationToVertical() self.renderer.AddActor2D(scalarbar) self.camera = vtk.vtkCamera() #self.renderer.GetActiveCamera() self.camera.SetPosition(0.0, 500.0, -1200.0) self.camera.SetFocalPoint(0, 0, -1200) self.camera.ComputeViewPlaneNormal() self.renderer.SetActiveCamera(self.camera) self.renderer.ResetCamera() self.interactor = vtk.vtkRenderWindowInteractor() self.interactor.SetRenderWindow(self.renwin)
def set_colorbar(title): scalarBar = vtk.vtkScalarBarActor() scalarBar.SetWidth(0.15) scalarBar.SetHeight(0.5) scalarBar.SetTitle(title) scalarBar.SetOrientationToVertical() scalarBar.GetTitleTextProperty().SetColor(0,0,0) scalarBar.GetLabelTextProperty().SetColor(0,0,0) scalarBar.SetPosition(0.8,0.4) lut = vtk.vtkLookupTable() nb_of_labels = 256 # rainbow Colormap lut.SetHueRange(0.666667,0.0) lut.SetSaturationRange(0.75,0.75) lut.SetValueRange(1.0,1.0) lut.SetAlphaRange(1.0,1.0) lut.SetNumberOfColors(nb_of_labels) lut.Build() scalarBar.SetLookupTable(lut) return scalarBar
def __init__(self,data_reader,scalar_bar_number): # Create a colorscale lookup table self.lut=vtk.vtkLookupTable() self.lut.SetNumberOfColors(256) self.lut.SetTableRange(data_reader.get_scalar_range()) self.lut.SetHueRange(0,1) self.lut.SetRange(data_reader.get_scalar_range()) self.lut.Build() self.actor= vtk.vtkScalarBarActor() self.actor.SetOrientationToVertical() self.actor.SetPosition( 0.9, 0.77-0.25*scalar_bar_number) self.actor.SetPosition2( 0.09, 0.24 ) self.propT = vtk.vtkTextProperty() self.propL = vtk.vtkTextProperty() self.propT.SetFontFamilyToArial() self.propT.SetColor(0.5,0.5,0.5) self.propT.ItalicOff() self.propT.BoldOn() self.propL.BoldOff() self.actor.SetLookupTable(self.lut)
def makeColorbar(self): """ create colorbar """ colorbar = vtk.vtkScalarBarActor() colorbar.SetLookupTable(self.mapper.GetLookupTable()) colorbar.SetWidth(0.085) colorbar.SetHeight(0.8) colorbar.SetPosition(0.9, 0.1) colorbar.SetLabelFormat(self.config.LabelFormat()) colorbar.SetNumberOfLabels(5) text_prop_cb = colorbar.GetLabelTextProperty() text_prop_cb.SetFontFamilyAsString('Arial') text_prop_cb.SetFontFamilyToArial() text_prop_cb.SetColor(self.fgColor) text_prop_cb.SetFontSize(1) text_prop_cb.ShadowOff() colorbar.SetLabelTextProperty(text_prop_cb) return colorbar
def init_scalar_bar (self): "Sets up the default scalar bar." debug ("In LutHandler::init_scalar_bar ()") self.sc_bar = vtk.vtkScalarBarActor () self.sc_bar.SetLookupTable (self.lut) self.sc_bar.GetPositionCoordinate ().SetCoordinateSystemToNormalizedViewport () self.set_horizontal () self.sc_bar.SetVisibility (0) self.sc_bar.SetNumberOfLabels (8) fg_color = Common.config.fg_color self.sc_bar.GetProperty ().SetColor(fg_color) if hasattr(self.sc_bar, "GetTitleTextProperty"): ttp = self.sc_bar.GetTitleTextProperty() ltp = self.sc_bar.GetLabelTextProperty() ttp.SetShadow (self.shadow_on_var.get ()) ltp.SetShadow (self.shadow_on_var.get ()) ttp.SetColor(fg_color) ltp.SetColor(fg_color) else: self.sc_bar.SetShadow (self.shadow_on_var.get ()) self.module_mgr.get_render_window ().add_actors (self.sc_bar)
def __init__(self, renwin, mod_m): self.renwin = renwin self.mod_m = mod_m self.sc_bar = sb = vtk.vtkScalarBarActor() self.lut = vtk.vtkLookupTable() self.lut.SetNumberOfColors(101) self.lut.Build() self.lut.SetRange(self.mod_m.get_scalar_data_range()) name = self.mod_m.get_scalar_data_name() if not name: name = " " self.sc_bar.SetTitle(name) sb.SetLookupTable(self.lut) sb.SetVisibility(0) sb.GetPositionCoordinate().SetCoordinateSystemToNormalizedViewport() self.set_horizontal () sb.SetNumberOfLabels (8) sb.GetProperty ().SetColor(*Common.config.fg_color) self.root = None self.legend_orient = Tkinter.IntVar() self.legend_orient.set(0)
def onColourBarVisibilityChangeEvent(self, evt): pane = self.renderPanes[0] if evt.GetVisibility(): # create actor if needed if self.colourbarActor is None: self.colourbarActor = vtk.vtkScalarBarActor() self.colourbarActor.SetOrientationToVertical() self.colourbarActor.SetNumberOfLabels(5) self.colourbarActor.SetLookupTable(self.GetLookupTable()) self.colourbarActor.SetWidth(0.1) # add actor pane.GetRenderer().AddActor(self.colourbarActor) self.colourbar_visibility = True else: # remove actor pane.GetRenderer().RemoveActor(self.colourbarActor) self.colourbar_visibility = False pane.Modified() pane.Render()
def _showScalarBarForProp(self, prop): """Show scalar bar for the data represented by the passed prop. If prop is None, the scalar bar will be removed and destroyed if present. """ destroyScalarBar = False if prop: # activate the scalarbar, connect to mapper of prop if prop.GetMapper() and prop.GetMapper().GetLookupTable(): if not hasattr(self, '_pdScalarBarActor'): self._pdScalarBarActor = vtk.vtkScalarBarActor() self._threedRenderer.AddViewProp(self._pdScalarBarActor) sname = "Unknown" s = prop.GetMapper().GetInput().GetPointData().GetScalars() if s and s.GetName(): sname = s.GetName() self._pdScalarBarActor.SetTitle(sname) self._pdScalarBarActor.SetLookupTable( prop.GetMapper().GetLookupTable()) self.threedFrame.threedRWI.Render() else: # the prop doesn't have a mapper or the mapper doesn't # have a LUT, either way, we switch off the thingy... destroyScalarBar = True else: # the user has clicked "somewhere else", so remove! destroyScalarBar = True if destroyScalarBar and hasattr(self, '_pdScalarBarActor'): self._threedRenderer.RemoveViewProp(self._pdScalarBarActor) del self._pdScalarBarActor
def add_widgets(self): # axes axes = vtk.vtkAxesActor() self.marker_widget = vtk.vtkOrientationMarkerWidget() self.marker_widget.SetInteractor(self.iren) self.marker_widget.SetOrientationMarker(axes) self.marker_widget.SetViewport(0.0, 0.0, 0.25, 0.25) # scalar bar self.scalarbar_actor = vtk.vtkScalarBarActor() self.scalarbar_actor.SetLookupTable(self.lut) self.scalarbar_widget = vtk.vtkScalarBarWidget() self.scalarbar_widget.SetInteractor(self.iren) self.scalarbar_widget.SetScalarBarActor(self.scalarbar_actor) # contour slider self.slider_rep = vtk.vtkSliderRepresentation2D() self.slider_rep.SetTitleText("contour") self.slider_rep.GetPoint1Coordinate().SetCoordinateSystemToNormalizedViewport() self.slider_rep.GetPoint1Coordinate().SetValue(0.65, 0.1) self.slider_rep.GetPoint2Coordinate().SetCoordinateSystemToNormalizedViewport() self.slider_rep.GetPoint2Coordinate().SetValue(0.95, 0.1) self.slider_widget = vtk.vtkSliderWidget() self.slider_widget.SetInteractor(self.iren) self.slider_widget.SetRepresentation(self.slider_rep) self.slider_widget.SetAnimationModeToAnimate() self.slider_widget.AddObserver(vtk.vtkCommand.InteractionEvent, self.update_contour);
def __init__(self,delta,wing): self.arrowColor = vtk.vtkColorTransferFunction() self.update_look_up_table() self.print_counter=0 self.ren = vtk.vtkRenderer() self.geo_reader = vtk.vtkUnstructuredGridReader() self.geo_reader.SetFileName(wing) self.vec_reader = vtk.vtkStructuredPointsReader() self.vec_reader.SetFileName(delta) """ This is for drawing the wing,""" geo_Mapper=vtk.vtkDataSetMapper() geo_Mapper.SetInputConnection(self.geo_reader.GetOutputPort()) geo_actor = vtk.vtkActor() geo_actor.SetMapper(geo_Mapper) self.ren.AddActor(geo_actor) """End of adding the wing """ self.ren.AddActor(self.create_stream_line(25,150,0,0.5)) #Add renderer to renderwindow and render self.renWin = vtk.vtkRenderWindow() self.renWin.AddRenderer(self.ren) self.renWin.SetSize(1920, 1080) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(self.renWin) iren.AddObserver('RightButtonPressEvent', self.capture_image, 1.0) # Scalar Bar actor scalar_bar = vtk.vtkScalarBarActor() scalar_bar.SetOrientationToHorizontal() scalar_bar.SetLookupTable(self.arrowColor) scalar_bar.SetTitle("Color map") scalar_bar.SetLabelFormat("%5.2f") scalar_bar.SetMaximumHeightInPixels(300) scalar_bar.SetMaximumWidthInPixels(60) # Scalar Bar Widget scalar_bar_widget = vtk.vtkScalarBarWidget() scalar_bar_widget.SetInteractor(iren) scalar_bar_widget.SetScalarBarActor(scalar_bar) scalar_bar_widget.On() self.ren.SetBackground(0,0,0) self.renWin.Render() iren.Start()