Skip to content

Commit bc50e51

Browse files
committed
Macro to creat a new <:InferenceVariable
1 parent d1f3c41 commit bc50e51

File tree

4 files changed

+41
-15
lines changed

4 files changed

+41
-15
lines changed

src/DistributedFactorGraphs.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ export getSolverData
123123

124124
export getVariableType
125125

126+
# Softtype functions
127+
export getDimension, getManifolds
128+
126129
# Small Data CRUD
127130
export SmallDataTypes, getSmallData, addSmallData!, updateSmallData!, deleteSmallData!, listSmallData, emptySmallData!
128131
export getSmallData, setSmallData!

src/entities/DFGVariable.jl

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,6 @@
44

55
abstract type InferenceVariable end
66

7-
"""
8-
$SIGNATURES
9-
Interface function to return the softtype dimention of an InferenceVariable, extend this function for all Types<:InferenceVariable.
10-
"""
11-
function getDimension end
12-
"""
13-
$SIGNATURES
14-
Interface function to return the softtype manifolds of an InferenceVariable, extend this function for all Types<:InferenceVariable.
15-
"""
16-
function getManifolds end
177
##==============================================================================
188
## VariableNodeData
199
##==============================================================================

src/services/DFGVariable.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,37 @@ Alias for [`getSofttype`](@ref).
5151
"""
5252
getVariableType(args...) = getSofttype(args...)
5353

54+
55+
##------------------------------------------------------------------------------
56+
## InferenceVariable
57+
##------------------------------------------------------------------------------
58+
"""
59+
$SIGNATURES
60+
Interface function to return the softtype dimention of an InferenceVariable, extend this function for all Types<:InferenceVariable.
61+
"""
62+
function getDimension end
63+
"""
64+
$SIGNATURES
65+
Interface function to return the softtype manifolds of an InferenceVariable, extend this function for all Types<:InferenceVariable.
66+
"""
67+
function getManifolds end
68+
69+
"""
70+
@defVariable StructName dimension manifolds
71+
A macro to create a new variable with name `StructName`, dimension and manifolds.
72+
Example:
73+
```
74+
DFG.@defVariable Pose2 3 (:Euclid, :Euclid, :Circular)
75+
```
76+
"""
77+
macro defVariable(structname, dimension::Int, manifolds)#::Vararg{Symbol})#NTuple{dimension, Symbol})
78+
# :(struct $structname <: InferenceVariable end)
79+
return esc(quote
80+
struct $structname <: InferenceVariable end
81+
DistributedFactorGraphs.getDimension(::$structname) = $dimension
82+
DistributedFactorGraphs.getManifolds(::$structname) = $manifolds
83+
end)
84+
end
5485
##------------------------------------------------------------------------------
5586
## solvedCount
5687
##------------------------------------------------------------------------------

test/testBlocks.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ using UUIDs
66
import Base: convert
77

88
# Test InferenceVariable Types
9-
struct TestSofttype1 <: InferenceVariable
10-
dims::Int
11-
manifolds::Tuple{Symbol}
12-
TestSofttype1() = new(1,(:Euclid,))
13-
end
9+
# struct TestSofttype1 <: InferenceVariable
10+
# dims::Int
11+
# manifolds::Tuple{Symbol}
12+
# TestSofttype1() = new(1,(:Euclid,))
13+
# end
14+
15+
DFG.@defVariable TestSofttype1 1 (:Euclid,)
1416

1517
struct TestSofttype2 <: InferenceVariable
1618
dims::Int

0 commit comments

Comments
 (0)