def update_nonrigid_grid(self): """This updates the nonrigid grid. Subject data must be added first. """ # create the bspline transform from this displacement field vtktrans = wma.register_two_subjects_nonrigid_bsplines.convert_transform_to_vtk( self.transform_as_array) # now compute a new displacement field from the transform, using the new grid resolution # This code always uses a grid of 200mm x 200mm x 200mm size_mm = 200.0 dims = self.nonrigid_grid_resolution spacing = size_mm / (dims - 1) origin = -size_mm / 2.0 grid = vtk.vtkTransformToGrid() grid.SetGridOrigin(origin, origin, origin) grid.SetGridSpacing(spacing, spacing, spacing) grid.SetGridExtent(0, dims - 1, 0, dims - 1, 0, dims - 1) grid.SetGridScalarTypeToFloat() grid.SetInput(vtktrans) grid.Update() # convert the vtkImageData displacement field back to a numpy object displacement_field_vtk = grid.GetOutput() #print displacement_field_vtk.GetPointData().GetArray(0) newtrans = vtk.util.numpy_support.vtk_to_numpy( displacement_field_vtk.GetPointData().GetArray(0)).ravel() #print newtrans.shape print("UPDATE NONRIGID GRID: ", self.nonrigid_grid_resolution, len(self.transform_as_array), "==>", len(newtrans), end=' ') self.transform_as_array = newtrans
def update_nonrigid_grid(self): """This updates the nonrigid grid. Subject data must be added first. """ # create the bspline transform from this displacement field vtktrans = wma.register_two_subjects_nonrigid_bsplines.convert_transform_to_vtk(self.transform_as_array) # now compute a new displacement field from the transform, using the new grid resolution # This code always uses a grid of 200mm x 200mm x 200mm size_mm = 200.0 dims = self.nonrigid_grid_resolution spacing = size_mm / (dims - 1) origin = -size_mm / 2.0 grid = vtk.vtkTransformToGrid() grid.SetGridOrigin(origin, origin, origin) grid.SetGridSpacing(spacing, spacing, spacing) grid.SetGridExtent(0, dims-1, 0, dims-1, 0, dims-1) grid.SetGridScalarTypeToFloat() grid.SetInput(vtktrans) grid.Update() # convert the vtkImageData displacement field back to a numpy object displacement_field_vtk = grid.GetOutput() #print displacement_field_vtk.GetPointData().GetArray(0) newtrans = vtk.util.numpy_support.vtk_to_numpy(displacement_field_vtk.GetPointData().GetArray(0)).ravel() #print newtrans.shape print "UPDATE NONRIGID GRID: ", self.nonrigid_grid_resolution, len(self.transform_as_array), "==>", len(newtrans), self.transform_as_array = newtrans
def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__( self, module_manager, vtk.vtkTransformToGrid(), 'Processing.', (), ('vtkImageData',), replaceDoc=True, inputFunctions=None, outputFunctions=None)
def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__(self, module_manager, vtk.vtkTransformToGrid(), 'Processing.', (), ('vtkImageData', ), replaceDoc=True, inputFunctions=None, outputFunctions=None)
def onExportGrid(self): """Converts the current thin plate transform to a grid""" self.hotUpdateButton = None state = self.registrationState() # since the transform is ras-to-ras, we find the extreme points # in ras space of the fixed (target) volume and fix the unoriented # box around it. Sample the grid transform at the resolution of # the fixed volume, which may be a bit overkill but it should aways # work without too much loss. rasBounds = [ 0, ] * 6 state.fixed.GetRASBounds(rasBounds) from math import floor, ceil origin = list(map(int, map(floor, rasBounds[::2]))) maxes = list(map(int, map(ceil, rasBounds[1::2]))) boundSize = [m - o for m, o in zip(maxes, origin)] spacing = state.fixed.GetSpacing() samples = [ceil(int(b / s)) for b, s in zip(boundSize, spacing)] extent = [ 0, ] * 6 extent[::2] = [ 0, ] * 3 extent[1::2] = samples extent = list(map(int, extent)) toGrid = vtk.vtkTransformToGrid() toGrid.SetGridOrigin(origin) toGrid.SetGridSpacing(state.fixed.GetSpacing()) toGrid.SetGridExtent(extent) toGrid.SetInput( state.transform.GetTransformFromParent()) # same in VTKv 5 & 6 toGrid.Update() gridTransform = slicer.vtkOrientedGridTransform() if vtk.VTK_MAJOR_VERSION < 6: gridTransform.SetDisplacementGrid( toGrid.GetOutput()) # different in VTKv 5 & 6 else: gridTransform.SetDisplacementGridData(toGrid.GetOutput()) gridNode = slicer.vtkMRMLGridTransformNode() gridNode.SetAndObserveTransformFromParent(gridTransform) gridNode.SetName(state.transform.GetName() + "-grid") slicer.mrmlScene.AddNode(gridNode)
def onExportGrid(self): """Converts the current thin plate transform to a grid""" state = self.registationState() # since the transform is ras-to-ras, we find the extreme points # in ras space of the fixed (target) volume and fix the unoriented # box around it. Sample the grid transform at the resolution of # the fixed volume, which may be a bit overkill but it should aways # work without too much loss. rasBounds = [0,]*6 state.fixed.GetRASBounds(rasBounds) from math import floor, ceil origin = map(int,map(floor,rasBounds[::2])) maxes = map(int,map(ceil,rasBounds[1::2])) boundSize = [m - o for m,o in zip(maxes,origin) ] spacing = state.fixed.GetSpacing() samples = [ceil(b / s) for b,s in zip(boundSize,spacing)] extent = [0,]*6 extent[::2] = [0,]*3 extent[1::2] = samples extent = map(int,extent) toGrid = vtk.vtkTransformToGrid() toGrid.SetGridOrigin(origin) toGrid.SetGridSpacing(state.fixed.GetSpacing()) toGrid.SetGridExtent(extent) toGrid.SetInput(state.transform.GetTransformFromParent()) # same in VTKv 5 & 6 toGrid.Update() gridTransform = vtk.vtkGridTransform() if vtk.VTK_MAJOR_VERSION < 6: gridTransform.SetDisplacementGrid(toGrid.GetOutput()) # different in VTKv 5 & 6 else: gridTransform.SetDisplacementGridData(toGrid.GetOutput()) gridNode = slicer.vtkMRMLGridTransformNode() gridNode.SetAndObserveTransformFromParent(gridTransform) gridNode.SetName(state.transform.GetName()+"-grid") slicer.mrmlScene.AddNode(gridNode)
def update_nonrigid_grid(self): """This updates the nonrigid grids. Subjects must be added first using add_polydata. """ # Apply the existing transform to the new grid new_transforms = list() for trans in self.transforms_as_array: # create the bspline transform from this displacement field vtktrans = wma.register_two_subjects_nonrigid_bsplines.convert_transform_to_vtk(trans) # now compute a new displacement field from the transform, using the new grid resolution # This code always uses a grid of 240mm x 240mm x 240mm # This MUST correspond to the size used in register_two_subjects_nonrigid_bsplines convert_transform_to_vtk #size_mm = 240.0 size_mm = 200.0 dims = self.nonrigid_grid_resolution spacing = size_mm / (dims - 1) origin = -size_mm / 2.0 grid = vtk.vtkTransformToGrid() grid.SetGridOrigin(origin, origin, origin) grid.SetGridSpacing(spacing, spacing, spacing) grid.SetGridExtent(0, dims-1, 0, dims-1, 0, dims-1) grid.SetGridScalarTypeToFloat() grid.SetInput(vtktrans) grid.Update() # convert the vtkImageData displacement field back to a numpy object displacement_field_vtk = grid.GetOutput() #print displacement_field_vtk.GetPointData().GetArray(0) newtrans = vtk.util.numpy_support.vtk_to_numpy(displacement_field_vtk.GetPointData().GetArray(0)) #print newtrans.shape new_transforms.append(newtrans.ravel()) # Update all the relevant variables (the spline transform does not change but all source and target points do) print "UPDATE NONRIGID GRID: ", self.nonrigid_grid_resolution, len(trans), "==>", len(new_transforms[-1]), "SHAPE:", newtrans.shape, "GRID:", grid self.transforms_as_array = new_transforms
p2 = vtk.vtkPoints() p2.SetNumberOfPoints(8) p2.SetPoint(0, 0, 0, 0) p2.SetPoint(1, 0, 255, 0) p2.SetPoint(2, 255, 0, 0) p2.SetPoint(3, 255, 255, 0) p2.SetPoint(4, 96, 159, 0) p2.SetPoint(5, 159, 159, 0) p2.SetPoint(6, 159, 96, 0) p2.SetPoint(7, 96, 96, 0) thinPlate = vtk.vtkThinPlateSplineTransform() thinPlate.SetSourceLandmarks(p2) thinPlate.SetTargetLandmarks(p1) thinPlate.SetBasisToR2LogR() # convert the thin plate spline into a grid transformToGrid = vtk.vtkTransformToGrid() transformToGrid.SetInput(thinPlate) transformToGrid.SetGridSpacing(16, 16, 1) transformToGrid.SetGridOrigin(-0.5, -0.5, 0) transformToGrid.SetGridExtent(0, 16, 0, 16, 0, 0) transformToGrid.Update() transform = vtk.vtkGridTransform() transform.SetDisplacementGridConnection(transformToGrid.GetOutputPort()) transform.SetInterpolationModeToCubic() # you must invert the transform before passing it to vtkImageReslice transform.Inverse() # apply the grid warp to the image reslice = vtk.vtkImageReslice() reslice.SetInputConnection(blend.GetOutputPort()) reslice.SetResliceTransform(transform) reslice.SetInterpolationModeToLinear()
p2.InsertNextPoint(-100,100,-50) p1.InsertNextPoint(-100,100,50) p2.InsertNextPoint(-100,100,50) p1.InsertNextPoint(100,-100,-50) p2.InsertNextPoint(100,-100,-50) p1.InsertNextPoint(100,-100,50) p2.InsertNextPoint(100,-100,50) p1.InsertNextPoint(100,100,-50) p2.InsertNextPoint(100,100,-50) p1.InsertNextPoint(100,100,50) p2.InsertNextPoint(100,100,50) transform = vtk.vtkThinPlateSplineTransform() transform.SetSourceLandmarks(p1) transform.SetTargetLandmarks(p2) transform.SetBasisToR() gridThinPlate = vtk.vtkTransformToGrid() gridThinPlate.SetInput(transform) gridThinPlate.SetGridExtent(0,64,0,64,0,50) gridThinPlate.SetGridSpacing(3.2,3.2,3.0) gridThinPlate.SetGridOrigin(-102.4,-102.4,-75) gridThinPlate.SetGridScalarTypeToUnsignedChar() gridThinPlate.Update() gridTransform = vtk.vtkGridTransform() gridTransform.SetDisplacementGridData(gridThinPlate.GetOutput()) gridTransform.SetDisplacementShift(gridThinPlate.GetDisplacementShift()) gridTransform.SetDisplacementScale(gridThinPlate.GetDisplacementScale()) reslice = vtk.vtkImageReslice() reslice.SetInputConnection(reader.GetOutputPort()) reslice.SetResliceTransform(gridTransform) reslice.SetInterpolationModeToLinear() reslice.SetOutputSpacing(1,1,1)
f12.SetTransform(t1.GetInverse()) m12 = vtk.vtkDataSetMapper() m12.SetInputConnection(f12.GetOutputPort()) a12 = vtk.vtkActor() a12.SetMapper(m12) a12.RotateY(90) a12.GetProperty().SetColor(0.9,0.9,0) #[a12 GetProperty] SetRepresentationToWireframe ren12 = vtk.vtkRenderer() ren12.SetViewport(0.0,0.0,0.25,0.5) ren12.ResetCamera(-0.5,0.5,-0.5,0.5,-1,1) ren12.AddActor(a12) renWin.AddRenderer(ren12) #-------------------------- # grid transform, cubic interpolation gridTrans = vtk.vtkTransformToGrid() gridTrans.SetInput(t1) gridTrans.SetGridOrigin(-1.5,-1.5,-1.5) gridTrans.SetGridExtent(0,60,0,60,0,60) gridTrans.SetGridSpacing(0.05,0.05,0.05) t2 = vtk.vtkGridTransform() t2.SetDisplacementGridConnection(gridTrans.GetOutputPort()) t2.SetInterpolationModeToCubic() f21 = vtk.vtkTransformPolyDataFilter() f21.SetInputConnection(ap.GetOutputPort()) f21.SetTransform(t2) m21 = vtk.vtkDataSetMapper() m21.SetInputConnection(f21.GetOutputPort()) a21 = vtk.vtkActor() a21.SetMapper(m21) a21.RotateY(90)
p2.InsertNextPoint(-100, 100, -50) p1.InsertNextPoint(-100, 100, 50) p2.InsertNextPoint(-100, 100, 50) p1.InsertNextPoint(100, -100, -50) p2.InsertNextPoint(100, -100, -50) p1.InsertNextPoint(100, -100, 50) p2.InsertNextPoint(100, -100, 50) p1.InsertNextPoint(100, 100, -50) p2.InsertNextPoint(100, 100, -50) p1.InsertNextPoint(100, 100, 50) p2.InsertNextPoint(100, 100, 50) transform = vtk.vtkThinPlateSplineTransform() transform.SetSourceLandmarks(p1) transform.SetTargetLandmarks(p2) transform.SetBasisToR() gridThinPlate = vtk.vtkTransformToGrid() gridThinPlate.SetInput(transform) gridThinPlate.SetGridExtent(0, 64, 0, 64, 0, 50) gridThinPlate.SetGridSpacing(3.2, 3.2, 3.0) gridThinPlate.SetGridOrigin(-102.4, -102.4, -75) gridThinPlate.SetGridScalarTypeToUnsignedChar() gridThinPlate.Update() gridTransform = vtk.vtkGridTransform() gridTransform.SetDisplacementGridData(gridThinPlate.GetOutput()) gridTransform.SetDisplacementShift(gridThinPlate.GetDisplacementShift()) gridTransform.SetDisplacementScale(gridThinPlate.GetDisplacementScale()) reslice = vtk.vtkImageReslice() reslice.SetInputConnection(reader.GetOutputPort()) reslice.SetResliceTransform(gridTransform) reslice.SetInterpolationModeToLinear() reslice.SetOutputSpacing(1, 1, 1)
p2.SetPoint(0,0,0,0) p2.SetPoint(1,0,255,0) p2.SetPoint(2,255,0,0) p2.SetPoint(3,255,255,0) p2.SetPoint(4,96,159,0) p2.SetPoint(5,159,159,0) p2.SetPoint(6,159,96,0) p2.SetPoint(7,96,96,0) thinPlate = vtk.vtkThinPlateSplineTransform() thinPlate.SetSourceLandmarks(p2) thinPlate.SetTargetLandmarks(p1) thinPlate.SetBasisToR2LogR() # convert the thin plate spline into a grid # for nearest neighbor interpolation, the grid should precicely # overlay the image you want to warp transformToGrid = vtk.vtkTransformToGrid() transformToGrid.SetInput(thinPlate) transformToGrid.SetGridSpacing(1,1,1) transformToGrid.SetGridOrigin(0,0,0) transformToGrid.SetGridExtent(0,255,0,255,0,0) transformToGrid.Update() transform = vtk.vtkGridTransform() transform.SetDisplacementGridConnection(transformToGrid.GetOutputPort()) transform.SetInterpolationModeToNearestNeighbor() # must lower the tolerance or it won't invert transform.SetInverseTolerance(2.0) # you must invert the transform before passing it to vtkImageReslice transform.Inverse() # apply the grid warp to the image reslice = vtk.vtkImageReslice() reslice.SetInputConnection(blend.GetOutputPort())
def __init__(self): ActorFactory.ActorFactory.__init__(self) # whether to display the volume self._ShowVolume = 1 self._StatusChange = 0 # create a clipping cube to go with the volume self._ClippingCube = ClippingCubeFactory.ClippingCubeFactory() self.AddChild(self._ClippingCube) self._CubeClippingPlanes = vtk.vtkPlaneCollection() for i in range(6): self._CubeClippingPlanes.AddItem(vtk.vtkPlane()) # for if we clip in with OrthoPlanes self._OrthoPlanes = None self._ShowOrthoPlanes = 1 self._OrthoPlanesLookupTables = {} self._OrthoPickThreshold = 0.0025 # corner clipping planes, in pairs with opposite normals self._CornerClippingPlanes = vtk.vtkPlaneCollection() for i in range(6): self._CornerClippingPlanes.AddItem(vtk.vtkPlane()) # clipping planes for the volume, sorted for the # three chunks that will make up the final volume self._ClippingPlanes = [ vtk.vtkPlaneCollection(), vtk.vtkPlaneCollection(), vtk.vtkPlaneCollection() ] for i in range(3): planes = self._ClippingPlanes[i] cplanes = self._CornerClippingPlanes bplanes = self._CubeClippingPlanes if i == 0: planes.AddItem(cplanes.GetItemAsObject(0)) planes.AddItem(bplanes.GetItemAsObject(1)) planes.AddItem(bplanes.GetItemAsObject(2)) planes.AddItem(bplanes.GetItemAsObject(3)) planes.AddItem(bplanes.GetItemAsObject(4)) planes.AddItem(bplanes.GetItemAsObject(5)) else: planes.AddItem(bplanes.GetItemAsObject(0)) planes.AddItem(cplanes.GetItemAsObject(1)) if i == 1: planes.AddItem(cplanes.GetItemAsObject(2)) planes.AddItem(bplanes.GetItemAsObject(3)) planes.AddItem(bplanes.GetItemAsObject(4)) planes.AddItem(bplanes.GetItemAsObject(5)) else: planes.AddItem(bplanes.GetItemAsObject(2)) planes.AddItem(cplanes.GetItemAsObject(3)) if i == 2: planes.AddItem(cplanes.GetItemAsObject(4)) planes.AddItem(bplanes.GetItemAsObject(5)) else: planes.AddItem(bplanes.GetItemAsObject(4)) planes.AddItem(bplanes.GetItemAsObject(5)) self._Input = None # generate the pipeline self._ImagePrefilter = vtk.vtkImageShrink3D() self._ImageReslice = vtk.vtkImageReslice() self._ImageReslice.SetInterpolationModeToLinear() self._ImageMapToColors = vtk.vtkImageMapToColors() self._ImageMapToColors.SetOutputFormatToRGBA() self._ImageToStructuredPoints = vtk.vtkImageToStructuredPoints() self._ImageClipsXY = [] self._PlanesXY = [] self._ActorsXY = [] self._PropertyXY = vtk.vtkProperty() self._PropertyXY.SetDiffuse(0) self._PropertyXY.SetAmbient(1) self._ImageClipsYZ = [] self._PlanesYZ = [] self._ActorsYZ = [] self._PropertyYZ = vtk.vtkProperty() self._PropertyYZ.SetDiffuse(0) self._PropertyYZ.SetAmbient(1) self._ImageClipsZX = [] self._PlanesZX = [] self._ActorsZX = [] self._PropertyZX = vtk.vtkProperty() self._PropertyZX.SetDiffuse(0) self._PropertyZX.SetAmbient(1) # a list of the renderer info self._RendererCurrentIndex = {} self._RendererActorList = {} self._RendererObserverList = {} # a transform to apply to the image self._ImageTransform = None self._TransformToGrid = vtk.vtkTransformToGrid() # the alpha pick threshold for the volume self._PickThreshold = 0.25 # the implicit volume for finding the gradient self._ImplicitVolume = vtk.vtkImplicitVolume() # the extent of the texture maps self._VolumeResolution = (64, 64, 64) # the bounds of the volume self._VolumeBounds = None
def __init__(self): ActorFactory.ActorFactory.__init__(self) # whether to display the volume self._ShowVolume = 1 self._StatusChange = 0 # create a clipping cube to go with the volume self._ClippingCube = ClippingCubeFactory.ClippingCubeFactory() self.AddChild(self._ClippingCube) self._CubeClippingPlanes = vtk.vtkPlaneCollection() for i in range(6): self._CubeClippingPlanes.AddItem(vtk.vtkPlane()) # for if we clip in with OrthoPlanes self._OrthoPlanes = None self._ShowOrthoPlanes = 1 self._OrthoPlanesLookupTables = {} self._OrthoPickThreshold = 0.0025 # corner clipping planes, in pairs with opposite normals self._CornerClippingPlanes = vtk.vtkPlaneCollection() for i in range(6): self._CornerClippingPlanes.AddItem(vtk.vtkPlane()) # clipping planes for the volume, sorted for the # three chunks that will make up the final volume self._ClippingPlanes = [vtk.vtkPlaneCollection(), vtk.vtkPlaneCollection(), vtk.vtkPlaneCollection()] for i in range(3): planes = self._ClippingPlanes[i] cplanes = self._CornerClippingPlanes bplanes = self._CubeClippingPlanes if i == 0: planes.AddItem(cplanes.GetItemAsObject(0)) planes.AddItem(bplanes.GetItemAsObject(1)) planes.AddItem(bplanes.GetItemAsObject(2)) planes.AddItem(bplanes.GetItemAsObject(3)) planes.AddItem(bplanes.GetItemAsObject(4)) planes.AddItem(bplanes.GetItemAsObject(5)) else: planes.AddItem(bplanes.GetItemAsObject(0)) planes.AddItem(cplanes.GetItemAsObject(1)) if i == 1: planes.AddItem(cplanes.GetItemAsObject(2)) planes.AddItem(bplanes.GetItemAsObject(3)) planes.AddItem(bplanes.GetItemAsObject(4)) planes.AddItem(bplanes.GetItemAsObject(5)) else: planes.AddItem(bplanes.GetItemAsObject(2)) planes.AddItem(cplanes.GetItemAsObject(3)) if i == 2: planes.AddItem(cplanes.GetItemAsObject(4)) planes.AddItem(bplanes.GetItemAsObject(5)) else: planes.AddItem(bplanes.GetItemAsObject(4)) planes.AddItem(bplanes.GetItemAsObject(5)) self._Input = None # generate the pipeline self._ImagePrefilter = vtk.vtkImageShrink3D() self._ImageReslice = vtk.vtkImageReslice() self._ImageReslice.SetInterpolationModeToLinear() self._ImageMapToColors = vtk.vtkImageMapToColors() self._ImageMapToColors.SetOutputFormatToRGBA() self._ImageToStructuredPoints = vtk.vtkImageToStructuredPoints() self._ImageClipsXY = [] self._PlanesXY = [] self._ActorsXY = [] self._PropertyXY = vtk.vtkProperty() self._PropertyXY.SetDiffuse(0) self._PropertyXY.SetAmbient(1) self._ImageClipsYZ = [] self._PlanesYZ = [] self._ActorsYZ = [] self._PropertyYZ = vtk.vtkProperty() self._PropertyYZ.SetDiffuse(0) self._PropertyYZ.SetAmbient(1) self._ImageClipsZX = [] self._PlanesZX = [] self._ActorsZX = [] self._PropertyZX = vtk.vtkProperty() self._PropertyZX.SetDiffuse(0) self._PropertyZX.SetAmbient(1) # a list of the renderer info self._RendererCurrentIndex = {} self._RendererActorList = {} self._RendererObserverList = {} # a transform to apply to the image self._ImageTransform = None self._TransformToGrid = vtk.vtkTransformToGrid() # the alpha pick threshold for the volume self._PickThreshold = 0.25 # the implicit volume for finding the gradient self._ImplicitVolume = vtk.vtkImplicitVolume() # the extent of the texture maps self._VolumeResolution = (64, 64, 64) # the bounds of the volume self._VolumeBounds = None
def __init__(self): ActorFactory.ActorFactory.__init__(self) self._LookupTable = None # lookup table is currently not used self._ColorTransferFunction = None self._OpacityTransferFunction = None self._RendererObserverList = {} # create a clipping cube to go with the volume self._ClippingCube = ClippingCubeFactory.ClippingCubeFactory() self.AddChild(self._ClippingCube) self._CubeClippingPlanes = vtk.vtkPlaneCollection() for i in range(6): self._CubeClippingPlanes.AddItem(vtk.vtkPlane()) # corner clipping planes, in pairs with opposite normals self._CornerClippingPlanes = vtk.vtkPlaneCollection() for i in range(6): self._CornerClippingPlanes.AddItem(vtk.vtkPlane()) # clipping planes for the volume, sorted for the # three chunks that will make up the final volume # (these are currently unused) self._ClippingPlanes = [vtk.vtkPlaneCollection(), vtk.vtkPlaneCollection(), vtk.vtkPlaneCollection()] for i in range(3): planes = self._ClippingPlanes[i] cplanes = self._CornerClippingPlanes bplanes = self._CubeClippingPlanes if i == 0: planes.AddItem(cplanes.GetItemAsObject(0)) planes.AddItem(bplanes.GetItemAsObject(1)) planes.AddItem(bplanes.GetItemAsObject(2)) planes.AddItem(bplanes.GetItemAsObject(3)) planes.AddItem(bplanes.GetItemAsObject(4)) planes.AddItem(bplanes.GetItemAsObject(5)) else: planes.AddItem(bplanes.GetItemAsObject(0)) planes.AddItem(cplanes.GetItemAsObject(1)) if i == 1: planes.AddItem(cplanes.GetItemAsObject(2)) planes.AddItem(bplanes.GetItemAsObject(3)) planes.AddItem(bplanes.GetItemAsObject(4)) planes.AddItem(bplanes.GetItemAsObject(5)) else: planes.AddItem(bplanes.GetItemAsObject(2)) planes.AddItem(cplanes.GetItemAsObject(3)) if i == 2: planes.AddItem(cplanes.GetItemAsObject(4)) planes.AddItem(bplanes.GetItemAsObject(5)) else: planes.AddItem(bplanes.GetItemAsObject(4)) planes.AddItem(bplanes.GetItemAsObject(5)) # generate the pipeline pieces self._Input = None # transform the full-resolution volume self._RayCastReslice = vtk.vtkImageReslice() self._RayCastReslice.SetInterpolationModeToLinear() # subsample the volume for low-res rendering self._ImagePrefilter1 = vtk.vtkImageShrink3D() self._ImagePrefilter2 = vtk.vtkImageShrink3D() # transform the subsampled volume self._ImageReslice1 = vtk.vtkImageReslice() self._ImageReslice1.SetInterpolationModeToLinear() self._ImageReslice2 = vtk.vtkImageReslice() self._ImageReslice2.SetInterpolationModeToLinear() # convert to RGBA for rendering (unused) self._ImageMapToColors = vtk.vtkImageMapToColors() self._ImageMapToColors.SetOutputFormatToRGBA() # strictly for VTK 3.2 compatibility self._ImageToStructuredPoints = vtk.vtkImageToStructuredPoints() # a transform to apply to the image self._ImageTransform = None self._TransformToGrid = vtk.vtkTransformToGrid() # the opacity pick threshold for the volume self._PickThreshold = 0.99 # the implicit volume for finding the gradient self._ImplicitVolume = vtk.vtkImplicitVolume() # the texture dimensions (later this will be set automatically # to provide the desired interactive rendering time) self._TextureSize = 128 # the bounds of the volume self._VolumeBounds = None # vtkVolume specific stuff self._VolumeProperty = vtk.vtkVolumeProperty() self._VolumeProperty.SetInterpolationTypeToLinear() rayCastFunction = vtk.vtkVolumeRayCastCompositeFunction() self._VolumeRayCastMapper = vtk.vtkVolumeRayCastMapper() self._VolumeRayCastMapper.SetVolumeRayCastFunction(rayCastFunction) self._VolumeRayCastMapper.SetClippingPlanes( self._ClippingCube.GetClippingPlanes()) try: # vtk 3.2 does not contain this function call: self._VolumeRayCastMapper.AutoAdjustSampleDistancesOff() except: pass self._VolumeTextureMapper1 = vtk.vtkVolumeTextureMapper2D() self._VolumeTextureMapper1.SetTargetTextureSize(old_div(self._TextureSize, 4), old_div(self._TextureSize, 4)) self._VolumeTextureMapper1.SetMaximumNumberOfPlanes( old_div(self._TextureSize, 2)) self._VolumeTextureMapper1.SetClippingPlanes( self._ClippingCube.GetClippingPlanes()) try: # vtk 3.2 does not contain this function call: # set to the amount of available texture memory (24MB is a good # start) self._VolumeTextureMapper1.SetMaximumStorageSize(24 * 1024 * 1024) except: pass self._VolumeTextureMapper2 = vtk.vtkVolumeTextureMapper2D() self._VolumeTextureMapper2.SetTargetTextureSize(self._TextureSize, self._TextureSize) self._VolumeTextureMapper2.SetMaximumNumberOfPlanes(self._TextureSize) self._VolumeTextureMapper2.SetClippingPlanes( self._ClippingCube.GetClippingPlanes()) try: # vtk 3.2 does not contain this function call: # set to the amount of available texture memory (24MB is a good # start) self._VolumeTextureMapper2.SetMaximumStorageSize(24 * 1024 * 1024) except: pass # set two levels of detail: texture and ray-casting self._Volume = vtk.vtkLODProp3D() self._Volume.PickableOff() idT1 = self._Volume.AddLOD(self._VolumeTextureMapper1, self._VolumeProperty, 0.02) idT2 = self._Volume.AddLOD(self._VolumeTextureMapper2, self._VolumeProperty, 0.1) # remember these LOD id numbers self._lod = [idT1, idT2] # idRC = self._Volume.AddLOD(self._VolumeRayCastMapper, # self._VolumeProperty, # 2.0) self._Volume.SetLODLevel(idT1, 2.0) self._Volume.SetLODLevel(idT2, 1.0)