Graphite  0.5.0
GPU-accelerated graph optimization framework
Loading...
Searching...
No Matches
bal.cuh
Go to the documentation of this file.
1
2#pragma once
4#include <Eigen/Core>
5#include <graphite/common.hpp>
6#include <graphite/factor.hpp>
7#include <graphite/vertex.hpp>
8
9namespace graphite {
10
11template <typename T> using Point = Eigen::Matrix<T, 3, 1>;
12
13template <typename T> using Camera = Eigen::Matrix<T, 9, 1>;
14
15template <typename T> struct PointTraits {
16 static constexpr size_t dimension = 3;
17 using Vertex = Point<T>;
18
19 template <typename P>
20 d_fn static void parameters(const Vertex &vertex, P *parameters) {
21 Eigen::Map<Eigen::Matrix<P, dimension, 1>> params_map(parameters);
22 params_map = vertex.template cast<P>();
23 }
24
25 d_fn static void update(Vertex &vertex, const T *delta) {
26 Eigen::Map<const Eigen::Matrix<T, dimension, 1>> d(delta);
27 vertex += d;
28 }
29};
30
31template <typename T> struct CameraTraits {
32 static constexpr size_t dimension = 9;
33 using State = Camera<T>; // State can be optionally defined
34 using Vertex = Camera<T>;
35
36 template <typename P>
37 d_fn static void parameters(const Vertex &vertex, P *parameters) {
38 Eigen::Map<Eigen::Matrix<P, dimension, 1>> params_map(parameters);
39 params_map = vertex.template cast<P>();
40 }
41
42 d_fn static void update(Vertex &vertex, const T *delta) {
43 Eigen::Map<const Eigen::Matrix<T, dimension, 1>> d(delta);
44 vertex += d;
45 }
46
47 // Defining the state requires custom setters and getters
48 d_fn static State get_state(const Vertex &vertex) { return vertex; }
49
50 d_fn static void set_state(Vertex &vertex, const State &state) {
51 vertex = state;
52 }
53};
54
55template <typename T, typename S>
56using PointDescriptor = VertexDescriptor<T, S, PointTraits<T>>;
57
58template <typename T, typename S>
59using CameraDescriptor = VertexDescriptor<T, S, CameraTraits<T>>;
60
61template <typename T, typename S> struct ReprojectionErrorTraits {
62 static constexpr size_t dimension = 2;
63 using VertexDescriptors =
64 std::tuple<CameraDescriptor<T, S>, PointDescriptor<T, S>>;
65 using Observation = Eigen::Matrix<T, dimension, 1>;
66 using Data = Empty;
67 using Loss = DefaultLoss<T, dimension>;
68 // using Differentiation = DifferentiationMode::Auto;
70
71 // You can pass in vertex references (class references), parameter blocks
72 // (pointer to 1D parameters), or both. The framework will automatically call
73 // your function with the correct arguments.
74 template <typename D>
75 d_fn static void error(const D *camera, const D *point,
76 const Observation &obs, D *error) {
77 bal_reprojection_error_simple<D, Observation, T>(camera, point, &obs,
78 error);
79 }
80
81 template <typename D, size_t I>
82 d_fn static void jacobian(const Camera<T> &camera, const Point<T> &point,
83 const Observation &obs, D *jacobian) {
84 bal_jacobian_simple<T, D, I>(camera.data(), point.data(), &obs, jacobian);
85 }
86};
87
88template <typename T, typename S>
89using ReprojectionError = FactorDescriptor<T, S, ReprojectionErrorTraits<T, S>>;
90
91} // namespace graphite
The top-level namespace for Graphite.
Definition eigen_solver.cpp:4
Definition bal.cuh:31
Definition differentiation.hpp:8
Definition types.hpp:46
Definition bal.cuh:15