Skip to content

Commit 9229e13

Browse files
committed
Refactoring and cleanup of DFG interface
1 parent 186618d commit 9229e13

File tree

5 files changed

+47
-25
lines changed

5 files changed

+47
-25
lines changed

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ getDescription(dfg::CloudGraphsDFG) = dfg.description
6363
setDescription(dfg::CloudGraphsDFG, description::String) = dfg.description = description
6464
getAddHistory(dfg::CloudGraphsDFG) = dfg.addHistory
6565
getSolverParams(dfg::CloudGraphsDFG) = dfg.solverParams
66-
function setSolverParams(dfg::CloudGraphsDFG, solverParams::T) where T <: AbstractParams
67-
dfg.solverParams = solverParams
66+
function setSolverParams(dfg::CloudGraphsDFG, solverParams::T)::T where T <: AbstractParams
67+
return dfg.solverParams = solverParams
6868
end
6969

7070
"""

src/Common.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
export sortVarNested
32
export isPrior, lsfPriors
43
export getData
@@ -7,6 +6,14 @@ export getFactorType, getfnctype
76
export lsTypes, lsfTypes
87
export lsWho, lsfWho
98

9+
## Utility functions for getting type names and modules (from IncrementalInference)
10+
function _getmodule(t::T) where T
11+
T.name.module
12+
end
13+
function _getname(t::T) where T
14+
T.name.name
15+
end
16+
1017
"""
1118
$(SIGNATURES)
1219
Test if all elements of the string is a number: Ex, "123" is true, "1_2" is false.

src/GraphsDFG/services/GraphsDFG.jl

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,20 @@ setDescription(dfg::GraphsDFG, description::String) = dfg.description = descript
2222
getInnerGraph(dfg::GraphsDFG) = dfg.g
2323
getAddHistory(dfg::GraphsDFG) = dfg.addHistory
2424
getSolverParams(dfg::GraphsDFG) = dfg.solverParams
25+
function setSolverParams(dfg::GraphsDFG, solverParams::T) where T <: AbstractParams
26+
dfg.solverParams = solverParams
27+
end
2528

26-
# setSolverParams(dfg::GraphsDFG, solverParams) = dfg.solverParams = solverParams
27-
function setSolverParams(dfg::GraphsDFG, solverParams::P) where P <: AbstractParams
28-
dfg.solverParams = solverParams
29+
"""
30+
$(SIGNATURES)
31+
Gets an empty and unique CloudGraphsDFG derived from an existing DFG.
32+
"""
33+
function _getDuplicatedEmptyDFG(dfg::GraphsDFG)::GraphsDFG
34+
newDfg = GraphsDFG{typeof(dfg.solverParams)}(;
35+
userId=dfg.userId, robotId=dfg.robotId, sessionId=dfg.sessionId,
36+
params=deepcopy(dfg.solverParams))
37+
newDfg.description ="(Copy of) $(dfg.description)"
38+
return newDfg
2939
end
3040

3141
"""
@@ -445,18 +455,6 @@ function getSubgraphAroundNode(dfg::GraphsDFG{P}, node::T, distance::Int64=1, in
445455
return addToDFG
446456
end
447457

448-
"""
449-
$(SIGNATURES)
450-
Gets an empty and unique CloudGraphsDFG derived from an existing DFG.
451-
"""
452-
function _getDuplicatedEmptyDFG(dfg::GraphsDFG)::GraphsDFG
453-
newDfg = GraphsDFG{typeof(dfg.solverParams)}(;
454-
userId=dfg.userId, robotId=dfg.robotId, sessionId=dfg.sessionId,
455-
params=deepcopy(dfg.solverParams))
456-
newDfg.description ="(Copy of) $(dfg.description)"
457-
return newDfg
458-
end
459-
460458
"""
461459
$(SIGNATURES)
462460
Get an adjacency matrix for the DFG, returned as a Matrix{Union{Nothing, Symbol}}.

src/services/AbstractDFG.jl

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
## ===== Interface for an AbstractDFG =====
12

23
"""
34
$(SIGNATURES)
@@ -25,15 +26,28 @@ function getSerializationModule(dfg::G)::Module where G <: AbstractDFG
2526
return Main
2627
end
2728

28-
## Utility functions for getting type names and modules (from IncrementalInference)
29-
function _getmodule(t::T) where T
30-
T.name.module
29+
# Accessors
30+
function getLabelDict(dfg::G) where G <: AbstractDFG
31+
error("getLabelDict not implemented for $(typeof(dfg))")
3132
end
32-
function _getname(t::T) where T
33-
T.name.name
33+
function getDescription(dfg::G) where G <: AbstractDFG
34+
error("getDescription not implemented for $(typeof(dfg))")
35+
end
36+
function setDescription(dfg::G, description::String) where G <: AbstractDFG
37+
error("setDescription not implemented for $(typeof(dfg))")
38+
end
39+
function getInnerGraph(dfg::G) where G <: AbstractDFG
40+
error("getInnerGraph not implemented for $(typeof(dfg))")
41+
end
42+
function getAddHistory(dfg::G) where G <: AbstractDFG
43+
error("getAddHistory not implemented for $(typeof(dfg))")
44+
end
45+
function getSolverParams(dfg::G) where G <: AbstractDFG
46+
error("getSolverParams not implemented for $(typeof(dfg))")
47+
end
48+
function setSolverParams(dfg::G, solverParams::T) where {G <: AbstractDFG, T <: AbstractParams}
49+
error("setSolverParams not implemented for $(typeof(dfg))")
3450
end
35-
36-
## Interface for an AbstractDFG
3751

3852
"""
3953
$(SIGNATURES)

test/interfaceTests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ end
9292
@test label(f1) == f1.label
9393
@test data(f1) == f1.data
9494
@test id(f1) == f1._internalId
95+
96+
@test getSolverParams(dfg) != nothing
97+
@test setSolverParams(dfg, getSolverParams(dfg)) == getSolverParams(dfg)
9598
end
9699

97100
# Connectivity test

0 commit comments

Comments
 (0)