1/**
2 * @file DummyFactor.h
3 *
4 * @brief A simple factor that can be used to trick gtsam solvers into believing a graph is connected.
5 *
6 * @date Sep 10, 2012
7 * @author Alex Cunningham
8 */
9
10#pragma once
11
12#include <gtsam_unstable/dllexport.h>
13#include <gtsam/nonlinear/NonlinearFactor.h>
14
15namespace gtsam {
16
17class GTSAM_UNSTABLE_EXPORT DummyFactor : public NonlinearFactor {
18protected:
19
20 // Store the dimensions of the variables and the dimension of the full system
21 std::vector<size_t> dims_;
22 size_t rowDim_; ///< choose dimension for the rows
23
24public:
25
26 /** Default constructor: don't use directly */
27 DummyFactor() : rowDim_(1) { }
28
29 /** standard binary constructor */
30 DummyFactor(const Key& key1, size_t dim1, const Key& key2, size_t dim2);
31
32 ~DummyFactor() override {}
33
34 // testable
35
36 /** print */
37 void print(const std::string& s = "", const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override;
38
39 /** Check if two factors are equal */
40 bool equals(const NonlinearFactor& f, double tol = 1e-9) const override;
41
42 // access
43
44 const std::vector<size_t>& dims() const { return dims_; }
45
46 // factor interface
47
48 /**
49 * Calculate the error of the factor - zero for dummy factors
50 */
51 double error(const Values& c) const override { return 0.0; }
52
53 /** get the dimension of the factor (number of rows on linearization) */
54 size_t dim() const override { return rowDim_; }
55
56 /** linearize to a GaussianFactor */
57 std::shared_ptr<GaussianFactor> linearize(const Values& c) const override;
58
59 /**
60 * Creates a shared_ptr clone of the factor - needs to be specialized to allow
61 * for subclasses
62 *
63 * By default, throws exception if subclass does not implement the function.
64 */
65 NonlinearFactor::shared_ptr clone() const override {
66 return std::static_pointer_cast<NonlinearFactor>(
67 r: NonlinearFactor::shared_ptr(new DummyFactor(*this)));
68 }
69
70};
71
72} // \namespace gtsam
73
74
75
76
77