@@ -64,6 +64,59 @@ function _getPriorType(_type::Type{<:InferenceVariable})
64
64
return getfield (_type. name. module, Symbol (:Prior , _type. name. name))
65
65
end
66
66
67
+ # #==============================================================================
68
+ # # Default Factors Function Macro
69
+ # #==============================================================================
70
+ export PackedSamplableBelief
71
+ # export pack, unpack, packDistribution, unpackDistribution
72
+
73
+ function pack end
74
+ function unpack end
75
+ function packDistribution end
76
+ function unpackDistribution end
77
+
78
+ abstract type PackedSamplableBelief end
79
+ StructTypes. StructType (:: Type{<:PackedSamplableBelief} ) = StructTypes. UnorderedStruct ()
80
+
81
+ """
82
+ @defFactorType StructName factortype<:AbstractFactor manifolds<:ManifoldsBase.AbstractManifold
83
+
84
+ A macro to create a new factor function with name `StructName` and manifolds. Note that
85
+ the `manifolds` is an object and *must* be a subtype of `ManifoldsBase.AbstractManifold`.
86
+ See documentation in [Manifolds.jl on making your own](https://juliamanifolds.github.io/Manifolds.jl/stable/examples/manifold.html).
87
+
88
+ Example:
89
+ ```
90
+ DFG.@defFactorType Pose2Pos2 AbstractManifoldMinimize SpecialEuclidean(2)
91
+ ```
92
+ """
93
+ macro defFactorType (structname, factortype, manifold)
94
+ packedstructname = Symbol (" Packed" , structname)
95
+ return esc (
96
+ quote
97
+ Base. @__doc__ struct $ structname{T} <: $factortype
98
+ Z:: T
99
+ end
100
+
101
+ Base. @__doc__ struct $ packedstructname{T <: PackedSamplableBelief } < :
102
+ AbstractPackedFactor
103
+ Z:: T
104
+ end
105
+
106
+ # user manifold must be a <:Manifold
107
+ @assert ($ manifold isa AbstractManifold) " @defFactorType of " *
108
+ string ($ structname) *
109
+ " requires that the " *
110
+ string ($ manifold) *
111
+ " be a subtype of `ManifoldsBase.AbstractManifold`"
112
+
113
+ DFG. getManifold (:: Type{$structname} ) = $ manifold
114
+ DFG. pack (d:: $structname ) = $ packedstructname (DFG. packDistribution (d. Z))
115
+ DFG. unpack (d:: $packedstructname ) = $ structname (DFG. unpackDistribution (d. Z))
116
+ end ,
117
+ )
118
+ end
119
+
67
120
# #==============================================================================
68
121
# # Factors
69
122
# #==============================================================================
0 commit comments