Merge pull request #856 from borglab/feature/wrap-nonlinearequality2
Wrap NonlinearEquality2release/4.3a0
commit
3d17e74eec
|
@ -290,24 +290,19 @@ struct traits<NonlinearEquality1<VALUE> >
|
||||||
* Simple binary equality constraint - this constraint forces two variables to
|
* Simple binary equality constraint - this constraint forces two variables to
|
||||||
* be the same.
|
* be the same.
|
||||||
*/
|
*/
|
||||||
template<class VALUE>
|
template <class T>
|
||||||
class NonlinearEquality2: public NoiseModelFactor2<VALUE, VALUE> {
|
class NonlinearEquality2 : public NoiseModelFactor2<T, T> {
|
||||||
public:
|
|
||||||
typedef VALUE X;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
typedef NoiseModelFactor2<VALUE, VALUE> Base;
|
using Base = NoiseModelFactor2<T, T>;
|
||||||
typedef NonlinearEquality2<VALUE> This;
|
using This = NonlinearEquality2<T>;
|
||||||
|
|
||||||
GTSAM_CONCEPT_MANIFOLD_TYPE(X)
|
GTSAM_CONCEPT_MANIFOLD_TYPE(T)
|
||||||
|
|
||||||
/// Default constructor to allow for serialization
|
/// Default constructor to allow for serialization
|
||||||
NonlinearEquality2() {
|
NonlinearEquality2() {}
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
typedef boost::shared_ptr<NonlinearEquality2<T>> shared_ptr;
|
||||||
typedef boost::shared_ptr<NonlinearEquality2<VALUE> > shared_ptr;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
|
@ -315,11 +310,10 @@ public:
|
||||||
* @param key2 the key for the second unknown variable to be constrained
|
* @param key2 the key for the second unknown variable to be constrained
|
||||||
* @param mu a parameter which really turns this into a strong prior
|
* @param mu a parameter which really turns this into a strong prior
|
||||||
*/
|
*/
|
||||||
NonlinearEquality2(Key key1, Key key2, double mu = 1000.0) :
|
NonlinearEquality2(Key key1, Key key2, double mu = 1e4)
|
||||||
Base(noiseModel::Constrained::All(traits<X>::dimension, std::abs(mu)), key1, key2) {
|
: Base(noiseModel::Constrained::All(traits<T>::dimension, std::abs(mu)),
|
||||||
}
|
key1, key2) {}
|
||||||
~NonlinearEquality2() override {
|
~NonlinearEquality2() override {}
|
||||||
}
|
|
||||||
|
|
||||||
/// @return a deep copy of this factor
|
/// @return a deep copy of this factor
|
||||||
gtsam::NonlinearFactor::shared_ptr clone() const override {
|
gtsam::NonlinearFactor::shared_ptr clone() const override {
|
||||||
|
@ -328,25 +322,24 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/// g(x) with optional derivative2
|
/// g(x) with optional derivative2
|
||||||
Vector evaluateError(const X& x1, const X& x2, boost::optional<Matrix&> H1 =
|
Vector evaluateError(
|
||||||
boost::none, boost::optional<Matrix&> H2 = boost::none) const override {
|
const T& x1, const T& x2, boost::optional<Matrix&> H1 = boost::none,
|
||||||
static const size_t p = traits<X>::dimension;
|
boost::optional<Matrix&> H2 = boost::none) const override {
|
||||||
|
static const size_t p = traits<T>::dimension;
|
||||||
if (H1) *H1 = -Matrix::Identity(p, p);
|
if (H1) *H1 = -Matrix::Identity(p, p);
|
||||||
if (H2) *H2 = Matrix::Identity(p, p);
|
if (H2) *H2 = Matrix::Identity(p, p);
|
||||||
return traits<X>::Local(x1,x2);
|
return traits<T>::Local(x1, x2);
|
||||||
}
|
}
|
||||||
|
|
||||||
GTSAM_MAKE_ALIGNED_OPERATOR_NEW
|
GTSAM_MAKE_ALIGNED_OPERATOR_NEW
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/// Serialization function
|
/// Serialization function
|
||||||
friend class boost::serialization::access;
|
friend class boost::serialization::access;
|
||||||
template <class ARCHIVE>
|
template <class ARCHIVE>
|
||||||
void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
|
void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
|
||||||
ar
|
ar& boost::serialization::make_nvp(
|
||||||
& boost::serialization::make_nvp("NoiseModelFactor2",
|
"NoiseModelFactor2", boost::serialization::base_object<Base>(*this));
|
||||||
boost::serialization::base_object<Base>(*this));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// \NonlinearEquality2
|
// \NonlinearEquality2
|
||||||
|
@ -355,5 +348,4 @@ template<typename VALUE>
|
||||||
struct traits<NonlinearEquality2<VALUE>> : Testable<NonlinearEquality2<VALUE>> {
|
struct traits<NonlinearEquality2<VALUE>> : Testable<NonlinearEquality2<VALUE>> {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
}// namespace gtsam
|
}// namespace gtsam
|
||||||
|
|
|
@ -824,4 +824,17 @@ virtual class NonlinearEquality : gtsam::NoiseModelFactor {
|
||||||
void serialize() const;
|
void serialize() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <T = {gtsam::Point2, gtsam::StereoPoint2, gtsam::Point3, gtsam::Rot2,
|
||||||
|
gtsam::SO3, gtsam::SO4, gtsam::SOn, gtsam::Rot3, gtsam::Pose2,
|
||||||
|
gtsam::Pose3, gtsam::Cal3_S2, gtsam::CalibratedCamera,
|
||||||
|
gtsam::PinholeCamera<gtsam::Cal3_S2>,
|
||||||
|
gtsam::PinholeCamera<gtsam::Cal3Bundler>,
|
||||||
|
gtsam::PinholeCamera<gtsam::Cal3Fisheye>,
|
||||||
|
gtsam::PinholeCamera<gtsam::Cal3Unified>,
|
||||||
|
gtsam::imuBias::ConstantBias}>
|
||||||
|
virtual class NonlinearEquality2 : gtsam::NoiseModelFactor {
|
||||||
|
NonlinearEquality2(Key key1, Key key2, double mu = 1e4);
|
||||||
|
gtsam::Vector evaluateError(const T& x1, const T& x2);
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace gtsam
|
} // namespace gtsam
|
||||||
|
|
|
@ -165,6 +165,5 @@ add_custom_target(
|
||||||
COMMAND
|
COMMAND
|
||||||
${CMAKE_COMMAND} -E env # add package to python path so no need to install
|
${CMAKE_COMMAND} -E env # add package to python path so no need to install
|
||||||
"PYTHONPATH=${GTSAM_PYTHON_BUILD_DIRECTORY}/$ENV{PYTHONPATH}"
|
"PYTHONPATH=${GTSAM_PYTHON_BUILD_DIRECTORY}/$ENV{PYTHONPATH}"
|
||||||
${PYTHON_EXECUTABLE} -m unittest discover
|
${PYTHON_EXECUTABLE} -m unittest discover -s "${GTSAM_PYTHON_BUILD_DIRECTORY}/gtsam/tests"
|
||||||
DEPENDS ${GTSAM_PYTHON_DEPENDENCIES}
|
DEPENDS ${GTSAM_PYTHON_DEPENDENCIES})
|
||||||
WORKING_DIRECTORY ${GTSAM_PYTHON_BUILD_DIRECTORY}/gtsam/tests)
|
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
"""
|
||||||
|
GTSAM Copyright 2010-2019, Georgia Tech Research Corporation,
|
||||||
|
Atlanta, Georgia 30332-0415
|
||||||
|
All Rights Reserved
|
||||||
|
|
||||||
|
See LICENSE for the license information
|
||||||
|
|
||||||
|
Unit tests for various factors.
|
||||||
|
|
||||||
|
Author: Varun Agrawal
|
||||||
|
"""
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
import gtsam
|
||||||
|
from gtsam.utils.test_case import GtsamTestCase
|
||||||
|
|
||||||
|
|
||||||
|
class TestNonlinearEquality2Factor(GtsamTestCase):
|
||||||
|
"""
|
||||||
|
Test various instantiations of NonlinearEquality2.
|
||||||
|
"""
|
||||||
|
def test_point3(self):
|
||||||
|
"""Test for Point3 version."""
|
||||||
|
factor = gtsam.NonlinearEquality2Point3(0, 1)
|
||||||
|
error = factor.evaluateError(gtsam.Point3(0, 0, 0),
|
||||||
|
gtsam.Point3(0, 0, 0))
|
||||||
|
|
||||||
|
np.testing.assert_allclose(error, np.zeros(3))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
Loading…
Reference in New Issue