Ejemplo n.º 1
0
    def _view_landmarks_3d(self, figure_id=None, new_figure=False, group=None):
        r"""
        Visualization of the PointCloud landmarks 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.
        group : `str`
            The landmark group to visualize. If ``None`` is passed, the first
            and only landmark group on the object will be visualized.

        Returns
        -------
        viewer : LandmarkViewer3d
            The Menpo3D viewer object.
        """
        try:
            from menpo3d.visualize import LandmarkViewer3d
            self_renderer = self.view(figure_id=figure_id,
                                      new_figure=new_figure)
            return LandmarkViewer3d(self_renderer.figure, False, self,
                                    self.landmarks[group]).render()
        except ImportError:
            from menpo.visualize import Menpo3dMissingError
            raise Menpo3dMissingError()
Ejemplo n.º 2
0
    def _view_3d(self, figure_id=None, new_figure=False, textured=True,
                 **kwargs):
        r"""
        Visualize the :map:`TexturedTriMesh` 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.
        textured : `bool`, optional
            If `True`, render the texture.

        Returns
        -------
        viewer : :map:`Renderer`
            The viewer object.
        """
        if textured:
            try:
                from menpo3d.visualize import TexturedTriMeshViewer3d
                return TexturedTriMeshViewer3d(
                    figure_id, new_figure, self.points,
                    self.trilist, self.texture,
                    self.tcoords.points).render(**kwargs)
            except ImportError:
                from menpo.visualize import Menpo3dMissingError
                raise Menpo3dMissingError()
        else:
            return super(TexturedTriMesh, self).view(figure_id=figure_id,
                                                     new_figure=new_figure,
                                                     **kwargs)
Ejemplo n.º 3
0
 def _view_3d(self, figure_id=None, new_figure=False, **kwargs):
     try:
         from menpo3d.visualize import LandmarkViewer3d
         return LandmarkViewer3d(figure_id, new_figure,
                                 self._pointcloud, self).render(**kwargs)
     except ImportError:
         from menpo.visualize import Menpo3dMissingError
         raise Menpo3dMissingError()
Ejemplo n.º 4
0
    def _view_3d(
        self,
        with_labels=None,
        without_labels=None,
        group="group",
        figure_id=None,
        new_figure=False,
        render_lines=True,
        line_colour=None,
        line_width=2,
        render_markers=True,
        marker_style="sphere",
        marker_size=None,
        marker_colour=None,
        marker_resolution=8,
        step=None,
        alpha=1.0,
        render_numbering=False,
        numbers_colour="k",
        numbers_size=None,
    ):
        try:
            from menpo3d.visualize import LandmarkViewer3d

            if with_labels is not None and without_labels is not None:
                raise ValueError("You may only pass one of `with_labels` or "
                                 "`without_labels`.")
            elif with_labels is not None:
                lmark_group = self.with_labels(with_labels)
            elif without_labels is not None:
                lmark_group = self.without_labels(without_labels)
            else:
                lmark_group = self  # Fall through
            landmark_viewer = LandmarkViewer3d(figure_id, new_figure, group,
                                               lmark_group)
            return landmark_viewer.render(
                render_lines=render_lines,
                line_colour=line_colour,
                line_width=line_width,
                render_markers=render_markers,
                marker_style=marker_style,
                marker_size=marker_size,
                marker_colour=marker_colour,
                marker_resolution=marker_resolution,
                step=step,
                alpha=alpha,
                render_numbering=render_numbering,
                numbers_colour=numbers_colour,
                numbers_size=numbers_size,
            )
        except ImportError as e:
            from menpo.visualize import Menpo3dMissingError

            raise Menpo3dMissingError(e)
Ejemplo n.º 5
0
    def _view_3d(self, figure_id=None, new_figure=False, **kwargs):
        r"""
        Visualization of the 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.

        Returns
        -------
        viewer : TriMeshViewer3D
            The Menpo3D viewer object.
        """
        try:
            from menpo3d.visualize import TriMeshViewer3d
            return TriMeshViewer3d(figure_id, new_figure, self.points,
                                   self.trilist).render(**kwargs)
        except ImportError:
            from menpo.visualize import Menpo3dMissingError
            raise Menpo3dMissingError()
