@@ -14,7 +14,7 @@ v1 = addVariable!(dfg, :a, ContinuousScalar, labels = [:POSE], solvable=0)
14
14
saveDFG(dfg, "/tmp/saveDFG")
15
15
```
16
16
"""
17
- function saveDFG (dfg:: G , folder:: String ) where G <: AbstractDFG
17
+ function saveDFG (dfg:: AbstractDFG , folder:: String ; compress :: Symbol = :gzip )
18
18
variables = getVariables (dfg)
19
19
factors = getFactors (dfg)
20
20
varFolder = " $folder /variables"
@@ -43,6 +43,19 @@ function saveDFG(dfg::G, folder::String) where G <: AbstractDFG
43
43
JSON2. write (io, fPacked)
44
44
close (io)
45
45
end
46
+
47
+ # compress newly saved folder, skip if not supported format
48
+ ! (compress in [:gzip ]) && return
49
+ savepath = folder[end ] == ' /' ? folder[1 : end - 1 ] : folder
50
+ savedir = dirname (savepath)
51
+ savename = splitpath (string (savepath))[end ]
52
+ @assert savename != " "
53
+ # temporarily change working directory to get correct zipped path
54
+ here = Base. pwd ()
55
+ Base. cd (savedir)
56
+ run (` tar -zcf $savepath .tar.gz $savename ` )
57
+ Base. rm (savename, recursive= true )
58
+ Base. cd (here)
46
59
end
47
60
48
61
"""
@@ -56,20 +69,46 @@ using DistributedFactorGraphs, IncrementalInference
56
69
# Create a DFG - can make one directly, e.g. GraphsDFG{NoSolverParams}() or use IIF:
57
70
dfg = initfg()
58
71
# Load the graph
59
- loadDFG("/tmp/savedgraph", IncrementalInference, dfg)
72
+ loadDFG("/tmp/savedgraph.tar.gz", IncrementalInference, dfg)
73
+ loadDFG("/tmp/savedgraph", IncrementalInference, dfg) # alternative
60
74
# Use the DFG as you do normally.
61
75
ls(dfg)
62
76
```
63
77
"""
64
- function loadDFG (folder:: String , iifModule, dfgLoadInto:: G ) where G <: AbstractDFG
78
+ function loadDFG (dst:: String , iifModule, dfgLoadInto:: G ; loaddir= joinpath (" /" ," tmp" ," caesar" ," random" )) where G <: AbstractDFG
79
+ # Check if zipped destination (dst) by first doing fuzzy search from user supplied dst
80
+ folder = dst # working directory for fileDFG variable and factor operations
81
+ dstname = dst # path name could either be legacy FileDFG dir or .tar.gz file of FileDFG files.
82
+ unzip = false
83
+ # add if doesn't have .tar.gz extension
84
+ lastdirname = splitpath (dstname)[end ]
85
+ if ! isdir (dst)
86
+ unzip = true
87
+ sdst = split (lastdirname, ' .' )
88
+ if sdst[end ] != " gz" # length(sdst) == 1 &&
89
+ dstname *= " .tar.gz"
90
+ lastdirname *= " .tar.gz"
91
+ end
92
+ end
93
+ # do actual unzipping
94
+ if unzip
95
+ @show sfolder = split (dstname, ' .' )
96
+ Base. mkpath (loaddir)
97
+ folder = joinpath (loaddir, lastdirname[1 : (end - length (" .tar.gz" ))]) # splitpath(string(sfolder[end-2]))[end]
98
+ @info " loadDFG detected a gzip $dstname -- unpacking via $loaddir now..."
99
+ Base. rm (folder, recursive= true , force= true )
100
+ # unzip the tar file
101
+ run (` tar -zxf $dstname -C $loaddir ` )
102
+ end
103
+ # extract the factor graph from fileDFG folder
65
104
variables = DFGVariable[]
66
105
factors = DFGFactor[]
67
106
varFolder = " $folder /variables"
68
107
factorFolder = " $folder /factors"
69
108
# Folder preparations
70
109
! isdir (folder) && error (" Can't load DFG graph - folder '$folder ' doesn't exist" )
71
- ! isdir (varFolder) && error (" Can't load DFG graph - folder '$folder ' doesn't exist" )
72
- ! isdir (factorFolder) && error (" Can't load DFG graph - folder '$folder ' doesn't exist" )
110
+ ! isdir (varFolder) && error (" Can't load DFG graph - folder '$varFolder ' doesn't exist" )
111
+ ! isdir (factorFolder) && error (" Can't load DFG graph - folder '$factorFolder ' doesn't exist" )
73
112
74
113
varFiles = readdir (varFolder)
75
114
factorFiles = readdir (factorFolder)
0 commit comments