Beispiel #1
0
def test_view():
    vpl.auto_figure(True)
    vpl.close()
    grads = np.array(vpl.geometry.orthogonal_bases(np.random.rand(3)))
    point = np.random.uniform(-10, 10, 3)
    vpl.quiver(np.broadcast_to(point, (3, 3)), grads, color=np.eye(3))

    vpl.view(focal_point=point, camera_position=point - grads[0],
             up_view=grads[1])
    vpl.reset_camera()

    vpl.text("Should be looking in the direction of the red arrow, "
             "with the green arrow pointing up")
    # Linux seems to need an extra prod to render this for some reason.
    vpl.show(block=False)
Beispiel #2
0
def test_text():
    text = vpl.text("spaghetti", (100, 150), color="g")
    assert text.text == "spaghetti"
    assert np.all(text.position[:2] == (100, 150))
    assert np.all(text.color == vpl.colors.as_rgb_a("g")[0])
    text.text = "not spaghetti"
    assert text.actor.GetInput() == text.text == "not spaghetti"
Beispiel #3
0
    def test_view(self):
        vpl.auto_figure(True)
        vpl.close()
        grads = np.array(vpl.geometry.orthogonal_bases(np.random.rand(3)))
        point = np.random.uniform(-10, 10, 3)
        vpl.quiver(np.broadcast_to(point, (3, 3)), grads, color=np.eye(3))

        vpl.view(focal_point=point,
                 camera_position=point - grads[0],
                 up_view=grads[1])
        #        vpl.view(camera_direction=grads[0],
        #                 up_view=grads[1],
        #                 )
        #
        vpl.reset_camera()
        #        vpl.view(point)

        vpl.text(
            "Should be looking in the direction of the red arrow, with the green arrow pointing up"
        )
        vpl.show()
Beispiel #4
0
    def _mouse_move_cb(self, invoker, name):
        if self._click_location:
            self.pick.update()
            if self._clicks_are_equal(self._click_location,
                                      self.pick.point_2D):
                return
            self._click_location = None
        # Only calling the super event with the mouse button down (which rotates
        # the model for left click) when we are sure that this click is not
        # meant to place a marker reduces the slight jolt when you click on with
        # a sensitive mouse. Move the lines below to the top of this method to
        # see what I mean.
        if self._super_on_mouse_move:
            call_super_callback()


if __name__ == "__main__":
    import vtkplotlib as vpl

    fig = vpl.QtFigure2()
    style = fig.style

    balls = vpl.quick_test_plot()
    rabbit = vpl.mesh_plot(vpl.data.get_rabbit_stl())
    rabbit.vertices -= [i.mean() for i in vpl.unzip_axes(rabbit.vertices)]
    rabbit.vertices /= 5
    text = vpl.text("text")

    vpl.show()
Beispiel #5
0
#    @position.setter
#    def position(self, position):
#        if self.use_pixels:
#            self._position = position
#        else:
#            self._position = tuple(int(i * j) for (i, j) in zip(position, self.fig.render_size))

    @property
    def text(self):
        return self.actor.GetInput()

    @text.setter
    def text(self, text_str):
        if not isinstance(text_str, str):
            text_str = str(text_str)
        self.actor.SetInput(text_str)


def resize_event_cb(*args):
    # print(args)
    self.actor.SetPosition(*(i // 2 for i in fig.render_size))


if __name__ == "__main__":
    import vtkplotlib as vpl

    fig = vpl.figure()
    fig.renWin.AddObserver(vtk.vtkCommand.ModifiedEvent, resize_event_cb)
    self = vpl.text("eggs", (100, 200))
    vpl.show()
Beispiel #6
0
 def test_text(self):
     vpl.text("text", (100, 100), color="g")
     vpl.show()
Beispiel #7
0
def test_zoom():
    vpl.scatter(np.random.uniform(-20, 20, (30, 3)), color="r")
    vpl.show(block=False)
    balls_to_ignore = vpl.scatter(np.random.uniform(-50, 50, (30, 3)))
    vpl.text("This should be ignored by zoom.")
    vpl.zoom_to_contents(plots_to_exclude=balls_to_ignore)
def test_legend():
    import vtkplotlib as vpl

    self = vpl.legend(None, fig=None)
    assert self.fig is None
    assert self.length == 0
    vpl.gcf().add_plot(self)

    self.set_entry(label="Blue Square", color="blue")

    sphere = vpl.scatter([0, 5, 10], color="g", fig=None, label="Ball")
    self.set_entry(sphere, color="b")
    self.set_entry(
        sphere,
        "Green ball",
    )

    rabbit = vpl.mesh_plot(vpl.data.get_rabbit_stl())
    self.set_entry(rabbit, "rabbit")

    rabbit_wire = vpl.plot(rabbit.vectors,
                           color=rabbit.vectors[:, :, 0],
                           label="octopus")
    self.set_entry(rabbit_wire)
    assert self.legend.GetEntryString(self.length - 1) == "octopus"

    # self.set_entry(vpl.quiver(np.zeros(3), np.array([-1, 0, 1])), "right")
    self.set_entry(None, label="shark", icon=vpl.data.ICONS["Right"])

    for size in ((.3, .4), (.3, .4, 0)):
        self.size = size
        assert np.array_equal(self.size, [.3, .4, 0])

    position = np.array(1) - self.size
    self.position = position
    assert np.array_equal(self.position, position)

    with pytest.raises(TypeError):
        self.set_entry(object())

    length = self.length
    for i in range(2):
        eggs = vpl.text3d("eggs", label="eggs")
        self.add_plots([eggs])
        # Re-adding labels shouldn't cause the legend to grow
        assert self.length == length + 1

    vpl.text("text")

    auto_legend = vpl.legend(position=(0, 0))
    auto_legend_no_label = vpl.legend(position=(0, .7),
                                      allow_no_label=True,
                                      allow_non_polydata_plots=True,
                                      color=(.2, .3, .4, .5))
    assert auto_legend_no_label.color == (.2, .3, .4)
    assert auto_legend_no_label.opacity == .5

    self.set_entry(vpl.scatter(np.arange(12).reshape((-1, 3)),
                               label="scatter"),
                   label="fish",
                   index=self.length + 3)

    self.add_plots(vpl.gcf().plots)
Beispiel #9
0
def test_text():
    vpl.text("text", (100, 100), color="g")