@@ -56,9 +56,16 @@ function getObservation(f::FactorDFG)
5656 # FIXME completely refactor to not need getTypeFromSerializationModule and just use StructTypes
5757 packtype = DFG. getTypeFromSerializationModule (" Packed" * f. fnctype)
5858 return packtype (; JSON3. read (f. observJSON)... )
59+ # return packtype(JSON3.read(f.observJSON))
5960end
6061
61- getWorkmem (f:: FactorCompute ) = f. workmem[]
62+ function getWorkmem (f:: FactorCompute )
63+ if isassigned (f. workmem)
64+ return f. workmem[]
65+ else
66+ return nothing
67+ end
68+ end
6269setWorkmem! (f:: FactorCompute , workmem:: FactorOperationalMemory ) = f. workmem[] = workmem
6370
6471"""
8491# # Default Factors Function Macro
8592# #==============================================================================
8693export PackedSamplableBelief
87- # export pack, unpack, packDistribution, unpackDistribution
8894
8995function pack end
9096function unpack end
@@ -94,38 +100,48 @@ function unpackDistribution end
94100abstract type PackedSamplableBelief end
95101StructTypes. StructType (:: Type{<:PackedSamplableBelief} ) = StructTypes. UnorderedStruct ()
96102
103+ # TODO remove, rather use StructTypes.jl properly
104+ function Base. convert (:: Type{<:PackedSamplableBelief} , nt:: Union{NamedTuple, JSON3.Object} )
105+ distrType = getTypeFromSerializationModule (nt. _type)
106+ return distrType (; nt... )
107+ end
108+
97109"""
98- @defFactorType StructName factortype<:AbstractFactor manifolds<:ManifoldsBase. AbstractManifold
110+ @defFactorType StructName factortype<:AbstractFactor manifolds<:AbstractManifold
99111
100- A macro to create a new factor function with name `StructName` and manifolds. Note that
101- the `manifolds ` is an object and *must* be a subtype of `ManifoldsBase.AbstractManifold`.
112+ A macro to create a new factor function with name `StructName` and manifold. Note that
113+ the `manifold ` is an object and *must* be a subtype of `ManifoldsBase.AbstractManifold`.
102114See documentation in [Manifolds.jl on making your own](https://juliamanifolds.github.io/Manifolds.jl/stable/examples/manifold.html).
103115
104116Example:
105117```
106- DFG.@defFactorType Pose2Pos2 AbstractManifoldMinimize SpecialEuclidean(2)
118+ DFG.@defFactorType Pose2Pose2 AbstractManifoldMinimize SpecialEuclidean(2)
107119```
108120"""
109121macro defFactorType (structname, factortype, manifold)
110122 packedstructname = Symbol (" Packed" , structname)
111123 return esc (
112124 quote
125+ # user manifold must be a <:Manifold
126+ @assert ($ manifold isa AbstractManifold) " @defFactorType manifold (" *
127+ string ($ manifold) *
128+ " ) is not an `AbstractManifold`"
129+
130+ @assert ($ factortype <: AbstractFactor ) " @defFactorType factortype (" *
131+ string ($ factortype) *
132+ " ) is not an `AbstractFactor`"
133+
113134 Base. @__doc__ struct $ structname{T} <: $factortype
114135 Z:: T
115136 end
116137
117- Base . @__doc__ struct $ packedstructname{T <: PackedSamplableBelief } < :
118- AbstractPackedFactor
119- Z:: T
138+ # TODO should this be $packedstructname{T <: PackedSamplableBelief}
139+ Base . @__doc__ struct $ packedstructname <: AbstractPackedFactor
140+ Z:: PackedSamplableBelief
120141 end
121142
122- # user manifold must be a <:Manifold
123- @assert ($ manifold isa AbstractManifold) " @defFactorType of " *
124- string ($ structname) *
125- " requires that the " *
126- string ($ manifold) *
127- " be a subtype of `ManifoldsBase.AbstractManifold`"
128-
143+ # $structname(; Z) = $structname(Z)
144+ $ packedstructname (; Z) = $ packedstructname (Z)
129145 DFG. getManifold (:: Type{$structname} ) = $ manifold
130146 DFG. pack (d:: $structname ) = $ packedstructname (DFG. packDistribution (d. Z))
131147 DFG. unpack (d:: $packedstructname ) = $ structname (DFG. unpackDistribution (d. Z))
@@ -223,26 +239,6 @@ getVariableOrder(fct::FactorCompute) = fct._variableOrderSymbols::Vector{Symbol}
223239getVariableOrder (fct:: FactorDFG ) = fct. _variableOrderSymbols:: Vector{Symbol}
224240getVariableOrder (dfg:: AbstractDFG , fct:: Symbol ) = getVariableOrder (getFactor (dfg, fct))
225241
226- # #------------------------------------------------------------------------------
227- # # solverData
228- # #------------------------------------------------------------------------------
229-
230- """
231- $SIGNATURES
232-
233- Retrieve solver data structure stored in a factor.
234- """
235- function getSolverData (f:: FactorCompute )
236- Base. depwarn (" getSolverData(f::FactorCompute) is deprecated" , :getSolverData )
237- if isassigned (getfield (f, :solverData ))
238- return getfield (f, :solverData )[]
239- else
240- return nothing
241- end
242- end
243-
244- setSolverData! (f:: FactorCompute , data:: GenericFunctionNodeData ) = f. solverData = data
245-
246242# #------------------------------------------------------------------------------
247243# # utility
248244# #------------------------------------------------------------------------------
0 commit comments