diff options
Diffstat (limited to 'julia/CrystFEL')
-rw-r--r-- | julia/CrystFEL/src/CrystFEL.jl | 2 | ||||
-rw-r--r-- | julia/CrystFEL/src/detgeom.jl | 140 | ||||
-rw-r--r-- | julia/CrystFEL/src/image.jl | 7 | ||||
-rw-r--r-- | julia/CrystFEL/src/indexing.jl | 3 |
4 files changed, 137 insertions, 15 deletions
diff --git a/julia/CrystFEL/src/CrystFEL.jl b/julia/CrystFEL/src/CrystFEL.jl index 9ab5d15f..bb1f1534 100644 --- a/julia/CrystFEL/src/CrystFEL.jl +++ b/julia/CrystFEL/src/CrystFEL.jl @@ -38,7 +38,7 @@ export rotatecell, compare_reindexed_cell_parameters include("detgeom.jl") using .DetGeoms -export Panel, DetGeom +export Panel, DetGeom, DetGeomPanel, DetGeomGroup, findgroup include("symmetry.jl") using .Symmetry diff --git a/julia/CrystFEL/src/detgeom.jl b/julia/CrystFEL/src/detgeom.jl index ba943d98..d8dc5972 100644 --- a/julia/CrystFEL/src/detgeom.jl +++ b/julia/CrystFEL/src/detgeom.jl @@ -1,7 +1,8 @@ module DetGeoms -export Panel +export DetGeom, DetGeomPanel, DetGeomGroup, InternalDetGeom, copydetgeom +export findgroup -mutable struct Panel +mutable struct InternalPanel name::Cstring cx::Cdouble cy::Cdouble @@ -21,27 +22,144 @@ mutable struct Panel end -mutable struct DetGeom - panels::Ptr{Panel} +mutable struct InternalDetGeomPanelGroup + name::Cstring + n_children::Cint + parent::Ptr{InternalDetGeomPanelGroup} + serial::Cint + cx::Cdouble + cy::Cdouble + cz::Cdouble + children::Ptr{Ptr{InternalDetGeomPanelGroup}} + panel::Ptr{InternalPanel} +end + + +mutable struct InternalDetGeom + panels::Ptr{InternalPanel} n_panels::Cint - top_group::Ptr{Cvoid} + top_group::Ptr{InternalDetGeomPanelGroup} end -function Base.show(io::IO, p::Panel) +mutable struct DetGeomPanel + name + corner + fsvec + ssvec + pixel_pitch + adu_per_photon + max_adu + w + h +end + +struct DetGeomGroup + serial + name + children + center # For rotation +end + + +mutable struct DetGeom + panels::Vector{DetGeomPanel} + topgroup::DetGeomGroup +end + + +function copy_dg_panel(p::InternalPanel) + DetGeomPanel(unsafe_string(p.name), + [p.cx, p.cy, p.cz], + [p.fsx, p.fsy, p.fsz], + [p.ssx, p.ssy, p.ssz], + p.pixel_pitch, p.adu_per_photon, p.max_adu, + p.w, p.h) +end + + +function copydggroup(panels, grp) + grpdata = unsafe_load(grp, 1) + name = unsafe_string(grpdata.name) + children = DetGeomGroup[] + if grpdata.n_children > 1 + for i in 1:grpdata.n_children + cdata = unsafe_load(grpdata.children, i) + push!(children, copydggroup(panels, cdata)) + end + DetGeomGroup(grpdata.serial, name, children, + [grpdata.cx, grpdata.cy, grpdata.cz]) + else + name = unsafe_string(grpdata.name) + pn = findfirst(x->x.name==name, panels) + DetGeomGroup(grpdata.serial, name, [panels[pn]], + [grpdata.cx, grpdata.cy, grpdata.cz]) + end +end + + +function copydetgeom(dg::Ptr{InternalDetGeom}) + dgdata = unsafe_load(dg, 1) + panels = DetGeomPanel[] + for i in 1:dgdata.n_panels + paneldata = unsafe_load(dgdata.panels, i) + push!(panels, copy_dg_panel(paneldata)) + end + topgroup = copydggroup(panels, dgdata.top_group) + DetGeom(panels, topgroup) +end + + +function seq100(ser, head) + if ser == 0 + () + elseif ser < 100 + (head...,ser % 100) + else + seq100(ser ÷ 100, (head..., ser % 100)) + end +end + +findgroup(dg::DetGeom, ser) = findgroup(dg.topgroup, ser, seq100(ser÷100, ())) + +function findgroup(group::DetGeomGroup, ser, path) + if length(path) == 0 + @assert(group.serial == ser) + return group + end + findgroup(group.children[path[1]], ser, path[2:end]) +end + + +function Base.show(io::IO, p::DetGeomPanel) write(io, "Panel(") write(io, "name=\"") - write(io, unsafe_string(p.name)) - write(io, "\", center=(") - show(io, p.cx); write(io, ", "); show(io, p.cy); write(io, ", "); show(io, p.cz) + write(io, p.name) + write(io, "\", corner=") + show(io, p.corner) write(io, "), fs=(") - show(io, p.fsx); write(io, ", "); show(io, p.fsy); write(io, ", "); show(io, p.fsz) + show(io, p.fsvec) write(io, "), ss=(") - show(io, p.ssx); write(io, ", "); show(io, p.ssy); write(io, ", "); show(io, p.ssz) + show(io, p.ssvec) write(io, "), size=(") show(io, p.w); write(io, ", "); show(io, p.h) write(io, "))") end +function showgroup(io, p::DetGeomPanel, prefix) + println(io, prefix, "Panel ", p.name, " (",p.w,"×",p.h,")") +end + +function showgroup(io, grp::DetGeomGroup, prefix) + println(io, prefix, "Group ", grp.name, " (serial number ", grp.serial, ")") + for child in grp.children + showgroup(io, child, prefix*" ") + end +end + +function Base.show(io::IO, ::MIME"text/plain", dg::DetGeom) + println(io, "Detector geometry structure with ", length(dg.panels), " panels") + showgroup(io, dg.topgroup, " ") +end end # of module diff --git a/julia/CrystFEL/src/image.jl b/julia/CrystFEL/src/image.jl index d648dba4..cd24ce01 100644 --- a/julia/CrystFEL/src/image.jl +++ b/julia/CrystFEL/src/image.jl @@ -4,7 +4,7 @@ using Printf import ..CrystFEL: libcrystfel import ..CrystFEL.DataTemplates: DataTemplate, InternalDataTemplate -import ..CrystFEL.DetGeoms: DetGeom +import ..CrystFEL.DetGeoms: InternalDetGeom, copydetgeom import ..CrystFEL.PeakLists: PeakList, InternalPeakList import ..CrystFEL.Crystals: Crystal, InternalCrystal import ..CrystFEL.RefLists: RefList, InternalRefList, UnmergedReflection @@ -29,7 +29,7 @@ mutable struct InternalImage n_crystals::Cint indexed_by::Cint n_indexing_tries::Cint - detgeom::Ptr{DetGeom} + detgeom::Ptr{InternalDetGeom} data_source_type::Cint filename::Cstring ev::Cstring @@ -135,6 +135,9 @@ function Base.getproperty(image::Image, name::Symbol) getfield(idata, :crystals), getfield(idata, :n_crystals)) + elseif name === :detgeom + return copydetgeom(getfield(idata, :detgeom)) + else getfield(idata, name) end diff --git a/julia/CrystFEL/src/indexing.jl b/julia/CrystFEL/src/indexing.jl index 543246ec..81a59b52 100644 --- a/julia/CrystFEL/src/indexing.jl +++ b/julia/CrystFEL/src/indexing.jl @@ -144,7 +144,8 @@ function index(image::Image, idxr::Indexer; mille=nothing) idxr.indexingpriv::Ptr{IndexingPriv}, C_NULL::Ptr{Cvoid}, C_NULL::Ptr{Cvoid}, - imille::Ptr{Cvoid})::Cvoid + imille::Ptr{Cvoid}, + 99::Cint)::Cvoid end |