Skip to content

Commit 989dae3

Browse files
committed
Clean up match class a smidge
1 parent 451dbea commit 989dae3

File tree

6 files changed

+23
-25
lines changed

6 files changed

+23
-25
lines changed

config/25.10.08_short_verify.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pipelines:
22
- pipeline: form
3-
name: 2_docs_fixed
3+
name: 4_docs_match_estimates
44

55
datasets:
66
# ncd20

form/feature/factor.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
// SOFTWARE.
2222
#include "form/feature/factor.hpp"
2323
#include "form/optimization/gtsam.hpp"
24-
#include <Eigen/src/Core/Matrix.h>
25-
#include <Eigen/src/Core/util/Constants.h>
26-
#include <gtsam/base/Matrix.h>
27-
#include <gtsam/base/Vector.h>
2824
#include <gtsam/linear/HessianFactor.h>
2925
#include <gtsam/linear/JacobianFactor.h>
3026
#include <gtsam/linear/NoiseModel.h>

form/feature/factor.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
// SOFTWARE.
2222
#pragma once
2323

24-
#include <gtsam/geometry/Point3.h>
2524
#include <gtsam/geometry/Pose3.h>
26-
#include <gtsam/nonlinear/NonlinearFactor.h>
2725
#include <vector>
2826

2927
#include "form/feature/features.hpp"

