vispy 0.9.5__cp38-cp38-win_amd64.whl → 0.14.0__cp38-cp38-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of vispy might be problematic. Click here for more details.

Files changed (103) hide show
  1. vispy/app/backends/_glfw.py +2 -2
  2. vispy/app/backends/_pyglet.py +8 -2
  3. vispy/app/backends/_qt.py +88 -63
  4. vispy/app/backends/_wx.py +6 -1
  5. vispy/app/canvas.py +4 -2
  6. vispy/app/tests/test_canvas.py +52 -1
  7. vispy/app/tests/test_context.py +5 -3
  8. vispy/color/color_array.py +8 -1
  9. vispy/color/colormap.py +5 -25
  10. vispy/geometry/meshdata.py +76 -38
  11. vispy/geometry/rect.py +6 -0
  12. vispy/geometry/tests/test_meshdata.py +72 -0
  13. vispy/gloo/buffer.py +12 -0
  14. vispy/gloo/gl/_constants.py +9 -5
  15. vispy/gloo/gl/_es2.py +8 -4
  16. vispy/gloo/gl/_gl2.py +2 -3
  17. vispy/gloo/gl/_proxy.py +1 -1
  18. vispy/gloo/gl/_pyopengl2.py +12 -7
  19. vispy/gloo/gl/tests/test_names.py +3 -0
  20. vispy/gloo/glir.py +26 -13
  21. vispy/gloo/program.py +39 -22
  22. vispy/gloo/tests/test_program.py +9 -2
  23. vispy/gloo/tests/test_texture.py +19 -2
  24. vispy/gloo/texture.py +46 -16
  25. vispy/gloo/wrappers.py +4 -2
  26. vispy/glsl/build_spatial_filters.py +241 -293
  27. vispy/glsl/misc/spatial-filters.frag +1299 -254
  28. vispy/io/_data/spatial-filters.npy +0 -0
  29. vispy/io/datasets.py +2 -2
  30. vispy/io/image.py +1 -1
  31. vispy/io/stl.py +3 -3
  32. vispy/scene/cameras/base_camera.py +6 -2
  33. vispy/scene/cameras/panzoom.py +10 -14
  34. vispy/scene/cameras/perspective.py +6 -0
  35. vispy/scene/cameras/tests/test_cameras.py +27 -0
  36. vispy/scene/cameras/tests/test_perspective.py +37 -0
  37. vispy/scene/cameras/turntable.py +39 -23
  38. vispy/scene/canvas.py +9 -5
  39. vispy/scene/events.py +9 -0
  40. vispy/scene/node.py +19 -2
  41. vispy/scene/tests/test_canvas.py +30 -1
  42. vispy/scene/tests/test_visuals.py +113 -0
  43. vispy/scene/visuals.py +6 -1
  44. vispy/scene/widgets/viewbox.py +3 -2
  45. vispy/testing/_runners.py +6 -12
  46. vispy/testing/_testing.py +3 -4
  47. vispy/util/check_environment.py +4 -4
  48. vispy/util/gallery_scraper.py +50 -32
  49. vispy/util/tests/test_gallery_scraper.py +2 -0
  50. vispy/util/transforms.py +1 -1
  51. vispy/util/wrappers.py +1 -1
  52. vispy/version.py +2 -3
  53. vispy/visuals/__init__.py +2 -0
  54. vispy/visuals/_scalable_textures.py +20 -17
  55. vispy/visuals/collections/array_list.py +3 -3
  56. vispy/visuals/collections/base_collection.py +1 -1
  57. vispy/visuals/ellipse.py +1 -1
  58. vispy/visuals/filters/__init__.py +3 -2
  59. vispy/visuals/filters/base_filter.py +120 -0
  60. vispy/visuals/filters/clipping_planes.py +24 -12
  61. vispy/visuals/filters/markers.py +28 -0
  62. vispy/visuals/filters/mesh.py +61 -6
  63. vispy/visuals/filters/tests/test_primitive_picking_filters.py +70 -0
  64. vispy/visuals/graphs/graph.py +1 -1
  65. vispy/visuals/image.py +114 -26
  66. vispy/visuals/image_complex.py +130 -0
  67. vispy/visuals/instanced_mesh.py +152 -0
  68. vispy/visuals/isocurve.py +1 -1
  69. vispy/visuals/line/dash_atlas.py +46 -41
  70. vispy/visuals/line/line.py +2 -5
  71. vispy/visuals/markers.py +310 -384
  72. vispy/visuals/mesh.py +2 -2
  73. vispy/visuals/shaders/function.py +3 -0
  74. vispy/visuals/shaders/tests/test_function.py +6 -0
  75. vispy/visuals/tests/test_axis.py +2 -2
  76. vispy/visuals/tests/test_image.py +92 -2
  77. vispy/visuals/tests/test_image_complex.py +36 -0
  78. vispy/visuals/tests/test_instanced_mesh.py +50 -0
  79. vispy/visuals/tests/test_markers.py +6 -0
  80. vispy/visuals/tests/test_mesh.py +17 -0
  81. vispy/visuals/tests/test_text.py +11 -0
  82. vispy/visuals/tests/test_volume.py +218 -12
  83. vispy/visuals/text/_sdf_cpu.cp38-win_amd64.pyd +0 -0
  84. vispy/visuals/text/_sdf_cpu.pyx +21 -23
  85. vispy/visuals/text/text.py +9 -3
  86. vispy/visuals/tube.py +2 -2
  87. vispy/visuals/visual.py +144 -3
  88. vispy/visuals/volume.py +300 -131
  89. {vispy-0.9.5.dist-info → vispy-0.14.0.dist-info}/LICENSE.txt +1 -1
  90. {vispy-0.9.5.dist-info → vispy-0.14.0.dist-info}/METADATA +218 -198
  91. {vispy-0.9.5.dist-info → vispy-0.14.0.dist-info}/RECORD +93 -96
  92. {vispy-0.9.5.dist-info → vispy-0.14.0.dist-info}/WHEEL +1 -1
  93. vispy/glsl/antialias/__init__.py +0 -0
  94. vispy/glsl/arrowheads/__init__.py +0 -0
  95. vispy/glsl/arrows/__init__.py +0 -0
  96. vispy/glsl/collections/__init__.py +0 -0
  97. vispy/glsl/colormaps/__init__.py +0 -0
  98. vispy/glsl/lines/__init__.py +0 -0
  99. vispy/glsl/markers/__init__.py +0 -0
  100. vispy/glsl/math/__init__.py +0 -0
  101. vispy/glsl/misc/__init__.py +0 -0
  102. vispy/glsl/transforms/__init__.py +0 -0
  103. {vispy-0.9.5.dist-info → vispy-0.14.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,152 @@
1
+ # -*- coding: utf-8 -*-
2
+ # -----------------------------------------------------------------------------
3
+ # Copyright (c) Vispy Development Team. All Rights Reserved.
4
+ # Distributed under the (new) BSD License. See LICENSE.txt for more info.
5
+ # -----------------------------------------------------------------------------
6
+
7
+ """An instanced version of MeshVisual with arbitrary shifts, transforms, and colors."""
8
+
9
+ from __future__ import division
10
+
11
+ import numpy as np
12
+
13
+ from ..gloo import VertexBuffer
14
+ from ..gloo.texture import downcast_to_32bit_if_needed
15
+ from ..color import ColorArray
16
+ from .filters import InstancedShadingFilter
17
+ from .shaders import Variable
18
+
19
+ from .mesh import MeshVisual
20
+
21
+
22
+ _VERTEX_SHADER = """
23
+ uniform bool use_instance_colors;
24
+
25
+ // these attributes will be defined on an instance basis
26
+ attribute vec3 shift;
27
+ attribute vec3 transform_x;
28
+ attribute vec3 transform_y;
29
+ attribute vec3 transform_z;
30
+
31
+ varying vec4 v_base_color;
32
+ void main() {
33
+
34
+ v_base_color = $color_transform($base_color);
35
+
36
+ // transform is generated from column vectors (new basis vectors)
37
+ // https://en.wikibooks.org/wiki/GLSL_Programming/Vector_and_Matrix_Operations#Constructors
38
+ mat3 instance_transform = mat3(transform_x, transform_y, transform_z);
39
+ vec3 pos_rotated = instance_transform * $to_vec4($position).xyz;
40
+ vec4 pos_shifted = $to_vec4(pos_rotated + shift);
41
+ gl_Position = $transform(pos_shifted);
42
+ }
43
+ """
44
+
45
+
46
+ class InstancedMeshVisual(MeshVisual):
47
+ """Instanced Mesh visual.
48
+
49
+ Mostly identical to MeshVisual, but additionally takes arrays of
50
+ of positions and transforms (optionally colors) to create multiple
51
+ instances of the mesh.
52
+
53
+ Instancing is a rendering technique that re-uses the same mesh data
54
+ by applying transformations to vertices and vertex data or textures,
55
+ wich can drastically improve performance compared to having many
56
+ simple MeshVisuals.
57
+
58
+ Parameters
59
+ ----------
60
+ instance_positions : (I, 3) array
61
+ Coordinates for each instance of the mesh.
62
+ instance_transforms : (I, 3, 3) array
63
+ Matrices for the transforms to apply to each instance.
64
+ instance_colors : ColorArray
65
+ Matrices of colors for each instance. Colors
66
+ *args : list
67
+ Positional arguments to pass to :class:`~vispy.visuals.mesh.MeshVisual`.
68
+ **kwargs : dict
69
+ Keyword arguments to pass to :class:`~vispy.visuals.mesh.MeshVisual`.
70
+
71
+ Examples
72
+ --------
73
+ See example `scene/instanced_mesh_visual.py` in the gallery.
74
+ """
75
+
76
+ _shaders = {
77
+ 'vertex': _VERTEX_SHADER,
78
+ 'fragment': MeshVisual._shaders['fragment'],
79
+ }
80
+
81
+ _shading_filter_class = InstancedShadingFilter
82
+
83
+ def __init__(self, *args, instance_positions, instance_transforms, instance_colors=None, **kwargs):
84
+ self._instance_positions = None
85
+ self._instance_positions_vbo = None
86
+ self._instance_transforms = None
87
+ self._instance_transforms_vbos = None
88
+ self._instance_colors = None
89
+ self._instance_colors_vbo = None
90
+ super().__init__(*args, **kwargs)
91
+ self.instance_positions = instance_positions
92
+ self.instance_transforms = instance_transforms
93
+ self.instance_colors = instance_colors
94
+
95
+ @property
96
+ def instance_positions(self):
97
+ return self._instance_positions
98
+
99
+ @instance_positions.setter
100
+ def instance_positions(self, pos):
101
+ pos = np.reshape(pos, (-1, 3))
102
+ if pos.ndim != 2 or pos.shape[-1] != 3:
103
+ raise ValueError(f'positions must be 3D coordinates, but provided data has shape {pos.shape}')
104
+ self._instance_positions = downcast_to_32bit_if_needed(pos, dtype=np.float32)
105
+ self._instance_positions_vbo = VertexBuffer(self._instance_positions, divisor=1)
106
+ self.mesh_data_changed()
107
+
108
+ @property
109
+ def instance_transforms(self):
110
+ return self._instance_transforms
111
+
112
+ @instance_transforms.setter
113
+ def instance_transforms(self, matrix):
114
+ matrix = np.reshape(matrix, (-1, 3, 3))
115
+ if matrix.ndim != 3 or matrix.shape[1:] != (3, 3):
116
+ raise ValueError(f'transforms must be an array of 3x3 matrices, but provided data has shape {matrix.shape}')
117
+ self._instance_transforms = downcast_to_32bit_if_needed(matrix, dtype=np.float32)
118
+ # copy if not c contiguous
119
+ self._instance_transforms_vbos = (
120
+ VertexBuffer(np.ascontiguousarray(self._instance_transforms[..., 0]), divisor=1),
121
+ VertexBuffer(np.ascontiguousarray(self._instance_transforms[..., 1]), divisor=1),
122
+ VertexBuffer(np.ascontiguousarray(self._instance_transforms[..., 2]), divisor=1),
123
+ )
124
+ self.mesh_data_changed()
125
+
126
+ @property
127
+ def instance_colors(self):
128
+ return self._instance_colors
129
+
130
+ @instance_colors.setter
131
+ def instance_colors(self, colors):
132
+ if colors is not None:
133
+ colors = ColorArray(colors)
134
+ self._instance_colors_vbo = VertexBuffer(colors.rgba, divisor=1)
135
+ else:
136
+ self._instance_colors_vbo = Variable('base_color', self._color.rgba)
137
+
138
+ self._instance_colors = colors
139
+ self.mesh_data_changed()
140
+
141
+ def _update_data(self):
142
+ with self.events.data_updated.blocker():
143
+ super()._update_data()
144
+
145
+ # set instance buffers
146
+ self.shared_program.vert['base_color'] = self._instance_colors_vbo
147
+ self.shared_program['transform_x'] = self._instance_transforms_vbos[0]
148
+ self.shared_program['transform_y'] = self._instance_transforms_vbos[1]
149
+ self.shared_program['transform_z'] = self._instance_transforms_vbos[2]
150
+ self.shared_program['shift'] = self._instance_positions_vbo
151
+
152
+ self.events.data_updated()
vispy/visuals/isocurve.py CHANGED
@@ -122,7 +122,7 @@ class IsocurveVisual(LineVisual):
122
122
  # this works for now and the existing examples, but should be tested
123
123
  # thoroughly also with the data-sanity check in set_data-function
124
124
  choice = np.nonzero((self.levels > self._data.min()) &
125
- (self._levels < self._data.max()))
125
+ (self.levels < self._data.max()))
126
126
  levels_to_calc = np.array(self.levels)[choice]
