vispy.visuals.transforms.linear module

class vispy.visuals.transforms.linear.MatrixTransform(matrix=None)[source]

Bases: vispy.visuals.transforms.base_transform.BaseTransform

Affine transformation class

Parameters
matrixarray-like | None

4x4 array to use for the transform.

Isometric = False
Linear = True
NonScaling = False
Orthogonal = False
glsl_imap = '\n        vec4 affine_transform_imap(vec4 pos) {\n            return $inv_matrix * pos;\n        }\n    '
glsl_map = '\n        vec4 affine_transform_map(vec4 pos) {\n            return $matrix * pos;\n        }\n    '
imap(coords)[source]

Inverse map coordinates

Parameters
coordsarray-like

Coordinates to inverse map.

Returns
coordsndarray

Coordinates.

property inv_matrix
map(coords)[source]

Map coordinates

Parameters
coordsarray-like

Coordinates to map.

Returns
coordsndarray

Coordinates.

property matrix
reset()[source]
rotate(angle, axis)[source]

Rotate the matrix by some angle about a given axis.

The rotation is applied after the transformations already present in the matrix.

Parameters
anglefloat

The angle of rotation, in degrees.

axisarray-like

The x, y and z coordinates of the axis vector to rotate around.

scale(scale, center=None)[source]

Scale the matrix about a given origin.

The scaling is applied after the transformations already present in the matrix.

Parameters
scalearray-like

Scale factors along x, y and z axes.

centerarray-like or None

The x, y and z coordinates to scale around. If None, (0, 0, 0) will be used.

set_frustum(l, r, b, t, n, f)[source]

Set the frustum

Parameters
lfloat

Left.

rfloat

Right.

bfloat

Bottom.

tfloat

Top.

nfloat

Near.

ffloat

Far.

set_mapping(points1, points2)[source]

Set to a 3D transformation matrix that maps points1 onto points2.

Parameters
points1array-like, shape (4, 3)

Four starting 3D coordinates.

points2array-like, shape (4, 3)

Four ending 3D coordinates.

set_ortho(l, r, b, t, n, f)[source]

Set ortho transform

Parameters
lfloat

Left.

rfloat

Right.

bfloat

Bottom.

tfloat

Top.

nfloat

Near.

ffloat

Far.

set_perspective(fov, aspect, near, far)[source]

Set the perspective

Parameters
fovfloat

Field of view.

aspectfloat

Aspect ratio.

nearfloat

Near location.

farfloat

Far location.

shader_imap()[source]

See shader_map.

shader_map()[source]

Return a shader Function that accepts only a single vec4 argument and defines new attributes / uniforms supplying the Function with any static input.

translate(pos)[source]

Translate the matrix

The translation is applied after the transformations already present in the matrix.

Parameters
posarrayndarray

Position to translate by.

class vispy.visuals.transforms.linear.NullTransform[source]

Bases: vispy.visuals.transforms.base_transform.BaseTransform

Transform having no effect on coordinates (identity transform).

Isometric = True
Linear = True
NonScaling = True
Orthogonal = True
glsl_imap = 'vec4 null_transform_imap(vec4 pos) {return pos;}'
glsl_map = 'vec4 null_transform_map(vec4 pos) {return pos;}'
imap(coords)[source]

Inverse map coordinates

Parameters
coordsarray-like

Coordinates to inverse map.

map(coords)[source]

Map coordinates

Parameters
coordsarray-like

Coordinates to map.

class vispy.visuals.transforms.linear.STTransform(scale=None, translate=None)[source]

Bases: vispy.visuals.transforms.base_transform.BaseTransform

Transform performing only scale and translate, in that order.

Parameters
scalearray-like

Scale factors for X, Y, Z axes.

translatearray-like

Scale factors for X, Y, Z axes.

Isometric = False
Linear = True
NonScaling = False
Orthogonal = True
as_matrix()[source]
classmethod from_mapping(x0, x1)[source]

Create an STTransform from the given mapping

See set_mapping for details.

Parameters
x0array-like

Start.

x1array-like

End.

Returns
tinstance of STTransform

The transform.

glsl_imap = '\n        vec4 st_transform_imap(vec4 pos) {\n            return vec4((pos.xyz - $translate.xyz * pos.w) / $scale.xyz,\n                        pos.w);\n        }\n    '
glsl_map = '\n        vec4 st_transform_map(vec4 pos) {\n            return vec4(pos.xyz * $scale.xyz + $translate.xyz * pos.w, pos.w);\n        }\n    '
imap(coords)[source]

Invert map coordinates

Parameters
coordsarray-like

Coordinates to inverse map.

Returns
coordsndarray

Coordinates.

map(coords)[source]

Map coordinates

Parameters
coordsarray-like

Coordinates to map.

Returns
coordsndarray

Coordinates.

move(move)[source]

Change the translation of this transform by the amount given.

Parameters
movearray-like

The values to be added to the current translation of the transform.

property scale
set_mapping(x0, x1, update=True)[source]

Configure this transform such that it maps points x0 => x1

Parameters
x0array-like, shape (2, 2) or (2, 3)

Start location.

x1array-like, shape (2, 2) or (2, 3)

End location.

updatebool

If False, then the update event is not emitted.

Examples

For example, if we wish to map the corners of a rectangle:

>>> p1 = [[0, 0], [200, 300]]

onto a unit cube:

>>> p2 = [[-1, -1], [1, 1]]

then we can generate the transform as follows:

>>> tr = STTransform()
>>> tr.set_mapping(p1, p2)
>>> assert tr.map(p1)[:,:2] == p2  # test
shader_imap()[source]

See shader_map.

shader_map()[source]

Return a shader Function that accepts only a single vec4 argument and defines new attributes / uniforms supplying the Function with any static input.

property translate
zoom(zoom, center=(0, 0, 0), mapped=True)[source]

Update the transform such that its scale factor is changed, but the specified center point is left unchanged.

Parameters
zoomarray-like

Values to multiply the transform’s current scale factors.

centerarray-like

The center point around which the scaling will take place.

mappedbool

Whether center is expressed in mapped coordinates (True) or unmapped coordinates (False).