Пример #1
0
    def _view_3d(self,
                 figure_id=None,
                 new_figure=True,
                 render_texture=True,
                 mesh_type='surface',
                 ambient_light=0.0,
                 specular_light=0.0,
                 colour='r',
                 line_width=2,
                 normals=None,
                 normals_colour='k',
                 normals_line_width=2,
                 normals_marker_style='2darrow',
                 normals_marker_resolution=8,
                 normals_marker_size=None,
                 step=None,
                 alpha=1.0):
        r"""
        Visualize the Coloured TriMesh in 3D.

        Parameters
        ----------
        figure_id : `object`, optional
            The id of the figure to be used.
        new_figure : `bool`, optional
            If ``True``, a new figure is created.
        render_texture : `bool`, optional
            If ``True``, then the texture is rendered. If ``False``, then only
            the TriMesh is rendered with the specified `colour`.
        mesh_type : ``{'surface', 'wireframe'}``, optional
            The representation type to be used for the mesh.
        ambient_light : `float`, optional
            The ambient light intensity. It must be in range ``[0., 1.]``.
        specular_light : `float`, optional
            The specular light intensity. It must be in range ``[0., 1.]``.
        colour : See Below, optional
            The colour of the mesh if `render_texture` is ``False``.
            Example options ::

                {r, g, b, c, m, k, w}
                or
                (3, ) ndarray

        line_width : `float`, optional
            The width of the lines, if there are any.
        normals : ``(n_points, 3)`` `ndarray` or ``None``, optional
            If ``None``, then the normals will not be rendered. If `ndarray`,
            then the provided normals will be rendered as well. Note that a
            normal must be provided for each point in the TriMesh.
        normals_colour : See Below, optional
            The colour of the normals.
            Example options ::

                {r, g, b, c, m, k, w}
                or
                (3, ) ndarray

        normals_line_width : `float`, optional
            The width of the lines of the normals. It only applies if `normals`
            is not ``None``.
        normals_marker_style : `str`, optional
            The style of the markers of the normals. It only applies if `normals`
            is not ``None``.
            Example options ::

                {2darrow, 2dcircle, 2dcross, 2ddash, 2ddiamond, 2dhooked_arrow,
                 2dsquare, 2dthick_arrow, 2dthick_cross, 2dtriangle, 2dvertex,
                 arrow, axes, cone, cube, cylinder, point, sphere}

        normals_marker_resolution : `int`, optional
            The resolution of the markers of the normals. For spheres, for
            instance, this is the number of divisions along theta and phi. It
            only applies if `normals` is not ``None``.
        normals_marker_size : `float` or ``None``, optional
            The size of the markers. This size can be seen as a scale factor
            applied to the size markers, which is by default calculated from
            the inter-marker spacing. If ``None``, then an optimal marker size
            value will be set automatically. It only applies if `normals` is not
            ``None``.
        step : `int` or ``None``, optional
            If `int`, then one every `step` normals will be rendered.
            If ``None``, then all vertexes will be rendered. It only applies if
            `normals` is not ``None``.
        alpha : `float`, optional
            Defines the transparency (opacity) of the object.

        Returns
        -------
        renderer : `menpo3d.visualize.ColouredTriMeshViewer3D`
            The Menpo3D rendering object.
        """
        if render_texture:
            try:
                from menpo3d.visualize import ColouredTriMeshViewer3d
                renderer = ColouredTriMeshViewer3d(figure_id, new_figure,
                                                   self.points, self.trilist,
                                                   self.colours)
                renderer.render(
                    mesh_type=mesh_type,
                    ambient_light=ambient_light,
                    specular_light=specular_light,
                    normals=normals,
                    normals_colour=normals_colour,
                    normals_line_width=normals_line_width,
                    normals_marker_style=normals_marker_style,
                    normals_marker_resolution=normals_marker_resolution,
                    normals_marker_size=normals_marker_size,
                    step=step,
                    alpha=alpha)
                return renderer
            except ImportError:
                from menpo.visualize import Menpo3dMissingError
                raise Menpo3dMissingError()
        else:
            try:
                from menpo3d.visualize import TriMeshViewer3d
                renderer = TriMeshViewer3d(figure_id, new_figure, self.points,
                                           self.trilist)
                renderer.render(
                    mesh_type=mesh_type,
                    line_width=line_width,
                    colour=colour,
                    normals=normals,
                    normals_colour=normals_colour,
                    normals_line_width=normals_line_width,
                    normals_marker_style=normals_marker_style,
                    normals_marker_resolution=normals_marker_resolution,
                    normals_marker_size=normals_marker_size,
                    step=step,
                    alpha=alpha)
                return renderer
            except ImportError:
                from menpo.visualize import Menpo3dMissingError
                raise Menpo3dMissingError()