notebook_tools.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:tissuelab 作者: VirtualPlants 项目源码 文件源码
def vtk_show_polydata(polydata, width=400, height=300, position=(0,0,-160), colormap_name='glasbey', **kwargs):
    """
    Takes vtkRenderer instance and returns an IPython Image with the rendering.
    """
    from tissuelab.gui.vtkviewer.colormap_utils import colormap_from_file
    from tissuelab.gui.vtkviewer.vtk_utils import define_lookuptable, get_polydata_cell_data

    point_radius = kwargs.get('point_radius',1.0)

    if (polydata.GetNumberOfCells() == 0) and (polydata.GetNumberOfPoints() > 0):
        sphere = vtk.vtkSphereSource()
        sphere.SetRadius(point_radius)
        sphere.SetThetaResolution(12)
        sphere.SetPhiResolution(12)
        glyph = vtk.vtkGlyph3D()
        glyph.SetScaleModeToDataScalingOff()
        glyph.SetColorModeToColorByScalar()
        glyph.SetSource(sphere.GetOutput())
        glyph.SetInput(polydata)
        glyph.Update()
        polydata = glyph.GetOutput()

    # colormap = colormap_from_file("/Users/gcerutti/Developpement/openalea/oalab-tissue/tissuelab/share/data/colormaps/glasbey.lut",name="glasbey")
    colormap = load_colormaps()[colormap_name]

    irange = kwargs.get('intensity_range', None)

    cell_data = get_polydata_cell_data(polydata)
    lut = define_lookuptable(cell_data,colormap_points=colormap._color_points,colormap_name=colormap.name,intensity_range=irange)

    VtkMapper = vtk.vtkPolyDataMapper()
    VtkMapper.SetInputConnection(polydata.GetProducerPort())
    VtkMapper.SetLookupTable(lut)

    VtkActor = vtk.vtkActor()
    VtkActor.SetMapper(VtkMapper)

    VtkRenderer = vtk.vtkRenderer()
    VtkRenderer.SetBackground(1.0, 1.0, 1.0)
    VtkRenderer.AddActor(VtkActor)

    VtkRenderer.GetActiveCamera().SetPosition(*position)

    return vtk_show(VtkRenderer, width=width, height=height)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号