Ejemplo n.º 6
0
    def _view_3d(self, figure_id=None, new_figure=False):
        r"""
        Visualization of the PointCloud 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.

        Returns
        -------
        viewer : PointCloudViewer3d
            The Menpo3D viewer object.
        """
        try:
            from menpo3d.visualize import PointCloudViewer3d
            return PointCloudViewer3d(figure_id, new_figure,
                                      self.points).render()
        except ImportError:
            from menpo.visualize import Menpo3dMissingError
            raise Menpo3dMissingError()
Ejemplo n.º 7
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,
        **kwargs,
    ):
        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 as e:
                from menpo.visualize import Menpo3dMissingError

                raise Menpo3dMissingError(e)
        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 as e:
                from menpo.visualize import Menpo3dMissingError

                raise Menpo3dMissingError(e)
Ejemplo n.º 8
0
    def _view_3d(
        self,
        figure_id=None,
        new_figure=True,
        render_markers=True,
        marker_style="sphere",
        marker_size=None,
        marker_colour="r",
        marker_resolution=8,
        step=None,
        alpha=1.0,
        render_numbering=False,
        numbers_colour="k",
        numbers_size=None,
        **kwargs,
    ):
        r"""
        Visualization of the PointCloud 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_markers : `bool`, optional
            If ``True``, the markers will be rendered.
        marker_style : `str`, optional
            The style of the markers.
            Example options ::

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

        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.
        marker_colour : See Below, optional
            The colour of the markers.
            Example options ::

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

        marker_resolution : `int`, optional
            The resolution of the markers. For spheres, for instance, this is
            the number of divisions along theta and phi.
        step : `int` or ``None``, optional
            If `int`, then one every `step` vertexes will be rendered.
            If ``None``, then all vertexes will be rendered.
        alpha : `float`, optional
            Defines the transparency (opacity) of the object.
        render_numbering : `bool`, optional
            If ``True``, the points will be numbered.
        numbers_colour : See Below, optional
            The colour of the numbers.
            Example options ::

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

        numbers_size : `float` or ``None``, optional
            The size of the numbers. This size can be seen as a scale factor
            applied to the numbers, which is by default calculated from
            the inter-marker spacing. If ``None``, then an optimal numbers size
            value will be set automatically.

        Returns
        -------
        renderer : `menpo3d.visualize.PointGraphViewer3d`
            The Menpo3D rendering object.
        """
        try:
            from menpo3d.visualize import PointGraphViewer3d

            edges = np.empty(0)
            renderer = PointGraphViewer3d(figure_id, new_figure, self.points,
                                          edges)
            renderer.render(
                render_lines=False,
                render_markers=render_markers,
                marker_style=marker_style,
                marker_size=marker_size,
                marker_colour=marker_colour,
                marker_resolution=marker_resolution,
                step=step,
                alpha=alpha,
                render_numbering=render_numbering,
                numbers_colour=numbers_colour,
                numbers_size=numbers_size,
            )
            return renderer
        except ImportError as e:
            from menpo.visualize import Menpo3dMissingError

            raise Menpo3dMissingError(e)
