Skip to content

Commit

Permalink
added support for visualizing arrays of NTuples and CartesianIndices
Browse files Browse the repository at this point in the history
  • Loading branch information
RainerHeintzmann committed Jul 23, 2024
1 parent 2764067 commit a666f0a
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/viewer_core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,12 @@ end
converts an array to a jtype array
"""
function to_jtype(anArray)
if isa(anArray, Base.Broadcast.Broadcasted)
anArray = collect(anArray)
end
if eltype(anArray) <: CartesianIndex
anArray = Tuple.(anArray)
end
ArrayElement = anArray[1]
if is_complex(anArray)
jtype=jfloat
Expand Down Expand Up @@ -815,6 +821,19 @@ function to_jtype(anArray)
elseif isa(ArrayElement, Gray)
anArray = rawview(channelview(permutedims(expanddims(anArray,5),(2,1,3,4,5))))
# anArray = expanddims(rawview(channelview(anArray)),5)
elseif isa(ArrayElement, NTuple)
singleton_dim = (ndims(anArray) < 4 || size(anArray,4) == 1) ? 4 : 5
sz = NDTools.expand_size(size(anArray), ntuple((d)->1, 5))
if (sz[singleton_dim] != 1)
error("Arrays of Tuples can only be visualized if the 4th or 5th dimension is singleton.")
end
newsize = ntuple((d) -> (d==1) ? length(ArrayElement) : sz[d-1], Val(5))
anArray = reinterpret(eltype(ArrayElement), @view anArray[:])
if (singleton_dim == 4)
anArray = permutedims(reshape(anArray, newsize), (2, 3, 4, 1, 5))
else
anArray = permutedims(reshape(anArray, newsize), (2, 3, 4, 5, 1))
end
end
ArrayElement = anArray[1]
if isa(ArrayElement, Float32)
Expand Down

0 comments on commit a666f0a

Please sign in to comment.