Пример #1
0
    def render_cuboid(self, cuboid: _geometry.Cuboid, *args, **kwargs):
        """
        Render a cuboid by rendering it as a rectangle with only the width
        and depth used because the height is assumed to be along the vertical
        axis with is perpendicular to the plane of a planar robot
        Parameters
        ----------
        cuboid
        args
        kwargs

        Returns
        -------

        """
        # get transformation to apply
        transform = kwargs.get('transformation', _HomogenousTransformation())

        faces = cuboid.faces
        vertices = cuboid.vertices

        # scale vertices to account for the dimensions
        vertices = transform.apply((vertices).T).T

        _mlab.triangular_mesh(
            *self._prepare_plot_coordinates(
                self._extract_coordinates(vertices.T)), faces,
            **update_recursive(
                dict(
                    name='cuboid',
                    representation='surface',
                    color=self._RGB2rgb((178, 178, 178)),
                    line_width=0.10,
                ), kwargs.pop('mesh', {})))
Пример #2
0
    def render_cylinder(self, cylinder: _geometry.Cylinder, *args, **kwargs):
        # get transformation to apply
        transform = kwargs.get('transformation', _HomogenousTransformation())

        # quicker access to width, depth, and height of cuboid
        radii = cylinder.radius
        height = cylinder.height

        theta = _np.linspace(0, 2 * _np.pi, num=36, endpoint=True)
        z = _np.linspace(-height / 2, height / 2, num=2, endpoint=True)
        theta, z = _np.meshgrid(theta, z)
        x = radii[0] * _np.cos(theta)
        y = radii[1] * _np.sin(theta)

        vertices = _np.stack((x, y, z), axis=1).T

        # apply transformation to the vertices
        try:
            vertices = transform.apply(vertices)
        except ValueError:
            vertices = _np.asarray(
                [transform.apply(page) for page in vertices.T]).T
            vertices = _np.stack(
                [transform.apply(page) for page in vertices.T], axis=0)

        # outside surface
        _mlab.surf(
            *self._prepare_plot_coordinates(
                self._extract_coordinates(_np.swapaxes(vertices, 0, 1))), )
        # # top and bottom caps
        for ring in vertices:
            _mlab.surf(
                *self._prepare_plot_coordinates(
                    self._extract_coordinates(ring)), )
Пример #3
0
    def render_platform_anchor(
            self,
            anchor: _robot.PlatformAnchor,
            *args,
            transformation: _HomogenousTransformation = None,
            **kwargs):
        # default value for transformation, if the platform has no pose
        if transformation is None:
            transformation = _HomogenousTransformation()

        # anchor index from outside
        aidx = kwargs.pop('loop_index', -1)
        # platform index from outside
        pidx = kwargs.pop('platform_index', -1)

        _mlab.points3d(
            *self._prepare_plot_coordinates(
                self._extract_coordinates(
                    transformation.apply(anchor.linear.position))),
            **update_recursive(
                dict(
                    name=f'platform {pidx}: anchor {aidx}',
                    color=(1, 0, 0),
                    scale_factor=0.10,
                    resolution=3,
                ), kwargs))
Пример #4
0
    def render_platform_anchor(self,
                               anchor: _robot.PlatformAnchor,
                               *args,
                               transformation: _HomogenousTransformation = None,
                               **kwargs):
        # default value for transformation, if the platform has no pose
        if transformation is None:
            transformation = _HomogenousTransformation()

        # anchor index from outside
        aidx = kwargs.pop('loop_index', -1)
        # platform index from outside
        pidx = kwargs.pop('platform_index', -1)

        self.figure.add_trace(
                self._scatter(
                        **self._prepare_plot_coordinates(
                                self._extract_coordinates(
                                        transformation.apply(
                                                anchor.linear.position))),
                        **update_recursive(dict(
                                mode='markers',
                                marker=dict(
                                        color='Red',
                                        size=3 if self._NUMBER_OF_AXES == 3
                                        else 5,
                                ),
                                name=f'platform {pidx}: anchor {aidx}',
                                hoverinfo='text',
                                hovertext=f'platform {pidx}: anchor {aidx}',
                                showlegend=False,
                        ), kwargs)
                )
        )