Ejemplo n.º 9
0
    def _view_3d(self, figure_id=None, new_figure=True, mesh_type='wireframe',
                 line_width=2, colour='r', marker_style='sphere',
                 marker_size=None, marker_resolution=8, 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"""
        Visualization of the 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.
        mesh_type : `str`, optional
            The representation type to be used for the mesh.
            Example options ::

                {surface, wireframe, points, mesh, fancymesh}

        line_width : `float`, optional
            The width of the lines, if there are any.
        colour : See Below, optional
            The colour of the markers.
            Example options ::

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

        marker_style : `str`, optional
            The style of the markers.
            Example options ::

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

        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 for the
            'fancymesh'.
        marker_resolution : `int`, optional
            The resolution of the markers. For spheres, for instance, this is
            the number of divisions along theta and phi. It only applies for
            the 'fancymesh'.
        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` markers will be rendered.
            If ``None``, then all vertexes will be rendered. It only applies for
            the 'fancymesh' and if `normals` is not ``None``.
        alpha : `float`, optional
            Defines the transparency (opacity) of the object.

        Returns
        -------
        renderer : `menpo3d.visualize.TriMeshViewer3D`
            The Menpo3D rendering object.
        """
        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,
                marker_style=marker_style, marker_size=marker_size,
                marker_resolution=marker_resolution, 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()
Ejemplo n.º 10
0
    def _view_3d(self,
                 with_labels=None,
                 without_labels=None,
                 group='group',
                 figure_id=None,
                 new_figure=True,
                 render_lines=True,
                 line_colour=None,
                 line_width=4,
                 render_markers=True,
                 marker_style='sphere',
                 marker_size=None,
                 marker_colour=None,
                 marker_resolution=8,
                 step=None,
                 alpha=1.0,
                 render_numbering=False,
                 numbers_colour='k',
                 numbers_size=None):
        """
        Visualize the landmark group in 3D.

        Parameters
        ----------
        with_labels : ``None`` or `str` or `list` of `str`, optional
            If not ``None``, only show the given label(s). Should **not** be
            used with the ``without_labels`` kwarg.
        without_labels : ``None`` or `str` or `list` of `str`, optional
            If not ``None``, show all except the given label(s). Should **not**
            be used with the ``with_labels`` kwarg.
        group : `str` or `None`, optional
            The landmark group to be visualized. If ``None`` and there are more
            than one landmark groups, an error is raised.
        figure_id : `object`, optional
            The id of the figure to be used.
        new_figure : `bool`, optional
            If ``True``, a new figure is created.
        render_lines : `bool`, optional
            If ``True``, then the lines will be rendered.
        line_colour : See Below, optional
            The colour of the lines. If ``None``, a different colour will be
            automatically selected for each label.
            Example options ::

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

        line_width : `float`, optional
            The width of the lines.
        render_markers : `bool`, optional
            If ``True``, then the markers will be rendered.
        marker_style : `str`, optional
            The style of the markers.
            Example options ::

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

        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.
        marker_colour : See Below, optional
            The colour of the markers. If ``None``, a different colour will be
            automatically selected for each label.
            Example options ::

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

        marker_resolution : `int`, optional
            The resolution of the markers. For spheres, for instance, this is
            the number of divisions along theta and phi.
        step : `int` or ``None``, optional
            If `int`, then one every `step` vertexes will be rendered.
            If ``None``, then all vertexes will be rendered.
        alpha : `float`, optional
            Defines the transparency (opacity) of the object.
        render_numbering : `bool`, optional
            If ``True``, the points will be numbered.
        numbers_colour : See Below, optional
            The colour of the numbers.
            Example options ::

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

        numbers_size : `float` or ``None``, optional
            The size of the numbers. This size can be seen as a scale factor
            applied to the numbers, which is by default calculated from
            the inter-marker spacing. If ``None``, then an optimal numbers size
            value will be set automatically.

        Returns
        -------
        renderer : `menpo3d.visualize.LandmarkViewer3d`
            The Menpo3D rendering object.

        Raises
        ------
        ValueError
            If both ``with_labels`` and ``without_labels`` are passed.
        """
        try:
            from menpo3d.visualize import LandmarkViewer3d
            if with_labels is not None and without_labels is not None:
                raise ValueError('You may only pass one of `with_labels` or '
                                 '`without_labels`.')
            elif with_labels is not None:
                lmark_group = self.with_labels(with_labels)
            elif without_labels is not None:
                lmark_group = self.without_labels(without_labels)
            else:
                lmark_group = self  # Fall through
            landmark_viewer = LandmarkViewer3d(figure_id, new_figure, group,
                                               lmark_group._pointcloud,
                                               lmark_group._labels_to_masks)
            return landmark_viewer.render(render_lines=render_lines,
                                          line_colour=line_colour,
                                          line_width=line_width,
                                          render_markers=render_markers,
                                          marker_style=marker_style,
                                          marker_size=marker_size,
                                          marker_colour=marker_colour,
                                          marker_resolution=marker_resolution,
                                          step=step,
                                          alpha=alpha,
                                          render_numbering=render_numbering,
                                          numbers_colour=numbers_colour,
                                          numbers_size=numbers_size)
        except ImportError:
            from menpo.visualize import Menpo3dMissingError
            raise Menpo3dMissingError()