/* * @file TransformConstraint.h * @brief A constraint for combining graphs by common landmarks and a transform node * @author Alex Cunningham */ #pragma once #include namespace gtsam { /** * A constraint between two landmarks in separate maps * Templated on: * Config : The overall config * PKey : Key of landmark being constrained * Point : Type of landmark * TKey : Key of transform used * Transform : Transform variable class * * The Point and Transform concepts must be Lie types, and the transform * relationship "Point = transform_from(Transform, Point)" must exist. * * This base class should be specialized to implement the cost function for * specific classes of landmarks */ template class TransformConstraint : public NonlinearEqualityConstraint3 { public: typedef NonlinearEqualityConstraint3 Base; typedef TransformConstraint This; /** * General constructor with all of the keys to variables in the map * Extracts everything necessary from the key types */ TransformConstraint(const PKey& foreignKey, const TKey& transKey, const PKey& localKey, double mu = 1000.0) : Base(foreignKey, transKey, localKey, Point().dim(), mu) {} virtual ~TransformConstraint(){} /** Combined cost and derivative function using boost::optional */ virtual Vector evaluateError(const Point& foreign, const Transform& trans, const Point& local, boost::optional Dforeign = boost::none, boost::optional Dtrans = boost::none, boost::optional Dlocal = boost::none) const { if (Dforeign) { Matrix Af; transform_from(trans, foreign, boost::none, Af); *Dforeign = Af; } if (Dtrans) { Matrix At; transform_from(trans, foreign, At, boost::none); *Dtrans = At; } if (Dlocal) { Point dummy; *Dlocal = -1* eye(dummy.dim()); } return gtsam::logmap(gtsam::between(local, transform_from(trans, foreign))); } }; } // \namespace gtsam