Exemplo n.º 1
0
    def __init__(self, arr, scale=[1.0, 1.0, 1.0], **traits):
        """
        Parameters
        ----------
        - arr : Array to be viewed.

        - scale : Scale the x, y and z axis as per passed values.
          Defaults to [1.0, 1.0, 1.0].
        """
        super(ImShow, self).__init__(**traits)

        assert len(arr.shape) == 2, "Only 2D arrays can be viewed!"

        ny, nx = arr.shape
        dx, dy, junk = numpy.array(scale) * 1.0
        xa = numpy.arange(0, nx * scale[0] - 0.1 * dx, dx, 'f')
        ya = numpy.arange(0, ny * scale[1] - 0.1 * dy, dy, 'f')

        arr_flat = numpy.ravel(arr)
        min_val = min(arr_flat)
        max_val = max(arr_flat)

        sp = _create_structured_points_direct(xa, ya)
        lut = self.lut
        lut.table_range = min_val, max_val
        a = lut.map_scalars(arr_flat, 0, 0)
        sp.point_data.scalars = a
        sp.point_data.scalars.name = 'scalars'
        sp.scalar_type = 'unsigned_char'
        sp.number_of_scalar_components = 4

        ia = tvtk.ImageActor(input=sp, interpolate=self.interpolate)

        self.actors.append(ia)
Exemplo n.º 2
0
def show_img(img, renderer=renderer):
    img_data = tvtk.ImageData(spacing=(1, 1, 1), origin=(0, 0, 0))
    img_data.point_data.scalars, img_data.dimensions = vtkimage_from_array(img)

    img_actor = tvtk.ImageActor()
    img_actor.set_input_data(img_data)
    img_actor.rotate_wxyz(45, 1, 0, 0)

    renderer.add_actor(img_actor)
    return img_actor
Exemplo n.º 3
0
def frame_to_actor(frame, width, height, b=5):
    # Dimensions with borders.
    w, h = width+2*b, height+2*b

    # Initialize array.
    data = np.zeros((w, h, 4))
    if frame is None:
        data[:,:,-1] = 255
        data[b:-b,b:-b,-1] = 0
    else:
        data[b:-b,b:-b,:3] = frame
        data[:,:,-1] = 255
    data = np.transpose(data, (1,0,2))
    colors = np.reshape(data, (w*h,4))
    
    # Create actor.
    image = tvtk.ImageData()
    image.point_data.scalars=tvtk.UnsignedCharArray()
    image.point_data.scalars.from_array(colors)
    image.dimensions = np.array((w, h, 1))
    actor = tvtk.ImageActor()
    configure_input(actor, image)
    
    return actor
Exemplo n.º 4
0
 def __init__(self, height, width):
     self.img_data = tvtk.ImageData(spacing=(1, 1, 1))
     img = np.zeros((height, width, 3), dtype=np.uint8)
     self.update_img(img)
     self.img_actor = tvtk.ImageActor(input=self.img_data)
Exemplo n.º 5
0
 def setup_pipeline(self):
     self.actor = tvtk.ImageActor()
Exemplo n.º 6
0
import numpy as np
from tvtk.api import tvtk

colors = np.random.randint(256, size=(100, 3))

an_image = tvtk.ImageData()
an_image.number_of_scalar_components = 3
# an_image.scalar_type='unsigned_char'
an_image.point_data.scalars = tvtk.UnsignedCharArray()
an_image.point_data.scalars.from_array(colors)
an_image.dimensions = np.array((10, 10, 1))

an_actor = tvtk.ImageActor()
an_actor.input = an_image
an_actor.interpolate = False

ren = tvtk.Renderer()
renWin = tvtk.RenderWindow()
renWin.add_renderer(ren)
ren.add_actor2d(an_actor)
iren = tvtk.RenderWindowInteractor()
iren.render_window = renWin
iren.interactor_style = tvtk.InteractorStyleTrackballCamera()
renWin.render()
iren.start()