Exemplo n.º 1
0
    def __init__(self,
                 mu,
                 cov,
                 std=2.,
                 cols=15,
                 rows=15,
                 depth=15,
                 subdivisions=3,
                 method='latitude',
                 vertex_colors=None,
                 face_colors=None,
                 color=(0.5, 0.5, 1, 1),
                 edge_color=None,
                 **kwargs):

        mesh = create_sphere(rows,
                             cols,
                             depth,
                             radius=std,
                             subdivisions=subdivisions,
                             method=method)

        # Take the spherical mesh and project through the covariance, like you do
        #  when sampling a multivariate gaussian.
        # https://en.wikipedia.org/wiki/Multivariate_normal_distribution#Drawing_values_from_the_distribution
        A = np.linalg.cholesky(cov)
        verts = mesh.get_vertices()
        verts2 = np.matmul(A[None, :, :], verts[:, :, None])
        verts3 = verts2 + mu[None, :, None]
        mesh.set_vertices(np.squeeze(verts3))

        self._mesh = MeshVisual(vertices=mesh.get_vertices(),
                                faces=mesh.get_faces(),
                                vertex_colors=vertex_colors,
                                face_colors=face_colors,
                                color=color)
        if edge_color:
            self._border = MeshVisual(vertices=mesh.get_vertices(),
                                      faces=mesh.get_edges(),
                                      color=edge_color,
                                      mode='lines')
        else:
            self._border = MeshVisual()

        CompoundVisual.__init__(self, [self._mesh, self._border], **kwargs)
        self.mesh.set_gl_state(polygon_offset_fill=True,
                               polygon_offset=(1, 1),
                               depth_test=True)
Exemplo n.º 2
0
def test_empty_mesh_wireframe():
    """Test that an empty mesh does not cause issues with wireframe filter"""
    mesh = MeshVisual()
    wf = WireframeFilter()
    mesh.attach(wf)

    # trigger update of filter
    wf.enabled = True
Exemplo n.º 3
0
    def __init__(self,
                 vertices=None,
                 simplices=None,
                 vertex_colors=None,
                 edge_color=None,
                 edge_width=1,
                 markers=None,
                 marker_colors=None,
                 marker_size=1,
                 **kwargs):
        """
        a mesh visualization toolkit that can also plot edges or markers

        Parameters
        ----------

        Notes
        -----
        """
        self._mesh = MeshVisual()
        self._edge = LineVisual()
        self._edge_color = Color(edge_color)
        self._marker = MarkersVisual()
        #
        self._vertex_colors = vertex_colors

        self._update()
        # initialize visuals
        CompoundVisual.__init__(self, [self._mesh, self._edge, self._marker],
                                **kwargs)
        # set default state, 'opaque', 'translucent' or 'additive'
        self._mesh.set_gl_state(
            preset="translucent",
            blend=True,
            depth_test=False,
            cull_face=False,
            polygon_offset_fill=True,
            polygon_offset=(1, 1),
        )
        # end
        self.freeze()

        def _update(self):
            """
            update parameters to visuals
            """
            raise NotImplementedError()

        @property
        def edge_color(self):
            """ get """
            return self._edge_color

        @edge_color.setter
        def edge_color(self, edge_color):
            """ set """
            self._edge_color = Color(edge_color)
            self._update()
Exemplo n.º 4
0
    def __init__(self, radius=1.0, directions=None, colors=None):

        # Convert spherical to cartesian
        points = np.array([util.tp2xyz(*x) for x in directions])

        # Create mesh
        import scipy.spatial
        ch = scipy.spatial.ConvexHull(points)
        mesh = MeshData(vertices=ch.points, faces=ch.simplices)

        self._mesh = MeshVisual(vertices=mesh.get_vertices(),
                                faces=mesh.get_faces(),
                                vertex_colors=colors)

        CompoundVisual.__init__(self, [self._mesh])
        self.mesh.set_gl_state(depth_test=True)