当前位置: 首页>>代码示例>>Python>>正文


Python vtk.vtkVolumeRayCastMapper函数代码示例

本文整理汇总了Python中vtk.vtkVolumeRayCastMapper函数的典型用法代码示例。如果您正苦于以下问题:Python vtkVolumeRayCastMapper函数的具体用法?Python vtkVolumeRayCastMapper怎么用?Python vtkVolumeRayCastMapper使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了vtkVolumeRayCastMapper函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _create_pipeline

    def _create_pipeline(self):
        # setup our pipeline

        self._otf = vtk.vtkPiecewiseFunction()
        self._ctf = vtk.vtkColorTransferFunction()

        self._volume_property = vtk.vtkVolumeProperty()
        self._volume_property.SetScalarOpacity(self._otf)
        self._volume_property.SetColor(self._ctf)
        self._volume_property.ShadeOn()
        self._volume_property.SetAmbient(0.1)
        self._volume_property.SetDiffuse(0.7)
        self._volume_property.SetSpecular(0.2)
        self._volume_property.SetSpecularPower(10)

        self._volume_raycast_function = vtk.vtkVolumeRayCastMIPFunction()
        self._volume_mapper = vtk.vtkVolumeRayCastMapper()

        # can also used FixedPoint, but then we have to use:
        # SetBlendModeToMaximumIntensity() and not SetVolumeRayCastFunction
        #self._volume_mapper = vtk.vtkFixedPointVolumeRayCastMapper()
        
        self._volume_mapper.SetVolumeRayCastFunction(
            self._volume_raycast_function)

        
        module_utils.setup_vtk_object_progress(self, self._volume_mapper,
                                           'Preparing render.')

        self._volume = vtk.vtkVolume()
        self._volume.SetProperty(self._volume_property)
        self._volume.SetMapper(self._volume_mapper)
开发者ID:fvpolpeta,项目名称:devide,代码行数:32,代码来源:MIPRender.py

示例2: main

def main(argv):
  if len(argv) < 2:
    print "usage:",argv[0]," data.vtk"
    exit(1)
  data_fn = argv[1]
  reader = vtk.vtkStructuredPointsReader()
  reader.SetFileName(data_fn)
  reader.Update()
  data = reader.GetOutput()
  updateColorOpacity()
  # composite function (using ray tracing)
  compositeFunction = vtk.vtkVolumeRayCastCompositeFunction()
  volumeMapper = vtk.vtkVolumeRayCastMapper()
  volumeMapper.SetVolumeRayCastFunction(compositeFunction)
  volumeMapper.SetInput(data)
  # make the volume
  #volume = vtk.vtkVolume()
  global volume
  volume.SetMapper(volumeMapper)
  volume.SetProperty(volumeProperty)
  # renderer
  renderer = vtk.vtkRenderer()
  renderWin = vtk.vtkRenderWindow()
  renderWin.AddRenderer(renderer)
  renderInteractor = vtk.vtkRenderWindowInteractor()
  renderInteractor.SetRenderWindow(renderWin)
  renderInteractor.AddObserver( vtk.vtkCommand.KeyPressEvent, keyPressed )
  renderer.AddVolume(volume)
  renderer.SetBackground(0,0,0)
  renderWin.SetSize(400, 400)
  renderInteractor.Initialize()
  renderWin.Render()
  renderInteractor.Start()
开发者ID:daniel-perry,项目名称:visualization,代码行数:33,代码来源:volume_render.py

示例3: axonComparison

def axonComparison(axons, N):
    axonsToRender = []
    for i in range(N):
        axon = axons.pop(random.randrange(len(axons)))
        axonsToRender.append(axon)
    bins = main.BINS
    data_matrix = numpy.zeros([500, 500, 500], dtype=numpy.uint16)
    dataImporter = vtk.vtkImageImport()
    data_string = data_matrix.tostring()
    dataImporter.CopyImportVoidPointer(data_string, len(data_string))
    dataImporter.SetDataScalarTypeToUnsignedChar()
    dataImporter.SetNumberOfScalarComponents(1)
    dataImporter.SetDataExtent(0, 500, 0, 500, 0, 500)
    dataImporter.SetWholeExtent(0, 500, 0, 500, 0, 500)
    volumeProperty = vtk.vtkVolumeProperty()
    compositeFunction = vtk.vtkVolumeRayCastCompositeFunction()
    volumeMapper = vtk.vtkVolumeRayCastMapper()
    volumeMapper.SetVolumeRayCastFunction(compositeFunction)
    volumeMapper.SetInputConnection(dataImporter.GetOutputPort())
    volume = vtk.vtkVolume()
    volume.SetMapper(volumeMapper)
    volume.SetProperty(volumeProperty)
    renderer = vtk.vtkRenderer()
    renderWin = vtk.vtkRenderWindow()
    renderWin.AddRenderer(renderer)
    renderInteractor = vtk.vtkRenderWindowInteractor()
    renderInteractor.SetRenderWindow(renderWin)
    renderer.SetBackground(1, 1, 1)
    renderWin.SetSize(400, 400)
    for axon in axonsToRender:
        renderer = Utils.renderSingleAxon(axon, renderer, [random.random(), random.random(), random.random()])
    renderWin.AddObserver("AbortCheckEvent", exitCheck)
    renderInteractor.Initialize()
    renderWin.Render()
    renderInteractor.Start()
