Skip to content

Commit 19177be

Browse files
committed
Internal API redesign
1 parent 2307206 commit 19177be

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+4304
-2986
lines changed

include/manif/Rn.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,32 @@
22
#define _MANIF_RN_H_
33

44
#include "manif/impl/macro.h"
5+
#include "manif/constants.h"
56
#include "manif/impl/utils.h"
6-
#include "manif/impl/lie_group_base.h"
7+
8+
#include "manif/impl/traits.h"
9+
#include "manif/impl/core/crtp.h"
10+
11+
#include "manif/impl/eigen.h"
12+
13+
#include "manif/impl/expr/expr.h"
14+
#include "manif/impl/random.h"
15+
#include "manif/impl/generator.h"
16+
#include "manif/impl/assignment_assert.h"
17+
18+
#include "lt/optional.hpp"
19+
720
#include "manif/impl/tangent_base.h"
21+
#include "manif/impl/lie_group_base.h"
822

923
#include "manif/impl/rn/Rn_properties.h"
1024
#include "manif/impl/rn/Rn_base.h"
1125
#include "manif/impl/rn/RnTangent_base.h"
1226
#include "manif/impl/rn/Rn.h"
27+
#include "manif/impl/rn/Rn_expr.h"
1328
#include "manif/impl/rn/RnTangent.h"
29+
#include "manif/impl/rn/RnTangent_expr.h"
30+
1431
#include "manif/impl/rn/Rn_map.h"
1532
#include "manif/impl/rn/RnTangent_map.h"
1633

include/manif/SE2.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,32 @@
22
#define _MANIF_SE2_H_
33

44
#include "manif/impl/macro.h"
5-
#include "manif/impl/lie_group_base.h"
5+
#include "manif/constants.h"
6+
#include "manif/impl/utils.h"
7+
8+
#include "manif/impl/traits.h"
9+
#include "manif/impl/core/crtp.h"
10+
11+
#include "manif/impl/eigen.h"
12+
13+
#include "manif/impl/expr/expr.h"
14+
#include "manif/impl/random.h"
15+
#include "manif/impl/generator.h"
16+
#include "manif/impl/assignment_assert.h"
17+
18+
#include "lt/optional.hpp"
19+
620
#include "manif/impl/tangent_base.h"
21+
#include "manif/impl/lie_group_base.h"
722

823
#include "manif/impl/se2/SE2_properties.h"
924
#include "manif/impl/se2/SE2_base.h"
1025
#include "manif/impl/se2/SE2Tangent_base.h"
1126
#include "manif/impl/se2/SE2.h"
27+
#include "manif/impl/se2/SE2_expr.h"
1228
#include "manif/impl/se2/SE2Tangent.h"
29+
#include "manif/impl/se2/SE2Tangent_expr.h"
30+
1331
#include "manif/impl/se2/SE2_map.h"
1432
#include "manif/impl/se2/SE2Tangent_map.h"
1533

include/manif/SE3.h

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,36 @@
11
#ifndef _MANIF_SE3_H_
22
#define _MANIF_SE3_H_
33

4-
#include "manif/impl/macro.h"
5-
#include "manif/impl/lie_group_base.h"
6-
#include "manif/impl/tangent_base.h"
4+
// #include "manif/impl/macro.h"
5+
// #include "manif/constants.h"
6+
// #include "manif/impl/utils.h"
7+
//
8+
// #include "manif/impl/traits.h"
9+
// #include "manif/impl/core/crtp.h"
10+
//
11+
// #include "manif/impl/eigen.h"
12+
//
13+
// #include "manif/impl/expr/expr.h"
14+
// #include "manif/impl/random.h"
15+
// #include "manif/impl/generator.h"
16+
// #include "manif/impl/assignment_assert.h"
17+
//
18+
// #include "lt/optional.hpp"
19+
//
20+
// #include "manif/impl/tangent_base.h"
21+
// #include "manif/impl/lie_group_base.h"
722

