Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue about SurfacePlotVisual #2517

Open
JintaoLee-Roger opened this issue Aug 19, 2023 · 2 comments
Open

issue about SurfacePlotVisual #2517

JintaoLee-Roger opened this issue Aug 19, 2023 · 2 comments

Comments

@JintaoLee-Roger
Copy link

Hi!

When I use SurfacePlot to draw a surface and seed color parameter, an error occurs:

File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.10/site-packages/vispy/visuals/surface_plot.py", line 129, in _prepare_mesh_colors
    colors = colors.reshape(num_vertices, 3)
ValueError: cannot reshape array of size 960000 into shape (240000,3)

I note that the _prepare_mesh_colors function in vispy/visuals/surface_plot.py is:

    def _prepare_mesh_colors(self, colors):
        if colors is None:
            return
        colors = np.asarray(colors)
        if colors.ndim == 3:
            # convert (width, height, 4) to (num_verts, 4)
            vert_shape = self.__vertices.shape
            num_vertices = vert_shape[0] * vert_shape[1]
            colors = colors.reshape(num_vertices, 3)
        return colors

The comment and document state that I should pass in a matrix of dimensions (width, height, 4), which will then be transformed into a matrix of dimensions (num_verts, 4). However, the code does not follow this approach; instead, it transforms it into a matrix of dimensions (num_verts, 3).

@djhoese
Copy link
Member

djhoese commented Aug 21, 2023

At first glance this does seem like a bug, but also what colors are you providing? RGB? RGBA?

Skimming through the code it does definitely seem like RGBA (4 elements) is the more performant way of providing the colors. Otherwise, VisPy adds the alpha channel itself which requires a copy of the color array. I'm not really sure how or why this is reshaping to 3 (RGB). If you feel up to it, it would be great if you could make a pull request fixing this.

@djhoese
Copy link
Member

djhoese commented Dec 1, 2023

Related #2542

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants