Skip to content

Commit 5005d33

Browse files
authored
Merge pull request #493 from JuliaRobotics/docs/20Q2/exampleplot
Docs examples
2 parents cfe583a + ccf1bbe commit 5005d33

File tree

3 files changed

+43
-27
lines changed

3 files changed

+43
-27
lines changed

docs/Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
[deps]
2+
Cairo = "159f3aea-2a34-519c-b102-8c37f9878175"
3+
Compose = "a81c6b42-2e10-5240-aca2-a61377ecd94b"
24
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
35
GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231"
6+
IncrementalInference = "904591bb-b899-562f-9e6f-b8df64c7d480"
47
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
58

69
[compat]

docs/src/BuildingGraphs.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
In this section constructing DFG graphs will be discussed. To start, bring DistributedFactorGraphs into your workspace:
44

5-
```julia
5+
```@example buildingGraphs; continued = true
66
using DistributedFactorGraphs
77
```
88

@@ -13,6 +13,8 @@ So for the following examples, IncrementalInference will be used to create the v
1313
```julia
1414
using Pkg
1515
Pkg.add("IncrementalInference")
16+
```
17+
```@example buildingGraphs; continued = true
1618
using IncrementalInference
1719
```
1820

@@ -28,16 +30,16 @@ To continue the example, run one of the following to create a DFG driver:
2830

2931
### Creating a LightDFG Graph
3032

31-
```julia
33+
```@example buildingGraphs; continued = true
3234
# Create a DFG with default solver parameters using the LightGraphs.jl driver.
33-
dfg = LightDFG{SolverParams}(params=SolverParams())
35+
dfg = LightDFG{SolverParams}(solverParams=SolverParams())
3436
```
3537

3638
### Creating a CloudGraphsDFG Graph
3739

3840
```julia
3941
# Create a DFG with no solver parameters (just to demonstrate the difference) using the CloudGraphs driver, and connect it to a local Neo4j instance.
40-
dfg = CloudGraphsDFG{NoSolverParams}("localhost", 7474, "neo4j", "test",
42+
cfg = CloudGraphsDFG{NoSolverParams}("localhost", 7474, "neo4j", "test",
4143
"testUser", "testRobot", "testSession")
4244
```
4345

@@ -60,7 +62,7 @@ In addition, the following optional parameters are provided:
6062

6163
Three variables are added:
6264

63-
```julia
65+
```@example buildingGraphs; continued = true
6466
v1 = addVariable!(dfg, :x0, ContinuousScalar, labels = [:POSE], solvable=1)
6567
v2 = addVariable!(dfg, :x1, ContinuousScalar, labels = [:POSE], solvable=1)
6668
v3 = addVariable!(dfg, :l0, ContinuousScalar, labels = [:LANDMARK], solvable=1)
@@ -79,7 +81,7 @@ Additionally, the solvable flag is also set to indicate that the factor can be u
7981

8082
Four factors are added: a prior, a linear conditional relationship with a normal distribution between x0 and x1, and a pair of linear conditional relationships between each pose and the landmark.
8183

82-
```julia
84+
```@example buildingGraphs; continued = true
8385
prior = addFactor!(dfg, [:x0], Prior(Normal(0,1)))
8486
f1 = addFactor!(dfg, [:x0; :x1], LinearConditional(Normal(50.0,2.0)), solvable=1)
8587
f1 = addFactor!(dfg, [:l0; :x0], LinearConditional(Normal(40.0,5.0)), solvable=1)
@@ -99,13 +101,19 @@ Reading, updating, and deleting all use DFG functions (as opposed to adding,
99101
where using the IncrementalInference functions are recommended).
100102

101103
Each variable and factor is uniquely identified by its label. The list of
102-
variable and factor labels can be retrieved with the `ls`/`listVariables` and
103-
`lsf`/`listFactors` functions:
104+
variable and factor labels can be retrieved with the [`ls`](@ref)/[`listVariables`](@ref) and
105+
[`lsf`](@ref)/[`listFactors`](@ref) functions:
106+
107+
For example listing the variables in the graph we created above:
108+
```@example buildingGraphs
109+
ls(dfg)
110+
```
111+
112+
Or listing the factors:
113+
```@example buildingGraphs
114+
lsf(dfg)
115+
```
104116