form/form.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,16 @@ Estimator::register_scan(const std::vector<Eigen::Vector3f> &scan) noexcept {
6666

6767
// ICP loop
6868
gtsam::Values new_values;
69+
auto estimates = [&](size_t i) { return m_constraints.get_pose(i); };
6970
for (size_t idx = 0; idx < m_params.matcher.max_num_rematches; ++idx) {
7071
auto before = m_constraints.get_current_pose();
7172

7273
// -------------------------------- Matching -------------------------------- //
7374
// Match each type of feature
7475
tuple::for_seq(SEQ, [&](auto I) {
7576
std::get<I>(m_matcher).template match<I>(std::get<I>(world_map),
76-
std::get<I>(keypoints), before,
77-
m_constraints, scan_constraints);
77+
std::get<I>(keypoints), estimates,
78+
scan_constraints);
7879
});
7980

8081
// ---------------------- Semi-Linearized Optimization ---------------------- //

form/optimization/gtsam.hpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,33 +35,34 @@ make it faster when sparsity isn't a concern.
3535
*/
3636
namespace form {
3737

38-
/// Extension of LM that uses dense optimization instead of sparse bayes tree solver.
38+
/// @brief Extension of LM that uses dense optimization instead of sparse bayes tree
39+
/// solver.
3940
class DenseLMOptimizer : public gtsam::LevenbergMarquardtOptimizer {
4041
public:
41-
/// Constructor
42+
/// @brief Constructor
4243
DenseLMOptimizer(const gtsam::NonlinearFactorGraph &graph,
4344
const gtsam::Values &initialValues,
4445
const gtsam::LevenbergMarquardtParams &params)
4546
: LevenbergMarquardtOptimizer(graph, initialValues, params) {}
4647

47-
/// Solve densely instead of using the sparse solver
48+
/// @brief Solve densely instead of using the sparse solver
4849
gtsam::VectorValues
4950
solve(const gtsam::GaussianFactorGraph &gfg,
5051
const gtsam::NonlinearOptimizerParams &params) const override {
5152
return gfg.optimizeDensely();
5253
}
5354
};
5455

55-
/// Factor that forces gtsam factors to use Hessian linearization instead of Jacobian
56-
/// linearization. This is more efficient when residual sizes are large and the
57-
/// problem is dense.
56+
/// @brief Factor that forces gtsam factors to use Hessian linearization instead of
57+
/// Jacobian linearization. This is more efficient when residual sizes are large and
58+
/// the problem is dense.
5859
class DenseFactor : public gtsam::NoiseModelFactor2<gtsam::Pose3, gtsam::Pose3> {
5960
public:
6061
DenseFactor(const gtsam::noiseModel::Base::shared_ptr &noiseModel,
6162
const gtsam::Key i, const gtsam::Key j)
6263
: gtsam::NoiseModelFactor2<gtsam::Pose3, gtsam::Pose3>(noiseModel, i, j) {}
6364

64-
// Blatantly stolen from here,
65+
// Blatantly stolen from here, just with last line changed:
6566
// https://github.com/borglab/gtsam/blob/develop/gtsam/nonlinear/NonlinearFactor.cpp#L152
6667
boost::shared_ptr<gtsam::GaussianFactor>
6768
linearize(const gtsam::Values &x) const override {
@@ -85,8 +86,8 @@ class DenseFactor : public gtsam::NoiseModelFactor2<gtsam::Pose3, gtsam::Pose3>
8586
}
8687
};
8788

88-
/// A fast isotropic noise model that uses a single sigma value for all dimensions.
89-
/// The gtsam version allocates a vector of sigmas, which is unnecessary
89+
/// @brief A fast isotropic noise model that uses a single sigma value for all
90+
/// dimensions. The gtsam version allocates a vector of sigmas, which is unnecessary
9091
class FastIsotropic : public gtsam::noiseModel::Gaussian {
9192
typedef boost::shared_ptr<FastIsotropic> shared_ptr;
9293

@@ -138,7 +139,8 @@ class FastIsotropic : public gtsam::noiseModel::Gaussian {
138139
}
139140
};
140141

141-
// Wrapper around a gtsam::NoiseModelFactor2 to allow for a fixed FIRST variable
142+
/// @brief Wrapper around a gtsam::NoiseModelFactor2 to allow for a fixed FIRST
143+
/// variable
142144
class BinaryFactorWrapper : public gtsam::NoiseModelFactor1<gtsam::Pose3> {
143145
using Base = gtsam::NoiseModelFactor1<gtsam::Pose3>;
144146
using Wrapped = gtsam::NoiseModelFactor2<gtsam::Pose3, gtsam::Pose3>;

form/optimization/matcher.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
// SOFTWARE.
22+
#include "form/feature/factor.hpp"
2223
#include "form/mapping/map.hpp"
23-
#include "form/optimization/constraints.hpp"
2424
#include "form/utils.hpp"
25+
#include <gtsam/geometry/Pose3.h>
2526
#include <tbb/concurrent_vector.h>
2627
#include <tbb/parallel_for.h>
2728

@@ -60,14 +61,13 @@ template <typename Point> class Matcher {
6061
/// @tparam I Index of the constraint type (0 for PlanePoint, 1 for PointPoint)
6162
/// @param map The voxel map to match against
6263
/// @param keypoints The keypoints to match
63-
/// @param init Initial pose estimate for the scan the keypoints come from
64-
/// @param manager The constraint manager containing the poses of all scans
64+
/// @param estimates Function that returns the pose estimate for a given FrameIndex
6565
/// @param scan_constraints Map from FrameIndex to a tuple of constraint vectors
6666
/// where the matched constraints will be added
6767
template <int I>
6868
void match(const VoxelMap<Point> &map, const std::vector<Point> &keypoints,
69-
const gtsam::Pose3 &init, const ConstraintManager &manager,
70-
tsl::robin_map<FrameIndex, std::tuple<PlanePoint::Ptr, PointPoint::Ptr>>
69+
const std::function<gtsam::Pose3(size_t)> &estimates,
70+
tsl::robin_map<size_t, std::tuple<PlanePoint::Ptr, PointPoint::Ptr>>
7171
&scan_constraints) {
7272
// Set everything up
7373
matches.clear();
@@ -76,6 +76,7 @@ template <typename Point> class Matcher {
7676
}
7777
matches.reserve(keypoints.size());
7878
auto max_dist_sqrd = m_params.max_dist_matching * m_params.max_dist_matching;
79+
auto init = estimates(keypoints.front().scan);
7980

8081
// Do the matching
8182
const auto range = tbb::blocked_range{keypoints.cbegin(), keypoints.cend()};
@@ -86,7 +87,7 @@ template <typename Point> class Matcher {
8687
// move back into local frames
8788
match.query = *kp;
8889
if (match.found()) {
89-
auto &scan_pose = manager.get_pose(match.point.scan);
90+
auto scan_pose = estimates(match.point.scan);
9091
match.point.transform_in_place(scan_pose.inverse());
9192
}
9293

0 commit comments

Comments
 (0)