shaders
#
|
Add a shader callback to the actor. |
|
Link a numpy array with vertex attribute. |
|
Merge GLSL shader code from a list of strings. |
|
Import a Fury shader. |
|
Load a Fury shader file. |
|
Load a shader from a file. |
|
Set and replace the shader template with a new one. |
|
This applies a specific opengl state (effect) or a list of effects just before the actor's shader is executed. |
|
Apply your own substitutions to the shader creation process. |
Module: shaders.base
#
alias of |
|
alias of |
|
alias of |
|
partial(func, *args, **keywords) - new function with partial application of the given arguments and keywords. |
|
|
Add a shader callback to the actor. |
|
Link a numpy array with vertex attribute. |
|
set_call_data_type(type) -- convenience decorator to easily set the CallDataType attribute for python function used as observer callback. |
|
Merge GLSL shader code from a list of strings. |
|
Return decorator function for deprecation warning / error. |
|
Enable global warnings. |
|
Import a Fury shader. |
|
Load a Fury shader file. |
|
Load a shader from a file. |
|
Load a text file. |
|
Set and replace the shader template with a new one. |
|
This applies a specific opengl state (effect) or a list of effects just before the actor's shader is executed. |
|
Apply your own substitutions to the shader creation process. |
add_shader_callback#
- fury.shaders.add_shader_callback(actor, callback, priority=0.0)[source]#
Add a shader callback to the actor.
- Parameters:
actor (vtkActor) – Fury actor you want to add the callback to.
callback (callable) – Function or class that contains 3 parameters: caller, event, calldata. This callback will be trigger at each UpdateShaderEvent event.
priority (float, optional) – Commands with a higher priority are called first.
- Returns:
id_observer – An unsigned Int tag which can be used later to remove the event or retrieve the vtkCommand used in the observer. See more at: https://vtk.org/doc/nightly/html/classvtkObject.html
- Return type:
Examples
add_shader_callback(actor, func_call1) id_observer = add_shader_callback(actor, func_call2) actor.GetMapper().RemoveObserver(id_observer)
Priority calls
test_values = [] def callbackLow(_caller, _event, calldata=None): program = calldata if program is not None: test_values.append(0) def callbackHigh(_caller, _event, calldata=None): program = calldata if program is not None: test_values.append(999) def callbackMean(_caller, _event, calldata=None): program = calldata if program is not None: test_values.append(500) fs.add_shader_callback( actor, callbackHigh, 999) fs.add_shader_callback( actor, callbackLow, 0) id_mean = fs.add_shader_callback( actor, callbackMean, 500) showm.start() # test_values = [999, 500, 0, 999, 500, 0, ...]
attribute_to_actor#
- fury.shaders.attribute_to_actor(actor, arr, attr_name, deep=True)[source]#
Link a numpy array with vertex attribute.
- Parameters:
actor (vtkActor) – Fury actor you want to add the vertex attribute to.
arr (ndarray) – Array to link to vertices.
attr_name (str) – Vertex attribute name. The vtk array will take the same name as the attribute.
deep (bool, optional) – If True a deep copy is applied, otherwise a shallow copy is applied. Default True.
compose_shader#
import_fury_shader#
- fury.shaders.import_fury_shader(shader_file)[source]#
Import a Fury shader.
- Parameters:
shader_file (str) – Filename of shader. The file must be in the fury/shaders directory and must have the one of the supported extensions specified by the Khronos Group (KhronosGroup/glslang).
- Returns:
code – GLSL shader code.
- Return type:
load#
load_shader#
- fury.shaders.load_shader(shader_file)[source]#
Load a shader from a file.
- Parameters:
shader_file (str) – Full path to a shader file ending with one of the file extensions defined by the Khronos Group (KhronosGroup/glslang).
- Returns:
code – GLSL shader code.
- Return type:
replace_shader_in_actor#
shader_apply_effects#
- fury.shaders.shader_apply_effects(window, actor, effects, priority=0)[source]#
This applies a specific opengl state (effect) or a list of effects just before the actor’s shader is executed.
- Parameters:
window (RenderWindow) – For example, this is provided by the ShowManager.window attribute.
actor (actor) –
effects (a function or a list of functions) –
priority (float, optional) – Related with the shader callback command. Effects with a higher priority are applied first and can be override by the others.
- Returns:
id_observer – An unsigned Int tag which can be used later to remove the event or retrieve the vtkCommand used in the observer. See more at: https://vtk.org/doc/nightly/html/classvtkObject.html
- Return type:
shader_to_actor#
- fury.shaders.shader_to_actor(actor, shader_type, impl_code='', decl_code='', block='valuepass', keep_default=True, replace_first=True, replace_all=False, debug=False)[source]#
Apply your own substitutions to the shader creation process.
A set of string replacements is applied to a shader template. This function let’s apply custom string replacements.
- Parameters:
actor (vtkActor) – Fury actor you want to set the shader code to.
shader_type (str) – Shader type: vertex, fragment
impl_code (str, optional) – Shader implementation code, should be a string or filename. Default None.
decl_code (str, optional) – Shader declaration code, should be a string or filename. Default None.
block (str, optional) – Section name to be replaced. VTK use of heavy string replacements to insert shader and make it flexible. Each section of the shader template have a specific name. For more information: https://vtk.org/Wiki/Shaders_In_VTK. The possible values are: position, normal, light, tcoord, color, clip, camera, prim_id, valuepass. by default valuepass
keep_default (bool, optional) – Keep the default block tag to let VTK replace it with its default behavior. Default True.
replace_first (bool, optional) – If True, apply this change before the standard VTK replacements. Default True.
replace_all (bool, optional) – [description], by default False
debug (bool, optional) – Introduce a small error to debug shader code. Default False.
Command
#
- fury.shaders.base.Command#
alias of
vtkCommand
DataObject
#
- fury.shaders.base.DataObject#
alias of
vtkDataObject
Shader
#
- fury.shaders.base.Shader#
alias of
vtkShader
partial
#
- class fury.shaders.base.partial[source]#
Bases:
object
partial(func, *args, **keywords) - new function with partial application of the given arguments and keywords.
- __init__()#
- args#
tuple of arguments to future partial calls
- func#
function object to use in future partial calls
- keywords#
dictionary of keyword arguments to future partial calls
add_shader_callback#
- fury.shaders.base.add_shader_callback(actor, callback, priority=0.0)[source]#
Add a shader callback to the actor.
- Parameters:
actor (vtkActor) – Fury actor you want to add the callback to.
callback (callable) – Function or class that contains 3 parameters: caller, event, calldata. This callback will be trigger at each UpdateShaderEvent event.
priority (float, optional) – Commands with a higher priority are called first.
- Returns:
id_observer – An unsigned Int tag which can be used later to remove the event or retrieve the vtkCommand used in the observer. See more at: https://vtk.org/doc/nightly/html/classvtkObject.html
- Return type:
Examples
add_shader_callback(actor, func_call1) id_observer = add_shader_callback(actor, func_call2) actor.GetMapper().RemoveObserver(id_observer)
Priority calls
test_values = [] def callbackLow(_caller, _event, calldata=None): program = calldata if program is not None: test_values.append(0) def callbackHigh(_caller, _event, calldata=None): program = calldata if program is not None: test_values.append(999) def callbackMean(_caller, _event, calldata=None): program = calldata if program is not None: test_values.append(500) fs.add_shader_callback( actor, callbackHigh, 999) fs.add_shader_callback( actor, callbackLow, 0) id_mean = fs.add_shader_callback( actor, callbackMean, 500) showm.start() # test_values = [999, 500, 0, 999, 500, 0, ...]
attribute_to_actor#
- fury.shaders.base.attribute_to_actor(actor, arr, attr_name, deep=True)[source]#
Link a numpy array with vertex attribute.
- Parameters:
actor (vtkActor) – Fury actor you want to add the vertex attribute to.
arr (ndarray) – Array to link to vertices.
attr_name (str) – Vertex attribute name. The vtk array will take the same name as the attribute.
deep (bool, optional) – If True a deep copy is applied, otherwise a shallow copy is applied. Default True.
calldata_type#
- fury.shaders.base.calldata_type(type)[source]#
set_call_data_type(type) – convenience decorator to easily set the CallDataType attribute for python function used as observer callback. For example:
import vtkmodules.util.calldata_type import vtkmodules.util.vtkConstants import vtkmodules.vtkCommonCore import vtkCommand, vtkLookupTable
@calldata_type(vtkConstants.VTK_STRING) def onError(caller, event, calldata):
print(“caller: %s - event: %s - msg: %s” % (caller.GetClassName(), event, calldata))
lt = vtkLookupTable() lt.AddObserver(vtkCommand.ErrorEvent, onError) lt.SetTableRange(2,1)
compose_shader#
deprecate_with_version#
- fury.shaders.base.deprecate_with_version(message, since='', until='', version_comparator=<function cmp_pkg_version>, warn_class=<class 'DeprecationWarning'>, error_class=<class 'fury.deprecator.ExpiredDeprecationError'>)[source]#
Return decorator function for deprecation warning / error.
The decorated function / method will:
Raise the given
warning_class
warning when the function / method gets called, up to (and including) version until (if specified);Raise the given
error_class
error when the function / method gets called, when the package version is greater than versionuntil
(if specified).
- Parameters:
message (str) – Message explaining deprecation, giving possible alternatives.
since (str, optional) – Released version at which object was first deprecated.
until (str, optional) – Last released version at which this function will still raise a deprecation warning. Versions higher than this will raise an error.
version_comparator (callable) – Callable accepting string as argument, and return 1 if string represents a higher version than encoded in the version_comparator`, 0 if the version is equal, and -1 if the version is lower. For example, the
version_comparator
may compare the input version string to the current package version string.warn_class (class, optional) – Class of warning to generate for deprecation.
error_class (class, optional) – Class of error to generate when
version_comparator
returns 1 for a given argument ofuntil
.
- Returns:
deprecator – Function returning a decorator.
- Return type:
func
enable_warnings#
import_fury_shader#
- fury.shaders.base.import_fury_shader(shader_file)[source]#
Import a Fury shader.
- Parameters:
shader_file (str) – Filename of shader. The file must be in the fury/shaders directory and must have the one of the supported extensions specified by the Khronos Group (KhronosGroup/glslang).
- Returns:
code – GLSL shader code.
- Return type:
load#
load_shader#
- fury.shaders.base.load_shader(shader_file)[source]#
Load a shader from a file.
- Parameters:
shader_file (str) – Full path to a shader file ending with one of the file extensions defined by the Khronos Group (KhronosGroup/glslang).
- Returns:
code – GLSL shader code.
- Return type:
load_text#
replace_shader_in_actor#
shader_apply_effects#
- fury.shaders.base.shader_apply_effects(window, actor, effects, priority=0)[source]#
This applies a specific opengl state (effect) or a list of effects just before the actor’s shader is executed.
- Parameters:
window (RenderWindow) – For example, this is provided by the ShowManager.window attribute.
actor (actor) –
effects (a function or a list of functions) –
priority (float, optional) – Related with the shader callback command. Effects with a higher priority are applied first and can be override by the others.
- Returns:
id_observer – An unsigned Int tag which can be used later to remove the event or retrieve the vtkCommand used in the observer. See more at: https://vtk.org/doc/nightly/html/classvtkObject.html
- Return type:
shader_to_actor#
- fury.shaders.base.shader_to_actor(actor, shader_type, impl_code='', decl_code='', block='valuepass', keep_default=True, replace_first=True, replace_all=False, debug=False)[source]#
Apply your own substitutions to the shader creation process.
A set of string replacements is applied to a shader template. This function let’s apply custom string replacements.
- Parameters:
actor (vtkActor) – Fury actor you want to set the shader code to.
shader_type (str) – Shader type: vertex, fragment
impl_code (str, optional) – Shader implementation code, should be a string or filename. Default None.
decl_code (str, optional) – Shader declaration code, should be a string or filename. Default None.
block (str, optional) – Section name to be replaced. VTK use of heavy string replacements to insert shader and make it flexible. Each section of the shader template have a specific name. For more information: https://vtk.org/Wiki/Shaders_In_VTK. The possible values are: position, normal, light, tcoord, color, clip, camera, prim_id, valuepass. by default valuepass
keep_default (bool, optional) – Keep the default block tag to let VTK replace it with its default behavior. Default True.
replace_first (bool, optional) – If True, apply this change before the standard VTK replacements. Default True.
replace_all (bool, optional) – [description], by default False
debug (bool, optional) – Introduce a small error to debug shader code. Default False.