def add_cursor(self, coords): # Create new cursor, mapper and actor new_cursor_id = self.next_cursor_id self.cursors[new_cursor_id] = { 'cursor3d': vtk.vtkCursor3D(), 'actor': vtk.vtkActor(), 'colour': None } self.next_cursor_id += 1 # Some setup of the cursor self.cursors[new_cursor_id]['cursor3d'].XShadowsOff() self.cursors[new_cursor_id]['cursor3d'].YShadowsOff() self.cursors[new_cursor_id]['cursor3d'].ZShadowsOff() self.cursors[new_cursor_id]['cursor3d'].OutlineOff() self.cursors[new_cursor_id]['cursor3d'].SetTranslationMode(1) self.cursors[new_cursor_id]['cursor3d'].SetFocalPoint( coords[0], coords[1], coords[2]) # Mapper setup mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection( self.cursors[new_cursor_id]['cursor3d'].GetOutputPort()) # Actor setup self.cursors[new_cursor_id]['actor'].SetMapper(mapper) # Add new cursor to screen self.renderer.AddActor(self.cursors[new_cursor_id]['actor']) self.update_cursor_style() return new_cursor_id
def __build_cross_lines(self): renderer = self.slice_data.overlay_renderer cross = vtk.vtkCursor3D() cross.AllOff() cross.AxesOn() self.cross = cross c = vtk.vtkCoordinate() c.SetCoordinateSystemToWorld() cross_mapper = vtk.vtkPolyDataMapper() cross_mapper.SetInput(cross.GetOutput()) #cross_mapper.SetTransformCoordinate(c) p = vtk.vtkProperty() p.SetColor(1, 0, 0) cross_actor = vtk.vtkActor() cross_actor.SetMapper(cross_mapper) cross_actor.SetProperty(p) cross_actor.VisibilityOff() # Only the slices are pickable cross_actor.PickableOff() self.cross_actor = cross_actor renderer.AddActor(cross_actor)
def add_active_cursor(self, coords, add_to=None, run_move_callback=True): subview = self.subview_lookup(coords[0], coords[1]) if add_to is None: new_cursor_id = self.next_cursor_id self.next_cursor_id += 1 self.active_cursors[new_cursor_id] = { 'cursor3ds': [None] * self.n_subviews, 'actors': [None] * self.n_subviews } else: new_cursor_id = add_to bounds = self.image_actor.GetBounds() ysize = bounds[3] - bounds[2] # Create new cursor and set it up new_cursor = vtk.vtkCursor3D() # Some setup of the cursor new_cursor.OutlineOff() new_cursor.XShadowsOff() new_cursor.YShadowsOff() new_cursor.ZShadowsOff() new_cursor.AxesOn() new_cursor.TranslationModeOn() new_cursor.SetFocalPoint([coords[0], ysize - coords[1], 0.05]) mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(new_cursor.GetOutputPort()) actor = vtk.vtkActor() actor.SetMapper(mapper) self.active_cursors[new_cursor_id]['actors'][subview] = actor self.active_cursors[new_cursor_id]['cursor3ds'][subview] = new_cursor # Add new cursor to screen self.renderer.AddActor(actor) self.update_cursor_style() if self.refresh_callback is not None: self.refresh_callback() return new_cursor_id
def __init__(self, point, color=None, opacity=None, radius=1, fig="gcf"): super().__init__(fig) self.source = vtk.vtkCursor3D() self.source.SetTranslationMode(True) self.source.OutlineOff() self.add_to_plot() self.radius = radius self.point = point self.color_opacity(color, opacity)
def add_passive_cursor(self, coords): new_cursor_id = self.next_cursor_id self.next_cursor_id += 1 bounds = self.image_actor.GetBounds() ysize = bounds[3] - bounds[2] # Create new cursor and set it up new_cursor = vtk.vtkCursor3D() # Some setup of the cursor new_cursor.OutlineOff() new_cursor.XShadowsOff() new_cursor.YShadowsOff() new_cursor.ZShadowsOff() new_cursor.AxesOn() new_cursor.TranslationModeOn() new_cursor.SetFocalPoint([coords[0], ysize - coords[1], 0.05]) mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(new_cursor.GetOutputPort()) actor = vtk.vtkActor() actor.SetMapper(mapper) actor.GetProperty().SetColor((0, 0, 1.)) actor.GetProperty().SetLineWidth(2) self.passive_cursors[new_cursor_id] = { 'cursor3d': new_cursor, 'actor': actor } # Add new cursor to screen self.renderer.AddActor(actor) self.update_cursor_style() if self.refresh_callback is not None: self.refresh_callback() return new_cursor_id
def _create_actors(self): # 1. create really small 3D cursor to place at relevant point d = 2 # 2 mm dimension cs = vtk.vtkCursor3D() cs.AllOff() cs.AxesOn() cs.SetModelBounds(-d, +d, -d, +d, -d, +d) cs.SetFocalPoint(0,0,0) m = vtk.vtkPolyDataMapper() m.SetInput(cs.GetOutput()) self.c3da = vtk.vtkActor() self.c3da.SetPickable(0) self.c3da.SetMapper(m) self.ren.AddActor(self.c3da) # 2. create caption actor with label ca = vtk.vtkCaptionActor2D() ca.GetProperty().SetColor(1,1,0) tp = ca.GetCaptionTextProperty() tp.SetColor(1,1,0) tp.ShadowOff() ca.SetPickable(0) ca.SetAttachmentPoint(0,0,0) # we'll move this later ca.SetPosition(25,10) ca.BorderOff() ca.SetWidth(0.3) ca.SetHeight(0.04) # this will be changed at the first property set ca.SetCaption('.') self.ca = ca self.ren.AddActor(ca)
def _create_actors(self): # 1. create really small 3D cursor to place at relevant point d = 2 # 2 mm dimension cs = vtk.vtkCursor3D() cs.AllOff() cs.AxesOn() cs.SetModelBounds(-d, +d, -d, +d, -d, +d) cs.SetFocalPoint(0, 0, 0) m = vtk.vtkPolyDataMapper() m.SetInput(cs.GetOutput()) self.c3da = vtk.vtkActor() self.c3da.SetPickable(0) self.c3da.SetMapper(m) self.ren.AddActor(self.c3da) # 2. create caption actor with label ca = vtk.vtkCaptionActor2D() ca.GetProperty().SetColor(1, 1, 0) tp = ca.GetCaptionTextProperty() tp.SetColor(1, 1, 0) tp.ShadowOff() ca.SetPickable(0) ca.SetAttachmentPoint(0, 0, 0) # we'll move this later ca.SetPosition(25, 10) ca.BorderOff() ca.SetWidth(0.3) ca.SetHeight(0.04) # this will be changed at the first property set ca.SetCaption('.') self.ca = ca self.ren.AddActor(ca)
reader = vtk.vtkMultiBlockPLOT3DReader() reader.SetXYZFileName("" + str(VTK_DATA_ROOT) + "/Data/combxyz.bin") reader.SetQFileName("" + str(VTK_DATA_ROOT) + "/Data/combq.bin") reader.SetScalarFunctionNumber(110) reader.Update() output = reader.GetOutput().GetBlock(0) # create outline outlineF = vtk.vtkStructuredGridOutlineFilter() outlineF.SetInputData(output) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outlineF.GetOutputPort()) outline = vtk.vtkActor() outline.SetMapper(outlineMapper) outline.GetProperty().SetColor(0, 0, 0) # create cursor cursor = vtk.vtkCursor3D() cursor.SetModelBounds(output.GetBounds()) cursor.SetFocalPoint(output.GetCenter()) cursor.AllOff() cursor.AxesOn() cursor.OutlineOn() cursor.XShadowsOn() cursor.YShadowsOn() cursor.ZShadowsOn() cursorMapper = vtk.vtkPolyDataMapper() cursorMapper.SetInputConnection(cursor.GetOutputPort()) cursorActor = vtk.vtkActor() cursorActor.SetMapper(cursorMapper) cursorActor.GetProperty().SetColor(1, 0, 0) # create probe probe = vtk.vtkProbeFilter()
reader = vtk.vtkMultiBlockPLOT3DReader() reader.SetXYZFileName("" + str(VTK_DATA_ROOT) + "/Data/combxyz.bin") reader.SetQFileName("" + str(VTK_DATA_ROOT) + "/Data/combq.bin") reader.SetScalarFunctionNumber(110) reader.Update() output = reader.GetOutput().GetBlock(0) # create outline outlineF = vtk.vtkStructuredGridOutlineFilter() outlineF.SetInputData(output) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outlineF.GetOutputPort()) outline = vtk.vtkActor() outline.SetMapper(outlineMapper) outline.GetProperty().SetColor(0,0,0) # create cursor cursor = vtk.vtkCursor3D() cursor.SetModelBounds(output.GetBounds()) cursor.SetFocalPoint(output.GetCenter()) cursor.AllOff() cursor.AxesOn() cursor.OutlineOn() cursor.XShadowsOn() cursor.YShadowsOn() cursor.ZShadowsOn() cursorMapper = vtk.vtkPolyDataMapper() cursorMapper.SetInputConnection(cursor.GetOutputPort()) cursorActor = vtk.vtkActor() cursorActor.SetMapper(cursorMapper) cursorActor.GetProperty().SetColor(1,0,0) # create probe probe = vtk.vtkProbeFilter()