Пример #5
0
    def render_ellipsoid(self, ellipsoid: _geometry.Ellipsoid, *args,
                         **kwargs):
        # get transformation to apply
        transform = kwargs.get('transformation', _HomogenousTransformation())

        # quicker access to width, depth, and height of cuboid
        radii = ellipsoid.radius

        az_ = _np.linspace(-_np.pi, _np.pi, num=36, endpoint=True)
        el_ = _np.linspace(-_np.pi / 2, _np.pi / 2, num=18, endpoint=True)
        az, el = _np.meshgrid(az_, el_)
        x = radii[0] * _np.cos(el) * _np.cos(az)
        y = radii[1] * _np.cos(el) * _np.sin(az)
        z = radii[2] * _np.sin(el)

        vertices = _np.stack((x, y, z), axis=1).T

        # apply transformation to the vertices
        try:
            vertices = transform.apply(vertices)
        except ValueError:
            vertices = _np.asarray(
                [transform.apply(page) for page in vertices.T]).T
            vertices = _np.stack(
                [transform.apply(page) for page in vertices.T], axis=0)

        # outside surface
        _mlab.surf(
            *self._prepare_plot_coordinates(
                self._extract_coordinates(_np.swapaxes(vertices, 0, 1))),
            **update_recursive(
                dict(
                    name='ellipsoid',
                    color=self._RGB2rgb((178, 178, 178)),
                    line_width=0.10,
                ), kwargs))

        # create a new linearly spaced elevation vector which spans from
        # all the way the south pole to the north pole
        el_ = _np.linspace(-_np.pi, _np.pi, num=36, endpoint=True)

        # calculate the circles of the principal planes (XY, YZ, XZ)
        circles = [(_np.vstack((
            radii[0] * _np.cos(az_),
            radii[1] * _np.sin(az_),
            _np.zeros_like(az_),
        )), 'rgb(0, 0, 255)'),
                   (_np.vstack((
                       _np.zeros_like(el_),
                       radii[1] * _np.cos(el_),
                       radii[2] * _np.sin(el_),
                   )), 'rgb(255, 0, 0)'),
                   (_np.vstack((
                       radii[0] * _np.cos(el_),
                       _np.zeros_like(el_),
                       radii[2] * _np.sin(el_),
                   )), 'rgb(0, 255, 0)')]

        for circle, color in circles:
            _mlab.surf(
                *self._prepare_plot_coordinates(
                    self._extract_coordinates(transform.apply(circle))), )
Пример #6
0
    def render_cuboid(self,
                      cuboid: _geometry.Cuboid,
                      *args,
                      **kwargs):
        """
        Render a cuboid by rendering it as a rectangle with only the width
        and depth used because the height is assumed to be along the vertical
        axis with is perpendicular to the plane of a planar robot
        Parameters
        ----------
        cuboid
        args
        kwargs

        Returns
        -------

        """
        # get transformation to apply
        transform = kwargs.get('transformation', _HomogenousTransformation())

        if self._NUMBER_OF_COORDINATES == 1:
            faces = _np.asarray(
                    [0, 1, 0]
            )
        elif self._NUMBER_OF_COORDINATES == 2:
            faces = _np.asarray(
                    [0, 1, 2, 3, 0]
            )
        else:
            faces = cuboid.faces

        vertices = cuboid.vertices

        # scale vertices to account for the dimensions
        vertices = transform.apply(vertices.T).T

        if self._NUMBER_OF_AXES == 3:
            self.figure.add_trace(
                    self._mesh(
                            **self._prepare_plot_coordinates(
                                    self._extract_coordinates(vertices.T)),
                            **self._prepare_plot_coordinates(faces.T,
                                                             ('i', 'j', 'k')),
                            **update_recursive(dict(
                                    facecolor=['rgb(178, 178, 178)']
                                              * faces.shape[0],
                                    vertexcolor=['rgb(0, 0, 0)']
                                                * vertices.shape[0],
                                    flatshading=True,
                                    opacity=0.75,
                                    showscale=False,
                                    name='cuboid',
                                    hoverinfo='skip',
                                    hovertext='',
                            ), kwargs.pop('mesh', {}))
                    )
            )

            # close faces
            faces = _np.append(faces, faces[:, 0, _np.newaxis], axis=1)

            # draw each edge separately
            for face in faces:
                self.figure.add_trace(
                        self._scatter(
                                **self._prepare_plot_coordinates(
                                        self._extract_coordinates(
                                                vertices[face, :].T)),
                                **update_recursive(dict(
                                        mode='lines',
                                        line=dict(
                                                color='rgb(0, 0, 0)',
                                        ),
                                        name='cuboid face',
                                        hoverinfo='skip',
                                        hovertext='',
                                        showlegend=False,
                                ), kwargs.pop('faces', {})),
                        )
                )
        else:
            self.figure.add_trace(
                    self._scatter(
                            **self._prepare_plot_coordinates(
                                    self._extract_coordinates(
                                            vertices.T[:, faces])),
                            **update_recursive(dict(
                                    mode='lines',
                                    fill='toself',
                                    line=dict(
                                            color='rgb(13, 13, 13)'
                                    ),
                                    fillcolor='rgb(178, 178, 178)',
                                    showlegend=False,
                                    name='cuboid',
                                    hoverinfo='skip',
                                    hovertext='',
                            ), kwargs.pop('mesh', {})),
                    )
            )