127
127
 
128
128
  # save minimum level index
@@ -2,6 +2,8 @@
2
2
  # Copyright (c) Vispy Development Team. All Rights Reserved.
3
3
  # Distributed under the (new) BSD License. See LICENSE.txt for more info.
4
4
 
5
+ from functools import lru_cache
6
+
5
7
  import numpy as np
6
8
 
7
9
 
@@ -40,46 +42,49 @@ class DashAtlas(object):
40
42
  self._atlas[key] = [self._index / float(self._data.shape[0]), period]
41
43
  self._index += 1
42
44
  self._dirty = True
43
- # self.add_pattern(value)
44
-
45
- def make_pattern(self, pattern, caps=[1, 1]):
46
- """ """
47
-
48
- # A pattern is defined as on/off sequence of segments
49
- # It must be a multiple of 2
50
- if len(pattern) > 1 and len(pattern) % 2:
51
- pattern = [pattern[0] + pattern[-1]] + pattern[1:-1]
52
- P = np.array(pattern)
53
-
54
- # Period is the sum of all segment length
55
- period = np.cumsum(P)[-1]
56
-
57
- # Find all start and end of on-segment only
58
- C, c = [], 0
59
- for i in range(0, len(P) + 2, 2):
60
- a = max(0.0001, P[i % len(P)])
61
- b = max(0.0001, P[(i + 1) % len(P)])
62
- C.extend([c, c + a])
63
- c += a + b
64
- C = np.array(C)
65
-
66
- # Build pattern
45
+
46
+ def make_pattern(self, pattern, caps=(1, 1)):
67
47
  length = self._data.shape[1]
