12#include <gtsam_unstable/dllexport.h>
33 center(p), radius(r) {
63 throw std::invalid_argument(
64 "SmartRangeFactor::addRange: adding duplicate measurement for key.");
68 size_t n =
keys_.size();
76 void print(
const std::string& s =
"",
77 const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const override {
78 std::cout << s <<
"SmartRangeFactor with " <<
size() <<
" measurements\n";
96 std::list<Circle2> circles;
98 for (
size_t j = 0; j < n; j++) {
103 Circle2 circle1 = circles.front();
104 boost::optional<Point2> best_fh;
105 auto bestCircle2 = boost::make_optional(
false, circle1);
108 for (
const Circle2& it : circles) {
110 double d =
distance2(circle1.center, it.center);
114 boost::optional<Point2> fh = circleCircleIntersection(
115 circle1.radius / d, it.radius / d);
118 if (fh && (!best_fh || fh->y() > best_fh->y())) {
125 if (bestCircle2 && best_fh) {
126 auto bestCircleCenter = bestCircle2->center;
127 std::list<Point2> intersections =
128 circleCircleIntersection(circle1.center, bestCircleCenter, best_fh);
131 double error1 = 0, error2 = 0;
132 Point2 p1 = intersections.front(), p2 = intersections.back();
133 for (
const Circle2& it : circles) {
137 return (error1 < error2) ? p1 : p2;
139 throw std::runtime_error(
"triangulate failed");
147 boost::optional<std::vector<Matrix>&> H = boost::none)
const override {
152 for (
size_t j = 0; j < n; j++)
153 (*H)[j] = Matrix::Zero(3, 1);
157 Vector
error = Z_1x1;
165 for (
size_t j = 0; j < n; j++) {
178 gtsam::NonlinearFactor::shared_ptr
clone()
const override {
179 return boost::static_pointer_cast<gtsam::NonlinearFactor>(
180 gtsam::NonlinearFactor::shared_ptr(
new This(*
this)));
Non-linear factor base classes.
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
Vector2 Point2
As of GTSAM 4, in order to make GTSAM more lean, it is now possible to just typedef Point2 to Vector2...
Definition: Point2.h:27
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:69
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:35
double distance2(const Point2 &p, const Point2 &q, OptionalJacobian< 1, 2 > H1, OptionalJacobian< 1, 2 > H2)
distance between two points
Definition: Point2.cpp:39
GTSAM_EXPORT double range(const Point2 &point, OptionalJacobian< 1, 3 > H1=boost::none, OptionalJacobian< 1, 2 > H2=boost::none) const
Calculate range to a landmark.
Definition: Pose2.cpp:253
const Point2 & translation() const
translation
Definition: Pose2.h:230
This is the base class for all factor types.
Definition: Factor.h:56
KeyVector keys_
The keys involved in this factor.
Definition: Factor.h:73
size_t size() const
Definition: Factor.h:136
static shared_ptr Variance(size_t dim, double variance, bool smart=true)
An isotropic noise model created by specifying a variance = sigma^2.
Definition: NoiseModel.cpp:573
Nonlinear factor base class.
Definition: NonlinearFactor.h:43
A nonlinear sum-of-squares factor with a zero-mean noise model implementing the density Templated on...
Definition: NonlinearFactor.h:162
double error(const Values &c) const override
Calculate the error of the factor.
Definition: NonlinearFactor.cpp:127
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
Print.
Definition: NonlinearFactor.cpp:63
const SharedNoiseModel & noiseModel() const
access to the noise model
Definition: NonlinearFactor.h:211
A non-templated config holding any types of Manifold-group elements.
Definition: Values.h:63
const ValueType at(Key j) const
Retrieve a variable by key j.
Definition: Values-inl.h:346
Definition: SmartRangeFactor.h:29
void addRange(Key key, double measuredRange)
Add a range measurement to a pose with given key.
Definition: SmartRangeFactor.h:61
std::vector< double > measurements_
Range measurements.
Definition: SmartRangeFactor.h:41
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
print
Definition: SmartRangeFactor.h:76
double variance_
variance on noise
Definition: SmartRangeFactor.h:42
Vector unwhitenedError(const Values &x, boost::optional< std::vector< Matrix > & > H=boost::none) const override
Error function without the NoiseModel, .
Definition: SmartRangeFactor.h:146
bool equals(const NonlinearFactor &f, double tol=1e-9) const override
Check if two factors are equal.
Definition: SmartRangeFactor.h:83
SmartRangeFactor()
Default constructor: don't use directly.
Definition: SmartRangeFactor.h:46
SmartRangeFactor(double s)
Constructor.
Definition: SmartRangeFactor.h:53
Point2 triangulate(const Values &x) const
Triangulate a point from at least three pose-range pairs Checks for best pair that includes first poi...
Definition: SmartRangeFactor.h:94
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition: SmartRangeFactor.h:178
Definition: SmartRangeFactor.h:31