Skip to content

Commit 04e6271

Browse files
committed
Implement AbstractTree interface
1 parent 6d99b6f commit 04e6271

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

Project.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ authors = ["nHackel <[email protected]> and contributors"]
44
version = "0.4.0"
55

66
[deps]
7+
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
78
LRUCache = "8ac3fa9e-de4c-5943-b1dc-09c6b5f20637"
89
Observables = "510215fc-4207-5dde-b226-833fc4488ee2"
910
Scratch = "6c6a2e73-6563-6170-7368-637461726353"
1011
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
1112
ThreadPools = "b189fb0b-2eb5-4ed4-bc0c-d34c51242431"
1213

1314
[compat]
15+
AbstractTrees = "0.4"
1416
LRUCache = "1.6"
1517
Observables = "0.5.5"
1618
Scratch = "1.2"
@@ -19,14 +21,14 @@ ThreadPools = "2.1"
1921
julia = "1.9"
2022

2123
[extras]
22-
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2324
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
2425
ImageGeoms = "9ee76f2b-840d-4475-b6d6-e485c9297852"
2526
ImagePhantoms = "71a99df6-f52c-4da1-bd2a-69d6f37f3252"
27+
LinearOperatorCollection = "a4a2c56f-fead-462a-a3ab-85921a5f2575"
2628
RadonKA = "86de8297-835b-47df-b249-c04e8db91db5"
2729
RegularizedLeastSquares = "1e9c538a-f78c-5de5-8ffb-0b6dbe892d23"
28-
LinearOperatorCollection = "a4a2c56f-fead-462a-a3ab-85921a5f2575"
2930
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
31+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3032

3133
[targets]
3234
test = ["Test", "RadonKA", "ImagePhantoms", "ImageGeoms", "CairoMakie", "LinearOperatorCollection", "RegularizedLeastSquares", "Statistics"]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
[![](https://img.shields.io/badge/docs-latest-blue.svg)](https://JuliaImageRecon.github.io/AbstractImageReconstruction.jl)
66

7-
[![codecov.io](http://codecov.io/github/JuliaImageRecon/AbstractImageReconstruction.jl/coverage.svg?branch=master)](http://codecov.io/github/JuliaImageRecon/AbstractImageReconstruction.jl?branch=master)
7+
[![codecov.io](http://codecov.io/github/JuliaImageRecon/AbstractImageReconstruction.jl/coverage.svg?branch=main)](http://codecov.io/github/JuliaImageRecon/AbstractImageReconstruction.jl?branch=main)
88

99

1010
This package contains an interface and type hierarchy for image reconstruction algorithms and their parameters, together with associated utility tools.

src/AbstractImageReconstruction.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ using ThreadPools
55
using Observables
66
using Scratch
77
using LRUCache
8+
using AbstractTrees
89

10+
import AbstractTrees: parent, children
911
import Base: put!, take!, fieldtypes, fieldtype, ismissing, propertynames, parent, hash, wait, isready, lock, unlock
1012

1113
include("AlgorithmInterface.jl")

src/RecoPlans/RecoPlans.jl

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,24 @@ Return the `Observable` for the `name` property of `plan`. Equivalent to `plan[n
6060
"""
6161
Base.getindex(plan::RecoPlan{T}, name::Symbol) where {T} = getfield(plan, :values)[name]
6262

63+
# Tree Interface
64+
"""
65+
parent(plan::RecoPlan)
66+
67+
Return the parent of `plan`.
68+
"""
69+
AbstractTrees.parent(plan::RecoPlan) = getfield(plan, :parent)
70+
AbstractTrees.ParentLinks(::Type{<:RecoPlan}) = AbstractTrees.StoredParents()
71+
function AbstractTrees.children(plan::RecoPlan)
72+
result = Vector{RecoPlan}()
73+
for prop in propertynames(plan)
74+
if getproperty(plan, prop) isa RecoPlan
75+
push!(result, getproperty(plan, prop))
76+
end
77+
end
78+
return result
79+
end
80+
6381
export types, type
6482
types(::AbstractRecoPlan{T}) where {T<:AbstractImageReconstructionParameters} = fieldtypes(T)
6583
type(::AbstractRecoPlan{T}, name::Symbol) where {T<:AbstractImageReconstructionParameters} = fieldtype(T, name)
@@ -179,13 +197,7 @@ end
179197
clear!(plan::RecoPlan{T}, preserve::Bool = true) where {T<:AbstractImageReconstructionAlgorithm} = clear!(plan.parameter, preserve)
180198

181199

182-
export parent, parent!, parentproperty, parentproperties
183-
"""
184-
parent(plan::RecoPlan)
185-
186-
Return the parent of `plan`.
187-
"""
188-
parent(plan::RecoPlan) = getfield(plan, :parent)
200+
export parent!, parentproperty, parentproperties
189201
"""
190202
parent!(plan::RecoPlan, parent::RecoPlan)
191203

0 commit comments

Comments
 (0)