Skip to content

Commit 17dbcca

Browse files
authored
Merge pull request #385 from JuliaRobotics/maint/20Q2/graphsmodule
Change GraphsDFG to module
2 parents 84bfe96 + 9c70fa3 commit 17dbcca

File tree

5 files changed

+67
-20
lines changed

5 files changed

+67
-20
lines changed

src/DistributedFactorGraphs.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ include("services/AbstractDFG.jl")
249249

250250
# In Memory Types
251251
include("GraphsDFG/GraphsDFG.jl")
252+
@reexport using .GraphsDFGs
252253
include("LightDFG/LightDFG.jl")
253254
@reexport using .LightDFGs
254255
#supported in Memory fg types

src/GraphsDFG/GraphsDFG.jl

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,49 @@
1+
module GraphsDFGs
2+
13
using Graphs
4+
using DocStringExtensions
5+
6+
using ...DistributedFactorGraphs
7+
8+
# import DFG functions to extend
9+
import ...DistributedFactorGraphs: setSolverParams!,
10+
getFactor,
11+
setDescription!,
12+
# getLabelDict,
13+
getUserData,
14+
setUserData!,
15+
getRobotData,
16+
setRobotData!,
17+
getSessionData,
18+
setSessionData!,
19+
addVariable!,
20+
getVariable,
21+
getAddHistory,
22+
addFactor!,
23+
getSolverParams,
24+
exists,
25+
isVariable,
26+
isFactor,
27+
getDescription,
28+
updateVariable!,
29+
updateFactor!,
30+
deleteVariable!,
31+
deleteFactor!,
32+
getVariables,
33+
listVariables,
34+
ls,
35+
getFactors,
36+
listFactors,
37+
lsf,
38+
isFullyConnected,
39+
hasOrphans,
40+
getNeighbors,
41+
buildSubgraph,
42+
copyGraph!,
43+
getBiadjacencyMatrix,
44+
_getDuplicatedEmptyDFG,
45+
toDot,
46+
toDotFile
247

348
# Imports
449
include("entities/GraphsDFG.jl")
@@ -7,4 +52,4 @@ include("services/GraphsDFG.jl")
752
# Exports
853
export GraphsDFG
954

10-
export toDot, toDotFile
55+
end

src/GraphsDFG/services/GraphsDFG.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,10 @@ Produces a dot-format of the graph for visualization.
266266
function toDot(dfg::GraphsDFG)::String
267267
return Graphs.to_dot(dfg.g)
268268
end
269+
270+
function toDotFile(dfg::GraphsDFG, fileName::String="/tmp/dfg.dot")::Nothing
271+
open(fileName, "w") do fid
272+
write(fid, Graphs.to_dot(dfg.g))
273+
end
274+
return nothing
275+
end

src/services/AbstractDFG.jl

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,18 +1086,17 @@ end
10861086

10871087

10881088
##==============================================================================
1089-
## DOT Files, falls back to GraphsDFG
1089+
## DOT Files, falls back to LightDFG dot functions
10901090
##==============================================================================
10911091
"""
10921092
$(SIGNATURES)
10931093
Produces a dot-format of the graph for visualization.
10941094
"""
10951095
function toDot(dfg::AbstractDFG)::String
1096-
#TODO implement convert
1097-
graphsdfg = GraphsDFG{NoSolverParams}()
1098-
copyGraph!(graphsdfg, dfg, listVariables(dfg), listFactors(dfg))
1099-
# Calls down to GraphsDFG.toDot
1100-
return toDot(graphsdfg)
1096+
#convert to LightDFG
1097+
ldfg = LightDFG{NoSolverParams}()
1098+
copyGraph!(ldfg, dfg, listVariables(dfg), listFactors(dfg))
1099+
return toDot(ldfg)
11011100
end
11021101

11031102
"""
@@ -1111,18 +1110,12 @@ Note
11111110
- Based on graphviz.org
11121111
"""
11131112
function toDotFile(dfg::AbstractDFG, fileName::String="/tmp/dfg.dot")::Nothing
1114-
#TODO implement convert
1115-
if isa(dfg, GraphsDFG)
1116-
graphsdfg = dfg
1117-
else
1118-
graphsdfg = GraphsDFG{NoSolverParams}()
1119-
copyGraph!(graphsdfg, dfg, listVariables(dfg), listFactors(dfg))
1120-
end
11211113

1122-
open(fileName, "w") do fid
1123-
write(fid,Graphs.to_dot(graphsdfg.g))
1124-
end
1125-
return nothing
1114+
#convert to LightDFG
1115+
ldfg = LightDFG{NoSolverParams}()
1116+
copyGraph!(ldfg, dfg, listVariables(dfg), listFactors(dfg))
1117+
1118+
return toDotFile(ldfg, fileName)
11261119
end
11271120

11281121
##==============================================================================

test/iifInterfaceTests.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ end
1919
@testset "Producing Dot Files" begin
2020
global dfg
2121
todotstr = toDot(dfg)
22-
#TODO consider using a regex, but for now test both orders
22+
#TODO consider using a regex, but for now test all orders
2323
todota = todotstr == "graph graphname {\n2 [\"label\"=\"a\",\"shape\"=\"ellipse\",\"fillcolor\"=\"red\",\"color\"=\"red\"]\n2 -- 3\n3 [\"label\"=\"abf1\",\"shape\"=\"box\",\"fillcolor\"=\"blue\",\"color\"=\"blue\"]\n1 [\"label\"=\"b\",\"shape\"=\"ellipse\",\"fillcolor\"=\"red\",\"color\"=\"red\"]\n1 -- 3\n}\n"
2424
todotb = todotstr == "graph graphname {\n2 [\"label\"=\"b\",\"shape\"=\"ellipse\",\"fillcolor\"=\"red\",\"color\"=\"red\"]\n2 -- 3\n3 [\"label\"=\"abf1\",\"shape\"=\"box\",\"fillcolor\"=\"blue\",\"color\"=\"blue\"]\n1 [\"label\"=\"a\",\"shape\"=\"ellipse\",\"fillcolor\"=\"red\",\"color\"=\"red\"]\n1 -- 3\n}\n"
2525
todotc = todotstr == "graph G {\na [color=red, shape=ellipse];\nb [color=red, shape=ellipse];\nabf1 [color=blue, shape=box];\na -- abf1\nb -- abf1\n}\n"
26-
@test (todota || todotb || todotc)
26+
todotd = todotstr == "graph G {\na [color=red, shape=ellipse];\nb [color=red, shape=ellipse];\nabf1 [color=blue, shape=box];\nb -- abf1\na -- abf1\n}\n"
27+
@test (todota || todotb || todotc || todotd)
2728
@test toDotFile(dfg, "something.dot") == nothing
2829
Base.rm("something.dot")
2930
end

0 commit comments

Comments
 (0)