3636
3737#include < fuse_core/constraint.h>
3838#include < fuse_core/eigen.h>
39- #include < fuse_core/local_parameterization.h>
4039#include < fuse_core/fuse_macros.h>
40+ #include < fuse_core/local_parameterization.h>
41+ #include < fuse_core/manifold.h>
4142#include < fuse_core/serialization.h>
4243#include < fuse_core/variable.h>
4344
5758#include < string>
5859#include < vector>
5960
60-
6161namespace fuse_constraints
6262{
63-
6463/* *
6564 * @brief A constraint that represents remaining marginal information on a set of variables
6665 *
@@ -93,7 +92,7 @@ class MarginalConstraint : public fuse_core::Constraint
9392 * @param[in] last_A Iterator pointing to one past the last A matrix
9493 * @param[in] b The b vector of the marginal cost (of the form A*(x - x_bar) + b)
9594 */
96- template <typename VariableIterator, typename MatrixIterator>
95+ template <typename VariableIterator, typename MatrixIterator>
9796 MarginalConstraint (
9897 const std::string& source,
9998 VariableIterator first_variable,
@@ -122,13 +121,20 @@ class MarginalConstraint : public fuse_core::Constraint
122121 */
123122 const std::vector<fuse_core::VectorXd>& x_bar () const { return x_bar_; }
124123
124+ #if !CERES_SUPPORTS_MANIFOLDS
125125 /* *
126126 * @brief Read-only access to the variable local parameterizations
127127 */
128128 const std::vector<fuse_core::LocalParameterization::SharedPtr>& localParameterizations () const
129129 {
130130 return local_parameterizations_;
131131 }
132+ #else
133+ /* *
134+ * @brief Read-only access to the variable local parameterizations
135+ */
136+ const std::vector<fuse_core::Manifold::SharedPtr>& manifolds () const { return manifolds_; }
137+ #endif
132138
133139 /* *
134140 * @brief Print a human-readable description of the constraint to the provided stream.
@@ -151,7 +157,11 @@ class MarginalConstraint : public fuse_core::Constraint
151157protected:
152158 std::vector<fuse_core::MatrixXd> A_; // !< The A matrices of the marginal constraint
153159 fuse_core::VectorXd b_; // !< The b vector of the marginal constraint
154- std::vector<fuse_core::LocalParameterization::SharedPtr> local_parameterizations_; // !< The local parameterizations
160+ #if !CERES_SUPPORTS_MANIFOLDS
161+ std::vector<fuse_core::LocalParameterization::SharedPtr> local_parameterizations_; // !< Parameterizations
162+ #else
163+ std::vector<fuse_core::Manifold::SharedPtr> manifolds_; // !< Manifolds
164+ #endif
155165 std::vector<fuse_core::VectorXd> x_bar_; // !< The linearization point of each involved variable
156166
157167private:
@@ -164,20 +174,23 @@ class MarginalConstraint : public fuse_core::Constraint
164174 * @param[in/out] archive - The archive object that holds the serialized class members
165175 * @param[in] version - The version of the archive being read/written. Generally unused.
166176 */
167- template <class Archive >
177+ template <class Archive >
168178 void serialize (Archive& archive, const unsigned int /* version */ )
169179 {
170- archive & boost::serialization::base_object<fuse_core::Constraint>(*this );
171- archive & A_;
172- archive & b_;
173- archive & local_parameterizations_;
174- archive & x_bar_;
180+ archive& boost::serialization::base_object<fuse_core::Constraint>(*this );
181+ archive& A_;
182+ archive& b_;
183+ #if !CERES_SUPPORTS_MANIFOLDS
184+ archive& local_parameterizations_;
185+ #else
186+ archive& manifolds_;
187+ #endif
188+ archive& x_bar_;
175189 }
176190};
177191
178192namespace detail
179193{
180-
181194/* *
182195 * @brief Return the UUID of the provided variable
183196 */
@@ -194,6 +207,7 @@ inline const fuse_core::VectorXd getCurrentValue(const fuse_core::Variable& vari
194207 return Eigen::Map<const fuse_core::VectorXd>(variable.data (), variable.size ());
195208}
196209
210+ #if !CERES_SUPPORTS_MANIFOLDS
197211/* *
198212 * @brief Return the local parameterization of the provided variable
199213 */
@@ -202,31 +216,52 @@ inline fuse_core::LocalParameterization::SharedPtr const getLocalParameterizatio
202216 return fuse_core::LocalParameterization::SharedPtr (variable.localParameterization ());
203217}
204218
219+ #else
220+ /* *
221+ * @brief Return the manifold of the provided variable
222+ */
223+ inline fuse_core::Manifold::SharedPtr const getManifold (const fuse_core::Variable& variable)
224+ {
225+ return fuse_core::Manifold::SharedPtr (variable.manifold ());
226+ }
227+ #endif
228+
205229} // namespace detail
206230
207- template <typename VariableIterator, typename MatrixIterator>
231+ template <typename VariableIterator, typename MatrixIterator>
208232MarginalConstraint::MarginalConstraint (
209233 const std::string& source,
210234 VariableIterator first_variable,
211235 VariableIterator last_variable,
212236 MatrixIterator first_A,
213237 MatrixIterator last_A,
214238 const fuse_core::VectorXd& b) :
215- Constraint (source,
216- boost::make_transform_iterator (first_variable, &fuse_constraints::detail::getUuid),
217- boost::make_transform_iterator(last_variable, &fuse_constraints::detail::getUuid)),
218- A_(first_A, last_A),
219- b_(b),
220- local_parameterizations_(boost::make_transform_iterator(first_variable,
221- &fuse_constraints::detail::getLocalParameterization),
222- boost::make_transform_iterator(last_variable,
223- &fuse_constraints::detail::getLocalParameterization)),
224- x_bar_(boost::make_transform_iterator(first_variable, &fuse_constraints::detail::getCurrentValue),
225- boost::make_transform_iterator(last_variable, &fuse_constraints::detail::getCurrentValue))
239+ Constraint (
240+ source,
241+ boost::make_transform_iterator (first_variable, &fuse_constraints::detail::getUuid),
242+ boost::make_transform_iterator(last_variable, &fuse_constraints::detail::getUuid)),
243+ A_(first_A, last_A),
244+ b_(b),
245+ #if !CERES_SUPPORTS_MANIFOLDS
246+ local_parameterizations_ (
247+ boost::make_transform_iterator (first_variable, &fuse_constraints::detail::getLocalParameterization),
248+ boost::make_transform_iterator(last_variable, &fuse_constraints::detail::getLocalParameterization)),
249+ #else
250+ manifolds_ (
251+ boost::make_transform_iterator (first_variable, &fuse_constraints::detail::getManifold),
252+ boost::make_transform_iterator(last_variable, &fuse_constraints::detail::getManifold)),
253+ #endif
254+ x_bar_ (
255+ boost::make_transform_iterator (first_variable, &fuse_constraints::detail::getCurrentValue),
256+ boost::make_transform_iterator(last_variable, &fuse_constraints::detail::getCurrentValue))
226257{
227258 assert (!A_.empty ());
228259 assert (A_.size () == x_bar_.size ());
260+ #if !CERES_SUPPORTS_MANIFOLDS
229261 assert (A_.size () == local_parameterizations_.size ());
262+ #else
263+ assert (A_.size () == manifolds_.size ());
264+ #endif
230265 assert (b_.rows () > 0 );
231266 assert (std::all_of (A_.begin (), A_.end (), [this ](const auto & A){ return A.rows () == this ->b_ .rows (); })); // NOLINT
232267 assert (std::all_of (boost::make_zip_iterator (boost::make_tuple (A_.begin (), first_variable)),
0 commit comments