23+
#include "manif/SO3.h"
24+
25+
#include "manif/impl/se3/SE3_utils.h"
826
#include "manif/impl/se3/SE3_properties.h"
927
#include "manif/impl/se3/SE3_base.h"
1028
#include "manif/impl/se3/SE3Tangent_base.h"
1129
#include "manif/impl/se3/SE3.h"
30+
#include "manif/impl/se3/SE3_expr.h"
1231
#include "manif/impl/se3/SE3Tangent.h"
32+
#include "manif/impl/se3/SE3Tangent_expr.h"
33+
1334
#include "manif/impl/se3/SE3_map.h"
1435
#include "manif/impl/se3/SE3Tangent_map.h"
1536

include/manif/SO2.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,32 @@
22
#define _MANIF_SO2_H_
33

44
#include "manif/impl/macro.h"
5+
#include "manif/constants.h"
56
#include "manif/impl/utils.h"
6-
#include "manif/impl/lie_group_base.h"
7+
8+
#include "manif/impl/traits.h"
9+
#include "manif/impl/core/crtp.h"
10+
11+
#include "manif/impl/eigen.h"
12+
13+
#include "manif/impl/expr/expr.h"
14+
#include "manif/impl/random.h"
15+
#include "manif/impl/generator.h"
16+
#include "manif/impl/assignment_assert.h"
17+
18+
#include "lt/optional.hpp"
19+
720
#include "manif/impl/tangent_base.h"
21+
#include "manif/impl/lie_group_base.h"
822

923
#include "manif/impl/so2/SO2_properties.h"
1024
#include "manif/impl/so2/SO2_base.h"
1125
#include "manif/impl/so2/SO2Tangent_base.h"
1226
#include "manif/impl/so2/SO2.h"
27+
#include "manif/impl/so2/SO2_expr.h"
1328
#include "manif/impl/so2/SO2Tangent.h"
29+
#include "manif/impl/so2/SO2Tangent_expr.h"
30+
1431
#include "manif/impl/so2/SO2_map.h"
1532
#include "manif/impl/so2/SO2Tangent_map.h"
1633

include/manif/SO3.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,32 @@
22
#define _MANIF_SO3_H_
33

44
#include "manif/impl/macro.h"
5-
#include "manif/impl/lie_group_base.h"
5+
#include "manif/constants.h"
6+
#include "manif/impl/utils.h"
7+
8+
#include "manif/impl/traits.h"
9+
#include "manif/impl/core/crtp.h"
10+
11+
#include "manif/impl/eigen.h"
12+
13+
#include "manif/impl/expr/expr.h"
14+
#include "manif/impl/random.h"
15+
#include "manif/impl/generator.h"
16+
#include "manif/impl/assignment_assert.h"
17+
18+
#include "lt/optional.hpp"
19+
620
#include "manif/impl/tangent_base.h"
21+
#include "manif/impl/lie_group_base.h"
722

823
#include "manif/impl/so3/SO3_properties.h"
924
#include "manif/impl/so3/SO3_base.h"
1025
#include "manif/impl/so3/SO3Tangent_base.h"
1126
#include "manif/impl/so3/SO3.h"
27+
#include "manif/impl/so3/SO3_expr.h"
1228
#include "manif/impl/so3/SO3Tangent.h"
29+
#include "manif/impl/so3/SO3Tangent_expr.h"
30+
1331
#include "manif/impl/so3/SO3_map.h"
1432
#include "manif/impl/so3/SO3Tangent_map.h"
1533

include/manif/impl/core/crtp.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef _MANIF_MANIF_IMPL_CRTP_H_
2+
#define _MANIF_MANIF_IMPL_CRTP_H_
3+
4+
namespace manif {
5+
namespace internal {
6+
7+
template <typename Derived>
8+
struct crtp
9+
{
10+
protected:
11+
/** Return reference to this as derived object */
12+
inline Derived &derived() & noexcept {
13+
return *static_cast<Derived *>(this);
14+
}
15+
/** Return reference to this as derived object */
16+
inline const Derived &derived() const & noexcept {
17+
return *static_cast<Derived const *>(this);
18+
}
19+
/** Return reference to this as derived object, when this is rvalue */
20+
inline Derived &&derived() && noexcept {
21+
return std::move(*static_cast<Derived *>(this));
22+
}
23+
};
24+
25+
} // namespace internal
26+
} // namespace manif
27+
28+
#endif // _MANIF_MANIF_IMPL_CRTP_H_

