Skip to content

Commit

Permalink
fix: General changes and cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaoDell committed Jul 21, 2023
1 parent b611368 commit 06dd4a1
Showing 1 changed file with 6 additions and 85 deletions.
91 changes: 6 additions & 85 deletions docs/experimental/viz_points_kde.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,77 +79,6 @@ def window_to_texture(
target_actor.GetProperty().SetTexture(texture_name, texture)


def texture_to_actor(
path_to_texture : str,
texture_name : str,
target_actor : actor.Actor,
blending_mode : str = "None",
wrap_mode : str = "ClampToBorder",
border_color : tuple = (
0.0,
0.0,
0.0,
1.0),
interpolate : bool = True):
"""Passes an imported texture to an actor.
Parameters
----------
path_to_texture : str
Texture image path.
texture_name : str
Name of the texture to be passed to the actor.
target_actor : actor.Actor
Target actor to receive the texture.
blending_mode : str
Texture blending mode. The options are:
1. None
2. Replace
3. Modulate
4. Add
5. AddSigned
6. Interpolate
7. Subtract
wrap_mode : str
Texture wrapping mode. The options are:
1. ClampToEdge
2. Repeat
3. MirroredRepeat
4. ClampToBorder
border_color : tuple (4, )
Texture RGBA border color.
interpolate : bool
Texture interpolation."""

wrap_mode_dic = {"ClampToEdge" : Texture.ClampToEdge,
"Repeat" : Texture.Repeat,
"MirroredRepeat" : Texture.MirroredRepeat,
"ClampToBorder" : Texture.ClampToBorder}

blending_mode_dic = {"None" : 0, "Replace" : 1,
"Modulate" : 2, "Add" : 3,
"AddSigned" : 4, "Interpolate" : 5,
"Subtract" : 6}

r, g, b, a = border_color

texture = Texture()

colormapArray = load_image(path_to_texture)
colormapData = rgb_to_vtk(colormapArray)

texture.SetInputDataObject(colormapData)
texture.SetBorderColor(r, g, b, a)
texture.SetWrap(wrap_mode_dic[wrap_mode])
texture.SetInterpolate(interpolate)
texture.MipmapOn()
texture.SetBlendingMode(blending_mode_dic[blending_mode])

target_actor.GetProperty().SetTexture(texture_name, texture)


def colormap_to_texture(
colormap : np.array,
texture_name : str,
Expand Down Expand Up @@ -208,7 +137,7 @@ def shader_custom_uniforms(actor : actor.Actor, shader_type : str):
raise ValueError("Shader type unknown.")


def normalize(array : np.array, min : float = 0.0, max : float = 1.0, axis : int = 0):
def normalize(array : np.array, min : float = 0.0, max : float = 1.0):
"""Converts an array to a given desired range.
Parameters
Expand Down Expand Up @@ -246,11 +175,8 @@ def normalize(array : np.array, min : float = 0.0, max : float = 1.0, axis : int
"""

tex_dec = """
const float normalizingFactor = 1.0; // Parameter to be better defined later
vec3 color_mapping(float intensity, float normalizingFactor){
float normalizedIntensity = intensity/normalizingFactor;
return texture(colormapTexture, vec2(normalizedIntensity,0)).rgb;
vec3 color_mapping(float intensity, sampler2D colormapTexture){;
return texture(colormapTexture, vec2(intensity, 0)).rgb;
}
"""

Expand All @@ -261,17 +187,12 @@ def normalize(array : np.array, min : float = 0.0, max : float = 1.0, axis : int
if(intensity<=0.0){
discard;
}else{
color = color_mapping(intensity, normalizingFactor).rgb;
color = color_mapping(intensity, colormapTexture).rgb;
fragOutput0 = vec4(color, 1.0);
}
"""


fs_dec = compose_shader([kde_dec])

fs_impl = compose_shader([kde_impl])


# Windows and scenes setup
width, height = (1920, 1080)
offWidth, offHeight = (1080, 1080)
Expand Down Expand Up @@ -321,8 +242,8 @@ def normalize(array : np.array, min : float = 0.0, max : float = 1.0, axis : int
0.0,
1.0),
scales=scale,
fs_dec=fs_dec,
fs_impl=fs_impl)
fs_dec=kde_dec,
fs_impl=kde_impl)

# Blending and uniforms setup
shader_apply_effects(off_manager.window, billboard, window.gl_disable_depth)
Expand Down

0 comments on commit 06dd4a1

Please sign in to comment.