开发者ID:EthanGlasserman,项目名称:Brainbow,代码行数:35,代码来源:Draw.py

示例4: RenderVTKVolume

def RenderVTKVolume(image, volprops):
    volmap = vtk.vtkVolumeRayCastMapper()
    volmap.SetVolumeRayCastFunction(vtk.vtkVolumeRayCastCompositeFunction())
    volmap.SetInputConnection(image.GetOutputPort())

    vol = vtk.vtkVolume()
    vol.SetMapper(volmap)
    vol.SetProperty(volprops)

    #Standard VTK stuff
    ren = vtk.vtkRenderer()
    ren.AddVolume(vol)
    ren.SetBackground((1, 1, 1))

    renwin = vtk.vtkRenderWindow()
    renwin.AddRenderer(ren)

    istyle = vtk.vtkInteractorStyleSwitch()
    istyle.SetCurrentStyleToTrackballCamera()

    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renwin)
    iren.SetInteractorStyle(istyle)

    renwin.Render()
    iren.Start()
开发者ID:jiahao,项目名称:openqube,代码行数:26,代码来源:viz.vtkGaussians.py

示例5: _setup_for_raycast

 def _setup_for_raycast(self):
     self._volume_raycast_function = \
                                   vtk.vtkVolumeRayCastCompositeFunction()
     
     self._volume_mapper = vtk.vtkVolumeRayCastMapper()
     self._volume_mapper.SetVolumeRayCastFunction(
         self._volume_raycast_function)
     
     module_utils.setup_vtk_object_progress(self, self._volume_mapper,
                                        'Preparing render.')
开发者ID:fvpolpeta,项目名称:devide,代码行数:10,代码来源:VolumeRender.py

示例6: main

def main(argv):
  if len(argv) < 2:
    print "usage:",argv[0]," data.nrrd data.cmap"
    exit(1)
  data_fn = argv[1]
  cmap_fn = argv[2]
  reader = vtk.vtkPNrrdReader()
  reader.SetFileName(data_fn)
  reader.Update()
  data = reader.GetOutput()
  # opacity function
  opacityFunction = vtk.vtkPiecewiseFunction()
  # color function
  colorFunction = vtk.vtkColorTransferFunction()
  cmap = open(cmap_fn, 'r')
  for line in cmap.readlines():
    parts = line.split()
    value = float(parts[0])
    r = float(parts[1])
    g = float(parts[2])
    b = float(parts[3])
    a = float(parts[4])
    opacityFunction.AddPoint(value, a)
    colorFunction.AddRGBPoint(value, r, g, b)
  # volume setup:
  #volumeProperty = vtk.vtkVolumeProperty()
  global volumeProperty
  volumeProperty.SetColor(colorFunction)
  volumeProperty.SetScalarOpacity(opacityFunction)
  # composite function (using ray tracing)
  compositeFunction = vtk.vtkVolumeRayCastCompositeFunction()
  volumeMapper = vtk.vtkVolumeRayCastMapper()
  volumeMapper.SetVolumeRayCastFunction(compositeFunction)
  volumeMapper.SetInput(data)
  # make the volume
  #volume = vtk.vtkVolume()
  global volume
  volume.SetMapper(volumeMapper)
  volume.SetProperty(volumeProperty)
  # renderer
  renderer = vtk.vtkRenderer()
  renderWin = vtk.vtkRenderWindow()
  renderWin.AddRenderer(renderer)
  renderInteractor = vtk.vtkRenderWindowInteractor()
  renderInteractor.SetRenderWindow(renderWin)
  renderInteractor.AddObserver( vtk.vtkCommand.KeyPressEvent, keyPressed )
  renderer.AddVolume(volume)
  renderer.SetBackground(0,0,0)
  renderWin.SetSize(400, 400)
  renderInteractor.Initialize()
  renderWin.Render()
  renderInteractor.Start()
开发者ID:daniel-perry,项目名称:rt,代码行数:52,代码来源:volume_render.py

示例7: volumeRender

def volumeRender(img, tf=[],spacing=[1.0,1.0,1.0]):
    importer = numpy2VTK(img,spacing)

    # Transfer Functions
    opacity_tf = vtk.vtkPiecewiseFunction()
    color_tf = vtk.vtkColorTransferFunction()

    if len(tf) == 0:
        tf.append([img.min(),0,0,0,0])
        tf.append([img.max(),1,1,1,1])

    for p in tf:
        color_tf.AddRGBPoint(p[0], p[1], p[2], p[3])
        opacity_tf.AddPoint(p[0], p[4])

    # working on the GPU
    # volMapper = vtk.vtkGPUVolumeRayCastMapper()
    # volMapper.SetInputConnection(importer.GetOutputPort())

    # # The property describes how the data will look
    # volProperty =  vtk.vtkVolumeProperty()
    # volProperty.SetColor(color_tf)
    # volProperty.SetScalarOpacity(opacity_tf)
    # volProperty.ShadeOn()
    # volProperty.SetInterpolationTypeToLinear()

    # working on the CPU
    volMapper = vtk.vtkVolumeRayCastMapper()
    compositeFunction = vtk.vtkVolumeRayCastCompositeFunction()
    compositeFunction.SetCompositeMethodToInterpolateFirst()
    volMapper.SetVolumeRayCastFunction(compositeFunction)
    volMapper.SetInputConnection(importer.GetOutputPort())

    # The property describes how the data will look
    volProperty =  vtk.vtkVolumeProperty()
    volProperty.SetColor(color_tf)
    volProperty.SetScalarOpacity(opacity_tf)
    volProperty.ShadeOn()
    volProperty.SetInterpolationTypeToLinear()
    
    # Do the lines below speed things up?
    # pix_diag = 5.0
    # volMapper.SetSampleDistance(pix_diag / 5.0)    
    # volProperty.SetScalarOpacityUnitDistance(pix_diag) 
    

    vol = vtk.vtkVolume()
    vol.SetMapper(volMapper)
    vol.SetProperty(volProperty)
    
    return [vol]
开发者ID:151706061,项目名称:Medical-Image-Analysis-IPython-Tutorials,代码行数:51,代码来源:volumerendering.py

示例8: save_vtk_image

def save_vtk_image(images, dst, i):    
    image_import = vtk.vtkImageImport()
    image_import.CopyImportVoidPointer(images.tostring(), len(images.tostring()))
    image_import.SetDataScalarTypeToUnsignedChar()
    image_import.SetNumberOfScalarComponents(1)
    image_import.SetDataExtent(0, images.shape[2] - 1, 0, images.shape[1] - 1, 0, images.shape[0] - 1)
    image_import.SetWholeExtent(0, images.shape[2] - 1, 0, images.shape[1] - 1, 0, images.shape[0] - 1)
    volume = vtk.vtkVolume()
    volume_mapper = vtk.vtkVolumeRayCastMapper()
    alpha_channel_func = vtk.vtkPiecewiseFunction()
    alpha_channel_func.AddPoint(0, 0.0)
#    alpha_channel_func.AddPoint(64, 0.3)
#    alpha_channel_func.AddPoint(128, 0.5)
    alpha_channel_func.AddPoint(100, 1.0)
    alpha_channel_func.ClampingOn()
    color_func = vtk.vtkPiecewiseFunction()
    color_func.AddPoint(5, 0.3)
    color_func.AddPoint(25, 0.5)
    color_func.AddPoint(125, 0.7)
    color_func.AddPoint(255, 1.0)
    volume_property = vtk.vtkVolumeProperty()
    volume_property.SetColor(color_func)
    volume_property.SetInterpolationTypeToLinear()
    volume_property.SetScalarOpacity(alpha_channel_func)
    volume.SetProperty(volume_property)
    volume_ray_cast_func = vtk.vtkVolumeRayCastMIPFunction()
    volume_mapper.SetInputConnection(image_import.GetOutputPort())
    volume_mapper.SetVolumeRayCastFunction(volume_ray_cast_func)
