1#![cfg_attr(feature = "simd", feature(portable_simd))]
2#![deny(missing_docs)]
3#![allow(clippy::needless_range_loop)]
4#![no_std]
5#![doc = include_str!(concat!("../", std::env!("CARGO_PKG_README")))]
6#![cfg_attr(nightly, feature(doc_auto_cfg))]
7
8#[doc = include_str!(concat!("../", core::env!("CARGO_PKG_README")))]
9#[cfg(doctest)]
10pub struct ReadmeDoctests;
11
12#[cfg(feature = "std")]
13extern crate std;
14
15mod complex;
16mod groups;
17mod lie_group;
18mod quaternion;
19mod sl2c;
20
21pub mod prelude {
37 pub use sophus_autodiff::prelude::*;
38
39 pub use crate::{
40 IsAffineGroup,
41 IsLieGroup,
42 };
43}
44
45use core::fmt::Debug;
46
47use sophus_autodiff::prelude::*;
48
49pub use crate::{
50 complex::*,
51 groups::{
52 affine_group_template::*,
53 galilean3::*,
54 isometry2::*,
55 isometry3::*,
56 rotation_boost3::*,
57 rotation2::*,
58 rotation3::*,
59 },
60 lie_group::{
61 LieGroup,
62 average::*,
63 factor_lie_group::*,
64 real_lie_group::*,
65 },
66 quaternion::*,
67 sl2c::*,
68};
69
70pub trait HasDisambiguate<
72 S: IsScalar<BATCH, DM, DN>,
73 const PARAMS: usize,
74 const BATCH: usize,
75 const DM: usize,
76 const DN: usize,
77>: Clone + Debug
78{
79 fn disambiguate(params: S::Vector<PARAMS>) -> S::Vector<PARAMS> {
94 params
95 }
96}
97
98pub trait IsLieGroupImpl<
108 S: IsScalar<BATCH, DM, DN>,
109 const DOF: usize,
110 const PARAMS: usize,
111 const POINT: usize,
112 const AMBIENT: usize,
113 const BATCH: usize,
114 const DM: usize,
115 const DN: usize,
116>:
117 IsParamsImpl<S, PARAMS, BATCH, DM, DN>
118 + IsTangent<S, DOF, BATCH, DM, DN>
119 + HasDisambiguate<S, PARAMS, BATCH, DM, DN>
120 + Clone
121 + Copy
122 + Debug
123{
124 type GenG<S2: IsScalar<BATCH, DM, DN>>: IsLieGroupImpl<S2, DOF, PARAMS, POINT, AMBIENT, BATCH, DM, DN>;
126 type RealG: IsLieGroupImpl<S::RealScalar, DOF, PARAMS, POINT, AMBIENT, BATCH, 0, 0>;
128 type DualG<const M: usize, const N: usize>: IsLieGroupImpl<S::DualScalar<M, N>, DOF, PARAMS, POINT, AMBIENT, BATCH, M, N>;
130
131 const IS_ORIGIN_PRESERVING: bool;
133 const IS_AXIS_DIRECTION_PRESERVING: bool;
135 const IS_DIRECTION_VECTOR_PRESERVING: bool;
137 const IS_SHAPE_PRESERVING: bool;
139 const IS_DISTANCE_PRESERVING: bool;
141 const IS_PARALLEL_LINE_PRESERVING: bool;
143
144 fn identity_params() -> S::Vector<PARAMS>;
146
147 fn adj(params: &S::Vector<PARAMS>) -> S::Matrix<DOF, DOF>;
151
152 fn ad(tangent: S::Vector<DOF>) -> S::Matrix<DOF, DOF>;
154
155 fn exp(omega: S::Vector<DOF>) -> S::Vector<PARAMS>;
157
158 fn log(params: &S::Vector<PARAMS>) -> S::Vector<DOF>;
160
161 fn hat(omega: S::Vector<DOF>) -> S::Matrix<AMBIENT, AMBIENT>;
163
164 fn vee(hat: S::Matrix<AMBIENT, AMBIENT>) -> S::Vector<DOF>;
166
167 fn group_mul(params1: &S::Vector<PARAMS>, params2: S::Vector<PARAMS>) -> S::Vector<PARAMS>;
171
172 fn inverse(params: &S::Vector<PARAMS>) -> S::Vector<PARAMS>;
174
175 fn transform(params: &S::Vector<PARAMS>, point: S::Vector<POINT>) -> S::Vector<POINT>;
179
180 fn to_ambient(point: S::Vector<POINT>) -> S::Vector<AMBIENT>;
182
183 fn compact(params: &S::Vector<PARAMS>) -> S::Matrix<POINT, AMBIENT>;
185
186 fn matrix(params: &S::Vector<PARAMS>) -> S::Matrix<AMBIENT, AMBIENT>;
188}
189
190pub trait IsRealLieGroupImpl<
192 S: IsRealScalar<BATCH>,
193 const DOF: usize,
194 const PARAMS: usize,
195 const POINT: usize,
196 const AMBIENT: usize,
197 const BATCH: usize,
198>: IsLieGroupImpl<S, DOF, PARAMS, POINT, AMBIENT, BATCH, 0, 0>
199{
200 fn da_a_mul_b(a: S::Vector<PARAMS>, b: S::Vector<PARAMS>) -> S::Matrix<PARAMS, PARAMS>;
202
203 fn db_a_mul_b(a: S::Vector<PARAMS>, b: S::Vector<PARAMS>) -> S::Matrix<PARAMS, PARAMS>;
205
206 fn dx_exp(tangent: S::Vector<DOF>) -> S::Matrix<PARAMS, DOF>;
208
209 fn dx_exp_x_at_0() -> S::Matrix<PARAMS, DOF>;
211
212 fn dx_exp_x_times_point_at_0(point: S::Vector<POINT>) -> S::Matrix<POINT, DOF>;
214
215 fn dparams_matrix(params: &S::Vector<PARAMS>, col_idx: usize) -> S::Matrix<POINT, PARAMS>;
219
220 fn has_shortest_path_ambiguity(params: &S::Vector<PARAMS>) -> S::Mask;
222
223 fn left_jacobian(tangent: S::Vector<DOF>) -> S::Matrix<DOF, DOF>;
231
232 fn inv_left_jacobian(tangent: S::Vector<DOF>) -> S::Matrix<DOF, DOF>;
234}
235
236pub trait IsLieFactorGroupImpl<
240 S: IsScalar<BATCH, DM, DN>,
241 const DOF: usize,
242 const PARAMS: usize,
243 const POINT: usize,
244 const BATCH: usize,
245 const DM: usize,
246 const DN: usize,
247>: IsLieGroupImpl<S, DOF, PARAMS, POINT, POINT, BATCH, DM, DN>
248{
249 type GenFactorG<S2: IsScalar<BATCH, M, N>, const M: usize, const N: usize>: IsLieFactorGroupImpl<S2, DOF, PARAMS, POINT, BATCH, M, N>;
251 type RealFactorG: IsLieFactorGroupImpl<S::RealScalar, DOF, PARAMS, POINT, BATCH, 0, 0>;
253 type DualFactorG<const M: usize, const N: usize>: IsLieFactorGroupImpl<S::DualScalar<M, N>, DOF, PARAMS, POINT, BATCH, M, N>;
255
256 fn mat_v(tangent: S::Vector<DOF>) -> S::Matrix<POINT, POINT>;
258
259 fn mat_v_inverse(tangent: S::Vector<DOF>) -> S::Matrix<POINT, POINT>;
261
262 fn adj_of_translation(
264 params: &S::Vector<PARAMS>,
265 point: S::Vector<POINT>,
266 ) -> S::Matrix<POINT, DOF>;
267
268 fn ad_of_translation(point: S::Vector<POINT>) -> S::Matrix<POINT, DOF>;
270}
271
272pub trait IsRealLieFactorGroupImpl<
274 S: IsRealScalar<BATCH>,
275 const DOF: usize,
276 const PARAMS: usize,
277 const POINT: usize,
278 const BATCH: usize,
279>:
280 IsLieGroupImpl<S, DOF, PARAMS, POINT, POINT, BATCH, 0, 0>
281 + IsLieFactorGroupImpl<S, DOF, PARAMS, POINT, BATCH, 0, 0>
282 + IsRealLieGroupImpl<S, DOF, PARAMS, POINT, POINT, BATCH>
283{
284 fn dx_mat_v(tangent: S::Vector<DOF>) -> [S::Matrix<POINT, POINT>; DOF];
286
287 fn dx_mat_v_inverse(tangent: S::Vector<DOF>) -> [S::Matrix<POINT, POINT>; DOF];
289
290 fn dparams_matrix_times_point(
292 params: &S::Vector<PARAMS>,
293 point: S::Vector<POINT>,
294 ) -> S::Matrix<POINT, PARAMS>;
295
296 fn left_jacobian_of_translation(
310 alpha: S::Vector<DOF>,
311 upsilon: S::Vector<POINT>,
312 ) -> S::Matrix<POINT, DOF>;
313}
314
315pub trait IsLieGroup<
317 S: IsScalar<BATCH, DM, DN>,
318 const DOF: usize,
319 const PARAMS: usize,
320 const POINT: usize,
321 const AMBIENT: usize,
322 const BATCH: usize,
323 const DM: usize,
324 const DN: usize,
325>: IsTangent<S, DOF, BATCH, DM, DN> + HasParams<S, PARAMS, BATCH, DM, DN>
326{
327 type G: IsLieGroupImpl<S, DOF, PARAMS, POINT, AMBIENT, BATCH, DM, DN>;
329 type GenG<S2: IsScalar<BATCH, DM, DN>>: IsLieGroupImpl<S2, DOF, PARAMS, POINT, AMBIENT, BATCH, DM, DN>;
331 type RealG: IsLieGroupImpl<S::RealScalar, DOF, PARAMS, POINT, AMBIENT, BATCH, 0, 0>;
333 type DualG<const M: usize, const N: usize>: IsLieGroupImpl<S::DualScalar<M, N>, DOF, PARAMS, POINT, AMBIENT, BATCH, M, N>;
335
336 const DOF: usize;
338 const PARAMS: usize;
340 const POINT: usize;
342 const AMBIENT: usize;
344
345 type GenGroup<S2: IsScalar<BATCH, DM, DN>, G2: IsLieGroupImpl<S2, DOF, PARAMS, POINT, AMBIENT, BATCH, DM, DN>>: IsLieGroup<
347 S2,
348 DOF,
349 PARAMS,
350 POINT,
351 AMBIENT,
352 BATCH
353 ,DM,DN
354 >;
355}
356
357pub trait IsAffineGroup<
359 S: IsScalar<BATCH, DM, DN>,
360 const DOF: usize,
361 const PARAMS: usize,
362 const POINT: usize,
363 const AMBIENT: usize,
364 const SDOF: usize,
365 const SPARAMS: usize,
366 const BATCH: usize,
367 const DM: usize,
368 const DN: usize,
369 FactorGroup: IsLieGroup<S, SDOF, SPARAMS, POINT, POINT, BATCH, DM, DN>,
370>: IsLieGroup<S, DOF, PARAMS, POINT, AMBIENT, BATCH, DM, DN>
371{
372 type Impl;
374
375 fn from_factor_and_translation(factor: FactorGroup, translation: S::Vector<POINT>) -> Self;
377
378 fn set_translation(&mut self, translation: S::Vector<POINT>);
380 fn translation(&self) -> S::Vector<POINT>;
382
383 fn set_factor(&mut self, factor: FactorGroup);
385
386 fn factor(&self) -> FactorGroup;
388}
389
390#[derive(Debug)]
392pub struct EmptySliceError;
393
394pub trait HasAverage<
396 S: IsSingleScalar<DM, DN>,
397 const DOF: usize,
398 const PARAMS: usize,
399 const POINT: usize,
400 const AMBIENT: usize,
401 const DM: usize,
402 const DN: usize,
403>: IsLieGroup<S, DOF, PARAMS, POINT, AMBIENT, 1, DM, DN> + core::marker::Sized
404{
405 fn average(parent_from_body_transforms: &[Self]) -> Result<Self, EmptySliceError>;
407}