diff --git a/include/core/problem/problem.h b/include/core/problem/problem.h index f92d39c8bdf99d7536695913df603a9a890dd1e0..5290dd78c4f313a9e1717e36c552d75fb7392816 100644 --- a/include/core/problem/problem.h +++ b/include/core/problem/problem.h @@ -44,8 +44,10 @@ class Problem : public std::enable_shared_from_this<Problem> // TODO move somewhere below public: - StateComposite getStateComposite() const; - StateComposite getStateComposite(const TimeStamp& _ts) const; + bool getStateComposite(StateComposite& _state) const; + bool getStateComposite(const TimeStamp& _ts, StateComposite& _state) const; + StateComposite getStateComposite() const; + StateComposite getStateComposite(const TimeStamp& _ts) const; diff --git a/include/core/processor/is_motion.h b/include/core/processor/is_motion.h index 25ded4c220ff100aca93995f35605cc15ca414ca..e289ec29854b510f2b99a763bca2d3f3758e11f2 100644 --- a/include/core/processor/is_motion.h +++ b/include/core/processor/is_motion.h @@ -23,9 +23,8 @@ class IsMotion public: // TODO move somewhere below - virtual bool getStateComposite(StateComposite& _state) const = 0; - virtual bool getStateComposite(const TimeStamp& _ts, StateComposite& _state) const = 0; - + virtual bool getStateComposite(StateComposite& _state) const = 0; + virtual bool getStateComposite(const TimeStamp& _ts, StateComposite& _state) const = 0; StateComposite getStateComposite() const; StateComposite getStateComposite(const TimeStamp& _ts) const; @@ -85,6 +84,13 @@ inline TimeStamp IsMotion::getCurrentTimeStamp() const return ts; } +inline Eigen::VectorXd IsMotion::getState(const TimeStamp& _ts) const +{ + Eigen::VectorXd x; + getState(_ts, x); + return x; +} + inline StateComposite IsMotion::getStateComposite() const { StateComposite state; @@ -99,13 +105,6 @@ inline StateComposite IsMotion::getStateComposite(const TimeStamp &_ts) const return state; } -inline Eigen::VectorXd IsMotion::getState(const TimeStamp& _ts) const -{ - Eigen::VectorXd x; - getState(_ts, x); - return x; -} - } /* namespace wolf */ diff --git a/include/core/state_block/has_state_blocks.h b/include/core/state_block/has_state_blocks.h index c7809b8e0ea301c50790c567412d8ceb9700c3a5..e9e9223512c390eb628d80a6d9b021c93dafa1d5 100644 --- a/include/core/state_block/has_state_blocks.h +++ b/include/core/state_block/has_state_blocks.h @@ -72,7 +72,8 @@ class HasStateBlocks void getState(Eigen::VectorXd& _state, const StateStructure& _sub_structure = StateStructure()) const; Eigen::VectorXd getState(const StateStructure& _sub_structure = StateStructure()) const; - StateComposite getStateComposite(); + StateComposite getStateComposite() const; + bool getStateComposite(StateComposite& _state) const; void setStateComposite(const StateComposite& _state); // Perturb state @@ -261,13 +262,19 @@ inline Eigen::VectorXd HasStateBlocks::getState(const StateStructure& _sub_struc return state; } -inline StateComposite HasStateBlocks::getStateComposite() +inline bool HasStateBlocks::getStateComposite(StateComposite& _state) const { - StateComposite state; for (auto& pair_key_sb : state_block_map_) { - state.emplace(pair_key_sb.first, pair_key_sb.second->getState()); + _state.emplace(pair_key_sb.first, pair_key_sb.second->getState()); } + return true; +} + +inline StateComposite HasStateBlocks::getStateComposite() const +{ + StateComposite state; + getStateComposite(state); return state; } diff --git a/src/problem/problem.cpp b/src/problem/problem.cpp index b7565f35c1751f7506137984f6fa40a1e655d43b..5e7a4150a6462f3d0d9891a68db6b72101579a06 100644 --- a/src/problem/problem.cpp +++ b/src/problem/problem.cpp @@ -376,17 +376,15 @@ void Problem::getCurrentStateAndStamp(Eigen::VectorXd& _state, TimeStamp& _ts) c _state = zeroState(); } -inline StateComposite Problem::getStateComposite() const +inline bool Problem::getStateComposite(StateComposite& _state) const { - StateComposite state; - if ( processor_is_motion_list_.empty() ) // Use last estimated frame's state { auto last_kf_or_aux = trajectory_ptr_->getLastKeyOrAuxFrame(); if (last_kf_or_aux) - state = last_kf_or_aux->getStateComposite(); + _state = last_kf_or_aux->getStateComposite(); else - state = StateComposite(); + _state = StateComposite(); } else // Compose from different processor motion { @@ -403,13 +401,13 @@ inline StateComposite Problem::getStateComposite() const { for (const auto& pair_key_vec : prc->getStateComposite(min_ts)) { - if (state.count(pair_key_vec.first) == 0) - state.insert(pair_key_vec); + if (_state.count(pair_key_vec.first) == 0) + _state.insert(pair_key_vec); } } } - return state; + return true; } diff --git a/src/processor/processor_motion.cpp b/src/processor/processor_motion.cpp index 11db736b56699ff204f8ff262d63236a625297a7..fb5661ebdb6db756d546d2cca4a946630cbb7e70 100644 --- a/src/processor/processor_motion.cpp +++ b/src/processor/processor_motion.cpp @@ -398,6 +398,25 @@ bool ProcessorMotion::getState(const TimeStamp& _ts, Eigen::VectorXd& _x) const return true; } +bool ProcessorMotion::getStateComposite(StateComposite& _state) const +{ + // TODO implement this + if (last_ptr_ && last_ptr_->getFrame()) + return getLast()->getFrame()->getStateComposite(_state); + else + return false; +} + +bool ProcessorMotion::getStateComposite(const TimeStamp& _ts, StateComposite& _state) const +{ + // TODO implement this + if (last_ptr_ && last_ptr_->getFrame()) + return getLast()->getFrame()->getStateComposite(_state); + else + return false; +} + + FrameBasePtr ProcessorMotion::setOrigin(const Eigen::VectorXd& _x_origin, const TimeStamp& _ts_origin) { FrameBasePtr key_frame_ptr = getProblem()->emplaceFrame(KEY, _x_origin, _ts_origin);