#    volume_mapper.SetSampleDistance(1)
#    volume_mapper.SetAutoAdjustSampleDistances(0)
#    volume_mapper.SetImageSampleDistance(1)
    volume.SetMapper(volume_mapper)
    
    ren = vtk.vtkRenderer()
    ren.AddVolume(volume)
    ren.SetBackground(0, 0, 0)
    renWin = vtk.vtkRenderWindow()
    renWin.SetSize(1024, 1024)
    renWin.AddRenderer(ren)
    renWin.Render()
    
    window_2_image = vtk.vtkWindowToImageFilter()
    window_2_image.SetInput(renWin)
    window_2_image.Update()
    
    png_writer = vtk.vtkPNGWriter()
    png_writer.SetFileName(dst + '%05d'%(i) + '.png')
    png_writer.SetInput(window_2_image.GetOutput())
    png_writer.Write()
开发者ID:sulei1324,项目名称:lab_codes,代码行数:49,代码来源:funs.py

示例9: volumeProperty

def volumeProperty(reader, opacityTransferFunction, colorTransferFunction):
    volumeProperty = vtk.vtkVolumeProperty()
    volumeProperty.SetColor(colorTransferFunction)
    volumeProperty.SetScalarOpacity(opacityTransferFunction)
    volumeProperty.ShadeOn()
    volumeProperty.SetSpecular(0.3)
    volumeProperty.SetInterpolationTypeToLinear()

    MIPFunction = vtk.vtkVolumeRayCastMIPFunction()

    volumeMapper = vtk.vtkVolumeRayCastMapper()
    volumeMapper.SetSampleDistance(1.0)
    volumeMapper.SetInput(reader.GetOutput())
    volumeMapper.SetVolumeRayCastFunction(MIPFunction)

    volume = vtk.vtkVolume()
    volume.SetMapper(volumeMapper)
    volume.SetProperty(volumeProperty)
    volume.RotateX(-90)
    return volume
开发者ID:arun04ceg,项目名称:3D-spatial-data,代码行数:20,代码来源:MIP.py

示例10: render_volume_data

    def render_volume_data(self, vtk_img_data):
        # Create transfer mapping scalar value to opacity
        opacity_transfer_function = vtk.vtkPiecewiseFunction()
        opacity_transfer_function.AddPoint(0, 0.0)
        opacity_transfer_function.AddPoint(50, 0.0)
        opacity_transfer_function.AddPoint(100, 0.8)
        opacity_transfer_function.AddPoint(1200, 0.8)

        # Create transfer mapping scalar value to color
        color_transfer_function = vtk.vtkColorTransferFunction()
        color_transfer_function.AddRGBPoint(0, 0.0, 0.0, 0.0)
        color_transfer_function.AddRGBPoint(50, 0.0, 0.0, 0.0)
        color_transfer_function.AddRGBPoint(100, 1.0, 0.0, 0.0)
        color_transfer_function.AddRGBPoint(1200, 1.0, 0.0, 0.0)

        # The property describes how the data will look
        volume_property = vtk.vtkVolumeProperty()
        volume_property.SetColor(color_transfer_function)
        volume_property.SetScalarOpacity(opacity_transfer_function)
        volume_property.ShadeOff()
        volume_property.SetInterpolationTypeToLinear()

        # The mapper / ray cast function know how to render the data
        compositeFunction = vtk.vtkVolumeRayCastCompositeFunction()
        volume_mapper = vtk.vtkVolumeRayCastMapper()
        volume_mapper.SetVolumeRayCastFunction(compositeFunction)
        if vtk.VTK_MAJOR_VERSION <= 5:
            volume_mapper.SetInput(vtk_img_data)
        else:
            volume_mapper.SetInputData(vtk_img_data)
        volume_mapper.SetBlendModeToMaximumIntensity()

        # The volume holds the mapper and the property and
        # can be used to position/orient the volume
        volume = vtk.vtkVolume()
        volume.SetMapper(volume_mapper)
        volume.SetProperty(volume_property)

        self.ren.AddVolume(volume)
        self.ren.ResetCamera()
        self.iren.Initialize()
开发者ID:CoderXv,项目名称:vas,代码行数:41,代码来源:VesselDisplayWindow.py

示例11: set_map_type

 def set_map_type(self, map_type):
     if map_type == self.map_type:
         return
     Common.state.busy ()
     if map_type == 0:
         self.map = vtk.vtkVolumeRayCastMapper ()
         self.map.SetVolumeRayCastFunction (self.ray_cast_func)
     elif map_type == 1:
         self.map = vtk.vtkVolumeTextureMapper2D()
     elif map_type == 2:
         self.map = vtk.vtkVolumeProMapper()
         self.renwin.get_active_camera().ParallelProjectionOn()
         tkMessageBox.showwarning("Notice!","Camera's projection type set to parallel projection!")
        
     self.map_type = map_type
     self.map.SetInput (self.mod_m.GetOutput ())
     self.act.SetMapper (self.map)
     if self.root and self.root.winfo_exists():
         self.make_map_gui()
         self.make_rcf_gui()
     self.renwin.Render ()     
     Common.state.idle ()            
