@@ -51,6 +51,51 @@ function _getPriorType(_type::Type{<:InferenceVariable})
5151 return getfield (_type. name. module, Symbol (:Prior , _type. name. name))
5252end
5353
54+
55+ # #==============================================================================
56+ # # Default Factors Function Macro
57+ # #==============================================================================
58+ function pack end
59+ function unpack end
60+ """
61+ @defFactorFunction StructName factortype<:AbstractFactor manifolds<:ManifoldsBase.AbstractManifold
62+
63+ A macro to create a new factor function with name `StructName` and manifolds. Note that
64+ the `manifolds` is an object and *must* be a subtype of `ManifoldsBase.AbstractManifold`.
65+ See documentation in [Manifolds.jl on making your own](https://juliamanifolds.github.io/Manifolds.jl/stable/examples/manifold.html).
66+
67+ Example:
68+ ```
69+ DFG.@defFactorFunction Pose2Pos2 AbstractManifoldMinimize SpecialEuclidean(2)
70+ ```
71+ """
72+ macro defFactorFunction (structname, factortype, manifold)
73+ packedstructname = Symbol (" Packed" , structname)
74+ return esc (
75+ quote
76+ Base. @__doc__ struct $ structname{T} <: $factortype
77+ Z:: T
78+ end
79+
80+ # Base.@__doc__ struct $packedstructname{T<:PackedSamplableBelief} <: AbstractPackedFactor
81+ Base. @__doc__ struct $ packedstructname{T} <: AbstractPackedFactor
82+ Z:: T
83+ end
84+
85+ # user manifold must be a <:Manifold
86+ @assert ($ manifold isa AbstractManifold) " @defVariable of " *
87+ string ($ structname) *
88+ " requires that the " *
89+ string ($ manifold) *
90+ " be a subtype of `ManifoldsBase.AbstractManifold`"
91+
92+ DFG. getManifold (:: Type{$structname} ) = $ manifold
93+ DFG. pack (d:: $structname ) = $ packedstructname (packDistribution (d. Z))
94+ DFG. unpack (d:: $packedstructname ) = $ structname (unpackDistribution (d. Z))
95+ end ,
96+ )
97+ end
98+
5499# #==============================================================================
55100# # Factors
56101# #==============================================================================
0 commit comments