def __init__(self): ''' Constructor ''' vtkPythonViewImage.__init__(self) # texture mapper in 3D: vtkVolumeMapper self.__VolumeMapper = None # texture mapper in 3D: vtkVolumeTextureMapper3D self.__VolumeTextureMapper = vtk.vtkVolumeTextureMapper3D() # volume ray cast mapper vtkFixedPointVolumeRayCastMapper self.__VolumeRayCastMapper = vtk.vtkFixedPointVolumeRayCastMapper() # volume property: vtkVolumeProperty self.__VolumeProperty = vtk.vtkVolumeProperty() # volume actor: vtkVolume self.__VolumeActor = vtk.vtkVolume() # opacity transfer function: vtkPiecewiseFunction self.__OpacityFunction = vtk.vtkPiecewiseFunction() # color transfer function: vtkColorTransferFunction self.__ColorFunction = vtk.vtkColorTransferFunction() # vtkProp3DCollection self.__PhantomCollection = vtk.vtkProp3DCollection() # blender: vtkImageBlend self.__Blender = None # image 3D cropping box callback: vtkImage3DCroppingBoxCallback self.__Callback = vtkPythonImage3DCroppingBoxCallback() # box widget: vtkOrientedBoxWidget # self.__BoxWidget = vtkOrientedBoxWidget() # Now I could not wrap vtkOrientedBoxWidget self.__BoxWidget = vtk.vtkBoxWidget() # vtkPlane widget: vtkPlaneWidget self.__PlaneWidget = vtk.vtkPlaneWidget() # annotated cube actor: vtkAnnotatedCubeActor, vtkOrientationMarkerWidget self.__Cube = vtk.vtkAnnotatedCubeActor() self.__Marker = vtk.vtkOrientationMarkerWidget() self.SetupVolumeRendering() self.SetupWidgets() self.ShowAnnotationsOn() self.getTextProperty().SetColor(0, 0, 0) self.SetBackground(0.9, 0.9, 0.9) # white self.__FirstRender = 1 self.__RenderingMode = self.PLANAR_RENDERING self.__VRQuality = 1 self.__InteractorStyleSwitcher = None
iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # --------------------------------------------------------- # read the volume reader = vtk.vtkImageReader2() reader.SetDataExtent(0, 63, 0, 63, 0, 92) reader.SetFileNameSliceOffset(1) reader.SetDataScalarTypeToUnsignedShort() reader.SetDataByteOrderToLittleEndian() reader.SetFilePrefix(str(VTK_DATA_ROOT) + "/Data/headsq/quarter") reader.SetDataSpacing(3.2, 3.2, 1.5) # --------------------------------------------------------- # set up the volume rendering volumeMapper = vtk.vtkVolumeTextureMapper3D() volumeMapper.SetInputConnection(reader.GetOutputPort()) volumeMapper.CroppingOn() volumeMapper.SetCroppingRegionPlanes((0.0, 141.6, 0.0, 201.6, 0.0, 138.0)) volumeColor = vtk.vtkColorTransferFunction() volumeColor.AddRGBPoint(0, 0.0, 0.0, 0.0) volumeColor.AddRGBPoint(180, 0.3, 0.1, 0.2) volumeColor.AddRGBPoint(1000, 1.0, 0.7, 0.6) volumeColor.AddRGBPoint(2000, 1.0, 1.0, 0.9) volumeScalarOpacity = vtk.vtkPiecewiseFunction() volumeScalarOpacity.AddPoint(0, 0.0) volumeScalarOpacity.AddPoint(180, 0.0) volumeScalarOpacity.AddPoint(1000, 0.2) volumeScalarOpacity.AddPoint(2000, 0.8)
opacityTransferFunction.AddPoint(600, 0.0) opacityTransferFunction.AddPoint(2000, 1.0) colorTransferFunction = vtk.vtkColorTransferFunction() colorTransferFunction.ClampingOff() colorTransferFunction.AddHSVPoint(0.0, 0.01, 1.0, 1.0) colorTransferFunction.AddHSVPoint(1000.0, 0.50, 1.0, 1.0) colorTransferFunction.AddHSVPoint(2000.0, 0.99, 1.0, 1.0) colorTransferFunction.SetColorSpaceToHSV() # Create properties, mappers, volume actors, and ray cast function volumeProperty = vtk.vtkVolumeProperty() volumeProperty.SetColor(colorTransferFunction) volumeProperty.SetScalarOpacity(opacityTransferFunction) volumeMapper = vtk.vtkVolumeTextureMapper3D() volumeMapper.SetInputConnection(changeFilter.GetOutputPort()) volumeMapper.SetSampleDistance(0.25) volume = vtk.vtkVolume() volume.SetMapper(volumeMapper) volume.SetProperty(volumeProperty) # Create geometric sphere sphereSource = vtk.vtkSphereSource() sphereSource.SetRadius(65) sphereSource.SetThetaResolution(20) sphereSource.SetPhiResolution(40) # Compute random scalars (colors) for each cell randomColors = vtk.vtkProgrammableAttributeDataFilter()
def updateMethod(self): """ Set the Rendering method used """ self.parameters["QualityValue"] = 0 if not self.initDone: return method = self.parameters["Method"] self.volumeProperty.SetScalarOpacity(self.otfs[method]) self.updateOpacityTransferFunction() tbl = [ "Ray cast", "Texture Map", "3D texture map", "MIP", "Isosurface" ] Logging.info("Volume rendering method: ", tbl[method], kw="rendering") #Ray Casting, RGBA Ray Casting, Texture Mapping, MIP composites = [ vtk.vtkVolumeRayCastCompositeFunction, None, None, vtk.vtkVolumeRayCastMIPFunction, vtk.vtkVolumeRayCastIsosurfaceFunction ] blendModes = [ "Composite", "Composite", "Composite", "MaximumIntensity", "Composite" ] if method in [RAYCAST, MIP, ISOSURFACE]: # Iso surfacing with fixedpoint mapper is not supported if method != ISOSURFACE: self.mapper = vtk.vtkFixedPointVolumeRayCastMapper() #self.mapper.SetAutoAdjustSampleDistances(1) self.sampleDistance = self.mapper.GetSampleDistance() #self.volumeProperty.IndependentComponentsOff() mode = blendModes[method] Logging.info("Setting fixed point rendering mode to ", mode, kw="rendering") eval("self.mapper.SetBlendModeTo%s()" % mode) else: self.mapper = vtk.vtkVolumeRayCastMapper() self.function = composites[method]() Logging.info("Using ray cast function ", self.function, kw="rendering") self.mapper.SetVolumeRayCastFunction(self.function) elif method == TEXTURE_MAPPING_3D: # 3d texture mapping self.mapper = vtk.vtkVolumeTextureMapper3D() self.sampleDistance = self.mapper.GetSampleDistance() elif method == TEXTURE_MAPPING: # texture mapping self.mapper = vtk.vtkVolumeTextureMapper2D() self.maxPlanes = self.mapper.GetMaximumNumberOfPlanes() # changed following because seems like a mistake, 19.7.2007 SS # if self.haveVolpro and self.method in [RAYCAST, ISOSURFACE, MIP] and self.parameters["UseVolumepro"]: if self.haveVolpro and method in [ RAYCAST, ISOSURFACE, MIP ] and self.parameters["UseVolumepro"]: # use volumepro accelerated rendering self.mapper = vtk.vtkVolumeProMapper() modes = [ "Composite", None, None, "MaximumIntensity", "MinimumIntensity" ] acc = modes[method] cmd = "self.mapper.SetBlendModeTo%s()" % acc Logging.info("Setting blending mode to ", acc, kw="rendering") eval(cmd) Logging.info("Setting parallel projetion", kw="rendering") self.renderer.GetActiveCamera().ParallelProjectionOn() #self.settingEdit.Enable(0) #self.qualitySlider.Enable(0) else: self.renderer.GetActiveCamera().ParallelProjectionOff() self.mapperUpdated = True
def renderIBC(filePrefix, imgLow, imgHigh): global picker, redCone, greenCone # # This example reads a volume dataset, extracts an isosurface that # represents the skin and displays it. # # The following reader is used to read a series of 2D slices (images) # that compose the volume. The slice dimensions are set, and the # pixel spacing. The data Endianness must also be specified. The reader # usese the FilePrefix in combination with the slice number to construct # filenames using the format FilePrefix.%d. (In this case the FilePrefix # is the root name of the file: quarter.) #vtkVolume16Reader v13R # v13R SetDataDimensions 1388 1040 # v13R SetDataByteOrderToBigEndian # v13R SetFilePrefix "IBC146h.R_s" # v13R SetImageRange 0 44 # v13R SetDataSpacing 1 1 2 # Image reader v13G = vtk.vtkTIFFReader() v13G.SetDataExtent(1, 1380, 1, 1030, imgLow, imgHigh) v13G.SetDataByteOrderToLittleEndian() v13G.SetFilePrefix(filePrefix) v13G.SetDataSpacing(0.1, 0.1, 0.6) # Gaussian Smoothing gaus_v13G = vtk.vtkImageGaussianSmooth() gaus_v13G.SetDimensionality(3) gaus_v13G.SetStandardDeviation(1) gaus_v13G.SetRadiusFactors(1, 1, 1) gaus_v13G.SetInput(v13G.GetOutput()) # Set up the volume rendering volumeMapper = vtk.vtkVolumeTextureMapper3D() volumeMapper.SetInput(v13G.GetOutput()) volume = vtk.vtkVolume() volume.SetMapper(volumeMapper) # Surface rendering bactExtractor = vtk.vtkMarchingCubes() bactExtractor.SetInputConnection(gaus_v13G.GetOutputPort()) bactExtractor.SetValue(0,20000) # bactNormals = vtk.vtkPolyDataNormals() # bactNormals.SetInputConnection(bactExtractor.GetOutputPort()) # bactNormals.SetFeatureAngle(90.0) # # bactStripper = vtk.vtkStripper() # bactStripper.SetInputConnection(bactNormals.GetOutputPort()) # bactLocator = vtk.vtkCellLocator() bactLocator.SetDataSet(bactExtractor.GetOutput()) bactLocator.LazyEvaluationOn() # # bactMapper = vtk.vtkPolyDataMapper() # bactMapper.SetInputConnection(bactStripper.GetOutputPort()) # bactMapper.ScalarVisibilityOff() # skinE_v13G = vtk.vtkContourFilter() ## skinE_v13G = vtk.vtkMarchingCubes() # skinE_v13G.UseScalarTreeOn() # skinE_v13G.SetInput(gaus_v13G.GetOutput()) # skinE_v13G.SetValue(0, 10000) # smooth_v13G = vtk.vtkSmoothPolyDataFilter() smooth_v13G.SetInput(bactExtractor.GetOutput()) smooth_v13G.SetNumberOfIterations(50) deci_v13G = vtk.vtkDecimatePro() deci_v13G.SetInput(smooth_v13G.GetOutput()) deci_v13G.SetTargetReduction(0.5) deci_v13G.PreserveTopologyOn() smoother_v13G = vtk.vtkSmoothPolyDataFilter() smoother_v13G.SetInput(deci_v13G.GetOutput()) smoother_v13G.SetNumberOfIterations(50) skinNormals_v13G = vtk.vtkPolyDataNormals() skinNormals_v13G.SetInput(deci_v13G.GetOutput()) skinNormals_v13G.SetFeatureAngle(60.0) skinStripper_v13G = vtk.vtkStripper() skinStripper_v13G.SetInput(skinNormals_v13G.GetOutput()) skinMapper_v13G = vtk.vtkPolyDataMapper() skinMapper_v13G.SetInput(skinStripper_v13G.GetOutput()) skinMapper_v13G.ScalarVisibilityOff() skin_v13G = vtk.vtkActor() skin_v13G.SetMapper(skinMapper_v13G) skin_v13G.GetProperty().SetDiffuseColor(0.2, 1, 0.2) skin_v13G.GetProperty().SetSpecular(.1) skin_v13G.GetProperty().SetSpecularPower(5) skin_v13G.GetProperty().SetOpacity(0.9) # It is convenient to create an initial view of the data. The FocalPoint # and Position form a vector direction. Later on (ResetCamera() method) # this vector is used to position the camera to look at the data in # this direction. aCamera = vtk.vtkCamera() aCamera.SetViewUp(0, 0, -1) aCamera.SetPosition(0, 1.1, 2) aCamera.SetFocalPoint(0, -0.25, 0) aCamera.ComputeViewPlaneNormal() # Actors are added to the renderer. An initial camera view is created. # The Dolly() method moves the camera towards the FocalPoint, # thereby enlarging the image. #aRenderer AddActor skin_v13R ren.AddActor(skin_v13G) ren.SetActiveCamera(aCamera) ren.ResetCamera() aCamera.Dolly(1.0) # Note that when camera movement occurs (as it does in the Dolly() # method), the clipping planes often need adjusting. Clipping planes # consist of two planes: near and far along the view direction. The # near plane clips out objects in front of the plane the far plane # clips out objects behind the plane. This way only what is drawn # between the planes is actually rendered. ren.ResetCameraClippingRange() # render renWin.Render() # CONE PICKER RENDER #--------------------------------------------------------- # the cone points along the -x axis coneSource = vtk.vtkConeSource() coneSource.CappingOn() coneSource.SetHeight(2) coneSource.SetRadius(1) coneSource.SetResolution(11) coneSource.SetCenter(1,0,0) coneSource.SetDirection(-1,0,0) coneMapper = vtk.vtkDataSetMapper() coneMapper.SetInputConnection(coneSource.GetOutputPort()) redCone = vtk.vtkActor() redCone.PickableOff() redCone.SetMapper(coneMapper) redCone.GetProperty().SetColor(1,0,0) greenCone = vtk.vtkActor() greenCone.PickableOff() greenCone.SetMapper(coneMapper) greenCone.GetProperty().SetColor(0,1,0) # Add the two cones (or just one, if you want) ren.AddViewProp(redCone) ren.AddViewProp(greenCone) #--------------------------------------------------------- # the picker picker = vtk.vtkVolumePicker() picker.SetTolerance(1e-6) picker.SetVolumeOpacityIsovalue(0.1) # locator is optional, but improves performance for large polydata picker.AddLocator(bactLocator) #--------------------------------------------------------- # custom interaction iren.AddObserver("MouseMoveEvent", MoveCursor) # END CONE PICKER RENDER # initialize and start the interactor iren.Initialize() iren.Start()
def _setup_for_3d_texture(self): self._volume_mapper = vtk.vtkVolumeTextureMapper3D() module_utils.setup_vtk_object_progress(self, self._volume_mapper, 'Preparing render.')
def __init__(self): #--------------------------------------------------------- # prep the volume for rendering at 128x128x128 self.ShiftScale = vtk.vtkImageShiftScale() self.ShiftScale.SetOutputScalarTypeToUnsignedShort() self.Reslice = vtk.vtkImageReslice() self.Reslice.SetInputConnection(self.ShiftScale.GetOutputPort()) self.Reslice.SetOutputExtent(0, 127, 0, 127, 0, 127) self.Reslice.SetInterpolationModeToCubic() #--------------------------------------------------------- # set up the volume rendering self.Mapper = vtk.vtkVolumeRayCastMapper() self.Mapper.SetInputConnection(self.Reslice.GetOutputPort()) volumeFunction = vtk.vtkVolumeRayCastCompositeFunction() self.Mapper.SetVolumeRayCastFunction(volumeFunction) self.Mapper3D = vtk.vtkVolumeTextureMapper3D() self.Mapper3D.SetInputConnection(self.Reslice.GetOutputPort()) self.Mapper2D = vtk.vtkVolumeTextureMapper2D() self.Mapper2D.SetInputConnection(self.Reslice.GetOutputPort()) self.Color = vtk.vtkColorTransferFunction() self.Color.AddRGBPoint(0, 0.0, 0.0, 0.0) self.Color.AddRGBPoint(180, 0.3, 0.1, 0.2) self.Color.AddRGBPoint(1200, 1.0, 0.7, 0.6) self.Color.AddRGBPoint(2500, 1.0, 1.0, 0.9) self.ScalarOpacity = vtk.vtkPiecewiseFunction() self.ScalarOpacity.AddPoint(0, 0.0) self.ScalarOpacity.AddPoint(180, 0.0) self.ScalarOpacity.AddPoint(1200, 0.2) self.ScalarOpacity.AddPoint(2500, 0.8) self.GradientOpacity = vtk.vtkPiecewiseFunction() self.GradientOpacity.AddPoint(0, 0.0) self.GradientOpacity.AddPoint(90, 0.5) self.GradientOpacity.AddPoint(100, 1.0) self.Property = vtk.vtkVolumeProperty() self.Property.SetColor(self.Color) self.Property.SetScalarOpacity(self.ScalarOpacity) #self.Property.SetGradientOpacity(self.GradientOpacity) self.Property.SetInterpolationTypeToLinear() self.Property.ShadeOff() self.Property.SetAmbient(0.6) self.Property.SetDiffuse(0.6) self.Property.SetSpecular(0.1) self.lod2D = self.AddLOD(self.Mapper2D, self.Property, 0.01) self.lod3D = self.AddLOD(self.Mapper3D, self.Property, 0.1) self.lodRC = self.AddLOD(self.Mapper, self.Property, 1.0) self.SetLODLevel(self.lod2D, 2.0) self.SetLODLevel(self.lod3D, 1.0) self.SetLODLevel(self.lodRC, 0.0) # disable ray casting #self.DisableLOD(self.lod3D) #self.DisableLOD(self.lod2D) self.DisableLOD(self.lodRC)
def __init__(self): #--------------------------------------------------------- # prep the volume for rendering at 128x128x128 self.ShiftScale = vtk.vtkImageShiftScale() self.ShiftScale.SetOutputScalarTypeToUnsignedShort() self.Reslice = vtk.vtkImageReslice() self.Reslice.SetInput(self.ShiftScale.GetOutput()) self.Reslice.SetOutputExtent(0, 127, 0, 127, 0, 127) self.Reslice.SetInterpolationModeToCubic() #--------------------------------------------------------- # set up the volume rendering self.Mapper = vtk.vtkVolumeRayCastMapper() self.Mapper.SetInput(self.Reslice.GetOutput()) volumeFunction = vtk.vtkVolumeRayCastCompositeFunction() self.Mapper.SetVolumeRayCastFunction(volumeFunction) self.Mapper3D = vtk.vtkVolumeTextureMapper3D() self.Mapper3D.SetInput(self.Reslice.GetOutput()) self.Mapper2D = vtk.vtkVolumeTextureMapper2D() self.Mapper2D.SetInput(self.Reslice.GetOutput()) self.Color = vtk.vtkColorTransferFunction() self.Color.AddRGBPoint(0,0.0,0.0,0.0) self.Color.AddRGBPoint(180,0.3,0.1,0.2) self.Color.AddRGBPoint(1200,1.0,0.7,0.6) self.Color.AddRGBPoint(2500,1.0,1.0,0.9) self.ScalarOpacity = vtk.vtkPiecewiseFunction() self.ScalarOpacity.AddPoint(0,0.0) self.ScalarOpacity.AddPoint(180,0.0) self.ScalarOpacity.AddPoint(1200,0.2) self.ScalarOpacity.AddPoint(2500,0.8) self.GradientOpacity = vtk.vtkPiecewiseFunction() self.GradientOpacity.AddPoint(0,0.0) self.GradientOpacity.AddPoint(90,0.5) self.GradientOpacity.AddPoint(100,1.0) self.Property = vtk.vtkVolumeProperty() self.Property.SetColor(self.Color) self.Property.SetScalarOpacity(self.ScalarOpacity) #self.Property.SetGradientOpacity(self.GradientOpacity) self.Property.SetInterpolationTypeToLinear() self.Property.ShadeOff() self.Property.SetAmbient(0.6) self.Property.SetDiffuse(0.6) self.Property.SetSpecular(0.1) self.lod2D = self.AddLOD(self.Mapper2D, self.Property, 0.01) self.lod3D = self.AddLOD(self.Mapper3D, self.Property, 0.1) self.lodRC = self.AddLOD(self.Mapper, self.Property, 1.0) self.SetLODLevel(self.lod2D, 2.0) self.SetLODLevel(self.lod3D, 1.0) self.SetLODLevel(self.lodRC, 0.0) # disable ray casting #self.DisableLOD(self.lod3D) #self.DisableLOD(self.lod2D) self.DisableLOD(self.lodRC)
def updateMethod(self): """ Set the Rendering method used """ self.parameters["QualityValue"] = 0 if not self.initDone: return method = self.parameters["Method"] self.volumeProperty.SetScalarOpacity(self.otfs[method]) self.updateOpacityTransferFunction() tbl = ["Ray cast", "Texture Map", "3D texture map", "MIP", "Isosurface"] Logging.info("Volume rendering method: ", tbl[method], kw = "rendering") #Ray Casting, RGBA Ray Casting, Texture Mapping, MIP composites = [vtk.vtkVolumeRayCastCompositeFunction, None, None, vtk.vtkVolumeRayCastMIPFunction, vtk.vtkVolumeRayCastIsosurfaceFunction ] blendModes = ["Composite", "Composite", "Composite", "MaximumIntensity", "Composite"] if method in [RAYCAST, MIP, ISOSURFACE]: # Iso surfacing with fixedpoint mapper is not supported if method != ISOSURFACE: self.mapper = vtk.vtkFixedPointVolumeRayCastMapper() #self.mapper.SetAutoAdjustSampleDistances(1) self.sampleDistance = self.mapper.GetSampleDistance() #self.volumeProperty.IndependentComponentsOff() mode = blendModes[method] Logging.info("Setting fixed point rendering mode to ", mode, kw = "rendering") eval("self.mapper.SetBlendModeTo%s()" % mode) else: self.mapper = vtk.vtkVolumeRayCastMapper() self.function = composites[method]() Logging.info("Using ray cast function ", self.function, kw = "rendering") self.mapper.SetVolumeRayCastFunction(self.function) elif method == TEXTURE_MAPPING_3D: # 3d texture mapping self.mapper = vtk.vtkVolumeTextureMapper3D() self.sampleDistance = self.mapper.GetSampleDistance() elif method == TEXTURE_MAPPING: # texture mapping self.mapper = vtk.vtkVolumeTextureMapper2D() self.maxPlanes = self.mapper.GetMaximumNumberOfPlanes() # changed following because seems like a mistake, 19.7.2007 SS # if self.haveVolpro and self.method in [RAYCAST, ISOSURFACE, MIP] and self.parameters["UseVolumepro"]: if self.haveVolpro and method in [RAYCAST, ISOSURFACE, MIP] and self.parameters["UseVolumepro"]: # use volumepro accelerated rendering self.mapper = vtk.vtkVolumeProMapper() modes = ["Composite", None, None, "MaximumIntensity", "MinimumIntensity"] acc = modes[method] cmd = "self.mapper.SetBlendModeTo%s()" % acc Logging.info("Setting blending mode to ", acc, kw = "rendering") eval(cmd) Logging.info("Setting parallel projetion", kw = "rendering") self.renderer.GetActiveCamera().ParallelProjectionOn() #self.settingEdit.Enable(0) #self.qualitySlider.Enable(0) else: self.renderer.GetActiveCamera().ParallelProjectionOff() self.mapperUpdated = True
def __init__(self, parent=None): #QtGui.QMainWindow.__init__(self, parent) self.dragging = False self.lasso_screen = [(0, 0), (100, 50)] if 0: self.frame = QtGui.QFrame() self.vl = QtGui.QVBoxLayout() self.vtkWidget = QVTKRenderWindowInteractor(self.frame) # monkey patch self.vtkWidget._original_mouseMoveEvent = self.vtkWidget.mouseMoveEvent self.vtkWidget.mouseMoveEvent = self.mouseMoveEvent self.vtkWidget._original_mousePressEvent = self.vtkWidget.mousePressEvent self.vtkWidget.mousePressEvent = self.mousePressEvent self.vtkWidget._original_mouseReleaseEvent = self.vtkWidget.mouseReleaseEvent self.vtkWidget.mouseReleaseEvent = self.mouseReleaseEvent if 0: self.vtkWidget._original_paintEvent = self.vtkWidget.paintEvent self.vtkWidget.paintEvent = self.paintEvent def test(): print QtGui.QPaintEngine.OpenGL return 0 self.vtkWidget.paintEngine = test self.vl.addWidget(self.vtkWidget) #self.overlay = Overlay(self.vtkWidget, self.frame) #self.vl.addWidget(self.overlay) #self.vl.addWidget(QtGui.QPushButton("test", self)) else: window = vtk.vtkXOpenGLRenderWindow() window.SetOffScreenRendering(True) self.ren = vtk.vtkRenderer() window.AddRenderer(self.ren) #self.iren = self.vtkWidget.GetRenderWindow().GetInteractor() #self.iren.GetInteractorStyle().SetCurrentStyleToTrackballCamera() #self.iren.GetInteractorStyle().AddObserver("MouseMoveEvent", self.mouseMoveEvent) #self.interactorStyle = MyInteractorStyle(self) #self.iren.SetInteractorStyle(self.interactorStyle) #import pdb #pdb.set_trace() # Create source #source = vtk.vtkSphereSource() #source.SetCenter(0, 0, 0) #source.SetRadius(5.0) if 0: self.levelSlider = QtGui.QSlider(QtCore.Qt.Horizontal, self) self.levelSlider.setRange(0, 100) self.levelSlider.sliderReleased.connect(self.sliderReleased) self.isoCheckbox = QtGui.QCheckBox("Show isosurface", self) self.volumeCheckbox = QtGui.QCheckBox("Show volume rendering", self) self.vl.addWidget(self.isoCheckbox) self.vl.addWidget(self.volumeCheckbox) self.vl.addWidget(self.levelSlider) self.isoCheckbox.setCheckState(QtCore.Qt.Checked) self.volumeCheckbox.setCheckState(QtCore.Qt.Checked) #self.formLayout = QtGui.QFormLayout(self) #self.formLayout.addRow("show isosurface", QCheckBox #self.vl.addItem(self.formLayout) imageData = createImageData() volumeMapper = vtk.vtkSmartVolumeMapper() volumeMapper = vtk.vtkVolumeTextureMapper3D() volumeMapper.SetBlendModeToComposite() #compositeFunction = vtk.vtkVolumeRayCastCompositeFunction() # We can finally create our volume. We also have to specify the data for it, as well as how the data will be rendered. #volumeMapper = vtk.vtkVolumeRayCastMapper() #volumeMapper.SetVolumeRayCastFunction(compositeFunction) volumeMapper.SetInputConnection(imageData.GetProducerPort()) volumeProperty = vtk.vtkVolumeProperty() volumeProperty.ShadeOff() volumeProperty.SetInterpolationType(vtk.VTK_LINEAR_INTERPOLATION) compositeOpacity = vtk.vtkPiecewiseFunction() compositeOpacity.AddPoint(0., 0.0) compositeOpacity.AddPoint(1., 0.105) compositeOpacity.AddPoint(2., 0.101) compositeOpacity.AddPoint(3., 0.102) volumeProperty.SetScalarOpacity(compositeOpacity) color = vtk.vtkColorTransferFunction() #color.AddRGBPoint(1, 1.0, 0.0, 0.0) color.AddRGBPoint(2, 0.0, 1.0, 0.0) color.AddRGBPoint(3, 0.0, 0.0, 1.0) volumeProperty.SetColor(color) volume = vtk.vtkVolume() volume.SetMapper(volumeMapper) volume.SetProperty(volumeProperty) self.ren.AddViewProp(volume) outline = vtk.vtkOutlineFilter() outline.SetInput(imageData) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) outlineActor.GetProperty().SetColor(0, 0, 0) self.ren.AddActor(outlineActor) self.lasso = Lasso(self.lasso_screen) self.ren.AddActor(self.lasso.actor) if 0: def onVolume(state): checked = state == QtCore.Qt.Checked if checked: volume.VisibilityOn() else: volume.VisibilityOff() self.vtkWidget.GetRenderWindow().Render() self.volumeCheckbox.stateChanged.connect(onVolume) #self.ren.ResetCamera() if 0: self.surface = vtk.vtkMarchingCubes() self.surface.SetInput(imageData) self.surface.ComputeNormalsOn() self.surface.SetValue(0, 100) #print surface #print surface.GetOutput() #print surface.GetOutputPort() # Create a mapper mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(self.surface.GetOutputPort()) mapper.ScalarVisibilityOff() print mapper import pdb #pdb.set_trace() # Create an actor actor = vtk.vtkActor() actor.SetMapper(mapper) actor.GetProperty().SetColor(1, 0, 0) actor.GetProperty().SetOpacity(1) self.ren.AddActor(actor) def onIso(state): checked = state == QtCore.Qt.Checked if checked: actor.VisibilityOn() else: actor.VisibilityOff() self.vtkWidget.GetRenderWindow().Render() self.isoCheckbox.stateChanged.connect(onIso) self.ren.ResetCamera() #self.frame.setLayout(self.vl) #self.setCentralWidget(self.frame) self.ren.SetBackground(1, 1, 1) #self.ren.SetOffScreenRendering(True) arr = vtk.vtkUnsignedCharArray() print "size", arr.GetDataSize() window.Render() print window.GetPixelData(0, 0, 10, 10, 0, arr) print "size", arr.GetDataSize() self.show() self.raise_() print "aap" self.iren.Initialize()