开发者ID:sldion,项目名称:DNACC,代码行数:22,代码来源:Volume.py

示例12: testVolumePicker

    def testVolumePicker(self):
        # volume render a medical data set

        # renderer and interactor
        ren = vtk.vtkRenderer()

        renWin = vtk.vtkRenderWindow()
        renWin.AddRenderer(ren)

        iRen = vtk.vtkRenderWindowInteractor()
        iRen.SetRenderWindow(renWin)

        # read the volume
        v16 = vtk.vtkVolume16Reader()
        v16.SetDataDimensions(64, 64)
        v16.SetImageRange(1, 93)
        v16.SetDataByteOrderToLittleEndian()
        v16.SetFilePrefix(VTK_DATA_ROOT + "/Data/headsq/quarter")
        v16.SetDataSpacing(3.2, 3.2, 1.5)

        #---------------------------------------------------------
        # set up the volume rendering

        rayCastFunction = vtk.vtkVolumeRayCastCompositeFunction()

        volumeMapper = vtk.vtkVolumeRayCastMapper()
        volumeMapper.SetInputConnection(v16.GetOutputPort())
        volumeMapper.SetVolumeRayCastFunction(rayCastFunction)

        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)

        volumeGradientOpacity = vtk.vtkPiecewiseFunction()
        volumeGradientOpacity.AddPoint(0, 0.0)
        volumeGradientOpacity.AddPoint(90, 0.5)
        volumeGradientOpacity.AddPoint(100, 1.0)

        volumeProperty = vtk.vtkVolumeProperty()
        volumeProperty.SetColor(volumeColor)
        volumeProperty.SetScalarOpacity(volumeScalarOpacity)
        volumeProperty.SetGradientOpacity(volumeGradientOpacity)
        volumeProperty.SetInterpolationTypeToLinear()
        volumeProperty.ShadeOn()
        volumeProperty.SetAmbient(0.6)
        volumeProperty.SetDiffuse(0.6)
        volumeProperty.SetSpecular(0.1)

        volume = vtk.vtkVolume()
        volume.SetMapper(volumeMapper)
        volume.SetProperty(volumeProperty)

        #---------------------------------------------------------
        # Do the surface rendering
        boneExtractor = vtk.vtkMarchingCubes()
        boneExtractor.SetInputConnection(v16.GetOutputPort())
        boneExtractor.SetValue(0, 1150)

        boneNormals = vtk.vtkPolyDataNormals()
        boneNormals.SetInputConnection(boneExtractor.GetOutputPort())
        boneNormals.SetFeatureAngle(60.0)

        boneStripper = vtk.vtkStripper()
        boneStripper.SetInputConnection(boneNormals.GetOutputPort())

        boneMapper = vtk.vtkPolyDataMapper()
        boneMapper.SetInputConnection(boneStripper.GetOutputPort())
        boneMapper.ScalarVisibilityOff()

        boneProperty = vtk.vtkProperty()
        boneProperty.SetColor(1.0, 1.0, 0.9)

        bone = vtk.vtkActor()
        bone.SetMapper(boneMapper)
        bone.SetProperty(boneProperty)

        #---------------------------------------------------------
        # Create an image actor

        table = vtk.vtkLookupTable()
        table.SetRange(0, 2000)
        table.SetRampToLinear()
        table.SetValueRange(0, 1)
        table.SetHueRange(0, 0)
        table.SetSaturationRange(0, 0)

        mapToColors = vtk.vtkImageMapToColors()
        mapToColors.SetInputConnection(v16.GetOutputPort())
        mapToColors.SetLookupTable(table)

        imageActor = vtk.vtkImageActor()
        imageActor.GetMapper().SetInputConnection(mapToColors.GetOutputPort())
#.........这里部分代码省略.........
开发者ID:151706061,项目名称:VTK,代码行数:101,代码来源:VolumePicker.py

示例13: volume