105-
- [`listVariables`](@ref)
106-
- [`ls`](@ref)
107-
- [`listFactors`](@ref)
108-
- [`lsf`](@ref)
109117

110118
To list all variables or factors (instead of just their labels), use the
111119
`getVariables` and `getFactors` functions:

docs/src/DrawingGraphs.md

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@ Pkg.add("GraphPlot")
1313

1414
Then bring `GraphPlot` in before DFG:
1515

16-
```julia
16+
```@example plots; continued = true
1717
using GraphPlot
1818
using DistributedFactorGraphs
1919
```
2020

21-
Any factor graph can then be drawn by calling `dfgplot`:
21+
Any factor graph can then be drawn by calling [`dfgplot`](@ref):
2222

23-
```julia
23+
```@example plots
24+
using Cairo # hide
2425
# Construct graph using IIF
2526
using IncrementalInference
2627
# Create graph
27-
dfg = LightDFG{SolverParams}(params=SolverParams())
28+
dfg = LightDFG{SolverParams}(solverParams=SolverParams())
2829
v1 = addVariable!(dfg, :x0, ContinuousScalar, labels = [:POSE], solvable=1)
2930
v2 = addVariable!(dfg, :x1, ContinuousScalar, labels = [:POSE], solvable=1)
3031
v3 = addVariable!(dfg, :l0, ContinuousScalar, labels = [:LANDMARK], solvable=1)
@@ -37,19 +38,22 @@ f1 = addFactor!(dfg, [:l0; :x1], LinearConditional(Normal(-10.0,5.0)), solvable=
3738
dfgplot(dfg)
3839
```
3940

40-
![imgs/initialgraph.jpg](imgs/initialgraph.jpg)
41-
42-
- [`dfgplot`](@ref)
43-
4441
### Rendering GraphPlot to PDF
4542

46-
The graph can be rendered to PDF or JPG in the following way:
43+
The graph can be rendered to PDF, SVG or JPG in the following way by including compose:
4744

48-
```julia
49-
# Save to PDF
45+
```@example plots
5046
using Compose
51-
draw(PDF("/tmp/graph.pdf", 16cm, 16cm), dfgplot(dfg))
47+
# lets add another variable and factor and plot it
48+
dfg.solverParams.graphinit = false # hide
49+
addVariable!(dfg, :x2, ContinuousScalar);
50+
addFactor!(dfg, [:x1; :x2], LinearConditional(Normal(50.0,2.0)));
51+
# Save to SVG
52+
draw(SVG("graph.svg", 10cm, 10cm), dfgplot(dfg));
53+
nothing # hide
5254
```
55+
![](graph.svg)
56+
5357

5458
### More Information
5559

@@ -63,12 +67,12 @@ and can be drawn by either:
6367
- Calling [`toDot`](@ref) on any graph to produce a string of the graph
6468
- Calling [`toDotFile`](@ref) on any graph to save it directly to a dotfile
6569

66-
```julia
70+
```@example
6771
using DistributedFactorGraphs
6872
# Construct graph using IIF
6973
using IncrementalInference
7074
# Create graph
71-
dfg = GraphsDFG{SolverParams}(params=SolverParams())
75+
dfg = LightDFG{SolverParams}(solverParams=SolverParams())
7276
v1 = addVariable!(dfg, :x0, ContinuousScalar, labels = [:POSE], solvable=1)
7377
v2 = addVariable!(dfg, :x1, ContinuousScalar, labels = [:POSE], solvable=1)
7478
v3 = addVariable!(dfg, :l0, ContinuousScalar, labels = [:LANDMARK], solvable=1)
@@ -79,5 +83,6 @@ f1 = addFactor!(dfg, [:l0; :x1], LinearConditional(Normal(-10.0,5.0)), solvable=
7983
# Save to dot file
8084
toDotFile(dfg, "/tmp/test.dot")
8185
# Open with xdot
82-
run(`xdot /tmp/test.dot`)
86+
# run(`xdot /tmp/test.dot`)
87+
# nothing # hide
8388
```

0 commit comments

Comments
 (0)