68
- Z = np.zeros((length, 4), dtype=np.float32)
69
- for i in np.arange(0, len(Z)):
70
- x = period * (i) / float(len(Z) - 1)
71
- index = np.argmin(abs(C - (x)))
72
- if index % 2 == 0:
73
- if x <= C[index]:
74
- dash_type = +1
75
- else:
76
- dash_type = 0
77
- dash_start, dash_end = C[index], C[index + 1]
48
+ return _make_pattern(length, pattern, caps)
49
+
50
+
51
+ @lru_cache(maxsize=32)
52
+ def _make_pattern(length, pattern, caps):
53
+ """Make a concrete dash pattern of a given length."""
54
+ # A pattern is defined as on/off sequence of segments
55
+ # It must be a multiple of 2
56
+ if len(pattern) > 1 and len(pattern) % 2:
57
+ pattern = [pattern[0] + pattern[-1]] + pattern[1:-1]
58
+ P = np.array(pattern)
59
+
60
+ # Period is the sum of all segment length
61
+ period = np.cumsum(P)[-1]
62
+
63
+ # Find all start and end of on-segment only
64
+ C, c = [], 0
65
+ for i in range(0, len(P) + 2, 2):
66
+ a = max(0.0001, P[i % len(P)])
67
+ b = max(0.0001, P[(i + 1) % len(P)])
68
+ C.extend([c, c + a])
69
+ c += a + b
70
+ C = np.array(C)
71
+
72
+ # Build pattern
73
+ Z = np.zeros((length, 4), dtype=np.float32)
74
+ for i in np.arange(0, len(Z)):
75
+ x = period * (i) / float(len(Z) - 1)
76
+ index = np.argmin(abs(C - (x)))
77
+ if index % 2 == 0:
78
+ if x <= C[index]:
79
+ dash_type = +1
80
+ else:
81
+ dash_type = 0
82
+ dash_start, dash_end = C[index], C[index + 1]
83
+ else:
84
+ if x > C[index]:
85
+ dash_type = -1
78
86
  else:
79
- if x > C[index]:
80
- dash_type = -1
81
- else:
82
- dash_type = 0
83
- dash_start, dash_end = C[index - 1], C[index]
84
- Z[i] = C[index], dash_type, dash_start, dash_end
85
- return Z, period
87
+ dash_type = 0
88
+ dash_start, dash_end = C[index - 1], C[index]
89
+ Z[i] = C[index], dash_type, dash_start, dash_end
90
+ return Z, period
@@ -327,8 +327,7 @@ class _GLLineVisual(Visual):
327
327
  if self._parent._changed['pos']:
328
328
  if self._parent._pos is None:
329
329
  return False
330
- # todo: does this result in unnecessary copies?
331
- pos = np.ascontiguousarray(self._parent._pos.astype(np.float32))
330
+ pos = np.ascontiguousarray(self._parent._pos, dtype=np.float32)
332
331
  self._pos_vbo.set_data(pos)
333
332
  self._program.vert['position'] = self._pos_vbo
334
333
  self._program.vert['to_vec4'] = self._ensure_vec4_func(pos.shape[-1])
@@ -437,9 +436,7 @@ class _AggLineVisual(Visual):
437
436
  if self._parent._changed['pos']:
438
437
  if self._parent._pos is None:
439
438
  return False
440
- # todo: does this result in unnecessary copies?
441
- self._pos = np.ascontiguousarray(
442
- self._parent._pos.astype(np.float32))
439
+ self._pos = np.ascontiguousarray(self._parent._pos, dtype=np.float32)
443
440
  bake = True
444
441
 
445
442
  if self._parent._changed['color']: