Ejemplo n.º 1
0
    def __init__(self,
                 actors,
                 captions=None,
                 caption_offset=(0, -100, 0),
                 cell_padding=0,
                 cell_shape="rect",
                 aspect_ratio=16 / 9.,
                 dim=None,
                 rotation_speed=1,
                 rotation_axis=(0, 1, 0)):

        # TODO: add rotation axis None by default

        self.container = grid(actors,
                              captions=captions,
                              caption_offset=caption_offset,
                              cell_padding=cell_padding,
                              cell_shape=cell_shape,
                              aspect_ratio=aspect_ratio,
                              dim=dim)
        self._actors = []
        self._actors_dict = {}
        self.rotation_speed = rotation_speed
        self.rotation_axis = rotation_axis

        for item in self.container._items:
            self._actors.append(item._items[0])
            self._actors_dict[item._items[0]] = {'x': -np.inf, 'y': -np.inf}

        super(GridUI, self).__init__(position=(0, 0, 0))
Ejemplo n.º 2
0
def test_grid(_interactive=False):
    vol1 = np.zeros((100, 100, 100))
    vol1[25:75, 25:75, 25:75] = 100
    contour_actor1 = actor.contour_from_roi(vol1, np.eye(4),
                                            (1., 0, 0), 1.)

    vol2 = np.zeros((100, 100, 100))
    vol2[25:75, 25:75, 25:75] = 100

    contour_actor2 = actor.contour_from_roi(vol2, np.eye(4),
                                            (1., 0.5, 0), 1.)
    vol3 = np.zeros((100, 100, 100))
    vol3[25:75, 25:75, 25:75] = 100

    contour_actor3 = actor.contour_from_roi(vol3, np.eye(4),
                                            (1., 0.5, 0.5), 1.)

    scene = window.Scene()
    actors = []
    texts = []

    actors.append(contour_actor1)
    text_actor1 = actor.text_3d('cube 1', justification='center')
    texts.append(text_actor1)

    actors.append(contour_actor2)
    text_actor2 = actor.text_3d('cube 2', justification='center')
    texts.append(text_actor2)

    actors.append(contour_actor3)
    text_actor3 = actor.text_3d('cube 3', justification='center')
    texts.append(text_actor3)

    actors.append(shallow_copy(contour_actor1))
    text_actor1 = 'cube 4'
    texts.append(text_actor1)

    actors.append(shallow_copy(contour_actor2))
    text_actor2 = 'cube 5'
    texts.append(text_actor2)

    actors.append(shallow_copy(contour_actor3))
    text_actor3 = 'cube 6'
    texts.append(text_actor3)

    # show the grid without the captions
    container = grid(actors=actors, captions=None,
                     caption_offset=(0, -40, 0),
                     cell_padding=(10, 10), dim=(2, 3))

    scene.add(container)

    scene.projection('orthogonal')

    counter = itertools.count()

    show_m = window.ShowManager(scene)

    show_m.initialize()

    def timer_callback(_obj, _event):
        nonlocal counter
        cnt = next(counter)
        # show_m.scene.zoom(1)
        show_m.render()
        if cnt == 5:
            show_m.exit()
            # show_m.destroy_timers()

    show_m.add_timer_callback(True, 200, timer_callback)
    show_m.start()

    arr = window.snapshot(scene)
    arr[arr < 100] = 0
    report = window.analyze_snapshot(arr)
    npt.assert_equal(report.objects, 6)

    scene.rm_all()

    counter = itertools.count()
    show_m = window.ShowManager(scene)
    show_m.initialize()
    # show the grid with the captions
    container = grid(actors=actors, captions=texts,
                     caption_offset=(0, -50, 0),
                     cell_padding=(10, 10),
                     dim=(3, 3))

    scene.add(container)

    show_m.add_timer_callback(True, 200, timer_callback)
    show_m.start()

    arr = window.snapshot(scene)
    report = window.analyze_snapshot(arr)
    npt.assert_equal(report.objects > 6, True)