Skip to content

Commit 51dde28

Browse files
authored
Merge pull request #3 from inuex35/claude/simplify-unit3-traits-BmPL5
Simplify Unit3 measurement error: use traits::Local instead of Measur…
2 parents b4ceb77 + a9a80e6 commit 51dde28

File tree

2 files changed

+3
-104
lines changed

2 files changed

+3
-104
lines changed

gtsam/geometry/MeasurementTraits.h

Lines changed: 0 additions & 81 deletions
This file was deleted.

gtsam/slam/GeneralSFMFactor.h

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
#pragma once
2222

23-
#include <gtsam/geometry/MeasurementTraits.h>
2423
#include <gtsam/geometry/PinholeCamera.h>
2524
#include <gtsam/geometry/Point2.h>
2625
#include <gtsam/geometry/Point3.h>
@@ -70,7 +69,6 @@ class GeneralSFMFactor: public NoiseModelFactorN<CAMERA, LANDMARK> {
7069
static const int ZDim = traits<Measurement>::dimension;
7170
typedef Eigen::Matrix<double, ZDim, DimC> JacobianC;
7271
typedef Eigen::Matrix<double, ZDim, DimL> JacobianL;
73-
typedef Eigen::Matrix<double, ZDim, ZDim> MeasurementJacobian;
7472

7573
protected:
7674

@@ -138,20 +136,8 @@ class GeneralSFMFactor: public NoiseModelFactorN<CAMERA, LANDMARK> {
138136
Vector evaluateError(const CAMERA& camera, const LANDMARK& point,
139137
OptionalMatrixType H1, OptionalMatrixType H2) const override {
140138
try {
141-
JacobianC Dcamera;
142-
JacobianL Dlandmark;
143-
Measurement predicted =
144-
camera.project2(point, H1 ? &Dcamera : nullptr, H2 ? &Dlandmark : nullptr);
145-
146-
MeasurementJacobian localJacobianStorage;
147-
OptionalJacobian<ZDim, ZDim> localJac((H1 || H2) ? &localJacobianStorage : nullptr);
148-
Vector error = Vector(internal::MeasurementErrorHelper<Measurement>::Evaluate(
149-
measured_, predicted, localJac));
150-
151-
if (H1) *H1 = localJac ? localJacobianStorage * Dcamera : Dcamera;
152-
if (H2) *H2 = localJac ? localJacobianStorage * Dlandmark : Dlandmark;
153-
154-
return error;
139+
Measurement predicted = camera.project2(point, H1, H2);
140+
return traits<Measurement>::Local(measured_, predicted);
155141
} catch (CheiralityException& e [[maybe_unused]]) {
156142
if (H1) *H1 = JacobianC::Zero();
157143
if (H2) *H2 = JacobianL::Zero();
@@ -174,13 +160,7 @@ class GeneralSFMFactor: public NoiseModelFactorN<CAMERA, LANDMARK> {
174160
const LANDMARK& point = values.at<LANDMARK>(key2);
175161
Measurement predicted = camera.project2(point, &Dcamera, &Dlandmark);
176162

177-
MeasurementJacobian localJacobianStorage;
178-
OptionalJacobian<ZDim, ZDim> localJac(&localJacobianStorage);
179-
b = -Vector(internal::MeasurementErrorHelper<Measurement>::Evaluate(
180-
measured_, predicted, localJac));
181-
182-
Dcamera = localJacobianStorage * Dcamera;
183-
Dlandmark = localJacobianStorage * Dlandmark;
163+
b = -Vector(traits<Measurement>::Local(measured_, predicted));
184164
} catch (CheiralityException& e [[maybe_unused]]) {
185165
Dcamera.setZero();
186166
Dlandmark.setZero();

0 commit comments

Comments
 (0)