include/manif/impl/core/storage.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef _MANIF_MANIF_IMPL_CORE_UNARY_STORAGE_H_
2+
#define _MANIF_MANIF_IMPL_CORE_UNARY_STORAGE_H_
3+
4+
namespace manif {
5+
namespace internal {
6+
7+
template <typename T>
8+
struct storage_selector {
9+
using type = T;
10+
};
11+
12+
template <typename T>
13+
struct storage_selector<T&> {
14+
using type = T&;
15+
};
16+
17+
template <typename T>
18+
struct storage_selector<const T&> {
19+
using type = const T&;
20+
};
21+
22+
template <typename T>
23+
struct storage_selector<T&&> {
24+
using type = T;
25+
};
26+
27+
template <typename T>
28+
using storage_t = typename storage_selector<T>::type;
29+
30+
} // namespace internal
31+
} // namespace manif
32+
33+
#endif // _MANIF_MANIF_IMPL_CORE_UNARY_STORAGE_H_
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#ifndef _MANIF_MANIF_IMPL_CORE_UNARY_STORAGE_H_
2+
#define _MANIF_MANIF_IMPL_CORE_UNARY_STORAGE_H_
3+
4+
5+
namespace manif {
6+
namespace internal {
7+
8+
template <typename Derived, typename RhsDerived_>
9+
struct UnaryStorage {
10+
private:
11+
// Hold a reference to leaf expressions to avoid copies, but a copy of other
12+
// expressions to avoid references to temporaries.
13+
using RhsStore = internal::storage_t<RhsDerived_>;
14+
15+
// Helper to lazily instantiate is_constructible check in forwarding constructor
16+
// We use this inside std::conjunction.
17+
template <typename...>
18+
struct copy_not_applicable : std::true_type {};
19+
20+
// Case for exactly one argument: need to check whether copy constructor applies
21+
template <typename Arg>
22+
struct copy_not_applicable<Arg>
23+
: tmp::bool_constant<!std::is_same<std::decay_t<Arg>, Derived>{}> {};
24+
25+
public:
26+
// Forward args to rhs (version for one argument)
27+
// Disable if copy ctor would apply - https://stackoverflow.com/a/39646176
28+
template <typename Arg,
29+
std::enable_if_t<tmp::conjunction<copy_not_applicable<Arg>,
30+
std::is_constructible<RhsStore, Arg>>{},
31+
bool> = true>
32+
explicit UnaryStorage(Arg &&arg) : rhs_{std::forward<Arg>(arg)} {}
33+
34+
// Forward args to rhs (version for 0 or more than 1 argument)
35+
template <
36+
typename... Args,
37+
std::enable_if_t<tmp::conjunction<copy_not_applicable<Args...>,
38+
std::is_constructible<RhsStore, Args...>>{},
39+
bool> = true>
40+
explicit UnaryStorage(Args &&... args) : rhs_{std::forward<Args>(args)...} {}
41+
42+
UnaryStorage() = delete;
43+
/** Copy constructor */
44+
UnaryStorage(const UnaryStorage &) = default;
45+
/** Move constructor */
46+
UnaryStorage(UnaryStorage &&) = default;
47+
/** Copy assignment operator */
48+
UnaryStorage &operator=(const UnaryStorage &) = default;
49+
/** Move assignment operator */
50+
UnaryStorage &operator=(UnaryStorage &&) = default;
51+
52+
const RhsStore &rhs() const & {
53+
return rhs_;
54+
}
55+
56+
RhsStore &rhs() & {
57+
return rhs_;
58+
}
59+
60+
RhsStore rhs() && {
61+
return rhs_;
62+
}
63+
64+
protected:
65+
RhsStore rhs_;
66+
};
67+
68+
} // namespace internal
69+
} // namespace manif
70+
71+
#endif // _MANIF_MANIF_IMPL_CORE_UNARY_STORAGE_H_

