Skip to content

Commit

Permalink
simplified set_colomap_no for phases
Browse files Browse the repository at this point in the history
  • Loading branch information
RainerHeintzmann committed Nov 29, 2024
1 parent a37d389 commit 9122be7
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions src/viewer_core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,24 +172,25 @@ function set_gamma(gamma=1.0, myviewer=nothing; element=0)
end

"""
add_colormap(mymap::Vector{RGB{T}}, myviewer=get_viewer()) where {T}
add_colormap(mymap::Vector{RGB{T}}, myviewer=get_viewer(); map_type=0) where {T}
adds a colormap to the viewer.
# Arguments:
* mymap: a colormap as a Vector of RGBs. See https://juliagraphics.github.io/Colors.jl/stable/colormapsandcolorscales/
* myviewer: the viewer to apply this to. By default the active viewer is used.
* N: the number of colors in the colormap. Default is 255.
* map_type: 0 for a normal colormap, 1 for a divergent colormap
For unclear reasons the use-defined colormaps do not show up in the menu, but are accessible via "c".
# Example:
```jldoctest
julia> v = @vv 2 .*(rand(10,10,10).-0.5)
julia> add_colormap(diverging_palette(0, 200, 32))
julia> add_colormap(diverging_palette(0, 200, 32); map_type=1)
julia> set_min_max_thresh(-1.0, 1.0, v)
```
"""
function add_colormap(mymap::Vector{RGB{T}}, myviewer=get_viewer()) where {T}
function add_colormap(mymap::Vector{RGB{T}}, myviewer=get_viewer(); map_type::Int=0) where {T}
sz = length(mymap);
red = zeros(UInt8, sz)
green = zeros(UInt8, sz)
Expand All @@ -202,10 +203,21 @@ function add_colormap(mymap::Vector{RGB{T}}, myviewer=get_viewer()) where {T}
bb = reinterpret(Int8, blue)

jbyteArr = Vector{jbyte}
jcall(myviewer, "add_colormap", Nothing, (jint, jbyteArr, jbyteArr, jbyteArr), sz, rb, gb, bb);
jcall(myviewer, "add_colormap", Nothing, (jint, jbyteArr, jbyteArr, jbyteArr, jint), sz, rb, gb, bb, map_type);
update_panels(myviewer)
end

"""
set_colormap_no(no, elem= nothing, myviewer=get_viewer())
sets the colormap number no for the element elem in myviewer. If elem is not given, the active element is used.
# Arguments
* no: the number of the colormap to set
* elem: the element to apply this to. By default (or if nothing) the active element is used.
* myviewer: the viewer to apply this to. By default the active viewer is used.
"""
function set_colormap_no(no, elem= nothing, myviewer=get_viewer())
if isnothing(elem)
elem=get_active_element(myviewer)
Expand All @@ -214,13 +226,14 @@ function set_colormap_no(no, elem= nothing, myviewer=get_viewer())
end

"""
add_colormap(cmap_name="RdBu", myviewer=get_viewer(); N=255)
add_colormap(cmap_name="RdBu", myviewer=get_viewer(); N=255, map_type=0)
adds a colormap ny name to the viewer.
# Arguments:
* cmap_name: a name that the function colormaps in the Colors package accepts. See https://juliagraphics.github.io/Colors.jl/stable/colormapsandcolorscales/ for possible names.
* myviewer: the viewer to apply this to. By default the active viewer is used.
* N: the number of colors in the colormap. Default is 255.
* map_type: 0 for a normal colormap, 1 for a divergent colormap
For unclear reasons the use-defined colormaps do not show up in the menu, but are accessible via "c".
# Example:
Expand All @@ -229,9 +242,12 @@ julia> v = @vv 2 .*(rand(10,10,10).-0.5)
julia> add_colormap("RdBu")
```
"""
function add_colormap(cmap_name="RdBu", myviewer=get_viewer(); N=255)
function add_colormap(cmap_name="RdBu", myviewer=get_viewer(); N=255, map_type=0)
mymap = colormap(cmap_name, N);
add_colormap(mymap, myviewer)
if cmap_name == "RdBu"
map_type = 1; # this is divergent
end
add_colormap(mymap, myviewer; map_type=map_type)
if cmap_name == "RdBu"
set_min_max_thresh(-1.0, 1.0, myviewer)
update_panels(myviewer)
Expand Down Expand Up @@ -1252,7 +1268,8 @@ function add_phase(data, data_element=0, data_time=0, viewer=nothing; name=nothi
viewer = view5d(phases, viewer; gamma=1.0, mode=DisplAddElement, element=phase_elem, name=name)
# all color updates need to only be done the first time
set_element(-1, viewer) # go to the last element.
process_keys("cccccccccccc", viewer) # toggle color mode 12x to reach the cyclic colormap
# process_keys("cccccccccccc", viewer) # toggle color mode 12x to reach the cyclic colormap
set_colormap_no(12, get_num_elements(viewer)-1, viewer)
process_keys("56", viewer) # for some reason this avoids dark pixels in the cyclic color display.
process_keys("vVe", viewer) # Toggle from additive into multiplicative display
if sz[4]==1
Expand Down

2 comments on commit 9122be7

@RainerHeintzmann
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:
Bugs were fixed regarding the naming while displaying multiple elements (@ve).
Added set_colormap_no() to simplify setting a specific element to a color.
Added the ability to push colormaps to the viewer via add_colormap(). This can be achieved either via names or RGB tables.
This version uses the JavaViewer View5D version V2.5.5-SNAPSHOT:
https://github.com/bionanoimaging/View5D/releases/tag/View5D_v2.5.5
New default colormaps ("RdBu", "RdBu_r") were added to the Viewer (in Java).

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/120375

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.0 -m "<description of version>" 9122be7b2be0ea3bdf3e2adc46a1228e2392b2a5
git push origin v0.6.0

Please # to comment.