def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__( self, module_manager, vtk.vtkOutlineCornerFilter(), 'Processing.', ('vtkDataSet',), ('vtkPolyData',), replaceDoc=True, inputFunctions=None, outputFunctions=None)
def __init__(self, rwi, renderer): # nnsmit-edit self.overlay_active = 0; # end edit self.rwi = rwi self.renderer = renderer istyle = vtk.vtkInteractorStyleTrackballCamera() rwi.SetInteractorStyle(istyle) # we unbind the existing mousewheel handler so it doesn't # interfere rwi.Unbind(wx.EVT_MOUSEWHEEL) rwi.Bind(wx.EVT_MOUSEWHEEL, self._handler_mousewheel) self.ipws = [vtk.vtkImagePlaneWidget() for _ in range(3)] lut = self.ipws[0].GetLookupTable() for ipw in self.ipws: ipw.SetInteractor(rwi) ipw.SetLookupTable(lut) # nnsmit-edit self.overlay_ipws = [vtk.vtkImagePlaneWidget() for _ in range(3)] lut2 = self.overlay_ipws[0].GetLookupTable() lut2.SetNumberOfTableValues(3) lut2.SetTableValue(0,0,0,0,0) lut2.SetTableValue(1,0.5,0,1,1) lut2.SetTableValue(2,1,0,0,1) lut2.Build() for ipw_overlay in self.overlay_ipws: ipw_overlay.SetInteractor(rwi) ipw_overlay.SetLookupTable(lut2) ipw_overlay.AddObserver('InteractionEvent', wx.EVT_MOUSEWHEEL) # now actually connect the sync_overlay observer for i,ipw in enumerate(self.ipws): ipw.AddObserver('InteractionEvent',lambda vtk_o, vtk_e, i=i: self.observer_sync_overlay(self.ipws,i)) # end edit # we only set the picker on the visible IPW, else the # invisible IPWs block picking! self.picker = vtk.vtkCellPicker() self.picker.SetTolerance(0.005) self.ipws[0].SetPicker(self.picker) self.outline_source = vtk.vtkOutlineCornerFilter() m = vtk.vtkPolyDataMapper() m.SetInput(self.outline_source.GetOutput()) a = vtk.vtkActor() a.SetMapper(m) a.PickableOff() self.outline_actor = a self.dv_orientation_widget = DVOrientationWidget(rwi) # this can be used by clients to store the current world # position self.current_world_pos = (0,0,0) self.current_index_pos = (0,0,0)
def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__( self, module_manager, vtk.vtkOutlineCornerFilter(), "Processing.", ("vtkDataSet",), ("vtkPolyData",), replaceDoc=True, inputFunctions=None, outputFunctions=None, )
def outline_corners(dataset, factor=0.2): """Produces an outline of the corners for the input dataset. Parameters ---------- factor : float, optional controls the relative size of the corners to the length of the corresponding bounds """ alg = vtk.vtkOutlineCornerFilter() alg.SetInputDataObject(dataset) alg.SetCornerFactor(factor) alg.Update() return wrap(alg.GetOutputDataObject(0))
def __init__(self, rwi, renderer): self.rwi = rwi self.renderer = renderer istyle = vtk.vtkInteractorStyleTrackballCamera() rwi.SetInteractorStyle(istyle) # we unbind the existing mousewheel handler so it doesn't # interfere rwi.Unbind(wx.EVT_MOUSEWHEEL) rwi.Bind(wx.EVT_MOUSEWHEEL, self._handler_mousewheel) self.ipws = [vtk.vtkImagePlaneWidget() for _ in range(3)] lut = self.ipws[0].GetLookupTable() for ipw in self.ipws: ipw.SetInteractor(rwi) ipw.SetLookupTable(lut) # we only set the picker on the visible IPW, else the # invisible IPWs block picking! self.picker = vtk.vtkCellPicker() self.picker.SetTolerance(0.005) self.ipws[0].SetPicker(self.picker) self.outline_source = vtk.vtkOutlineCornerFilter() m = vtk.vtkPolyDataMapper() m.SetInput(self.outline_source.GetOutput()) a = vtk.vtkActor() a.SetMapper(m) a.PickableOff() self.outline_actor = a self.dv_orientation_widget = DVOrientationWidget(rwi) # this can be used by clients to store the current world # position self.current_world_pos = (0,0,0) self.current_index_pos = (0,0,0)
def __init__(self, rwi, renderer): self.rwi = rwi self.renderer = renderer istyle = vtk.vtkInteractorStyleTrackballCamera() rwi.SetInteractorStyle(istyle) # we unbind the existing mousewheel handler so it doesn't # interfere rwi.Unbind(wx.EVT_MOUSEWHEEL) rwi.Bind(wx.EVT_MOUSEWHEEL, self._handler_mousewheel) #This is a collection of 1- or 3-component image plane widgets. Each entry corresponds to a single overlay. self.ipw_triads = {} self.add_overlay( 0, [0, 0, 0, 0.1] ) #Almost-transparent black - for showing the pickable plane stored at id = 0. # we only set the picker on the visible IPW, else the # invisible IPWs block picking! self.picker = vtk.vtkCellPicker() self.picker.SetTolerance(0.005) self.ipw_triads[0][0].SetPicker(self.picker) self.outline_source = vtk.vtkOutlineCornerFilter() m = vtk.vtkPolyDataMapper() m.SetInput(self.outline_source.GetOutput()) a = vtk.vtkActor() a.SetMapper(m) a.PickableOff() self.outline_actor = a self.dv_orientation_widget = DVOrientationWidget(rwi) # this can be used by clients to store the current world # position self.current_world_pos = (0, 0, 0) self.current_index_pos = (0, 0, 0)
def __init__(self, rwi, renderer): self.rwi = rwi self.renderer = renderer istyle = vtk.vtkInteractorStyleTrackballCamera() rwi.SetInteractorStyle(istyle) # we unbind the existing mousewheel handler so it doesn't # interfere rwi.Unbind(wx.EVT_MOUSEWHEEL) rwi.Bind(wx.EVT_MOUSEWHEEL, self._handler_mousewheel) #This is a collection of 1- or 3-component image plane widgets. Each entry corresponds to a single overlay. self.ipw_triads = {} self.add_overlay(0, [0, 0, 0, 0.1]) #Almost-transparent black - for showing the pickable plane stored at id = 0. # we only set the picker on the visible IPW, else the # invisible IPWs block picking! self.picker = vtk.vtkCellPicker() self.picker.SetTolerance(0.005) self.ipw_triads[0][0].SetPicker(self.picker) self.outline_source = vtk.vtkOutlineCornerFilter() m = vtk.vtkPolyDataMapper() m.SetInput(self.outline_source.GetOutput()) a = vtk.vtkActor() a.SetMapper(m) a.PickableOff() self.outline_actor = a self.dv_orientation_widget = DVOrientationWidget(rwi) # this can be used by clients to store the current world # position self.current_world_pos = (0,0,0) self.current_index_pos = (0,0,0)
iren.SetRenderWindow(renWin) # create pipeline # reader = vtk.vtkSTLReader() reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/42400-IDGH.stl") dicer = vtk.vtkOBBDicer() dicer.SetInputConnection(reader.GetOutputPort()) dicer.SetNumberOfPointsPerPiece(1000) dicer.Update() isoMapper = vtk.vtkDataSetMapper() isoMapper.SetInputConnection(dicer.GetOutputPort()) isoMapper.SetScalarRange(0,dicer.GetNumberOfActualPieces()) isoActor = vtk.vtkActor() isoActor.SetMapper(isoMapper) isoActor.GetProperty().SetColor(0.7,0.3,0.3) outline = vtk.vtkOutlineCornerFilter() 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(isoActor) ren1.SetBackground(1,1,1) renWin.SetSize(400,400) ren1.SetBackground(0.5,0.5,0.6) # render the image #
def __init__(self, rwi, renderer): # nnsmit-edit self.overlay_active = 0; self.overlay_active_voxels = 0; self.overlay_active_100band1 = 0; self.overlay_active_100band2 = 0; self.overlay_active_100band3 = 0; self.overlay_active_50band1 = 0; self.overlay_active_50band2 = 0; self.overlay_active_50band3 = 0; # end edit self.rwi = rwi self.renderer = renderer istyle = vtk.vtkInteractorStyleTrackballCamera() rwi.SetInteractorStyle(istyle) # we unbind the existing mousewheel handler so it doesn't # interfere rwi.Unbind(wx.EVT_MOUSEWHEEL) rwi.Bind(wx.EVT_MOUSEWHEEL, self._handler_mousewheel) self.ipws = [vtk.vtkImagePlaneWidget() for _ in range(3)] lut = self.ipws[0].GetLookupTable() for ipw in self.ipws: ipw.SetInteractor(rwi) ipw.SetLookupTable(lut) # IPWS for overlay self.overlay_ipws = [vtk.vtkImagePlaneWidget() for _ in range(3)] lut = self.overlay_ipws[0].GetLookupTable() lut.SetNumberOfTableValues(3) lut.SetTableValue(0,0,0,0,0) lut.SetTableValue(1,0.5,0,1,1) lut.SetTableValue(2,1,0,0,1) lut.Build() for ipw_overlay in self.overlay_ipws: ipw_overlay.SetInteractor(rwi) ipw_overlay.SetLookupTable(lut) ipw_overlay.AddObserver('InteractionEvent', wx.EVT_MOUSEWHEEL) # IPWS for voxels selected in scatterplot self.overlay_ipws_voxels = [vtk.vtkImagePlaneWidget() for _ in range(3)] lut = self.overlay_ipws_voxels[0].GetLookupTable() lut.SetNumberOfTableValues(3) lut.SetTableValue(0,0,0,0,0) lut.SetTableValue(1,0.5,0,1,1) lut.SetTableValue(2,1,0,0,1) lut.Build() for ipw_overlay in self.overlay_ipws_voxels: ipw_overlay.SetInteractor(rwi) ipw_overlay.SetLookupTable(lut) ipw_overlay.AddObserver('InteractionEvent', wx.EVT_MOUSEWHEEL) # IPWS for overlay of 100%band in first row self.overlay_ipws_100band1 = [vtk.vtkImagePlaneWidget() for _ in range(3)] lut1 = self.overlay_ipws_100band1[0].GetLookupTable() lut1.SetNumberOfTableValues(3) lut1.SetTableValue(0,0,0,0,0) lut1.SetTableValue(1, 1, 1, 0, 1) lut1.SetTableValue(2, 1,1,0, 1) lut1.Modified() lut1.Build() for ipw_overlay in self.overlay_ipws_100band1: ipw_overlay.SetInteractor(rwi) ipw_overlay.SetLookupTable(lut1) ipw_overlay.AddObserver('InteractionEvent', wx.EVT_MOUSEWHEEL) # IPWS for overlay of 50%band in first row self.overlay_ipws_50band1 = [vtk.vtkImagePlaneWidget() for _ in range(3)] lut1 = self.overlay_ipws_50band1[0].GetLookupTable() lut1.SetNumberOfTableValues(3) lut1.SetTableValue(0,0,0,0,0) lut1.SetTableValue(1, 1, 1, 0, 1) lut1.SetTableValue(2, 1,1,0, 1) lut1.Modified() lut1.Build() for ipw_overlay in self.overlay_ipws_50band1: ipw_overlay.SetInteractor(rwi) ipw_overlay.SetLookupTable(lut1) ipw_overlay.AddObserver('InteractionEvent', wx.EVT_MOUSEWHEEL) # IPWS for overlay of 100%band in second row self.overlay_ipws_100band2 = [vtk.vtkImagePlaneWidget() for _ in range(3)] #lut2 = self.overlay_ipws_100band2[0].GetLookupTable() #lut2.SetNumberOfTableValues(3) #lut2.SetTableValue(0,0,0,0,0) #lut2.SetTableValue(1, 0.98,0,0, 0.37) #lut2.SetTableValue(2, 0.98,0,0, 0.37) #lut2.Modified() #lut2.Build() for ipw_overlay in self.overlay_ipws_100band2: ipw_overlay.SetInteractor(rwi) #ipw_overlay.SetLookupTable(lut2) ipw_overlay.AddObserver('InteractionEvent', wx.EVT_MOUSEWHEEL) # IPWS for overlay of 100%band in second row self.overlay_ipws_50band2 = [vtk.vtkImagePlaneWidget() for _ in range(3)] #lut2 = self.overlay_ipws_100band2[0].GetLookupTable() #lut2.SetNumberOfTableValues(3) #lut2.SetTableValue(0,0,0,0,0) #lut2.SetTableValue(1, 0.98,0,0, 0.37) #lut2.SetTableValue(2, 0.98,0,0, 0.37) #lut2.Modified() #lut2.Build() for ipw_overlay in self.overlay_ipws_50band2: ipw_overlay.SetInteractor(rwi) #ipw_overlay.SetLookupTable(lut2) ipw_overlay.AddObserver('InteractionEvent', wx.EVT_MOUSEWHEEL) # IPWS for overlay of 100%band in third row self.overlay_ipws_100band3 = [vtk.vtkImagePlaneWidget() for _ in range(3)] lut3 = self.overlay_ipws_100band3[0].GetLookupTable() lut3.SetNumberOfTableValues(3) lut3.SetTableValue(0,0,0,0,0) lut3.SetTableValue(1,0,0.643,0.941, 0.5) lut3.SetTableValue(2,0,0.643,0.941, 0.5) lut3.Modified() lut3.Build() for ipw_overlay in self.overlay_ipws_100band3: ipw_overlay.SetInteractor(rwi) ipw_overlay.SetLookupTable(lut3) ipw_overlay.AddObserver('InteractionEvent', wx.EVT_MOUSEWHEEL) # IPWS for overlay of 50%band in third row self.overlay_ipws_50band3 = [vtk.vtkImagePlaneWidget() for _ in range(3)] lut3 = self.overlay_ipws_50band3[0].GetLookupTable() lut3.SetNumberOfTableValues(3) lut3.SetTableValue(0,0,0,0,0) lut3.SetTableValue(1,0,0.643,0.941, 0.5) lut3.SetTableValue(2,0,0.643,0.941, 0.5) lut3.Modified() lut3.Build() for ipw_overlay in self.overlay_ipws_50band3: ipw_overlay.SetInteractor(rwi) ipw_overlay.SetLookupTable(lut3) ipw_overlay.AddObserver('InteractionEvent', wx.EVT_MOUSEWHEEL) # now actually connect the sync_overlay observer for i,ipw in enumerate(self.ipws): ipw.AddObserver('InteractionEvent',lambda vtk_o, vtk_e, i=i: self.observer_sync_overlay(self.ipws,i)) # end edit # we only set the picker on the visible IPW, else the # invisible IPWs block picking! self.picker = vtk.vtkCellPicker() self.picker.SetTolerance(0.005) self.ipws[0].SetPicker(self.picker) self.outline_source = vtk.vtkOutlineCornerFilter() m = vtk.vtkPolyDataMapper() m.SetInput(self.outline_source.GetOutput()) a = vtk.vtkActor() a.SetMapper(m) a.PickableOff() self.outline_actor = a self.dv_orientation_widget = DVOrientationWidget(rwi) # this can be used by clients to store the current world # position self.current_world_pos = (0,0,0) self.current_index_pos = (0,0,0)
def addAxes(axtype=None, c=None): """Draw axes on scene. Available axes types: :param int axtype: - 0, no axes, - 1, draw three gray grid walls - 2, show cartesian axes from (0,0,0) - 3, show positive range of cartesian axes from (0,0,0) - 4, show a triad at bottom left - 5, show a cube at bottom left - 6, mark the corners of the bounding box - 7, draw a simple ruler at the bottom of the window - 8, show the ``vtkCubeAxesActor`` object - 9, show the bounding box outLine - 10, show three circles representing the maximum bounding box """ vp = settings.plotter_instance if axtype is not None: vp.axes = axtype # overrride r = vp.renderers.index(vp.renderer) if not vp.axes: return if c is None: # automatic black or white c = (0.9, 0.9, 0.9) if numpy.sum(vp.renderer.GetBackground()) > 1.5: c = (0.1, 0.1, 0.1) if not vp.renderer: return if vp.axes_exist[r]: return # calculate max actors bounds bns = [] for a in vp.actors: if a and a.GetPickable(): b = a.GetBounds() if b: bns.append(b) if len(bns): max_bns = numpy.max(bns, axis=0) min_bns = numpy.min(bns, axis=0) vbb = (min_bns[0], max_bns[1], min_bns[2], max_bns[3], min_bns[4], max_bns[5]) else: vbb = vp.renderer.ComputeVisiblePropBounds() max_bns = vbb min_bns = vbb sizes = (max_bns[1] - min_bns[0], max_bns[3] - min_bns[2], max_bns[5] - min_bns[4]) ############################################################ if vp.axes == 1 or vp.axes == True: # gray grid walls nd = 4 # number of divisions in the smallest axis off = -0.04 # label offset step = numpy.min(sizes) / nd if not step: # bad proportions, use vtkCubeAxesActor vp.addAxes(axtype=8, c=c) vp.axes = 1 return rx, ry, rz = numpy.rint(sizes / step).astype(int) if max([rx / ry, ry / rx, rx / rz, rz / rx, ry / rz, rz / ry]) > 15: # bad proportions, use vtkCubeAxesActor vp.addAxes(axtype=8, c=c) vp.axes = 1 return gxy = shapes.Grid(pos=(0.5, 0.5, 0), normal=[0, 0, 1], bc=None, resx=rx, resy=ry) gxz = shapes.Grid(pos=(0.5, 0, 0.5), normal=[0, 1, 0], bc=None, resx=rz, resy=rx) gyz = shapes.Grid(pos=(0, 0.5, 0.5), normal=[1, 0, 0], bc=None, resx=rz, resy=ry) gxy.alpha(0.06).wire(False).color(c).lineWidth(1) gxz.alpha(0.04).wire(False).color(c).lineWidth(1) gyz.alpha(0.04).wire(False).color(c).lineWidth(1) xa = shapes.Line([0, 0, 0], [1, 0, 0], c=c, lw=1) ya = shapes.Line([0, 0, 0], [0, 1, 0], c=c, lw=1) za = shapes.Line([0, 0, 0], [0, 0, 1], c=c, lw=1) xt, yt, zt, ox, oy, oz = [None] * 6 if vp.xtitle: xtitle = vp.xtitle if min_bns[0] <= 0 and max_bns[1] > 0: # mark x origin ox = shapes.Cube([-min_bns[0] / sizes[0], 0, 0], side=0.008, c=c) if len(vp.xtitle) == 1: # add axis length info xtitle = vp.xtitle + " /" + utils.precision(sizes[0], 4) wpos = [1 - (len(vp.xtitle) + 1) / 40, off, 0] xt = shapes.Text(xtitle, pos=wpos, normal=(0, 0, 1), s=0.025, c=c, justify="bottom-right") if vp.ytitle: if min_bns[2] <= 0 and max_bns[3] > 0: # mark y origin oy = shapes.Cube([0, -min_bns[2] / sizes[1], 0], side=0.008, c=c) yt = shapes.Text(vp.ytitle, pos=(0, 0, 0), normal=(0, 0, 1), s=0.025, c=c, justify="bottom-right") if len(vp.ytitle) == 1: wpos = [off, 1 - (len(vp.ytitle) + 1) / 40, 0] yt.pos(wpos) else: wpos = [off * 0.7, 1 - (len(vp.ytitle) + 1) / 40, 0] yt.rotateZ(90).pos(wpos) if vp.ztitle: if min_bns[4] <= 0 and max_bns[5] > 0: # mark z origin oz = shapes.Cube([0, 0, -min_bns[4] / sizes[2]], side=0.008, c=c) zt = shapes.Text(vp.ztitle, pos=(0, 0, 0), normal=(1, -1, 0), s=0.025, c=c, justify="bottom-right") if len(vp.ztitle) == 1: wpos = [off * 0.6, off * 0.6, 1 - (len(vp.ztitle) + 1) / 40] zt.rotate(90, (1, -1, 0)).pos(wpos) else: wpos = [off * 0.3, off * 0.3, 1 - (len(vp.ztitle) + 1) / 40] zt.rotate(180, (1, -1, 0)).pos(wpos) acts = [gxy, gxz, gyz, xa, ya, za, xt, yt, zt, ox, oy, oz] for a in acts: if a: a.PickableOff() aa = Assembly(acts) aa.pos(min_bns[0], min_bns[2], min_bns[4]) aa.SetScale(sizes) aa.PickableOff() vp.renderer.AddActor(aa) vp.axes_exist[r] = aa elif vp.axes == 2 or vp.axes == 3: vbb = vp.renderer.ComputeVisiblePropBounds() # to be double checked xcol, ycol, zcol = "db", "dg", "dr" s = 1 alpha = 1 centered = False x0, x1, y0, y1, z0, z1 = vbb dx, dy, dz = x1 - x0, y1 - y0, z1 - z0 aves = numpy.sqrt(dx * dx + dy * dy + dz * dz) / 2 x0, x1 = min(x0, 0), max(x1, 0) y0, y1 = min(y0, 0), max(y1, 0) z0, z1 = min(z0, 0), max(z1, 0) if vp.axes == 3: if x1 > 0: x0 = 0 if y1 > 0: y0 = 0 if z1 > 0: z0 = 0 dx, dy, dz = x1 - x0, y1 - y0, z1 - z0 acts = [] if x0 * x1 <= 0 or y0 * z1 <= 0 or z0 * z1 <= 0: # some ranges contain origin zero = shapes.Sphere(r=aves / 120 * s, c="k", alpha=alpha, res=10) acts += [zero] if len(vp.xtitle) and dx > aves / 100: xl = shapes.Cylinder([[x0, 0, 0], [x1, 0, 0]], r=aves / 250 * s, c=xcol, alpha=alpha) xc = shapes.Cone(pos=[x1, 0, 0], c=xcol, alpha=alpha, r=aves / 100 * s, height=aves / 25 * s, axis=[1, 0, 0], res=10) wpos = [ x1 - (len(vp.xtitle) + 1) * aves / 40 * s, -aves / 25 * s, 0 ] # aligned to arrow tip if centered: wpos = [(x0 + x1) / 2 - len(vp.xtitle) / 2 * aves / 40 * s, -aves / 25 * s, 0] xt = shapes.Text(vp.xtitle, pos=wpos, normal=(0, 0, 1), s=aves / 40 * s, c=xcol) acts += [xl, xc, xt] if len(vp.ytitle) and dy > aves / 100: yl = shapes.Cylinder([[0, y0, 0], [0, y1, 0]], r=aves / 250 * s, c=ycol, alpha=alpha) yc = shapes.Cone(pos=[0, y1, 0], c=ycol, alpha=alpha, r=aves / 100 * s, height=aves / 25 * s, axis=[0, 1, 0], res=10) wpos = [ -aves / 40 * s, y1 - (len(vp.ytitle) + 1) * aves / 40 * s, 0 ] if centered: wpos = [ -aves / 40 * s, (y0 + y1) / 2 - len(vp.ytitle) / 2 * aves / 40 * s, 0 ] yt = shapes.Text(vp.ytitle, pos=(0, 0, 0), normal=(0, 0, 1), s=aves / 40 * s, c=ycol) yt.rotate(90, [0, 0, 1]).pos(wpos) acts += [yl, yc, yt] if len(vp.ztitle) and dz > aves / 100: zl = shapes.Cylinder([[0, 0, z0], [0, 0, z1]], r=aves / 250 * s, c=zcol, alpha=alpha) zc = shapes.Cone(pos=[0, 0, z1], c=zcol, alpha=alpha, r=aves / 100 * s, height=aves / 25 * s, axis=[0, 0, 1], res=10) wpos = [ -aves / 50 * s, -aves / 50 * s, z1 - (len(vp.ztitle) + 1) * aves / 40 * s ] if centered: wpos = [ -aves / 50 * s, -aves / 50 * s, (z0 + z1) / 2 - len(vp.ztitle) / 2 * aves / 40 * s ] zt = shapes.Text(vp.ztitle, pos=(0, 0, 0), normal=(1, -1, 0), s=aves / 40 * s, c=zcol) zt.rotate(180, (1, -1, 0)).pos(wpos) acts += [zl, zc, zt] for a in acts: a.PickableOff() ass = Assembly(acts) ass.PickableOff() vp.renderer.AddActor(ass) vp.axes_exist[r] = ass elif vp.axes == 4: axact = vtk.vtkAxesActor() axact.SetShaftTypeToCylinder() axact.SetCylinderRadius(0.03) axact.SetXAxisLabelText(vp.xtitle) axact.SetYAxisLabelText(vp.ytitle) axact.SetZAxisLabelText(vp.ztitle) axact.GetXAxisShaftProperty().SetColor(0, 0, 1) axact.GetZAxisShaftProperty().SetColor(1, 0, 0) axact.GetXAxisTipProperty().SetColor(0, 0, 1) axact.GetZAxisTipProperty().SetColor(1, 0, 0) bc = numpy.array(vp.renderer.GetBackground()) if numpy.sum(bc) < 1.5: lc = (1, 1, 1) else: lc = (0, 0, 0) axact.GetXAxisCaptionActor2D().GetCaptionTextProperty().BoldOff() axact.GetYAxisCaptionActor2D().GetCaptionTextProperty().BoldOff() axact.GetZAxisCaptionActor2D().GetCaptionTextProperty().BoldOff() axact.GetXAxisCaptionActor2D().GetCaptionTextProperty().ItalicOff() axact.GetYAxisCaptionActor2D().GetCaptionTextProperty().ItalicOff() axact.GetZAxisCaptionActor2D().GetCaptionTextProperty().ItalicOff() axact.GetXAxisCaptionActor2D().GetCaptionTextProperty().ShadowOff() axact.GetYAxisCaptionActor2D().GetCaptionTextProperty().ShadowOff() axact.GetZAxisCaptionActor2D().GetCaptionTextProperty().ShadowOff() axact.GetXAxisCaptionActor2D().GetCaptionTextProperty().SetColor(lc) axact.GetYAxisCaptionActor2D().GetCaptionTextProperty().SetColor(lc) axact.GetZAxisCaptionActor2D().GetCaptionTextProperty().SetColor(lc) axact.PickableOff() icn = addIcon(axact, size=0.1) vp.axes_exist[r] = icn elif vp.axes == 5: axact = vtk.vtkAnnotatedCubeActor() axact.GetCubeProperty().SetColor(0.75, 0.75, 0.75) axact.SetTextEdgesVisibility(0) axact.SetFaceTextScale(0.4) axact.GetXPlusFaceProperty().SetColor(colors.getColor("b")) axact.GetXMinusFaceProperty().SetColor(colors.getColor("db")) axact.GetYPlusFaceProperty().SetColor(colors.getColor("g")) axact.GetYMinusFaceProperty().SetColor(colors.getColor("dg")) axact.GetZPlusFaceProperty().SetColor(colors.getColor("r")) axact.GetZMinusFaceProperty().SetColor(colors.getColor("dr")) axact.PickableOff() icn = addIcon(axact, size=0.06) vp.axes_exist[r] = icn elif vp.axes == 6: ocf = vtk.vtkOutlineCornerFilter() ocf.SetCornerFactor(0.1) largestact, sz = None, -1 for a in vp.actors: if a.GetPickable(): b = a.GetBounds() d = max(b[1] - b[0], b[3] - b[2], b[5] - b[4]) if sz < d: largestact = a sz = d if isinstance(largestact, Assembly): ocf.SetInputData(largestact.getActor(0).GetMapper().GetInput()) else: ocf.SetInputData(largestact.polydata()) ocf.Update() ocMapper = vtk.vtkHierarchicalPolyDataMapper() ocMapper.SetInputConnection(0, ocf.GetOutputPort(0)) ocActor = vtk.vtkActor() ocActor.SetMapper(ocMapper) bc = numpy.array(vp.renderer.GetBackground()) if numpy.sum(bc) < 1.5: lc = (1, 1, 1) else: lc = (0, 0, 0) ocActor.GetProperty().SetColor(lc) ocActor.PickableOff() vp.renderer.AddActor(ocActor) vp.axes_exist[r] = ocActor elif vp.axes == 7: # draws a simple ruler at the bottom of the window ls = vtk.vtkLegendScaleActor() ls.RightAxisVisibilityOff() ls.TopAxisVisibilityOff() ls.LegendVisibilityOff() ls.LeftAxisVisibilityOff() ls.GetBottomAxis().SetNumberOfMinorTicks(1) ls.GetBottomAxis().GetProperty().SetColor(c) ls.GetBottomAxis().GetLabelTextProperty().SetColor(c) ls.GetBottomAxis().GetLabelTextProperty().BoldOff() ls.GetBottomAxis().GetLabelTextProperty().ItalicOff() ls.GetBottomAxis().GetLabelTextProperty().ShadowOff() ls.PickableOff() vp.renderer.AddActor(ls) vp.axes_exist[r] = ls elif vp.axes == 8: ca = vtk.vtkCubeAxesActor() ca.SetBounds(vbb) if vp.camera: ca.SetCamera(vp.camera) else: ca.SetCamera(vp.renderer.GetActiveCamera()) ca.GetXAxesLinesProperty().SetColor(c) ca.GetYAxesLinesProperty().SetColor(c) ca.GetZAxesLinesProperty().SetColor(c) for i in range(3): ca.GetLabelTextProperty(i).SetColor(c) ca.GetTitleTextProperty(i).SetColor(c) ca.SetTitleOffset(5) ca.SetFlyMode(3) ca.SetXTitle(vp.xtitle) ca.SetYTitle(vp.ytitle) ca.SetZTitle(vp.ztitle) if vp.xtitle == "": ca.SetXAxisVisibility(0) ca.XAxisLabelVisibilityOff() if vp.ytitle == "": ca.SetYAxisVisibility(0) ca.YAxisLabelVisibilityOff() if vp.ztitle == "": ca.SetZAxisVisibility(0) ca.ZAxisLabelVisibilityOff() ca.PickableOff() vp.renderer.AddActor(ca) vp.axes_exist[r] = ca return elif vp.axes == 9: src = vtk.vtkCubeSource() src.SetXLength(vbb[1] - vbb[0]) src.SetYLength(vbb[3] - vbb[2]) src.SetZLength(vbb[5] - vbb[4]) src.Update() ca = Actor(src.GetOutput(), c=c, alpha=0.5, wire=1) ca.pos((vbb[0] + vbb[1]) / 2, (vbb[3] + vbb[2]) / 2, (vbb[5] + vbb[4]) / 2) ca.PickableOff() vp.renderer.AddActor(ca) vp.axes_exist[r] = ca elif vp.axes == 10: x0 = (vbb[0] + vbb[1]) / 2, (vbb[3] + vbb[2]) / 2, (vbb[5] + vbb[4]) / 2 rx, ry, rz = (vbb[1] - vbb[0]) / 2, (vbb[3] - vbb[2]) / 2, (vbb[5] - vbb[4]) / 2 rm = max(rx, ry, rz) xc = shapes.Disc(x0, (0, 0, 1), r1=rm, r2=rm, c='lr', bc=None, res=1, resphi=72) yc = shapes.Disc(x0, (0, 1, 0), r1=rm, r2=rm, c='lg', bc=None, res=1, resphi=72) zc = shapes.Disc(x0, (1, 0, 0), r1=rm, r2=rm, c='lb', bc=None, res=1, resphi=72) xc.clean().alpha(0.2).wire().lineWidth(2.5).PickableOff() yc.clean().alpha(0.2).wire().lineWidth(2.5).PickableOff() zc.clean().alpha(0.2).wire().lineWidth(2.5).PickableOff() ca = xc + yc + zc ca.PickableOff() vp.renderer.AddActor(ca) vp.axes_exist[r] = ca else: colors.printc('~bomb Keyword axes must be in range [0-10].', c=1) colors.printc(''' ~target Available axes types: 0 = no axes, 1 = draw three gray grid walls 2 = show cartesian axes from (0,0,0) 3 = show positive range of cartesian axes from (0,0,0) 4 = show a triad at bottom left 5 = show a cube at bottom left 6 = mark the corners of the bounding box 7 = draw a simple ruler at the bottom of the window 8 = show the vtkCubeAxesActor object 9 = show the bounding box outline 10 = show three circles representing the maximum bounding box ''', c=1, bold=0) if not vp.axes_exist[r]: vp.axes_exist[r] = True return
iren.SetRenderWindow(renWin) # create pipeline # reader = vtk.vtkSTLReader() reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/42400-IDGH.stl") dicer = vtk.vtkOBBDicer() dicer.SetInputConnection(reader.GetOutputPort()) dicer.SetNumberOfPointsPerPiece(1000) dicer.Update() isoMapper = vtk.vtkDataSetMapper() isoMapper.SetInputConnection(dicer.GetOutputPort()) isoMapper.SetScalarRange(0, dicer.GetNumberOfActualPieces()) isoActor = vtk.vtkActor() isoActor.SetMapper(isoMapper) isoActor.GetProperty().SetColor(0.7, 0.3, 0.3) outline = vtk.vtkOutlineCornerFilter() 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(isoActor) ren1.SetBackground(1, 1, 1) renWin.SetSize(400, 400) ren1.SetBackground(0.5, 0.5, 0.6) # render the image #