include/manif/impl/expr/act.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#ifndef _MANIF_MANIF_IMPL_EXPR_ACT_H_
2+
#define _MANIF_MANIF_IMPL_EXPR_ACT_H_
3+
4+
namespace manif {
5+
6+
// MANIF_DECLARE_BINARY_EXPR(Act);
7+
8+
template <typename _Lhs, typename _Rhs>
9+
struct ActExpr
10+
: internal::ExprBase<ActExpr<_Lhs, _Rhs>>
11+
{
12+
using ExprDerived = ActExpr<_Lhs, _Rhs>;
13+
using Base = internal::ExprBase<ExprDerived>;
14+
15+
using LieGroup = typename _Lhs::LieGroup;
16+
using Scalar = typename internal::traits<LieGroup>::Scalar;
17+
18+
using LhsOptJacobianRef = ::tl::optional<Eigen::Ref<Eigen::Matrix<Scalar, internal::traits<LieGroup>::Dim, internal::traits<LieGroup>::DoF>>>;
19+
using RhsOptJacobianRef = ::tl::optional<Eigen::Ref<Eigen::Matrix<Scalar, internal::traits<LieGroup>::Dim, internal::traits<LieGroup>::Dim>>>;
20+
21+
using Ret = ReturnType<ExprDerived>;
22+
23+
using Base::derived;
24+
using Base::eval;
25+
26+
ActExpr(const _Lhs& lhsptr,
27+
const _Rhs& rhsptr,
28+
LhsOptJacobianRef& J_ret_lhs = {},
29+
RhsOptJacobianRef& J_ret_rhs = {})
30+
: lhsptr_(lhsptr)
31+
, rhsptr_(rhsptr)
32+
, J_ret_lhs_(J_ret_lhs)
33+
, J_ret_rhs_(J_ret_rhs) { }
34+
35+
protected:
36+
37+
friend Base;
38+
Ret evalImpl() const
39+
{
40+
return internal::ExprEvaluator<ExprDerived>::run(
41+
lhsptr_, rhsptr_, J_ret_lhs_, J_ret_rhs_);
42+
}
43+
44+
const _Lhs& lhsptr_;
45+
const _Rhs& rhsptr_;
46+
mutable LhsOptJacobianRef J_ret_lhs_;
47+
mutable RhsOptJacobianRef J_ret_rhs_;
48+
};
49+
50+
namespace internal {
51+
52+
template <template <typename _Derived> class _LieGroupBase,
53+
typename _Derived, typename _DerivedOther>
54+
struct ReturnTypeHelper<ActExpr<_LieGroupBase<_Derived>, _DerivedOther>>
55+
{
56+
using type = typename traits<_Derived>::Vector;
57+
};
58+
59+
} // namespace internal
60+
} // namespace manif
61+
62+
#endif // _MANIF_MANIF_IMPL_EXPR_ACT_H_

include/manif/impl/expr/adj.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef _MANIF_MANIF_IMPL_EXPR_ADJ_H_
2+
#define _MANIF_MANIF_IMPL_EXPR_ADJ_H_
3+
4+
namespace manif {
5+
6+
MANIF_DECLARE_UNARY_EXPR(Adj);
7+
8+
namespace internal {
9+
10+
// Default expression return type
11+
12+
template <template <typename _LieGroupDerived> class _LieGroupDerivedBase, typename _LieGroupDerived>
13+
struct ReturnTypeHelper<AdjExpr<_LieGroupDerivedBase<_LieGroupDerived>>>
14+
{
15+
using type = typename internal::traits<_LieGroupDerived>::Jacobian;
16+
};
17+
18+
} // namespace internal
19+
} // namespace manif
20+
21+
#endif // _MANIF_MANIF_IMPL_EXPR_ADJ_H_

0 commit comments

Comments
 (0)