def main(select=3, **kwargs):
    """Script main function.

    select: int
        1: Medical data
        2: Blocky data, different every time
        3: Two donuts
        4: Ellipsoid

    """
    import visvis as vv  # noqa: delay import visvis and GUI libraries

    # Create test volume
    if select == 1:
        vol = vv.volread('stent')
        isovalue = kwargs.pop('level', 800)
    elif select == 2:
        vol = vv.aVolume(20, 128)
        isovalue = kwargs.pop('level', 0.2)
    elif select == 3:
        with timer('computing donuts'):
            vol = donuts()
        isovalue = kwargs.pop('level', 0.0)
        # Uncommenting the line below will yield different results for
        # classic MC
        # vol *= -1
    elif select == 4:
        vol = ellipsoid(4, 3, 2, levelset=True)
        isovalue = kwargs.pop('level', 0.0)
    else:
        raise ValueError('invalid selection')

    # Get surface meshes
    with timer('finding surface lewiner'):
        vertices1, faces1 = marching_cubes_lewiner(vol, isovalue, **kwargs)[:2]

    with timer('finding surface classic'):
        vertices2, faces2 = marching_cubes_classic(vol, isovalue, **kwargs)

    # Show
    vv.figure(1)
    vv.clf()
    a1 = vv.subplot(121)
    vv.title('Lewiner')
    m1 = vv.mesh(np.fliplr(vertices1), faces1)
    a2 = vv.subplot(122)
    vv.title('Classic')
    m2 = vv.mesh(np.fliplr(vertices2), faces2)
    a1.camera = a2.camera

    # visvis uses right-hand rule, gradient_direction param uses left-hand rule
    m1.cullFaces = m2.cullFaces = 'front'  # None, front or back

    vv.use().Run()
示例#2
0
def main(select=3, **kwargs):
    """Script main function.

    select: int
        1: Medical data
        2: Blocky data, different every time
        3: Two donuts
        4: Ellipsoid

    """
    import visvis as vv  # noqa: delay import visvis and GUI libraries

    # Create test volume
    if select == 1:
        vol = vv.volread('stent')
        isovalue = kwargs.pop('level', 800)
    elif select == 2:
        vol = vv.aVolume(20, 128)
        isovalue = kwargs.pop('level', 0.2)
    elif select == 3:
        with timer('computing donuts'):
            vol = donuts()
        isovalue = kwargs.pop('level', 0.0)
        # Uncommenting the line below will yield different results for
        # classic MC
        # vol *= -1
    elif select == 4:
        vol = ellipsoid(4, 3, 2, levelset=True)
        isovalue = kwargs.pop('level', 0.0)
    else:
        raise ValueError('invalid selection')

    # Get surface meshes
    with timer('finding surface lewiner'):
        vertices1, faces1 = marching_cubes_lewiner(vol, isovalue, **kwargs)[:2]

    with timer('finding surface classic'):
        vertices2, faces2 = marching_cubes_classic(vol, isovalue, **kwargs)

    # Show
    vv.figure(1)
    vv.clf()
    a1 = vv.subplot(121)
    vv.title('Lewiner')
    m1 = vv.mesh(np.fliplr(vertices1), faces1)
    a2 = vv.subplot(122)
    vv.title('Classic')
    m2 = vv.mesh(np.fliplr(vertices2), faces2)
    a1.camera = a2.camera

    # visvis uses right-hand rule, gradient_direction param uses left-hand rule
    m1.cullFaces = m2.cullFaces = 'front'  # None, front or back

    vv.use().Run()
示例#3
0
    while not cropper3d._finished:
        vv.processEvents()
        time.sleep(0.01)

    # Clean up figure (close if we opened it)
    fig.Clear()
    fig.DrawNow()
    if figCleanup:
        fig.Destroy()

    # Obtain ranges
    rx = cropper3d._range_transversal._rangex
    ry = cropper3d._range_transversal._rangey
    rz = cropper3d._range_coronal._rangey

    # Perform crop
    vol2 = vol[rz.min:rz.max, ry.min:ry.max, rx.min:rx.max]

    # Done
    return vol2