Пример #7
0
    def render_ellipsoid(self, ellipsoid: _geometry.Ellipsoid, *args,
                         **kwargs):
        # get transformation to apply
        transform = kwargs.get('transformation', _HomogenousTransformation())

        # quicker access to width, depth, and height of cuboid
        radii = ellipsoid.radius

        if self._NUMBER_OF_COORDINATES == 1:
            x = [-radii[0], radii[0]]
            y = [0, 0]
            z = [0, 0]
        elif self._NUMBER_OF_COORDINATES == 2:
            theta = _np.linspace(0, 2 * _np.pi, num=36, endpoint=True)
            x = radii[0] * _np.cos(theta)
            y = radii[1] * _np.sin(theta)
            z = _np.zeros_like(x)
        elif self._NUMBER_OF_COORDINATES == 3:
            az_ = _np.linspace(-_np.pi, _np.pi, num=36, endpoint=True)
            el_ = _np.linspace(-_np.pi / 2, _np.pi / 2, num=18, endpoint=True)
            az, el = _np.meshgrid(az_, el_)
            x = radii[0] * _np.cos(el) * _np.cos(az)
            y = radii[1] * _np.cos(el) * _np.sin(az)
            z = radii[2] * _np.sin(el)

        vertices = _np.stack((x, y, z), axis=1).T

        # apply transformation to the vertices
        try:
            vertices = transform.apply(vertices)
        except ValueError:
            vertices = _np.asarray(
                    [transform.apply(page) for page in vertices.T]).T
            vertices = _np.stack([transform.apply(page) for page in vertices.T],
                                 axis=0)

        if self._NUMBER_OF_AXES == 3:
            # outside surface
            self.figure.add_trace(
                    self._surface(
                            **self._prepare_plot_coordinates(
                                    self._extract_coordinates(
                                            _np.swapaxes(vertices, 0, 1))),
                            opacity=0.75,
                            colorscale=[[0, 'rgb(178, 178, 178)'],
                                        [1, 'rgb(178, 178, 178)']],
                            showscale=False,
                            cmin=0,
                            cmax=1,
                            name='cylinder',
                            hoverinfo='skip',
                            hovertext='',
                    )
            )

            # create a new linearly spaced elevation vector which spans from
            # all the way the south pole to the north pole
            el_ = _np.linspace(-_np.pi, _np.pi, num=36, endpoint=True)

            # calculate the circles of the principal planes (XY, YZ, XZ)
            circles = [
                    (_np.vstack((
                            radii[0] * _np.cos(az_),
                            radii[1] * _np.sin(az_),
                            _np.zeros_like(az_),
                    )), 'rgb(0, 0, 255)'),
                    (_np.vstack((
                            _np.zeros_like(el_),
                            radii[1] * _np.cos(el_),
                            radii[2] * _np.sin(el_),
                    )), 'rgb(255, 0, 0)'),
                    (_np.vstack((
                            radii[0] * _np.cos(el_),
                            _np.zeros_like(el_),
                            radii[2] * _np.sin(el_),
                    )), 'rgb(0, 255, 0)')
            ]

            for circle, color in circles:
                self.figure.add_trace(
                        self._scatter(
                                **self._prepare_plot_coordinates(
                                        self._extract_coordinates(
                                                transform.apply(circle))
                                ),
                                mode='lines',
                                line=dict(
                                        color=color,
                                ),
                                name='cylinder caps',
                                hoverinfo='skip',
                                hovertext='',
                                showlegend=False,
                        )
                )
        else:
            self.figure.add_trace(
                    self._scatter(
                            **self._prepare_plot_coordinates(
                                    self._extract_coordinates(vertices)),
                            mode='lines',
                            fill='toself',
                            line=dict(
                                    color='rgb(13, 13, 13)'
                            ),
                            fillcolor='rgb(178, 178, 178)',
                            showlegend=False,
                            name='cuboid',
                            hoverinfo='skip',
                            hovertext='',
                    )
            )
Пример #8
0
    def render_cylinder(self,
                        cylinder: _geometry.Cylinder,
                        *args, **kwargs):
        # get transformation to apply
        transform = kwargs.get('transformation', _HomogenousTransformation())

        # quicker access to width, depth, and height of cuboid
        radii = cylinder.radius
        height = cylinder.height

        if self._NUMBER_OF_COORDINATES == 1:
            x = [-radii[0], radii[0]]
            y = [0, 0]
            z = [0, 0]
        elif self._NUMBER_OF_COORDINATES == 2:
            theta = _np.linspace(0, 2 * _np.pi, num=36, endpoint=True)
            x = radii[0] * _np.cos(theta)
            y = radii[1] * _np.sin(theta)
            z = _np.zeros_like(x)
        elif self._NUMBER_OF_COORDINATES == 3:
            theta = _np.linspace(0, 2 * _np.pi, num=36, endpoint=True)
            z = _np.linspace(-height / 2, height / 2, num=2, endpoint=True)
            theta, z = _np.meshgrid(theta, z)
            x = radii[0] * _np.cos(theta)
            y = radii[1] * _np.sin(theta)

        vertices = _np.stack((x, y, z), axis=1).T

        # apply transformation to the vertices
        try:
            vertices = transform.apply(vertices)
        except ValueError:
            vertices = _np.asarray(
                    [transform.apply(page) for page in vertices.T]).T
            vertices = _np.stack([transform.apply(page) for page in vertices.T],
                                 axis=0)

        if self._NUMBER_OF_AXES == 3:
            # outside surface
            self.figure.add_trace(
                    self._surface(
                            **self._prepare_plot_coordinates(
                                    self._extract_coordinates(
                                            _np.swapaxes(vertices, 0, 1))),
                            opacity=0.75,
                            colorscale=[[0, 'rgb(178, 178, 178)'],
                                        [1, 'rgb(178, 178, 178)']],
                            showscale=False,
                            cmin=0,
                            cmax=1,
                            name='cylinder',
                            hoverinfo='skip',
                            hovertext='',
                    )
            )
            # # top and bottom caps
            for ring in vertices:
                self.figure.add_trace(
                        self._scatter(
                                **self._prepare_plot_coordinates(
                                        self._extract_coordinates(ring)
                                ),
                                mode='lines',
                                line=dict(
                                        color='rgb(0, 0, 0)',
                                ),
                                name='cylinder caps',
                                hoverinfo='skip',
                                hovertext='',
                                showlegend=False,
                        )
                )
        else:
            self.figure.add_trace(
                    self._scatter(
                            **self._prepare_plot_coordinates(
                                    self._extract_coordinates(vertices)),
                            mode='lines',
                            fill='toself',
                            line=dict(
                                    color='rgb(13, 13, 13)'
                            ),
                            fillcolor='rgb(178, 178, 178)',
                            showlegend=False,
                            name='cuboid',
                            hoverinfo='skip',
                            hovertext='',
                    )
            )