def _repr_mimebundle_(self, include=None, exclude=None): layoutManager = slicer.app.layoutManager() if self.viewLayout: setViewLayout(self.viewLayout) if self.center: slicer.util.resetSliceViews() for viewId in range(layoutManager.threeDViewCount): reset3DView(viewId) slicer.util.setViewControllersVisible(False) slicer.app.processEvents() slicer.util.forceRenderAllViews() screenshot = layoutManager.viewport().grab() slicer.util.setViewControllersVisible(True) bArray = qt.QByteArray() buffer = qt.QBuffer(bArray) buffer.open(qt.QIODevice.WriteOnly) screenshot.save(buffer, "PNG") dataValue = bArray.toBase64().data().decode() dataType = "image/png" return { dataType: dataValue }
def _repr_mimebundle_(self, include=None, exclude=None): layoutManager = slicer.app.layoutManager() slicer.app.processEvents() sliceWidget = layoutManager.sliceWidget(self.viewName) if self.positionPercent is not None: sliceBounds = [0,0,0,0,0,0] sliceWidget.sliceLogic().GetLowestVolumeSliceBounds(sliceBounds) positionMin = sliceBounds[4] positionMax = sliceBounds[5] position = positionMin + self.positionPercent / 100.0 * (positionMax - positionMin) sliceWidget.sliceController().sliceOffsetSlider().setValue(position) sliceView = sliceWidget.sliceView() sliceView.forceRender() screenshot = sliceView.grab() bArray = qt.QByteArray() buffer = qt.QBuffer(bArray) buffer.open(qt.QIODevice.WriteOnly) #screenshot.save(buffer, "PNG") screenshot.save(buffer, "JPG") dataValue = bArray.toBase64().data().decode() #dataType = "image/png" dataType = "image/jpeg" return { dataType: dataValue }
def __init__(self, viewName=None, positionPercent=None): if not viewName: viewName = "Red" layoutManager = slicer.app.layoutManager() slicer.app.processEvents() sliceWidget = layoutManager.sliceWidget(viewName) if positionPercent is not None: sliceBounds = [0,0,0,0,0,0] sliceWidget.sliceLogic().GetLowestVolumeSliceBounds(sliceBounds) positionMin = sliceBounds[4] positionMax = sliceBounds[5] position = positionMin + positionPercent / 100.0 * (positionMax - positionMin) sliceWidget.sliceController().sliceOffsetSlider().setValue(position) sliceView = sliceWidget.sliceView() sliceView.forceRender() screenshot = sliceView.grab() bArray = qt.QByteArray() buffer = qt.QBuffer(bArray) buffer.open(qt.QIODevice.WriteOnly) #screenshot.save(buffer, "PNG") screenshot.save(buffer, "JPG") self.dataValue = bArray.toBase64().data().decode() #self.dataType = "image/png" self.dataType = "image/jpeg"
def __init__(self, modelNode, imageSize=None, orientation=None, zoom=None, showFeatureEdges=False): # rollPitchYawDeg orientation = [0, 0, 0] if orientation is None else orientation zoom = 1.0 if zoom is None else zoom imageSize = [300, 300] if imageSize is None else imageSize showFeatureEdges = showFeatureEdges modelPolyData = modelNode.GetPolyData() renderer = vtk.vtkRenderer() renderer.SetBackground(1, 1, 1) renderer.SetUseDepthPeeling(1) renderer.SetMaximumNumberOfPeels(100) renderer.SetOcclusionRatio(0.1) renWin = vtk.vtkRenderWindow() renWin.OffScreenRenderingOn() renWin.SetSize(imageSize[0], imageSize[1]) renWin.SetAlphaBitPlanes(1) # for depth peeling renWin.SetMultiSamples(0) # for depth peeling renWin.AddRenderer(renderer) # Must be called after iren and renderer are linked or there will be problems renderer.Render() modelNormals = vtk.vtkPolyDataNormals() modelNormals.SetInputData(modelPolyData) modelMapper = vtk.vtkPolyDataMapper() modelMapper.SetInputConnection(modelNormals.GetOutputPort()) modelActor = vtk.vtkActor() modelActor.SetMapper(modelMapper) modelActor.GetProperty().SetColor(0.9, 0.9, 0.9) modelActor.GetProperty().SetOpacity(0.8) renderer.AddActor(modelActor) triangleFilter = vtk.vtkTriangleFilter() triangleFilter.SetInputConnection(modelNormals.GetOutputPort()) if showFeatureEdges: edgeExtractor = vtk.vtkFeatureEdges() edgeExtractor.SetInputConnection(triangleFilter.GetOutputPort()) edgeExtractor.ColoringOff() edgeExtractor.BoundaryEdgesOn() edgeExtractor.ManifoldEdgesOn() edgeExtractor.NonManifoldEdgesOn() modelEdgesMapper = vtk.vtkPolyDataMapper() modelEdgesMapper.SetInputConnection(edgeExtractor.GetOutputPort()) modelEdgesMapper.SetResolveCoincidentTopologyToPolygonOffset() modelEdgesActor = vtk.vtkActor() modelEdgesActor.SetMapper(modelEdgesMapper) modelEdgesActor.GetProperty().SetColor(0.0, 0.0, 0.0) renderer.AddActor(modelEdgesActor) # Set projection to parallel to enable estimate distances renderer.GetActiveCamera().ParallelProjectionOn() renderer.GetActiveCamera().Roll(orientation[0]) renderer.GetActiveCamera().Pitch(orientation[1]) renderer.GetActiveCamera().Yaw(orientation[2]) renderer.ResetCamera() renderer.GetActiveCamera().Zoom(zoom) windowToImageFilter = vtk.vtkWindowToImageFilter() windowToImageFilter.SetInput(renWin) windowToImageFilter.Update() screenshot = ctk.ctkVTKWidgetsUtils.vtkImageDataToQImage( windowToImageFilter.GetOutput()) bArray = qt.QByteArray() buffer = qt.QBuffer(bArray) buffer.open(qt.QIODevice.WriteOnly) screenshot.save(buffer, "PNG") self.dataValue = bArray.toBase64().data().decode() self.dataType = "image/png"
def pixelmapAsRaw(pixmap): byteArray = qt.QByteArray() buffer = qt.QBuffer(byteArray) pixmap.save(buffer, "PNG") return "data:image/png;base64," + byteArray.toBase64().data()