Esempio n. 1
0
def default_OTF(x1, x2):
    """Creates a default opacity transfer function.
    """
    maxs = max(x1, x2)
    mins = min(x1, x2)
    otf = PiecewiseFunction()
    otf.add_point(mins, 0.0)
    otf.add_point(maxs, 0.2)
    return otf
Esempio n. 2
0
def show_volume(D,
                cm="Spectral",
                minfact=0.1,
                maxfact=0.9,
                visible=True,
                normalize=True):
    print "Show volume"
    mind = D.min()
    D -= D.min()

    src = mlab.pipeline.scalar_field(D)
    ptpd = D.ptp()
    if normalize:
        R = (mind + minfact * ptpd, mind + maxfact * ptpd)
    else:
        R = (minfact - mind, maxfact - mind)

    v = mlab.pipeline.volume(src, vmin=R[0], vmax=R[1])

    if False and not (cm == "Spectral"):
        ctf = ColorTransferFunction()
        ctf.range = R
        ctf.add_rgb_point(mind, 1, 1, 1)
        ctf.add_rgb_point(R[0], 1, 1, 1)
        ctf.add_rgb_point(R[1], 0, 0, 0)
        ctf.add_rgb_point(mind + ptpd, 0, 0, 0)
        v._volume_property.set_color(ctf)
        v._ctf = ctf
        v.update_ctf = True

    if False:
        from enthought.tvtk.util.ctf import PiecewiseFunction
        otf = PiecewiseFunction()
        otf.add_point(mind, 0)
        otf.add_point(R[0], 0)
        #otf.add_point(R[0]+0.1*ptpd, 0.1)
        #otf.add_point(R[0]+0.2*ptpd, 0.3)
        #otf.add_point(R[0]+0.3*ptpd, 0.5)
        otf.add_point(R[0] + 0.2 * ptpd, 0.7)
        otf.add_point(R[1], 1.0)
        otf.add_point(mind + ptpd, 1.0)
        v._otf = otf
        v._volume_property.set_scalar_opacity(otf)
        v.update_ctf = True
        v.volume_mapper.cropping_region_planes = np.array(
            [0., 1., 0., 1., 0., 1.])
        v.volume_mapper.lock_sample_distance_to_input_spacing = True

    print "done"
Esempio n. 3
0
def make_volume_prop(mins=255, maxs=355):
    """Make a volume property for the testing."""
    table = tvtk.VolumeProperty()
    ctf = ColorTransferFunction()
    ds = (maxs - mins) / 4.0
    try:
        ctf.range = (mins, maxs)
    except Exception:
        # VTK versions < 5.2 don't seem to need this.
        pass
    ctf.add_rgb_point(mins, 0.00, 0.0, 1.00)
    ctf.add_rgb_point(mins + ds, 0.25, 0.5, 0.75)
    ctf.add_rgb_point(mins + 2 * ds, 0.50, 1.0, 0.50)
    ctf.add_rgb_point(mins + 3 * ds, 0.75, 0.5, 0.25)
    ctf.add_rgb_point(maxs, 1.00, 0.0, 0.00)
    otf = PiecewiseFunction()
    otf.add_point(mins, 0.0)
    otf.add_point(maxs, 0.2)
    table.set_color(ctf)
    table.set_scalar_opacity(otf)
    return table, ctf, otf
Esempio n. 4
0
# Use a GeometryFilter to cut out a slab
geom = mlab.pipeline.user_defined(edges, filter='GeometryFilter')
geom.filter.extent = [-0.8*extent, 0.8*extent, 
                      -0.2*extent, 0.2*extent,
                      -0.8*extent, 0.8*extent, ]
geom.filter.extent_clipping = True

# Display connections in the selected slab as thick tubes.
mlab.pipeline.surface(mlab.pipeline.tube(geom, 
                            tube_radius=0.25,
                            tube_sides=10,
                        ),
            colormap='Paired')

# Display the scalar field with volume rendering.
vol = mlab.pipeline.volume(delaunay)

# Change the opacity transfer function
from enthought.tvtk.util.ctf import PiecewiseFunction
otf = PiecewiseFunction()
otf.add_point(0, 0)
otf.add_point(N, 0.02)
vol._otf = otf
vol._volume_property.set_scalar_opacity(otf)

# And now choose a view, and re-enable rendering.
mlab.view(166, 80, 82)
fig.scene.disable_render = False
mlab.show()