Skip to content

Commit 5ea997c

Browse files
authored
Merge pull request #73 from JuliaRobotics/fearure/subgraph_dispatch
getSubGraphAroundNode conversions
2 parents 28b2173 + be719fa commit 5ea997c

File tree

5 files changed

+32
-8
lines changed

5 files changed

+32
-8
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ RoME = "91fb55c2-4c03-5a59-ba21-f4ea956187b8"
3131
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3232

3333
[targets]
34-
test = ["Test"]
34+
test = ["Test", "RoME"]

src/LightGraphsDFG/services/LightGraphsDFG.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,22 @@ function getSubgraphAroundNode(dfg::LightGraphsDFG{P}, node::T, distance::Int64=
470470
return addToDFG
471471
end
472472

473+
474+
function getSubgraphAroundNode(dfg::LightGraphsDFG{<:AbstractParams}, node::DFGNode, distance::Int64=1, includeOrphanFactors::Bool=false, addToDFG::AbstractDFG=LightGraphsDFG{AbstractParams}())::AbstractDFG
475+
if !haskey(dfg.g.metaindex[:label], node.label)
476+
error("Variable/factor with label '$(node.label)' does not exist in the factor graph")
477+
end
478+
479+
# Get a list of all unique neighbors inside 'distance'
480+
ns = neighborhood(dfg.g, dfg.g[node.label,:label], distance)
481+
482+
# Copy the section of graph we want
483+
_copyIntoGraph!(dfg, addToDFG, map(n->get_prop(dfg.g, n, :label), ns), includeOrphanFactors)
484+
# _copyIntoGraph!(dfg, addToDFG, ns, includeOrphanFactors)
485+
return addToDFG
486+
end
487+
488+
473489
"""
474490
$(SIGNATURES)
475491
Get a deep subgraph copy from the DFG given a list of variables and factors.

src/services/AbstractDFG.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ function _copyIntoGraph!(sourceDFG::G, destDFG::H, variableFactorLabels::Vector{
4242

4343
# Now we have to add all variables first,
4444
for variable in sourceVariables
45-
addVariable!(destDFG, deepcopy(variable))
45+
if !exists(destDFG, variable)
46+
addVariable!(destDFG, deepcopy(variable))
47+
end
4648
end
4749
# And then all factors to the destDFG.
4850
for factor in sourceFactors
@@ -57,7 +59,9 @@ function _copyIntoGraph!(sourceDFG::G, destDFG::H, variableFactorLabels::Vector{
5759
end
5860
# Only if we have all of them should we add it (otherwise strange things may happen on evaluation)
5961
if includeOrphanFactors || length(factVariableIds) == length(sourceFactorVariableIds)
60-
addFactor!(destDFG, factVariableIds, deepcopy(factor))
62+
if !exists(destDFG, factor)
63+
addFactor!(destDFG, factVariableIds, deepcopy(factor))
64+
end
6165
end
6266
end
6367
return nothing

test/HexagonalLightGraphs.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
using Revise
2-
using Neo4j # So that DFG initializes the database driver.
31
using RoME
42
using DistributedFactorGraphs
5-
using Test
63

74
# start with an empty factor graph object
8-
# fg = initfg()
9-
fg = LightGraphsDFG{SolverParams}( solverParams=SolverParams())
5+
fg = LightGraphsDFG{SolverParams}( params=SolverParams())
106

117
# Add the first pose :x0
128
x0 = addVariable!(fg, :x0, Pose2)

test/runtests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ for api in apis
1212
end
1313
end
1414

15+
if !(get(ENV, "TRAVIS", "") == "true")
16+
@testset "Local Testsets" begin
17+
@testset "HexagonalLightGraphs" begin
18+
include("HexagonalLightGraphs.jl")
19+
end
20+
end
21+
end
22+
1523
# Test other interfaces that are not yet compatible for the general tests.
1624
# @testset "CloudGraphsDFG Drive: " begin
1725
# include("cloudGraphsDFGTests.jl")

0 commit comments

Comments
 (0)