#.........这里部分代码省略.........
        #print 'reslice GetOutputOrigin', reslice.GetOutputOrigin()
        #print 'reslice GetOutputExtent',reslice.GetOutputExtent()
        #print 'reslice GetOutputSpacing',reslice.GetOutputSpacing()
    
        changeFilter=vtk.vtkImageChangeInformation() 
        changeFilter.SetInput(reslice.GetOutput())
        #changeFilter.SetInput(im)
        if center_origin:
            changeFilter.SetOutputOrigin(-vol.shape[0]/2.0+0.5,-vol.shape[1]/2.0+0.5,-vol.shape[2]/2.0+0.5)
            print 'ChangeFilter ', changeFilter.GetOutputOrigin()
        
    opacity = vtk.vtkPiecewiseFunction()
    for i in range(opacitymap.shape[0]):
        opacity.AddPoint(opacitymap[i,0],opacitymap[i,1])

    color = vtk.vtkColorTransferFunction()
    for i in range(colormap.shape[0]):
        color.AddRGBPoint(colormap[i,0],colormap[i,1],colormap[i,2],colormap[i,3])
        
    if(maptype==0): 
    
        property = vtk.vtkVolumeProperty()
        property.SetColor(color)
        property.SetScalarOpacity(opacity)
        
        if trilinear:
            property.SetInterpolationTypeToLinear()
        else:
            prop.SetInterpolationTypeToNearest()
            
        if info:
            print('mapper VolumeTextureMapper2D')
        mapper = vtk.vtkVolumeTextureMapper2D()
        if affine == None:
            mapper.SetInput(im)
        else:
            #mapper.SetInput(reslice.GetOutput())
            mapper.SetInput(changeFilter.GetOutput())
        
    
    if (maptype==1):

        property = vtk.vtkVolumeProperty()
        property.SetColor(color)
        property.SetScalarOpacity(opacity)
        property.ShadeOn()
        if trilinear:
            property.SetInterpolationTypeToLinear()
        else:
            prop.SetInterpolationTypeToNearest()

        if iso:
            isofunc=vtk.vtkVolumeRayCastIsosurfaceFunction()
            isofunc.SetIsoValue(iso_thr)
        else:
            compositeFunction = vtk.vtkVolumeRayCastCompositeFunction()
        
        if info:
            print('mapper VolumeRayCastMapper')
            
        mapper = vtk.vtkVolumeRayCastMapper()
        if iso:
            mapper.SetVolumeRayCastFunction(isofunc)
            if info:
                print('Isosurface')
        else:
            mapper.SetVolumeRayCastFunction(compositeFunction)   
            
            #mapper.SetMinimumImageSampleDistance(0.2)
            if info:
                print('Composite')
             
        if affine == None:
            mapper.SetInput(im)
        else:
            #mapper.SetInput(reslice.GetOutput())    
            mapper.SetInput(changeFilter.GetOutput())
            #Return mid position in world space    
            #im2=reslice.GetOutput()
            #index=im2.FindPoint(vol.shape[0]/2.0,vol.shape[1]/2.0,vol.shape[2]/2.0)
            #print 'Image Getpoint ' , im2.GetPoint(index)
           
        
    volum = vtk.vtkVolume()
    volum.SetMapper(mapper)
    volum.SetProperty(property)

    if info :  
         
        print 'Origin',   volum.GetOrigin()
        print 'Orientation',   volum.GetOrientation()
        print 'OrientationW',    volum.GetOrientationWXYZ()
        print 'Position',    volum.GetPosition()
        print 'Center',    volum.GetCenter()  
        print 'Get XRange', volum.GetXRange()
        print 'Get YRange', volum.GetYRange()
        print 'Get ZRange', volum.GetZRange()  
        print 'Volume data type', vol.dtype
        
    return volum
开发者ID:arokem,项目名称:Fos,代码行数:101,代码来源:fos.py

示例14: viz

