Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef HECTOR_POSE_ESTIMATION_SUBSTATE_H
00030 #define HECTOR_POSE_ESTIMATION_SUBSTATE_H
00031
00032 #include <hector_pose_estimation/state.h>
00033
00034 namespace hector_pose_estimation {
00035
00036 class SubState
00037 {
00038 public:
00039 SubState(State& state) : state_(state) {}
00040 virtual ~SubState() {}
00041
00042 virtual int getDimension() const = 0;
00043 virtual int getIndex() const = 0;
00044
00045 virtual void reset() {}
00046 virtual void updated() {}
00047 virtual void normalize() {}
00048
00049 protected:
00050 State& state_;
00051 template <int _Dimension> class initializer;
00052 };
00053
00054 template <int _Dimension> class SubState::initializer {
00055 public:
00056 enum { Dimension = _Dimension };
00057 initializer(State& state) : index_(state.getDimension()) {
00058 IndexType newDimension = index_ + Dimension;
00059 state.x().conservativeResize(newDimension);
00060 state.P().conservativeResize(newDimension);
00061 }
00062 protected:
00063 const IndexType index_;
00064 };
00065
00066 template <> class SubState::initializer<0> {
00067 public:
00068 enum { Dimension = State::Dimension };
00069 initializer(State&) : index_(0) {}
00070 protected:
00071 const IndexType index_;
00072 };
00073
00074 template <int _Dimension>
00075 class SubState_ : public SubState, public SubState::initializer<_Dimension>
00076 {
00077 public:
00078 enum { Dimension = SubState::initializer<_Dimension>::Dimension };
00079 typedef ColumnVector_<Dimension> Vector;
00080
00081 typedef VectorBlock<State::Vector,Dimension> VectorSegment;
00082 typedef Block<State::Covariance::Base,Dimension,Dimension> CovarianceBlock;
00083 typedef Block<State::Covariance::Base,State::Dimension,Dimension> CrossVarianceBlock;
00084
00085 typedef VectorBlock<const State::Vector,Dimension> ConstVectorSegment;
00086 typedef Block<const State::Covariance::Base,Dimension,Dimension> ConstCovarianceBlock;
00087 typedef Block<const State::Covariance::Base,State::Dimension,Dimension> ConstCrossVarianceBlock;
00088
00089 typedef boost::shared_ptr<SubState_<_Dimension> > Ptr;
00090
00091 using SubState::initializer<_Dimension>::index_;
00092
00093 public:
00094 SubState_(State& state)
00095 : SubState(state)
00096 , SubState::initializer<_Dimension>(state)
00097
00098
00099
00100 {
00101 }
00102 virtual ~SubState_() {}
00103
00104 int getDimension() const { return Dimension; }
00105 int getIndex() const { return index_; }
00106
00107 ConstVectorSegment getVector() const { return state_.getVector().segment<Dimension>(index_); }
00108 ConstCovarianceBlock getCovariance() const { return state_.getCovariance().block<Dimension,Dimension>(index_,index_); }
00109 template <int Size> VectorBlock<const typename Vector::Base, Size> getSegment(IndexType start) const { return state_.getVector().segment<Dimension>(index_ + start); }
00110
00111 VectorSegment x() { return state_.x().segment<Dimension>(index_); }
00112 CovarianceBlock P() { return state_.P().block<Dimension,Dimension>(index_,index_); }
00113 CrossVarianceBlock P01() { return state_.P().block<State::Dimension,Dimension>(0,index_); }
00114 };
00115
00116 extern template class SubState_<0>;
00117
00118 template <int SubDimension>
00119 boost::shared_ptr<SubState_<SubDimension> > State::getSubState(const Model *model) const {
00120 return boost::shared_dynamic_cast<SubState_<SubDimension> >(substates_by_model_.count(model) ? substates_by_model_.at(model).lock() : SubStatePtr());
00121 }
00122
00123 template <>
00124 inline boost::shared_ptr<BaseState> State::getSubState<0>(const Model *) const {
00125 return base_;
00126 }
00127
00128 template <int SubDimension>
00129 boost::shared_ptr<SubState_<SubDimension> > State::getSubState(const std::string& name) const {
00130 return boost::shared_dynamic_cast<SubState_<SubDimension> >(substates_by_name_.count(name) ? substates_by_name_.at(name).lock() : SubStatePtr());
00131 }
00132
00133 template <int SubDimension>
00134 boost::shared_ptr<SubState_<SubDimension> > State::addSubState(const Model *model, const std::string& name) {
00135 boost::shared_ptr<SubState_<SubDimension> > substate;
00136 if (!name.empty()) substate = getSubState<SubDimension>(name);
00137 if (!substate) {
00138 substate.reset(new SubState_<SubDimension>(*this));
00139 substates_.push_back(boost::shared_static_cast<SubState>(substate));
00140 if (!name.empty()) substates_by_name_[name] = SubStateWPtr(boost::shared_static_cast<SubState>(substate));
00141 }
00142 substates_by_model_[model] = SubStateWPtr(boost::shared_static_cast<SubState>(substate));
00143 return substate;
00144 }
00145
00146 }
00147
00148 #endif // HECTOR_POSE_ESTIMATION_SUBSTATE_H