1
-
2
- # #==============================================================================
3
- # # Blobentry - compare
4
- # #==============================================================================
5
-
6
- import Base: ==
7
-
8
- @generated function == (x:: T , y:: T ) where {T <: Blobentry }
9
- return mapreduce (n -> :(x.$ n == y.$ n), (a, b) -> :($ a && $ b), fieldnames (x))
10
- end
11
-
12
1
# #==============================================================================
13
2
# # Blobentry - common
14
3
# #==============================================================================
@@ -85,49 +74,26 @@ Finds and returns the first blob entry that matches the filter.
85
74
86
75
Also see: [`getBlobentry`](@ref)
87
76
"""
88
- function getfirstBlobentry (var:: AbstractGraphVariable , blobId:: UUID )
89
- for (k, v) in var. dataDict
90
- if blobId == v. blobId
91
- return v
92
- end
93
- end
94
- throw (KeyError (" No blobEntry with blobId $(blobId) found in variable $(getLabel (var)) " ))
95
- end
96
-
97
- function getfirstBlobentry (dfg:: AbstractDFG , label:: Symbol , blobId:: UUID )
98
- return getfirstBlobentry (getVariable (dfg, label), blobId)
99
- end
100
-
101
- function getfirstBlobentry (var:: AbstractGraphVariable , key:: Regex )
102
- for (k, v) in var. dataDict
103
- if occursin (key, string (v. label))
104
- return v
105
- end
106
- end
107
- throw (
108
- KeyError (
109
- " No blobEntry with label matching regex $(key) found in variable $(getLabel (var)) " ,
110
- ),
111
- )
112
- end
113
-
114
- function getfirstBlobentry (var:: VariableDFG , key:: Regex )
115
- firstIdx = findfirst (x -> contains (string (x. label), key), var. blobEntries)
116
- if isnothing (firstIdx)
117
- throw (KeyError (" $key " ))
77
+ function getfirstBlobentry (
78
+ v:: AbstractGraphVariable ;
79
+ labelFilter:: Union{Nothing, Function} = nothing ,
80
+ blobIdFilter:: Union{Nothing, Function} = nothing ,
81
+ )
82
+ entries = getBlobentries (v; labelFilter, blobIdFilter)
83
+ if isempty (entries)
84
+ return nothing
85
+ else
86
+ return entries[1 ]
118
87
end
119
- return var. blobEntries[firstIdx]
120
88
end
121
89
122
- function getfirstBlobentry (dfg:: AbstractDFG , label:: Symbol , key:: Regex )
123
- els = listBlobentries (dfg, label)
124
- firstIdx = findfirst (contains (key), string .(els))
125
- isnothing (firstIdx) && throw (
126
- KeyError (
127
- " No blobEntry with label matching regex $(key) found in variable $(label) " ,
128
- ),
129
- )
130
- return getBlobentry (dfg, label, els[firstIdx])
90
+ function getfirstBlobentry (
91
+ dfg:: AbstractDFG ,
92
+ label:: Symbol ;
93
+ labelFilter:: Union{Nothing, Function} = nothing ,
94
+ blobIdFilter:: Union{Nothing, Function} = nothing ,
95
+ )
96
+ return getfirstBlobentry (getVariable (dfg, label); labelFilter, blobIdFilter)
131
97
end
132
98
133
99
# TODO Consider autogenerating all methods of the form:
@@ -140,22 +106,18 @@ end
140
106
# @eval DistributedFactorGraphs $met(dfg::AbstractDFG, label::Symbol, args...; kwargs...) = $met(getVariable(dfg, label), args...; kwargs...)
141
107
# end
142
108
143
- function getBlobentry (dfg:: AbstractDFG , label :: Symbol , key :: Symbol )
144
- return getBlobentry (getVariable (dfg, label ), key )
109
+ function getBlobentry (dfg:: AbstractDFG , varLabel :: Symbol , label :: Symbol )
110
+ return getBlobentry (getVariable (dfg, varLabel ), label )
145
111
end
146
- # getBlobentry(dfg::AbstractDFG, label::Symbol, key::Symbol) = getBlobentry(getVariable(dfg, label), key)
147
112
148
113
"""
149
114
$(SIGNATURES)
150
- Add Data Entry to a DFG variable
115
+ Add a `Blobentry` to a variable
151
116
Should be extended if DFG variable is not returned by reference.
152
117
153
- Also see: [`getBlobentry`](@ref), [`addBlob!`](@ref), [`mergeBlobentries !`](@ref)
118
+ Also see: [`getBlobentry`](@ref), [`addBlob!`](@ref), [`mergeBlobentry !`](@ref)
154
119
"""
155
- function addBlobentry! (var:: AbstractGraphVariable , entry:: Blobentry )
156
- # see https://github.com/JuliaRobotics/DistributedFactorGraphs.jl/issues/985
157
- # blobId::Union{UUID,Nothing} = (isnothing(entry.blobId) ? entry.id : entry.blobId),
158
- # blobSize::Int = (hasfield(Blobentry, :size) ? entry.size : -1)
120
+ function addBlobentry! (var:: VariableCompute , entry:: Blobentry )
159
121
haskey (var. dataDict, entry. label) && throw (LabelExistsError (" Blobentry" , entry. label))
160
122
var. dataDict[entry. label] = entry
161
123
return entry
@@ -197,37 +159,28 @@ end
197
159
198
160
"""
199
161
$(SIGNATURES)
200
- Delete a blob entry from the factor graph.
201
- Note this doesn't remove it from any data stores.
162
+ Delete a `Blobentry` from the factor graph variable.
202
163
203
164
Notes:
204
- - users responsibility to delete data in db before deleting entry
165
+ - This doesn't remove the associated `Blob` from any Blobstores.
205
166
"""
206
- function deleteBlobentry! (var:: AbstractGraphVariable , key:: Symbol )
207
- pop! (var. dataDict, key)
167
+ function deleteBlobentry! (var:: VariableCompute , key:: Symbol )
168
+ ! hasBlobentry (var, key) && throw (LabelNotFoundError (" Blobentry" , key))
169
+ delete! (var. dataDict, key)
208
170
return 1
209
171
end
210
172
211
173
function deleteBlobentry! (var:: VariableDFG , key:: Symbol )
212
- if ! hasBlobentry (var, key)
213
- throw (
214
- KeyError (
215
- " No dataEntry label $(key) found in variable $(getLabel (var)) . Available keys: $(keys (var. dataDict)) " ,
216
- ),
217
- )
218
- end
174
+ ! hasBlobentry (var, key) && throw (LabelNotFoundError (" Blobentry" , key))
219
175
deleteat! (var. blobEntries, findfirst (x -> x. label == key, var. blobEntries))
220
176
return 1
221
177
end
222
178
223
179
function deleteBlobentry! (dfg:: AbstractDFG , label:: Symbol , key:: Symbol )
224
- # users responsibility to delete data in db before deleting entry
225
- # !isVariable(dfg, label) && return nothing
226
180
return deleteBlobentry! (getVariable (dfg, label), key)
227
181
end
228
182
229
183
function deleteBlobentry! (var:: AbstractGraphVariable , entry:: Blobentry )
230
- # users responsibility to delete data in db before deleting entry
231
184
return deleteBlobentry! (var, entry. label)
232
185
end
233
186
@@ -240,73 +193,66 @@ end
240
193
241
194
Does a blob entry exist with `blobLabel`.
242
195
"""
243
- hasBlobentry (var:: AbstractGraphVariable , blobLabel:: Symbol ) =
244
- haskey (var. dataDict, blobLabel)
196
+ hasBlobentry (v:: VariableCompute , blobLabel:: Symbol ) = haskey (v. dataDict, blobLabel)
245
197
246
- function hasBlobentry (var :: VariableDFG , label:: Symbol )
247
- return label in getproperty .(var . blobEntries, :label )
198
+ function hasBlobentry (v :: VariableDFG , label:: Symbol )
199
+ return label in getproperty .(v . blobEntries, :label )
248
200
end
249
201
250
202
"""
251
203
$(SIGNATURES)
252
204
253
- Get blob entries, Vector{Blobentry}
205
+ Get blob entries, returns a ` Vector{Blobentry}`.
254
206
"""
255
- function getBlobentries (var:: AbstractGraphVariable )
256
- # or should we return the iterator, Base.ValueIterator{Dict{Symbol,Blobentry}}?
257
- return collect (values (var. dataDict))
207
+ function getBlobentries (v:: VariableCompute )
208
+ return collect (values (v. dataDict))
258
209
end
259
210
260
- function getBlobentries (var :: VariableDFG )
261
- return var . blobEntries
211
+ function getBlobentries (v :: VariableDFG )
212
+ return copy (v . blobEntries)
262
213
end
263
214
264
- function getBlobentries (dfg:: AbstractDFG , label:: Symbol )
265
- # !isVariable(dfg, label) && return nothing
266
- # or should we return the iterator, Base.ValueIterator{Dict{Symbol,Blobentry}}?
267
- return getBlobentries (getVariable (dfg, label))
268
- end
269
-
270
- function getBlobentries (dfg:: AbstractDFG , label:: Symbol , regex:: Regex )
271
- entries = getBlobentries (dfg, label)
272
- return filter (entries) do e
273
- return occursin (regex, string (e. label))
274
- end
215
+ function getBlobentries (
216
+ v:: AbstractGraphVariable ;
217
+ labelFilter:: Union{Nothing, Function} = nothing ,
218
+ blobIdFilter:: Union{Nothing, Function} = nothing ,
219
+ )
220
+ entries = getBlobentries (v)
221
+ filterDFG! (entries, labelFilter, x -> string (x. label))
222
+ filterDFG! (entries, blobIdFilter, x -> string (x. blobId))
223
+ return entries
275
224
end
276
225
277
226
function getBlobentries (
278
227
dfg:: AbstractDFG ,
279
- label:: Symbol ,
280
- skey:: Union{Symbol, <:AbstractString} ,
228
+ variableLabel:: Symbol ;
229
+ labelFilter:: Union{Nothing, Function} = nothing ,
230
+ blobIdFilter:: Union{Nothing, Function} = nothing ,
281
231
)
282
- return getBlobentries (dfg, label, Regex ( string (skey)) )
232
+ return getBlobentries (getVariable ( dfg, variableLabel); labelFilter, blobIdFilter )
283
233
end
284
234
285
- """
286
- $(SIGNATURES)
287
-
288
- Get all blob entries matching a Regex pattern over variables
289
-
290
- Notes
291
- - Use `dropEmpties=true` to not include empty lists in result.
292
- - Use keyword `varList` for which variables to search through.
293
- """
294
- function getBlobentriesVariables (
295
- dfg:: AbstractDFG ,
296
- bLblPattern:: Regex ;
297
- varList:: AbstractVector{Symbol} = sort (listVariables (dfg); lt = natural_lt),
298
- dropEmpties:: Bool = false ,
235
+ function gatherBlobentries (
236
+ dfg:: AbstractDFG ;
237
+ labelFilter:: Union{Nothing, Function} = nothing ,
238
+ blobIdFilter:: Union{Nothing, Function} = nothing ,
239
+ solvableFilter:: Union{Nothing, Function} = nothing ,
240
+ tagsFilter:: Union{Nothing, Function} = nothing ,
241
+ typeFilter:: Union{Nothing, Function} = nothing ,
242
+ variableLabelFilter:: Union{Nothing, Function} = nothing ,
299
243
)
300
- RETLIST = Vector {Vector{Blobentry}} ()
301
- @showprogress " Get entries matching $bLblPattern " for vl in varList
302
- bes = filter (s -> occursin (bLblPattern, string (s. label)), listBlobentries (dfg, vl))
303
- # only push to list if there are entries on this variable
304
- (! dropEmpties || 0 < length (bes)) ? nothing : continue
305
- push! (RETLIST, bes)
244
+ vls = listVariables (
245
+ dfg;
246
+ solvableFilter,
247
+ tagsFilter,
248
+ typeFilter,
249
+ labelFilter = variableLabelFilter,
250
+ )
251
+ return map (vls) do vl
252
+ return vl => getBlobentries (dfg, vl; labelFilter, blobIdFilter)
306
253
end
307
-
308
- return RETLIST
309
254
end
255
+ const collectBlobentries = gatherBlobentries
310
256
311
257
"""
312
258
$(SIGNATURES)
@@ -321,7 +267,6 @@ function listBlobentries(var::VariableDFG)
321
267
end
322
268
323
269
function listBlobentries (dfg:: AbstractDFG , label:: Symbol )
324
- # !isVariable(dfg, label) && return nothing
325
270
return listBlobentries (getVariable (dfg, label))
326
271
end
327
272
@@ -357,66 +302,6 @@ function listBlobentrySequence(
357
302
return ents_[findall (entMsk)] |> _sort
358
303
end
359
304
360
- """
361
- $SIGNATURES
362
-
363
- Add a blob entry into the destination variable which already exists
364
- in a source variable.
365
-
366
- See also: [`addBlobentry!`](@ref), [`getBlobentry`](@ref), [`listBlobentries`](@ref), [`getBlob`](@ref)
367
- """
368
- function mergeBlobentries! (
369
- dst:: AbstractDFG ,
370
- dlbl:: Symbol ,
371
- src:: AbstractDFG ,
372
- slbl:: Symbol ,
373
- bllb:: Union{Symbol, UUID, <:AbstractString, Regex} ,
374
- )
375
- #
376
- _makevec (s) = [s;]
377
- _makevec (s:: AbstractVector ) = s
378
- des_ = getBlobentry (src, slbl, bllb)
379
- des = _makevec (des_)
380
- # don't add data entries that already exist
381
- dde = listBlobentries (dst, dlbl)
382
- # HACK, verb list should just return vector of Symbol. NCE36
383
- _getid (s) = s
384
- _getid (s:: Blobentry ) = s. id
385
- uids = _getid .(dde) # (s->s.id).(dde)
386
- filter! (s -> ! (_getid (s) in uids), des)
387
- # add any data entries not already in the destination variable, by uuid
388
- return addBlobentry! .(dst, dlbl, des)
389
- end
390
-
391
- function mergeBlobentries! (
392
- dst:: AbstractDFG ,
393
- dlbl:: Symbol ,
394
- src:: AbstractDFG ,
395
- slbl:: Symbol ,
396
- :: Colon = :,
397
- )
398
- des = listBlobentries (src, slbl)
399
- # don't add data entries that already exist
400
- uids = listBlobentries (dst, dlbl)
401
- # verb list should just return vector of Symbol. NCE36
402
- filter! (s -> ! (s in uids), des)
403
- if 0 < length (des)
404
- union (((s -> mergeBlobentries! (dst, dlbl, src, slbl, s)). (des)). .. )
405
- end
406
- end
407
-
408
- function mergeBlobentries! (
409
- dest:: AbstractDFG ,
410
- src:: AbstractDFG ,
411
- w... ;
412
- varList:: AbstractVector = listVariables (dest) |> sortDFG,
413
- )
414
- @showprogress 1 " merging data entries" for vl in varList
415
- mergeBlobentries! (dest, vl, src, vl, w... )
416
- end
417
- return varList
418
- end
419
-
420
305
"""
421
306
$SIGNATURES
422
307
0 commit comments