if __name__ == '__main__':
    # testing
    import os

    vol1 = vv.aVolume(size=128)
    vol2 = crop3d(vol1)
    print('shape1:', vol1.shape)
    print('shape2:', vol2.shape)
示例#4
0
    while not cropper3d._finished:
        vv.processEvents()
        time.sleep(0.01)
    
    # Clean up figure (close if we opened it)
    fig.Clear()
    fig.DrawNow()
    if figCleanup:    
        fig.Destroy()
    
    # Obtain ranges
    rx = cropper3d._range_transversal._rangex
    ry = cropper3d._range_transversal._rangey
    rz = cropper3d._range_coronal._rangey
    
    # Perform crop
    vol2 = vol[rz.min:rz.max, ry.min:ry.max, rx.min:rx.max]
    
    # Done
    return vol2

    
if __name__ == '__main__':
    # testing
    import os
    
    vol1 = vv.aVolume(size=128)
    vol2 = crop3d(vol1)
    print('shape1:', vol1.shape)
    print('shape2:', vol2.shape)
    
示例#5
0
#!/usr/bin/env python
""" This example demonstrates rendering a color volume.
This example demonstrates two render styles. Note that
all render styles are capable of rendering color data.
"""

import numpy as np
import visvis as vv
app = vv.use()

# Use vv.aVolume to create random bars for each color plane
N = 64
vol = np.empty((N, N, N, 3), dtype='float32')
for i in range(3):
    vol[:, :, :, i] = vv.aVolume(10, N)

# Show
vv.figure()
a1 = vv.subplot(121)
t1 = vv.volshow(vol[:, :, :, :], renderStyle='mip')
vv.title('color MIP render')
a2 = vv.subplot(122)
t2 = vv.volshow(vol[:, :, :, :], renderStyle='iso')
t2.isoThreshold = 0.5
vv.title('color ISO-surface render')

# Share cameras
a1.camera = a2.camera

# Run app
app.Run()
示例#6
0
#!/usr/bin/env python
""" This example illustrates visualizing a four dimensional data set
(a series of 3D volumes). The same method can be used to visualize
the motion of lines, images, meshes, etc.
"""
import visvis as vv

# create multiple instances of the same volume (simulate motion)
vols = [vv.aVolume()]
for i in range(9):
    vol = vols[i].copy()
    vol[2:] = vol[:-2]
    vol[:2] = 0
    vols.append(vol)

# create figure, axes, and data container object
f = vv.clf()
a = vv.gca()
m = vv.MotionDataContainer(a)

# create volumes, loading them into opengl memory, and insert into container.
for vol in vols:
    t = vv.volshow(vol)
    t.parent = m
    t.colormap = vv.CM_HOT
    # Remove comments to use iso-surface rendering
    #t.renderStyle = 'iso'
    #t.isoThreshold = 0.2    

