vispy.visuals.transforms.nonlinear module

class vispy.visuals.transforms.nonlinear.LogTransform(base=None)[source]

Bases: vispy.visuals.transforms.base_transform.BaseTransform

Transform perfoming logarithmic transformation on three axes.

Maps (x, y, z) => (log(base.x, x), log(base.y, y), log(base.z, z))

No transformation is applied for axes with base == 0.

If base < 0, then the inverse function is applied: x => base.x ** x

Parameters
basearray-like

Base for the X, Y, Z axes.

Isometric = False
Linear = False
NonScaling = False
Orthogonal = True
property base

base is a tuple (x, y, z) containing the log base that should be applied to each axis of the input vector. If any axis has a base <= 0, then that axis is not affected.

glsl_imap = '\n        vec4 LogTransform_map(vec4 pos) {\n            if($base.x > 1.0)\n                pos.x = log(pos.x) / log($base.x);\n            else if($base.x < -1.0)\n                pos.x = pow(-$base.x, pos.x);\n\n            if($base.y > 1.0)\n                pos.y = log(pos.y) / log($base.y);\n            else if($base.y < -1.0)\n                pos.y = pow(-$base.y, pos.y);\n\n            if($base.z > 1.0)\n                pos.z = log(pos.z) / log($base.z);\n            else if($base.z < -1.0)\n                pos.z = pow(-$base.z, pos.z);\n            return pos;\n        }\n        '
glsl_map = '\n        vec4 LogTransform_map(vec4 pos) {\n            if($base.x > 1.0)\n                pos.x = log(pos.x) / log($base.x);\n            else if($base.x < -1.0)\n                pos.x = pow(-$base.x, pos.x);\n\n            if($base.y > 1.0)\n                pos.y = log(pos.y) / log($base.y);\n            else if($base.y < -1.0)\n                pos.y = pow(-$base.y, pos.y);\n\n            if($base.z > 1.0)\n                pos.z = log(pos.z) / log($base.z);\n            else if($base.z < -1.0)\n                pos.z = pow(-$base.z, pos.z);\n            return pos;\n        }\n        '
imap(coords)[source]

Return obj mapped through the inverse transformation.

Parameters
objtuple (x,y) or (x,y,z)

array with shape (…, 2) or (…, 3)

map(coords, base=None)[source]

Return obj mapped through the forward transformation.

Parameters
objtuple (x,y) or (x,y,z)

array with shape (…, 2) or (…, 3)

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.

class vispy.visuals.transforms.nonlinear.Magnify1DTransform(mag=3, radii=(7, 10), center=(0, 0))[source]

Bases: vispy.visuals.transforms.nonlinear.MagnifyTransform

A 1-dimensional analog of MagnifyTransform. This transform expands its input along the x-axis, around a center x value.

glsl_imap = '\n        vec4 mag_transform(vec4 pos) {\n            float dist = pos.x - $center.x;\n            if (dist == 0. || abs(dist) > $radii.y || $mag == 1) {\n                return pos;\n            }\n            float dir = dist / abs(dist);\n            \n            if( abs(dist) < $radii.x ) {\n                dist = dist * $mag;\n            }\n            else {\n                float r1 = $radii.x;\n                float r2 = $radii.y;\n                float x = (abs(dist) - r1) / (r2 - r1);\n                dist = dir * texture2D($trans, vec2(0., x)).r * $trans_max;\n            }\n\n            return vec4($center.x + dist, pos.y, pos.z, pos.w);\n        }'
glsl_map = '\n        vec4 mag_transform(vec4 pos) {\n            float dist = pos.x - $center.x;\n            if (dist == 0. || abs(dist) > $radii.y || $mag == 1) {\n                return pos;\n            }\n            float dir = dist / abs(dist);\n            \n            if( abs(dist) < $radii.x ) {\n                dist = dist * $mag;\n            }\n            else {\n                float r1 = $radii.x;\n                float r2 = $radii.y;\n                float x = (abs(dist) - r1) / (r2 - r1);\n                dist = dir * texture2D($trans, vec2(0., x)).r * $trans_max;\n            }\n\n            return vec4($center.x + dist, pos.y, pos.z, pos.w);\n        }'
class vispy.visuals.transforms.nonlinear.MagnifyTransform(mag=3, radii=(7, 10), center=(0, 0))[source]

Bases: vispy.visuals.transforms.base_transform.BaseTransform

Magnifying lens transform.

This transform causes a circular region to appear with larger scale around its center point.

Parameters
magfloat

Magnification factor. Objects around the transform’s center point will appear scaled by this amount relative to objects outside the circle.

radii(float, float)

Inner and outer radii of the “lens”. Objects inside the inner radius appear scaled, whereas objects outside the outer radius are unscaled, and the scale factor transitions smoothly between the two radii.

center: (float, float)

The center (x, y) point of the “lens”.

Notes

This transform works by segmenting its input coordinates into three regions–inner, outer, and transition. Coordinates in the inner region are multiplied by a constant scale factor around the center point, and coordinates in the transition region are scaled by a factor that transitions smoothly from the inner radius to the outer radius.

Smooth functions that are appropriate for the transition region also tend to be difficult to invert analytically, so this transform instead samples the function numerically to allow trivial inversion. In OpenGL, the sampling is implemented as a texture holding a lookup table.

Linear = False
property center

The (x, y) center point of the transform.

glsl_imap = '\n        vec4 mag_transform(vec4 pos) {\n            vec2 d = vec2(pos.x - $center.x, pos.y - $center.y);\n            float dist = length(d);\n            if (dist == 0. || dist > $radii.y || ($mag<1.01 && $mag>0.99)) {\n                return pos;\n            }\n            vec2 dir = d / dist;\n            \n            if( dist < $radii.x ) {\n                dist = dist * $mag;\n            }\n            else {\n                \n                float r1 = $radii.x;\n                float r2 = $radii.y;\n                float x = (dist - r1) / (r2 - r1);\n                float s = texture2D($trans, vec2(0., x)).r * $trans_max;\n                \n                dist = s;\n            }\n\n            d = $center + dir * dist;\n            return vec4(d, pos.z, pos.w);\n        }'
glsl_map = '\n        vec4 mag_transform(vec4 pos) {\n            vec2 d = vec2(pos.x - $center.x, pos.y - $center.y);\n            float dist = length(d);\n            if (dist == 0. || dist > $radii.y || ($mag<1.01 && $mag>0.99)) {\n                return pos;\n            }\n            vec2 dir = d / dist;\n            \n            if( dist < $radii.x ) {\n                dist = dist * $mag;\n            }\n            else {\n                \n                float r1 = $radii.x;\n                float r2 = $radii.y;\n                float x = (dist - r1) / (r2 - r1);\n                float s = texture2D($trans, vec2(0., x)).r * $trans_max;\n                \n                dist = s;\n            }\n\n            d = $center + dir * dist;\n            return vec4(d, pos.z, pos.w);\n        }'
imap(coords)[source]

Return obj mapped through the inverse transformation.

Parameters
objtuple (x,y) or (x,y,z)

array with shape (…, 2) or (…, 3)

property mag

The scale factor used in the central region of the transform.

map(x, _inverse=False)[source]

Return obj mapped through the forward transformation.

Parameters
objtuple (x,y) or (x,y,z)

array with shape (…, 2) or (…, 3)

property radii

The inner and outer radii of the circular area bounding the transform.

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.

class vispy.visuals.transforms.nonlinear.PolarTransform[source]

Bases: vispy.visuals.transforms.base_transform.BaseTransform

Polar transform

Maps (theta, r, z) to (x, y, z), where x = r*cos(theta) and y = r*sin(theta).

Isometric = False
Linear = False
NonScaling = False
Orthogonal = False
glsl_imap = '\n        vec4 polar_transform_map(vec4 pos) {\n            // TODO: need some modulo math to handle larger theta values..?\n            float theta = atan(pos.y, pos.x);\n            float r = length(pos.xy);\n            return vec4(theta, r, pos.z, 1.);\n        }\n        '
glsl_map = '\n        vec4 polar_transform_map(vec4 pos) {\n            return vec4(pos.y * cos(pos.x), pos.y * sin(pos.x), pos.z, 1.);\n        }\n        '
imap(coords)[source]

Return obj mapped through the inverse transformation.

Parameters
objtuple (x,y) or (x,y,z)

array with shape (…, 2) or (…, 3)

map(coords)[source]

Return obj mapped through the forward transformation.

Parameters
objtuple (x,y) or (x,y,z)

array with shape (…, 2) or (…, 3)