Skip to content

Updating collections #1505

@thomasdeneux

Description

@thomasdeneux

Hello, I don't find how to update basic values of collections.

For example, i can create a points collection:

points = PointCollection("agg", color="shared", size="local")
n = 1000
self.points.append(np.random.normal(0.0, 0.5, (self.n, 3))
    color=np.column_stack((np.random.random((self.n, 3)), np.ones(self.n))),
    size=8)

But trying to change its vertices coordinates:

points['position'] = np.random.normal(0.0, 0.5, (self.n, 3))

Gives me the error:

File "/AlphaI/test.py", line 36, in change
  self.points['position'] = pos
File "/vispy/vispy/visuals/collections/collection.py", line 192, in __setitem__
  BaseCollection.__setitem__(self, key, value)
File "/vispy/vispy/visuals/collections/base_collection.py", line 432, in __setitem__
  V[key] = data
File "/vispy/vispy/gloo/buffer.py", line 271, in __setitem__
  raise ValueError("Cannot set non-contiguous data on buffer")

Besides, I managed to update the colors:

points['color'] = np.column_stack((np.random.random((self.n, 3)), np.ones(self.n)))
canvas.update()  # this involves redrawing the points

This was possible only with color="shared" when constructing the PointCollection object, while color="local" resulted in the same error as above when trying to update the color; but i could not guess appropriately what these keywords mean. I tried a similar position="shared" but this was not accepted. In general i am suffering from the lack of documentation!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions