@@ -32,22 +32,14 @@ namespace gtsam {
32
32
template <typename F>
33
33
class TransferFactor : public NoiseModelFactorN <F, F> {
34
34
EdgeKey key1_, key2_; // /< the two EdgeKeys
35
- Point2 pa, pb, pc; // /< The points in the three views
35
+ std::vector<std::tuple<Point2, Point2, Point2>>
36
+ triplets_; // /< Point triplets
36
37
37
38
public:
38
39
/* *
39
- * @brief Constructor for the TransferFactor class.
40
+ * @brief Constructor for a single triplet of points
40
41
*
41
- * Uses EdgeKeys to determine how to use the two fundamental matrix unknowns
42
- * F1 and F2, to transfer points pa and pb to the third view, and minimize the
43
- * difference with pc.
44
- *
45
- * The edge keys must represent valid edges for the transfer operation,
46
- * specifically one of the following configurations:
47
- * - (a, c) and (b, c)
48
- * - (a, c) and (c, b)
49
- * - (c, a) and (b, c)
50
- * - (c, a) and (c, b)
42
+ * @note: batching all points for the same transfer will be much faster.
51
43
*
52
44
* @param key1 First EdgeKey specifying F1: (a, c) or (c, a).
53
45
* @param key2 Second EdgeKey specifying F2: (b, c) or (c, b).
@@ -62,9 +54,25 @@ class TransferFactor : public NoiseModelFactorN<F, F> {
62
54
: NoiseModelFactorN<F, F>(model, key1, key2),
63
55
key1_ (key1),
64
56
key2_ (key2),
65
- pa (pa),
66
- pb (pb),
67
- pc (pc) {}
57
+ triplets_ ({std::make_tuple (pa, pb, pc)}) {}
58
+
59
+ /* *
60
+ * @brief Constructor that accepts a vector of point triplets.
61
+ *
62
+ * @param key1 First EdgeKey specifying F1: (a, c) or (c, a).
63
+ * @param key2 Second EdgeKey specifying F2: (b, c) or (c, b).
64
+ * @param triplets A vector of triplets containing (pa, pb, pc).
65
+ * @param model An optional SharedNoiseModel that defines the noise model
66
+ * for this factor. Defaults to nullptr.
67
+ */
68
+ TransferFactor (
69
+ EdgeKey key1, EdgeKey key2,
70
+ const std::vector<std::tuple<Point2, Point2, Point2>>& triplets,
71
+ const SharedNoiseModel& model = nullptr )
72
+ : NoiseModelFactorN<F, F>(model, key1, key2),
73
+ key1_ (key1),
74
+ key2_ (key2),
75
+ triplets_ (triplets) {}
68
76
69
77
// Create Matrix3 objects based on EdgeKey configurations
70
78
std::pair<Matrix3, Matrix3> getMatrices (const F& F1, const F& F2) const {
@@ -83,17 +91,27 @@ class TransferFactor : public NoiseModelFactorN<F, F> {
83
91
}
84
92
}
85
93
86
- // / vector of errors returns 2D vector
94
+ // / vector of errors returns 2*N vector
87
95
Vector evaluateError (const F& F1, const F& F2,
88
96
OptionalMatrixType H1 = nullptr ,
89
97
OptionalMatrixType H2 = nullptr ) const override {
90
- std::function<Point2 (F, F)> transfer = [&](const F& F1, const F& F2) {
98
+ std::function<Vector (const F&, const F&)> transfer = [&](const F& F1,
99
+ const F& F2) {
100
+ Vector errors (2 * triplets_.size ());
101
+ size_t idx = 0 ;
91
102
auto [Fca, Fcb] = getMatrices (F1, F2);
92
- return Transfer (Fca, pa, Fcb, pb);
103
+ for (const auto & tuple : triplets_) {
104
+ const auto & [pa, pb, pc] = tuple;
105
+ Point2 transferredPoint = Transfer (Fca, pa, Fcb, pb);
106
+ Vector2 error = transferredPoint - pc;
107
+ errors.segment <2 >(idx) = error;
108
+ idx += 2 ;
109
+ }
110
+ return errors;
93
111
};
94
- if (H1) *H1 = numericalDerivative21<Point2 , F, F>(transfer, F1, F2);
95
- if (H2) *H2 = numericalDerivative22<Point2 , F, F>(transfer, F1, F2);
96
- return transfer (F1, F2) - pc ;
112
+ if (H1) *H1 = numericalDerivative21<Vector , F, F>(transfer, F1, F2);
113
+ if (H2) *H2 = numericalDerivative22<Vector , F, F>(transfer, F1, F2);
114
+ return transfer (F1, F2);
97
115
}
98
116
};
99
117
0 commit comments