Ejemplo n.º 1
0
def generate_thumbnail(infile, outfile, size=None):
    """Generate a thumbnail or previewfile into 'outfile' using the design file in 'infile'"""
    mesh = Mesh.from_file(infile)
    vpl.mesh_plot(mesh)

    # Front of design and slightly up
    vpl.view(camera_position=[0, -1, 0.5])
    vpl.save_fig(outfile, pixels=size or [1280, 1280], off_screen=True)
Ejemplo n.º 2
0
    def test_qfigure(self):
        fig = vpl.QtFigure("a qt widget figure")

        self.assertIs(fig, vpl.gcf())

        direction = np.array([1, 0, 0])
        vpl.quiver(np.array([0, 0, 0]), direction)
        vpl.view(camera_direction=direction)
        vpl.reset_camera()

        vpl.show()
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
    def test_multi_figures(self):
        vpl.close()

        vpl.auto_figure(False)

        plot = vpl.plot(np.random.uniform(-10, 10, (10, 3)), join_ends=True)
        figs = []
        for i in range(1, 4):
            fig = vpl.figure("figure {}".format(i))
            fig += plot
            vpl.view(camera_direction=np.random.uniform(-1, 1, 3), fig=fig)
            vpl.reset_camera(fig)

            fig.show(False)
            figs.append(fig)
        fig.show()

        vpl.auto_figure(True)
Ejemplo n.º 5
0
def test_qfigure():
    vpl.QtFigure._abc_assert_no_abstract_methods()

    self = vpl.QtFigure("a Qt widget figure")

    assert self is vpl.gcf()

    direction = np.array([1, 0, 0])
    vpl.quiver(np.array([0, 0, 0]), direction)
    vpl.view(camera_direction=direction)
    vpl.reset_camera()

    self.show(block=False)
    self.close()

    self.showMaximized(block=not VTKPLOTLIB_WINDOWLESS_TEST)
    out = vpl.screenshot_fig(fig=self)
    vpl.close(fig=self)

    globals().update(locals())
    return out
Ejemplo n.º 6
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()
Ejemplo n.º 7
0
def renderimage(tread,options):
    reifenflanke = 'rimAndShoulder/reifenflanke.stl'
    modulfelge = 'rimAndShoulder/modulfelge.stl'

    # Read the STL using numpy-stl
    geom = mesh.Mesh.from_file(tread)
    shoulder = mesh.Mesh.from_file(reifenflanke)
    rim = mesh.Mesh.from_file(modulfelge)
    
# Plot the mesh
    vpl.mesh_plot(geom,color=[76,76,76])
    if options == 'full':
        vpl.mesh_plot(shoulder,color=[76,76,76])
        vpl.mesh_plot(rim,color=[1,1,1])

# Show the figure
    vpl.view(camera_direction = [0.8,0.5,0],up_view=[0,0,1])
    #fig = vpl.gcf()
    #fig.background_color = "transparent"
  #vpl.show()
    #name = 'render.png'
    vpl.save_fig('render/render.png',off_screen=True,magnification=2)
    vpl.close()
Ejemplo n.º 8
0
def get_projections(file, camera_directions=CAMERA_DIRS):
    """ Get projection views in given camera directions from an STL file.

    Returns: Numpy array of shape (PROJ_SHAPE, len(camera_directions)).
    """
    views = []
    for dir in camera_directions[::-1]:
        mesh = Mesh.from_file(file)
        vpl.mesh_plot(mesh, color="black")
        r = vpl.view(camera_position=(0, 0, 0), camera_direction=dir)
        vpl.reset_camera()
        vpl.zoom_to_contents(padding=1)
        # Upscale first so downscale is more accurate
        arr = vpl.screenshot_fig(magnification=10, off_screen=True)
        # Change 3-channel RGB image to single channel binary matrix
        arr = cv2.cvtColor(arr, cv2.COLOR_BGR2GRAY)
        arr[arr == 0] = 1
        arr[arr == 218] = 0
        arr = cv2.resize(arr, dsize=PROJ_SHAPE, interpolation=cv2.INTER_LINEAR)
        vpl.close()
        views.append(arr)
    views = np.array(views).reshape(
        (PROJ_SHAPE[0], PROJ_SHAPE[1], len(camera_directions)))
    return views
Ejemplo n.º 9
0
    @property
    def window_name(self):
        if hasattr(self, "_renWin"):
            return self.renWin.GetWindowName()
        return self._window_name

    @window_name.setter
    def window_name(self, window_name):
        if hasattr(self, "_renWin"):
            self.renWin.SetWindowName(window_name)
        self._window_name = window_name


if __name__ == "__main__":
    Figure._abc_assert_no_abstract_methods()
    import vtkplotlib as vpl

    self = vpl.figure("a normal vtk figure")

    # vpl.plot(np.random.uniform(-10, 10, (20, 3)))

    direction = np.array([1, 0, 0])
    vpl.quiver(np.array([0, 0, 0]), direction)
    vpl.view(camera_direction=direction)
    vpl.reset_camera()

    # vpl.save_fig(Path.home() / "img.jpg", 1080)

    self.show()