def viz():
    opaq = 0.01
     
    # We begin by creating the data we want to render.
    # For this tutorial, we create a 3D-image containing three overlaping cubes.
    # This data can of course easily be replaced by data from a medical CT-scan or anything else three dimensional.
    # The only limit is that the data must be reduced to unsigned 8 bit or 16 bit integers.
    img = Image.open('imagen3.png').convert('L')
    img = np.asarray(img)
    print img.shape

    Nx = sqrt(img.shape[0])
    Ny = Nx
    Nz = img.shape[1]

    data_matrix = zeros([Nx, Ny, Nz], dtype=uint8)

    for i in range(0,Nz-1):
         temp = img[Nx*i:Nx*(i+1),:]
         data_matrix[:,:,i] = np.uint8(255)-temp
    

    #for i in range(0,maxcoordZ-1):
    #    for k in range(0,maxcoord-1):
    #        data_matrix[k,:,i] = np.uint8(255)-np.array(occupied[i*maxcoord2+k*maxcoord:i*maxcoord2+(k+1)*maxcoord]).astype(np.uint8)

    #data_matrix = occupied#data_matrix[20:150, 20:150, 20:150] = randint(0,150)

    # For VTK to be able to use the data, it must be stored as a VTK-image. This can be done by the vtkImageImport-class which
    # imports raw data and stores it.
    dataImporter = vtk.vtkImageImport()
    # The preaviusly created array is converted to a string of chars and imported.
    data_string = data_matrix.tostring()
    dataImporter.CopyImportVoidPointer(data_string, len(data_string))
    # The type of the newly imported data is set to unsigned char (uint8)
    dataImporter.SetDataScalarTypeToUnsignedChar()
    # Because the data that is imported only contains an intensity value (it isnt RGB-coded or someting similar), the importer
    # must be told this is the case.
    dataImporter.SetNumberOfScalarComponents(1)
    # The following two functions describe how the data is stored and the dimensions of the array it is stored in. For this
    # simple case, all axes are of length 75 and begins with the first element. For other data, this is probably not the case.
    # I have to admit however, that I honestly dont know the difference between SetDataExtent() and SetWholeExtent() although
    # VTK complains if not both are used.
    dataImporter.SetDataExtent(0, Nx-1, 0, Ny-1, 0, Nz-1)
    dataImporter.SetWholeExtent(0, Nx-1, 0, Ny-1, 0, Nz-1)
     
    # The following class is used to store transparencyv-values for later retrival. In our case, we want the value 0 to be
    # completly opaque whereas the three different cubes are given different transperancy-values to show how it works.
    alphaChannelFunc = vtk.vtkPiecewiseFunction()
    alphaChannelFunc.AddPoint(0, 0)
    alphaChannelFunc.AddPoint(255, opaq)
     
    # This class stores color data and can create color tables from a few color points. For this demo, we want the three cubes
    # to be of the colors red green and blue.
    colorFunc = vtk.vtkColorTransferFunction()
    colorFunc.AddRGBPoint(0, 0.0, 0.0, 0.0)
    colorFunc.AddRGBPoint(255,0.8, 0.7, 0.6)
     
    # The preavius two classes stored properties. Because we want to apply these properties to the volume we want to render,
    # we have to store them in a class that stores volume prpoperties.
    volumeProperty = vtk.vtkVolumeProperty()
    volumeProperty.SetColor(colorFunc)
    volumeProperty.SetScalarOpacity(alphaChannelFunc)
     
    # This class describes how the volume is rendered (through ray tracing).
    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(dataImporter.GetOutputPort())
     
    # The class vtkVolume is used to pair the preaviusly declared volume as well as the properties to be used when rendering that volume.
    volume = vtk.vtkVolume()
    volume.SetMapper(volumeMapper)
    volume.SetProperty(volumeProperty)
     
    # With almost everything else ready, its time to initialize the renderer and window, as well as creating a method for exiting the application
    renderer = vtk.vtkRenderer()
    renderWin = vtk.vtkRenderWindow()
    renderWin.AddRenderer(renderer)
    renderInteractor = vtk.vtkRenderWindowInteractor()
    renderInteractor.SetRenderWindow(renderWin)
     
    # We add the volume to the renderer ...
    renderer.AddVolume(volume)
    # ... set background color to white ...
    renderer.SetBackground(0,0,0)
    # ... and set window size.
    renderWin.SetSize(800, 800)
     
    # A simple function to be called when the user decides to quit the application.
    def exitCheck(obj, event):
        if obj.GetEventPending() != 0:
            obj.SetAbortRender(1)
     
    # Tell the application to use the function as an exit check.
    renderWin.AddObserver("AbortCheckEvent", exitCheck)
     
    renderInteractor.Initialize()
    # Because nothing will be rendered without any input, we order the first render manually before control is handed over to the main-loop.
#.........这里部分代码省略.........
开发者ID:rbaravalle,项目名称:Pysys,代码行数:101,代码来源:viz.py

示例15: show3

def show3(data_matrix = None): # pragma: no coverage

    import vtk
# We begin by creating the data we want to render.
# For this tutorial, we create a 3D-image containing three overlaping cubes.
# This data can of course easily be replaced by data from a medical CT-scan or anything else three dimensional.
# The only limit is that the data must be reduced to unsigned 8 bit or 16 bit integers.
    import pdb; pdb.set_trace()
    if data_matrix == None:
        data_matrix = zeros([75, 75, 75], dtype=uint8)
        data_matrix[0:35, 0:35, 0:35] = 50
        data_matrix[25:55, 25:55, 25:55] = 100
        data_matrix[45:74, 45:74, 45:74] = 150
    else:
        data_matrix[data_matrix==1] = 50
        data_matrix[data_matrix==2] = 100
    val0 = 0
    val1 = 50
    val2 = 100
    val3 = 150

