Exemplo n.º 1
0
 def RenderImage(self, origImg):
     self.ren[0].RemoveVolume(self.volume)
     self.ren[0].RemoveActor(self.outLine)
     # create volume
     volumeImport = vtk.vtkImageImport()
     data_string = origImg.tostring()
     if origImg.dtype == np.uint16:
         volumeImport.CopyImportVoidPointer(data_string, len(data_string))
         volumeImport.SetDataScalarTypeToUnsignedShort()
     else:
         volumeImport.CopyImportVoidPointer(data_string, len(data_string))
         volumeImport.SetDataScalarTypeToUnsignedChar()
     volumeImport.SetNumberOfScalarComponents(1)
     sz = origImg.shape
     volumeImport.SetDataExtent(0, sz[2] - 1, 0, sz[1] - 1, 0, sz[0] - 1)
     volumeImport.SetWholeExtent(0, sz[2] - 1, 0, sz[1] - 1, 0, sz[0] - 1)
     volumeImport.Update()
     self.importData.DeepCopy(volumeImport.GetOutput())
     self.volumeSize = sz
     #
     alphaChannelFunc = vtk.vtkPiecewiseFunction()
     alphaChannelFunc.AddPoint(0, 0.0)
     alphaChannelFunc.AddPoint(10, 0.9)
     #
     self.colorFunc.AddRGBPoint(1, 0.0, 0.0, 0.0)
     self.colorFunc.AddRGBPoint(255, 1.0, 1.0, 1.0)
     #
     volumeProperty = vtk.vtkVolumeProperty()
     volumeProperty.SetColor(self.colorFunc)
     volumeProperty.SetScalarOpacity(alphaChannelFunc)
     volumeProperty.SetInterpolationType(3)
     #
     volumeMapper = vtk.vtkSmartVolumeMapper()
     volumeMapper.SetBlendModeToMaximumIntensity()
     # volumeMapper.SetVolumeRayCastFunction(compositeFunction)
     volumeMapper.SetInterpolationModeToCubic()
     volumeMapper.SetInputConnection(volumeImport.GetOutputPort())
     self.volume.SetMapper(volumeMapper)
     self.volume.SetProperty(volumeProperty)
     self.volume.SetUserTransform(self.transform)
     #
     outLineSource = vtk.vtkVolumeOutlineSource()
     outLineSource.SetVolumeMapper(volumeMapper)
     outLineMapper = vtk.vtkPolyDataMapper()
     outLineMapper.SetInputConnection(outLineSource.GetOutputPort())
     self.outLine.SetMapper(outLineMapper)
     self.outLine.GetProperty().SetColor(0, 1, 1)
     self.outLine.SetUserTransform(self.transform)
     self.ren[0].AddVolume(self.volume)
     self.ren[0].AddActor(self.outLine)
     self.ren[0].ResetCamera()
Exemplo n.º 2
0
volumeProperty.SetAmbient(0.6)
volumeProperty.SetDiffuse(0.6)
volumeProperty.SetSpecular(0.1)

volume = vtk.vtkLODProp3D()
lod2D = volume.AddLOD(volumeMapper2D, volumeProperty, 0.01)
lod3D = volume.AddLOD(volumeMapper3D, volumeProperty, 0.1)
lodRC = volume.AddLOD(volumeMapper, volumeProperty, 1.0)
volume.SetLODLevel(lod2D, 2.0)
volume.SetLODLevel(lod3D, 1.0)
volume.SetLODLevel(lodRC, 0.0)
# disable ray casting
#volume.DisableLOD(lod3D)
volume.DisableLOD(lodRC)

cropOutlineSource = vtk.vtkVolumeOutlineSource()
cropOutlineSource.SetVolumeMapper(volumeMapper)
cropOutlineSource.GenerateScalarsOn()
cropOutlineSource.SetActivePlaneId(0)

cropOutlineMapper = vtk.vtkPolyDataMapper()
cropOutlineMapper.SetInputConnection(cropOutlineSource.GetOutputPort())

cropOutline = vtk.vtkActor()
cropOutline.SetMapper(cropOutlineMapper)

#---------------------------------------------------------
# Do the surface rendering
skinExtractor = vtk.vtkMarchingCubes()
skinExtractor.SetInputConnection(reader.GetOutputPort())
skinExtractor.SetValue(0,500)
clippingPlanes.AddItem(plane4)
clippingPlanes.AddItem(plane5)
clippingPlanes.AddItem(plane6)

# Cropping planes are in data coords
volumeMapper1 = vtk.vtkFixedPointVolumeRayCastMapper()
volumeMapper1.SetInputConnection(reader.GetOutputPort())
volumeMapper1.CroppingOn()
volumeMapper1.SetCroppingRegionPlanes(16, 33, 16, 33, 16, 33)
volumeMapper1.SetClippingPlanes(clippingPlanes)

volume1 = vtk.vtkVolume()
volume1.SetMapper(volumeMapper1)
volume1.SetProperty(volumeProperty)

outline1 = vtk.vtkVolumeOutlineSource()
outline1.SetVolumeMapper(volumeMapper1)
outline1.GenerateFacesOn()
outline1.GenerateScalarsOn()

preTrans1 = vtk.vtkTransformPolyDataFilter()
preTrans1.SetInputConnection(outline1.GetOutputPort())
preTrans1.SetTransform(userTrans)

outlineClip1 = vtk.vtkClipClosedSurface()
outlineClip1.SetInputConnection(preTrans1.GetOutputPort())
outlineClip1.SetClippingPlanes(clippingPlanes)
outlineClip1.GenerateFacesOff()
outlineClip1.GenerateOutlineOn()
outlineClip1.SetScalarModeToColors()
outlineClip1.SetClipColor(1, 1, 0)
Exemplo n.º 4
0
volumeProperty.SetAmbient(0.6)
volumeProperty.SetDiffuse(0.6)
volumeProperty.SetSpecular(0.1)

volume = vtk.vtkLODProp3D()
lod2D = volume.AddLOD(volumeMapper2D, volumeProperty, 0.01)
lod3D = volume.AddLOD(volumeMapper3D, volumeProperty, 0.1)
lodRC = volume.AddLOD(volumeMapper, volumeProperty, 1.0)
volume.SetLODLevel(lod2D, 2.0)
volume.SetLODLevel(lod3D, 1.0)
volume.SetLODLevel(lodRC, 0.0)
# disable ray casting
#volume.DisableLOD(lod3D)
volume.DisableLOD(lodRC)

cropOutlineSource = vtk.vtkVolumeOutlineSource()
cropOutlineSource.SetVolumeMapper(volumeMapper)
cropOutlineSource.GenerateScalarsOn()
cropOutlineSource.SetActivePlaneId(0)

cropOutlineMapper = vtk.vtkPolyDataMapper()
cropOutlineMapper.SetInputConnection(cropOutlineSource.GetOutputPort())

cropOutline = vtk.vtkActor()
cropOutline.SetMapper(cropOutlineMapper)

#---------------------------------------------------------
# Do the surface rendering
skinExtractor = vtk.vtkMarchingCubes()
skinExtractor.SetInputConnection(reader.GetOutputPort())
skinExtractor.SetValue(0, 500)