Skip to content

Commit 3a2c125

Browse files
committed
ordereddict and logo
1 parent e4bd65c commit 3a2c125

File tree

4 files changed

+52
-41
lines changed

4 files changed

+52
-41
lines changed

DICOMTree_logo.png

20 KB
Loading

Project.toml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ version = "0.1.0"
55

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

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# DICOMTree
22

3-
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.
3+
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.
44
The package have been tested with CT Scanner, RTDose and RTStruct files.
55

6+
<p align="center">
7+
<img src="DICOMTree_logo.png" alt="DICOMTree Logo" width="100">
8+
</p>
9+
610
## Documentation & installation
711

812
Install with:

src/DICOMTree.jl

+46-40
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
module DICOMTree
22
import Term.Trees: Tree, TreeCharSet, print_node, print_key, Theme, TERM_THEME, _TREE_PRINTING_TITLE
33
import Term.Style: apply_style
4+
45
using DICOM
6+
using OrderedCollections: OrderedDict
57

68
export Tree
79

@@ -68,55 +70,25 @@ function Tree(
6870
title::Union{String,Nothing}="",
6971
prefix::String=" ",
7072
kwargs...
71-
)
73+
)::Tree
74+
7275
_TREE_PRINTING_TITLE[] = title
7376
_theme = TERM_THEME[]
7477
TERM_THEME[] = theme
7578

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

78-
format(x, md) = x
79-
80-
function format(x::AbstractArray, md)::Tree
81-
return (Tree(Dict("Size" => string(size(x)), "Type" => typeof(x)),
82-
guides=guides,
83-
title="Array",
84-
maxdepth=md))
85-
end
86-
87-
function format(x::Vector, md)::Tree
88-
if length(x) <= 6
89-
return Tree(string(x), guides=guides)
90-
else
91-
return Tree(Dict("Length" => length(x),
92-
"ElementsType" => eltype(x),
93-
"Overview" => string(x[begin:begin+2])[1:end-1] * ", ..., " * string(x[end-3:end-1])[2:end]), guides=guides, title="Vector", maxdepth=md)
94-
end
95-
end
96-
97-
function format(x::DICOM.DICOMData, md)::Tree
98-
return Tree(x.meta, guides=guides, title="", maxdepth=md)
99-
end
100-
101-
function format(x::Vector{DICOM.DICOMData}, md)::Tree
102-
if md >= 2
103-
return Tree(Tree.(x, with_keys=with_keys, guides=guides, title="", maxdepth=md), guides=guides, title="", maxdepth=md)
104-
else
105-
return Tree(Dict("Length" => length(keys(x))), guides=guides, title="Vector of DICOMData", maxdepth=md)
106-
end
107-
end
108-
109-
110-
tree = Dict()
111-
11281
if with_keys
113-
for symbol in keys(dicom.meta)
114-
tree[symbol] = format(dicom[symbol], md - 1)
82+
tree = OrderedDict{Tuple{UInt16, UInt16}, Any}()
83+
tag_keys = keys(sort(dicom.meta))
84+
for symbol in tag_keys
85+
tree[symbol] = _format(dicom[symbol], md - 1, guides, with_keys)
11586
end
11687
else
117-
tag_names = get_name_from_tag.(keys(dicom.meta))
88+
tree = OrderedDict{Symbol, Any}()
89+
tag_names = get_name_from_tag.(keys(sort(dicom.meta)))
11890
for symbol in tag_names
119-
tree[symbol] = format(dicom[symbol], md - 1)
91+
tree[symbol] = _format(dicom[symbol], md - 1, guides, with_keys)
12092
end
12193
end
12294

@@ -141,9 +113,43 @@ function Tree(
141113
title::Union{String,Nothing}="",
142114
prefix::String=" ",
143115
kwargs...
144-
)
116+
)::Tree
145117
md = haskey(kwargs, :maxdepth) ? kwargs[:maxdepth] : 2
146118
return Tree(Tree.(dicom_vector, with_keys=with_keys, guides=guides, title="", maxdepth=md), guides=guides, title="", maxdepth=md)
147119
end
148120

121+
122+
_format(x, md, guides, with_keys) = x
123+
124+
function _format(x::AbstractArray, md, guides, with_keys)::Tree
125+
return (Tree(Dict("Size" => string(size(x)), "Type" => typeof(x)),
126+
guides=guides,
127+
title="Array",
128+
maxdepth=md))
129+
end
130+
131+
function _format(x::Vector, md, guides, with_keys)::Tree
132+
if length(x) <= 6
133+
return Tree(string(x), guides=guides)
134+
else
135+
return Tree(Dict("Length" => length(x),
136+
"ElementsType" => eltype(x),
137+
"Overview" => string(x[begin:begin+2])[1:end-1] * ", ..., " * string(x[end-3:end-1])[2:end]), guides=guides, title="Vector", maxdepth=md)
138+
end
139+
end
140+
141+
function _format(x::DICOM.DICOMData, md, guides, with_keys)::Tree
142+
return Tree(x.meta, guides=guides, title="", maxdepth=md)
149143
end
144+
145+
function _format(x::Vector{DICOM.DICOMData}, md, guides, with_keys)::Tree
146+
if md >= 2
147+
return Tree(Tree.(x, with_keys=with_keys, guides=guides, title="", maxdepth=md), guides=guides, title="", maxdepth=md)
148+
else
149+
return Tree(Dict("Length" => length(keys(x))), guides=guides, title="Vector of DICOMData", maxdepth=md)
150+
end
151+
end
152+
153+
154+
end
155+

0 commit comments

Comments
 (0)