# For VTK to be able to use the data, it must be stored as a VTK-image. This can be done by the vtkImageImport-class which
# imports raw data and stores it.
    dataImporter = vtk.vtkImageImport()
# The preaviusly created array is converted to a string of chars and imported.
    data_string = data_matrix.tostring()
    dataImporter.CopyImportVoidPointer(data_string, len(data_string))
# The type of the newly imported data is set to unsigned char (uint8)
    dataImporter.SetDataScalarTypeToUnsignedChar()
# Because the data that is imported only contains an intensity value (it isnt RGB-coded or someting similar), the importer
# must be told this is the case.
    dataImporter.SetNumberOfScalarComponents(1)
# The following two functions describe how the data is stored and the dimensions of the array it is stored in. For this
# simple case, all axes are of length 75 and begins with the first element. For other data, this is probably not the case.
# I have to admit however, that I honestly dont know the difference between SetDataExtent() and SetWholeExtent() although
# VTK complains if not both are used.
    #dataImporter.SetDataExtent(0, 74, 0, 74, 0, 74)
    #dataImporter.SetWholeExtent(0, 74, 0, 74, 0, 74)
    dataImporter.SetDataExtent(0, data_matrix.shape[0]-1, 0, data_matrix.shape[1]-1, 0,data_matrix.shape[2]-1 )
    dataImporter.SetWholeExtent(0, data_matrix.shape[0]-1, 0, data_matrix.shape[1]-1, 0,data_matrix.shape[2]-1 )
    
# The following class is used to store transparencyv-values for later retrival. In our case, we want the value 0 to be
# completly opaque whereas the three different cubes are given different transperancy-values to show how it works.
    alphaChannelFunc = vtk.vtkPiecewiseFunction()
    alphaChannelFunc.AddPoint(val0, 0.0)
    alphaChannelFunc.AddPoint(val1, 0.05)
    alphaChannelFunc.AddPoint(val2, 0.1)
    alphaChannelFunc.AddPoint(val3, 0.2)
    
# This class stores color data and can create color tables from a few color points. For this demo, we want the three cubes
# to be of the colors red green and blue.
    colorFunc = vtk.vtkColorTransferFunction()
    colorFunc.AddRGBPoint(val1, 1.0, 0.0, 0.0)
    colorFunc.AddRGBPoint(val2, 0.0, 1.0, 0.0)
    colorFunc.AddRGBPoint(val3, 0.0, 0.0, 1.0)
    
# The preavius two classes stored properties. Because we want to apply these properties to the volume we want to render,
# we have to store them in a class that stores volume prpoperties.
    volumeProperty = vtk.vtkVolumeProperty()
    volumeProperty.SetColor(colorFunc)
    volumeProperty.SetScalarOpacity(alphaChannelFunc)
    
# This class describes how the volume is rendered (through ray tracing).
    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(dataImporter.GetOutputPort())
    
# The class vtkVolume is used to pair the preaviusly declared volume as well as the properties to be used when rendering that volume.
    volume = vtk.vtkVolume()
    volume.SetMapper(volumeMapper)
    volume.SetProperty(volumeProperty)
    
# With almost everything else ready, its time to initialize the renderer and window, as well as creating a method for exiting the application
    renderer = vtk.vtkRenderer()
    renderWin = vtk.vtkRenderWindow()
    renderWin.AddRenderer(renderer)
    renderInteractor = vtk.vtkRenderWindowInteractor()
    renderInteractor.SetRenderWindow(renderWin)
    
# We add the volume to the renderer ...
    renderer.AddVolume(volume)
# ... set background color to white ...
    renderer.SetBackground(0,0,0)
# ... and set window size.
    renderWin.SetSize(400, 400)
    
# A simple function to be called when the user decides to quit the application.
    def exitCheck(obj, event):
        if obj.GetEventPending() != 0:
            obj.SetAbortRender(1)
    
# Tell the application to use the function as an exit check.
    renderWin.AddObserver("AbortCheckEvent", exitCheck)
    
    renderInteractor.Initialize()
# Because nothing will be rendered without any input, we order the first render manually before control is handed over to the main-loop.
    renderWin.Render()
    renderInteractor.Start()
#.........这里部分代码省略.........
开发者ID:vlukes,项目名称:lisa,代码行数:101,代码来源:show3.py


注:本文中的vtk.vtkVolumeRayCastMapper函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。