# set some settings
a.daspect = 1,1,-1
示例#7
0
文件: test.py 项目: chiluf/visvis
    # Create test volume
    SELECT = 3
    if SELECT == 0:
        import pirt
        vol = np.zeros((100, 100, 100), 'float32')
        vol[50, 50, 50] = 200.0

        vol = pirt.gfilter(vol, 20)
        isovalue = vol.max() * 0.5
    elif SELECT == 1:
        s = vv.ssdf.load(
            '/home/almar/data/cropped/stents_valve/cropped_pat102.bsdf')
        vol = s.vol.astype('float32')
        isovalue = 800
    elif SELECT == 2:
        vol = vv.aVolume(20, 256)  # Different every time
        isovalue = 0.2
    elif SELECT == 3:
        n = 48
        a, b = 2.5 / n, -1.25
        isovalue = 0.0
        #
        vol = np.empty((n, n, n), 'float32')
        for iz in range(vol.shape[0]):
            for iy in range(vol.shape[1]):
                for ix in range(vol.shape[2]):
                    z, y, x = float(iz) * a + b, float(iy) * a + b, float(
                        ix) * a + b
                    vol[iz, iy,
                        ix] = (((8 * x)**2 + (8 * y - 2)**2 +
                                (8 * z)**2 + 16 - 1.85 * 1.85) *
示例#8
0
    for i in range(3):
        vv.SliceTexture(proxy, vol, i, centre[i])
    
    # set clim
    if isinstance(clim,list):
        clim = tuple(clim)
    if isinstance(clim, tuple):
        proxy.SetClim(clim)
    
    # set colormap
    if cm is not None:
        proxy.colormap = cm
    
    # adjust axes
    if axesAdjust:
        if axes.daspectAuto is None:
            axes.daspectAuto = False
        axes.cameraType = '3d'
        axes.SetLimits()
    
    # done
    axes.Draw()
    return proxy


if __name__ == "__main__":
    import visvis as vv
    vol = vv.aVolume()
    vol[:30,:30,:30] += 0.3
    t = volshow2(vol)
示例#9
0
#!/usr/bin/env python
""" This example demonstrates rendering a color volume.
This example demonstrates two render styles. Note that
all render styles are capable of rendering color data.
"""

import numpy as np
import visvis as vv
app = vv.use()

# Use vv.aVolume to create random bars for each color plane
N = 64
vol = np.empty((N,N,N,3), dtype='float32')
for i in range(3):
    vol[:,:,:,i] = vv.aVolume(10,N)

# Show
vv.figure()
a1 = vv.subplot(121); 
t1 = vv.volshow(vol[:,:,:,:], renderStyle = 'mip')
vv.title('color MIP render')
a2 = vv.subplot(122); 
t2 = vv.volshow(vol[:,:,:,:], renderStyle = 'iso')
t2.isoThreshold = 0.5
vv.title('color ISO-surface render')

# Share cameras
a1.camera = a2.camera

# Run app
app.Run()
示例#10
0
from skimage.measure import marching_cubes_classic, marching_cubes_lewiner
from skimage.draw import ellipsoid


# Create test volume
SELECT = 3
gradient_dir = 'descent'  # ascent or descent

if SELECT == 1:
    # Medical data
    vol = vv.volread('stent')
    isovalue = 800

elif SELECT == 2:
    # Blocky data
    vol = vv.aVolume(20, 128) # Different every time
    isovalue = 0.2

elif SELECT == 3:
    # Generate two donuts using a formula by Thomas Lewiner
    n = 48
    a, b = 2.5 / n, -1.25
    isovalue = 0.0
    #
    vol = np.empty((n, n, n), 'float32')
    for iz in range(vol.shape[0]):
        for iy in range(vol.shape[1]):
            for ix in range(vol.shape[2]):
                z, y, x = float(iz)*a+b, float(iy)*a+b, float(ix)*a+b
                vol[iz, iy, ix] = ( (
                    (8*x)**2 + (8*y-2)**2 + (8*z)**2 + 16 - 1.85*1.85 ) * ( (8*x)**2 +
示例#11
0
# The appearance of the line objects can be set in their
# constructor, or by using their properties
line1.lc, line1.mc = 'g', 'b'
line2.lc, line2.mc = 'y', 'r'

# Display a legend
a1.legend = "Astronaut's face", "Astronaut's helmet"

# Create second axes (with a black background)
a2 = vv.subplot(122)
a2.bgcolor = 'k'
a2.axis.axisColor = 'w'

# Display a texture
vol = vv.aVolume(2)  # returns a test volume as a numpy array
texture3d = vv.volshow(vol)

# Display a mesh using one of the "solid" functions
mesh = vv.solidTeapot((32, 32, 80), scaling=(50, 50, 50))
mesh.faceColor = 0.4, 1, 0.4
mesh.specular = 'r'

# Set orthographic projection
a2.camera.fov = 45

# Create labels for the axis
a2.axis.xLabel = 'x-axis'
a2.axis.yLabel = 'y-axis'
a2.axis.zLabel = 'z-axis'
示例#12
0
# The appearance of the line objects can be set in their
# constructor, or by using their properties
line1.lc, line1.mc = 'g', 'b'
line2.lc, line2.mc = 'y', 'r'

# Display a legend
a1.legend = "Lena's face", "Lena's shoulder"


# Create second axes (with a black background)
a2 = vv.subplot(122)
a2.bgcolor = 'k'
a2.axis.axisColor = 'w'

# Display a texture 
vol = vv.aVolume(2) # returns a test volume as a numpy array
texture3d = vv.volshow(vol)

# Display a mesh using one of the "solid" functions
mesh = vv.solidTeapot((32,32,80), scaling=(50,50,50))
mesh.faceColor = 0.4, 1, 0.4
mesh.specular = 'r'

# Set orthographic projection
a2.camera.fov = 45

# Create labels for the axis
a2.axis.xLabel = 'x-axis'
a2.axis.yLabel = 'y-axis'
a2.axis.zLabel = 'z-axis'
示例#13
0
#!/usr/bin/env python
""" This example illustrates visualizing a four dimensional data set
(a series of 3D volumes). The same method can be used to visualize
the motion of lines, images, meshes, etc.
"""
import visvis as vv

# create multiple instances of the same volume (simulate motion)
vols = [vv.aVolume()]
for i in range(9):
    vol = vols[i].copy()
    vol[2:] = vol[:-2]
    vol[:2] = 0
    vols.append(vol)

# create figure, axes, and data container object
f = vv.clf()
a = vv.gca()
m = vv.MotionDataContainer(a)

# create volumes, loading them into opengl memory, and insert into container.
for vol in vols:
    t = vv.volshow(vol)
    t.parent = m
    t.colormap = vv.CM_HOT
    # Remove comments to use iso-surface rendering
    #t.renderStyle = 'iso'
    #t.isoThreshold = 0.2

# set some settings
a.daspect = 1,1,-1
示例#14
0
#!/usr/bin/env python
""" This example demonstrates rendering a color volume.
We demonstrate two renderers capable of rendering color data:
the colormip and coloriso renderer.
"""

import visvis as vv

app = vv.use()

# Create volume (smooth a bit)
if True:

    vol0 = vv.aVolume()
    vol = vol0.copy() * 0.5
    vol[1:, :, :] += 0.3 * vol0[:-1, :, :]
    vol[:-1, :, :] += 0.3 * vol0[1:, :, :]
    vol[:, 1:, :] += 0.3 * vol0[:, :-1, :]
    vol[:, :-1, :] += 0.3 * vol0[:, 1:, :]
    vol[:, :, 1:] += 0.3 * vol0[:, :, :-1]
    vol[:, :, :-1] += 0.3 * vol0[:, :, 1:]
else:
    # My personal test
    from visvis import ssdf
    s = ssdf.load(
        '/home/almar/data/dicom/cropped/croppedReg_pat01_gravity.bsdf')
    vol = s.vol

##

# Create figure and make subplots with different renderers
示例#15
0
#!/usr/bin/env python

import visvis as vv
import numpy as np
app = vv.use()
vv.clf()

# create volume
vol = vv.aVolume(size=64)

# set labels
vv.xlabel('x axis')
vv.ylabel('y axis')
vv.zlabel('z axis')

# show
t = vv.volshow(vol, renderStyle='mip')
# try the differtent render styles, for examample
# "t.renderStyle='iso'" or "t.renderStyle='ray'"
# If the drawing hangs, your video drived decided to render in software mode.
# This is unfortunately (as far as I know) not possible to detect.
# It might help if your data is shaped a power of 2.

# Get axes and set camera to orthographic mode (with a field of view of 70)
a = vv.gca()
a.camera.fov = 45

# Create colormap editor wibject.
vv.ColormapEditor(a)

# Start app
示例#16
0
#!/usr/bin/env python

import visvis as vv
import numpy as np
app = vv.use()
vv.clf()

# create volume
vol = vv.aVolume(size=64)

# set labels
vv.xlabel('x axis')
vv.ylabel('y axis')
vv.zlabel('z axis')

# show
t = vv.volshow(vol, renderStyle='mip')
# try the differtent render styles, for examample 
# "t.renderStyle='iso'" or "t.renderStyle='ray'"
# If the drawing hangs, your video drived decided to render in software mode.
# This is unfortunately (as far as I know) not possible to detect. 
# It might help if your data is shaped a power of 2.

# Get axes and set camera to orthographic mode (with a field of view of 70)
a = vv.gca()
a.camera.fov = 45

# Create colormap editor wibject.
vv.ColormapEditor(a)

# Start app
示例#17
0
from skimage.measure import marching_cubes_classic, marching_cubes_lewiner
from skimage.draw import ellipsoid

# Create test volume
SELECT = 3
gradient_dir = 'descent'  # ascent or descent

if SELECT == 1:
    # Medical data
    vol = vv.volread('stent')
    isovalue = 800

elif SELECT == 2:
    # Blocky data
    vol = vv.aVolume(20, 128)  # Different every time
    isovalue = 0.2

elif SELECT == 3:
    # Generate two donuts using a formula by Thomas Lewiner
    n = 48
    a, b = 2.5 / n, -1.25
    isovalue = 0.0
    #
    vol = np.empty((n, n, n), 'float32')
    for iz in range(vol.shape[0]):
        for iy in range(vol.shape[1]):
            for ix in range(vol.shape[2]):
                z, y, x = float(iz) * a + b, float(iy) * a + b, float(
                    ix) * a + b
                vol[iz, iy, ix] = (((8 * x)**2 + (8 * y - 2)**2 +
示例#18
0
 
 # Create test volume
 SELECT = 3
 if SELECT == 0:
     import pirt
     vol = np.zeros((100,100,100), 'float32')
     vol[50,50,50] = 200.0
     
     vol = pirt.gfilter(vol, 20)
     isovalue = vol.max() *0.5
 elif SELECT == 1:
     s = vv. ssdf.load('/home/almar/data/cropped/stents_valve/cropped_pat102.bsdf')
     vol = s.vol.astype('float32')
     isovalue = 800
 elif SELECT == 2:
     vol = vv.aVolume(20, 256) # Different every time
     isovalue = 0.2
 elif SELECT == 3:
     n = 48
     a, b = 2.5/n, -1.25
     isovalue = 0.0
     #
     vol = np.empty((n,n,n), 'float32')
     for iz in range(vol.shape[0]):
         for iy in range(vol.shape[1]):
             for ix in range(vol.shape[2]):
                 z, y, x = float(iz)*a+b, float(iy)*a+b, float(ix)*a+b
                 vol[iz,iy,ix] = ( ( 
                     (8*x)**2 + (8*y-2)**2 + (8*z)**2 + 16 - 1.85*1.85 ) * ( (8*x)**2 +
                     (8*y-2)**2 + (8*z)**2 + 16 - 1.85*1.85 ) - 64 * ( (8*x)**2 + (8*y-2)**2 )
                     ) * ( ( (8*x)**2 + ((8*y-2)+4)*((8*y-2)+4) + (8*z)**2 + 16 - 1.85*1.85 )
示例#19
0
#!/usr/bin/env python
""" This example demonstrates rendering a color volume.
We demonstrate two renderers capable of rendering color data:
the colormip and coloriso renderer.
"""

import visvis as vv
app = vv.use()

# Create volume (smooth a bit)
if True:
    
    vol0 = vv.aVolume()
    vol = vol0.copy()*0.5
    vol[1:,:,:] += 0.3 * vol0[:-1,:,:]
    vol[:-1,:,:] += 0.3 * vol0[1:,:,:]
    vol[:,1:,:] += 0.3 * vol0[:,:-1,:]
    vol[:,:-1,:] += 0.3 * vol0[:,1:,:]
    vol[:,:,1:] += 0.3 * vol0[:,:,:-1]
    vol[:,:,:-1] += 0.3 * vol0[:,:,1:]
else:
    # My personal test
    from visvis import ssdf
    s = ssdf.load('/home/almar/data/dicom/cropped/croppedReg_pat01_gravity.bsdf')
    vol = s.vol

##

# Create figure and make subplots with different renderers
vv.figure(1); vv.clf()
RS = ['mip', 'iso', 'edgeray', 'ray', 'litray']