Skip to content

Commit c73f942

Browse files
authored
Merge pull request #112 from JuliaRobotics/cherrypick/3Q19/lsWho
FEATURE backport lsWho, lsfWho
2 parents d956859 + bba7bb0 commit c73f942

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

src/Common.jl

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,71 @@ function lsTypes(dfg::G)::Dict{Symbol, Vector{String}} where G <: AbstractDFG
230230
end
231231
return alltypes
232232
end
233+
234+
235+
function ls(dfg::G, ::Type{T}; solveKey::Symbol=:default) where {G <: AbstractDFG, T <: InferenceVariable}
236+
xx = getVariables(dfg)
237+
mask = getVariableType.(xx, solveKey=solveKey) .|> typeof .== T
238+
vxx = view(xx, mask)
239+
map(x->x.label, vxx)
240+
end
241+
242+
243+
function ls(dfg::G, ::Type{T}) where {G <: AbstractDFG, T <: FunctorInferenceType}
244+
xx = getFactors(dfg)
245+
names = getfield.(typeof.(getFactorType.(xx)), :name) .|> Symbol
246+
vxx = view(xx, names .== Symbol(T))
247+
map(x->x.label, vxx)
248+
end
249+
250+
function lsf(dfg::G, ::Type{T}) where {G <: AbstractDFG, T <: FunctorInferenceType}
251+
ls(dfg, T)
252+
end
253+
254+
255+
"""
256+
$(SIGNATURES)
257+
Gives back all factor labels that fit the bill:
258+
lsWho(dfg, :Pose3)
259+
260+
Dev Notes
261+
- Cloud versions will benefit from less data transfer
262+
- `ls(dfg::C, ::T) where {C <: CloudDFG, T <: ..}`
263+
264+
Related
265+
266+
ls, lsf, lsfPriors
267+
"""
268+
function lsWho(dfg::AbstractDFG, type::Symbol; solveKey::Symbol=:default)::Vector{Symbol}
269+
vars = getVariables(dfg)
270+
labels = Symbol[]
271+
for v in vars
272+
varType = typeof(getVariableType(v, solveKey=solveKey)).name |> Symbol
273+
varType == type && push!(labels, v.label)
274+
end
275+
return labels
276+
end
277+
278+
279+
"""
280+
$(SIGNATURES)
281+
Gives back all factor labels that fit the bill:
282+
lsfWho(dfg, :Point2Point2)
283+
284+
Dev Notes
285+
- Cloud versions will benefit from less data transfer
286+
- `ls(dfg::C, ::T) where {C <: CloudDFG, T <: ..}`
287+
288+
Related
289+
290+
ls, lsf, lsfPriors
291+
"""
292+
function lsfWho(dfg::AbstractDFG, type::Symbol)::Vector{Symbol}
293+
facs = getFactors(dfg)
294+
labels = Symbol[]
295+
for f in facs
296+
facType = typeof(getFactorType(f)).name |> Symbol
297+
facType == type && push!(labels, f.label)
298+
end
299+
return labels
300+
end

0 commit comments

Comments
 (0)