Beispiel #1
0
def test_save_and_load_polydata():
    l_ext = ["vtk", "fib", "ply", "xml"]
    fname = "temp-io"

    for ext in l_ext:
        with InTemporaryDirectory() as odir:
            data = np.random.randint(0, 255, size=(50, 3))

            pd = vtk.vtkPolyData()
            pd.SetPoints(numpy_to_vtk_points(data))

            fname_path = pjoin(odir, "{0}.{1}".format(fname, ext))
            save_polydata(pd, fname_path)

            npt.assert_equal(os.path.isfile(fname_path), True)
            assert_greater(os.stat(fname_path).st_size, 0)

            out_pd = load_polydata(fname_path)
            out_data = numpy_support.vtk_to_numpy(out_pd.GetPoints().GetData())

            npt.assert_array_equal(data, out_data)

    npt.assert_raises(IOError, save_polydata, vtk.vtkPolyData(), "test.vti")
    npt.assert_raises(IOError, save_polydata, vtk.vtkPolyData(), "test.obj")
    npt.assert_raises(IOError, load_polydata, "test.vti")
Beispiel #2
0
def test_save_and_load_options():
    l_ext = ["ply", "vtk"]
    l_options = [{
        'color_array_name': 'horizon',
    }, {
        'binary': True,
    }]
    fname = "temp-io"

    for ext, option in zip(l_ext, l_options):
        with InTemporaryDirectory() as odir:
            data = np.random.randint(0, 255, size=(50, 3))

            pd = vtk.vtkPolyData()
            pd.SetPoints(numpy_to_vtk_points(data))

            fname_path = pjoin(odir, "{0}.{1}".format(fname, ext))
            save_polydata(pd, fname_path, **option)

            npt.assert_equal(os.path.isfile(fname_path), True)
            assert_greater(os.stat(fname_path).st_size, 0)

            out_pd = load_polydata(fname_path)
            out_data = numpy_support.vtk_to_numpy(out_pd.GetPoints().GetData())

            npt.assert_array_equal(data, out_data)

    l_ext = ["stl", "obj"]
    l_options = [{}, {
        'is_mni_obj': True,
    }]
    for ext, option in zip(l_ext, l_options):
        with InTemporaryDirectory() as odir:
            data = np.random.randint(0, 255, size=(50, 3))

            pd = vtk.vtkPolyData()
            pd.SetPoints(numpy_to_vtk_points(data))

            fname_path = pjoin(odir, "{0}.{1}".format(fname, ext))
            save_polydata(pd, fname_path, **option)

            npt.assert_equal(os.path.isfile(fname_path), True)
            assert_greater(os.stat(fname_path).st_size, 0)
Beispiel #3
0
                         [1, 2, 3],
                         [3, 4, 5], #good
                         [5, 6, 7],
                         [7, 8, 9], #good
                         [1, 9, 3], #good
                         [3, 7, 9], #good
                         [3, 5, 7]], dtype='i8') #good

utils.set_polydata_vertices(my_polydata, my_vertices)
utils.set_polydata_triangles(my_polydata, my_triangles)

file_name = "my_star2D.vtk"
save_polydata(my_polydata, file_name)
print("Surface saved in " + file_name)

star_polydata = load_polydata(file_name)

star_vertices = utils.get_polydata_vertices(star_polydata)
colors = star_vertices * 255
utils.set_polydata_colors(star_polydata, colors)

print("new surface colors")
print(utils.get_polydata_colors(star_polydata))

# get vtkActor
star_actor = utils.get_actor_from_polydata(star_polydata)
star_actor.GetProperty().BackfaceCullingOff()
# Create a scene
scene = window.Scene()
scene.add(star_actor)
scene.set_camera(position=(0, 0, 7), focal_point=(0, 0, 0))
Beispiel #4
0
radius = 0.002
sphere_actor = actor.sphere(center, window.colors.blue_medium, radius)

##############################################################################
# Also creating a text actor to add below the sphere.

text_actor = actor.text_3d("Bloomington, Indiana", (-0.42, 0.31, 0.03),
                           window.colors.white, 0.004)
utils.rotate(text_actor, (-90, 0, 1, 0))

##############################################################################
# Let's also import a model of a satellite to visualize circling the moon.

fetch_viz_models()
satellite_filename = read_viz_models("satellite_obj.obj")
satellite = io.load_polydata(satellite_filename)
satellite_actor = utils.get_actor_from_polydata(satellite)

satellite_actor.SetPosition(-0.75, 0.1, 0.4)
satellite_actor.SetScale(0.005, 0.005, 0.005)

##############################################################################
# In the ``timer_callback`` function, use if statements to specify when
# certain events will happen in the animation, based on the position that
# the counter is at. So, for example, the earth actor will continue to
# rotate while the count is less than 450.


def timer_callback(_obj, _event):
    cnt = next(counter)
    showm.render()
Beispiel #5
0
import vtk

###############################################################################
# Let's download  and load the model

from fury.data.fetcher import fetch_viz_models, read_viz_models
fetch_viz_models()
model = read_viz_models('utah.obj')

###############################################################################
#
# Let's start by loading the polydata of choice.
# For this example we use the standard utah teapot model.
# currently supported formats include OBJ, VKT, FIB, PLY, STL and XML

utah = io.load_polydata(model)
utah = utils.get_polymapper_from_polydata(utah)
utah = utils.get_actor_from_polymapper(utah)
mapper = utah.GetMapper()

###############################################################################
# To change the default shader we add a shader replacement.
# Specify vertex shader using vtkShader.Vertex
# Specify fragment shader using vtkShader.Fragment

mapper.AddShaderReplacement(
    vtk.vtkShader.Vertex, "//VTK::ValuePass::Dec", True, """
    //VTK::ValuePass::Dec
    out vec4 myVertexVC;
    """, False)
Beispiel #6
0
                         [2, 3, 14],
                         [3, 14, 15], #end of left side, start of top
                         [0, 7, 12],
                         [7, 12, 19], #end of top, start of bottom
                         [3, 15, 16],
                         [3, 4, 16], #end of shape
                         ], dtype='i8')

utils.set_polydata_vertices(my_polydata, my_vertices)
utils.set_polydata_triangles(my_polydata, my_triangles)

file_name = "my_rhombicube.vtk"
save_polydata(my_polydata, file_name)
print("Surface saved in " + file_name)

rhombicube_polydata = load_polydata(file_name)

rhombicube_vertices = utils.get_polydata_vertices(rhombicube_polydata)
colors = rhombicube_vertices * 255
utils.set_polydata_colors(rhombicube_polydata, colors)

print("new surface colors")
print(utils.get_polydata_colors(rhombicube_polydata))

# get vtkActor
rhombicube_actor = utils.get_actor_from_polydata(rhombicube_polydata)
rhombicube_actor.GetProperty().BackfaceCullingOff() #gets rid of the winding order issue (look at later and other algorithms that get rid of winding order)

# Create a scene
scene = window.Scene()
scene.add(rhombicube_actor)
Beispiel #7
0
from dipy.viz import window, actor
from dipy.data import get_fnames
from dipy.tracking.mesh import (random_coordinates_from_surface,
                                seeds_from_surface_coordinates)

from fury.io import load_polydata
from fury.utils import (get_polydata_triangles, get_polydata_vertices,
                        get_actor_from_polydata, normals_from_v_f)

"""
Fetch and load a surface
"""

brain_lh = get_fnames("fury_surface")
polydata = load_polydata(brain_lh)

"""
Extract the triangles and vertices
"""

triangles = get_polydata_triangles(polydata)
vts = get_polydata_vertices(polydata)


"""
Display the surface
===============================================

First, create an actor from the polydata, to display in the scene
"""