Skip to content

Commit

Permalink
ordereddict and logo
Browse files Browse the repository at this point in the history
  • Loading branch information
fdekerme committed Apr 13, 2024
1 parent e4bd65c commit 3a2c125
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 41 deletions.
Binary file added DICOMTree_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version = "0.1.0"

[deps]
DICOM = "a26e6606-dd52-5f6a-a97f-4f611373d757"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Term = "22787eb5-b846-44ae-b979-8e399b8463ab"

Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# DICOMTree

A little Julia package for visualizing DICOM file metadata in the form of a tree. The main function is the Tree function, which is simply a dispatch of the eponymous function in the Term.jl package to the DICOMData type in the DICOM.jl package.
A little Julia package for visualizing DICOM file metadata in the form of a tree. The main function is the Tree function, which is simply a dispatch of the eponymous function in the [Term.jl](https://github.com/FedeClaudi/Term.jl) package to the ```DICOMData``` type in the [DICOM.jl](https://github.com/JuliaHealth/DICOM.jl) package.
The package have been tested with CT Scanner, RTDose and RTStruct files.

<p align="center">
<img src="DICOMTree_logo.png" alt="DICOMTree Logo" width="100">
</p>

## Documentation & installation

Install with:
Expand Down
86 changes: 46 additions & 40 deletions src/DICOMTree.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
module DICOMTree
import Term.Trees: Tree, TreeCharSet, print_node, print_key, Theme, TERM_THEME, _TREE_PRINTING_TITLE
import Term.Style: apply_style

using DICOM
using OrderedCollections: OrderedDict

export Tree

Expand Down Expand Up @@ -68,55 +70,25 @@ function Tree(
title::Union{String,Nothing}="",
prefix::String=" ",
kwargs...
)
)::Tree

_TREE_PRINTING_TITLE[] = title
_theme = TERM_THEME[]
TERM_THEME[] = theme

md = haskey(kwargs, :maxdepth) ? kwargs[:maxdepth] : 2

format(x, md) = x

function format(x::AbstractArray, md)::Tree
return (Tree(Dict("Size" => string(size(x)), "Type" => typeof(x)),
guides=guides,
title="Array",
maxdepth=md))
end

function format(x::Vector, md)::Tree
if length(x) <= 6
return Tree(string(x), guides=guides)
else
return Tree(Dict("Length" => length(x),
"ElementsType" => eltype(x),
"Overview" => string(x[begin:begin+2])[1:end-1] * ", ..., " * string(x[end-3:end-1])[2:end]), guides=guides, title="Vector", maxdepth=md)
end
end

function format(x::DICOM.DICOMData, md)::Tree
return Tree(x.meta, guides=guides, title="", maxdepth=md)
end

function format(x::Vector{DICOM.DICOMData}, md)::Tree
if md >= 2
return Tree(Tree.(x, with_keys=with_keys, guides=guides, title="", maxdepth=md), guides=guides, title="", maxdepth=md)
else
return Tree(Dict("Length" => length(keys(x))), guides=guides, title="Vector of DICOMData", maxdepth=md)
end
end


tree = Dict()

if with_keys
for symbol in keys(dicom.meta)
tree[symbol] = format(dicom[symbol], md - 1)
tree = OrderedDict{Tuple{UInt16, UInt16}, Any}()
tag_keys = keys(sort(dicom.meta))
for symbol in tag_keys
tree[symbol] = _format(dicom[symbol], md - 1, guides, with_keys)
end
else
tag_names = get_name_from_tag.(keys(dicom.meta))
tree = OrderedDict{Symbol, Any}()
tag_names = get_name_from_tag.(keys(sort(dicom.meta)))
for symbol in tag_names
tree[symbol] = format(dicom[symbol], md - 1)
tree[symbol] = _format(dicom[symbol], md - 1, guides, with_keys)
end
end

Expand All @@ -141,9 +113,43 @@ function Tree(
title::Union{String,Nothing}="",
prefix::String=" ",
kwargs...
)
)::Tree
md = haskey(kwargs, :maxdepth) ? kwargs[:maxdepth] : 2
return Tree(Tree.(dicom_vector, with_keys=with_keys, guides=guides, title="", maxdepth=md), guides=guides, title="", maxdepth=md)
end


_format(x, md, guides, with_keys) = x

function _format(x::AbstractArray, md, guides, with_keys)::Tree
return (Tree(Dict("Size" => string(size(x)), "Type" => typeof(x)),
guides=guides,
title="Array",
maxdepth=md))
end

function _format(x::Vector, md, guides, with_keys)::Tree
if length(x) <= 6
return Tree(string(x), guides=guides)
else
return Tree(Dict("Length" => length(x),
"ElementsType" => eltype(x),
"Overview" => string(x[begin:begin+2])[1:end-1] * ", ..., " * string(x[end-3:end-1])[2:end]), guides=guides, title="Vector", maxdepth=md)
end
end

function _format(x::DICOM.DICOMData, md, guides, with_keys)::Tree
return Tree(x.meta, guides=guides, title="", maxdepth=md)
end

function _format(x::Vector{DICOM.DICOMData}, md, guides, with_keys)::Tree
if md >= 2
return Tree(Tree.(x, with_keys=with_keys, guides=guides, title="", maxdepth=md), guides=guides, title="", maxdepth=md)
else
return Tree(Dict("Length" => length(keys(x))), guides=guides, title="Vector of DICOMData", maxdepth=md)
end
end


end

0 comments on commit 3a2c125

Please sign in to comment.