diff --git a/include/core/frame/frame_base.h b/include/core/frame/frame_base.h index 848fa3f12f21e709286a61cd37edb4122fe361bc..7234284a5d00ebcb66f6f9a2efee2c38c9745bbd 100644 --- a/include/core/frame/frame_base.h +++ b/include/core/frame/frame_base.h @@ -102,6 +102,12 @@ class FrameBase : public NodeBase, public HasStateBlocks, public std::enable_sha FrameBasePtr getNextFrame() const; const CaptureBasePtrList& getCaptureList() const; + template <class C> + CaptureBasePtr getCaptureOfType() const; + CaptureBasePtr getCaptureOfType(const std::string& type) const; + template <class C> + CaptureBasePtrList getCapturesOfType() const; + CaptureBasePtrList getCapturesOfType(const std::string& type) const; CaptureBasePtr getCaptureOf(const SensorBaseConstPtr _sensor_ptr) const; CaptureBasePtr getCaptureOf(const SensorBasePtr _sensor_ptr, const std::string& type) const; CaptureBasePtrList getCapturesOf(const SensorBasePtr _sensor_ptr) const; @@ -208,6 +214,25 @@ inline void FrameBase::setTrajectory(TrajectoryBasePtr _trj_ptr) trajectory_ptr_ = _trj_ptr; } +template <class C> +inline CaptureBasePtr FrameBase::getCaptureOfType() const +{ + for (CaptureBasePtr capture_ptr : getCaptureList()) + if (std::dynamic_pointer_cast<C>(capture_ptr) != nullptr) + return capture_ptr; + return nullptr; +} + +template <class C> +inline CaptureBasePtrList FrameBase::getCapturesOfType() const +{ + CaptureBasePtrList captures; + for (CaptureBasePtr capture_ptr : getCaptureList()) + if (std::dynamic_pointer_cast<C>(capture_ptr) != nullptr) + captures.push_back(capture_ptr); + return captures; +} + } // namespace wolf #endif diff --git a/src/frame/frame_base.cpp b/src/frame/frame_base.cpp index 95233cf96e55c29910aa8ac13168e220b3cde136..71e344552517ef659bb3ae60f66abbb95c25056f 100644 --- a/src/frame/frame_base.cpp +++ b/src/frame/frame_base.cpp @@ -175,6 +175,23 @@ void FrameBase::removeCapture(CaptureBasePtr _capt_ptr) capture_list_.remove(_capt_ptr); } +CaptureBasePtr FrameBase::getCaptureOfType(const std::string& type) const +{ + for (CaptureBasePtr capture_ptr : getCaptureList()) + if (capture_ptr->getType() == type) + return capture_ptr; + return nullptr; +} + +CaptureBasePtrList FrameBase::getCapturesOfType(const std::string& type) const +{ + CaptureBasePtrList captures; + for (CaptureBasePtr capture_ptr : getCaptureList()) + if (capture_ptr->getType() == type) + captures.push_back(capture_ptr); + return captures; +} + CaptureBasePtr FrameBase::getCaptureOf(const SensorBasePtr _sensor_ptr, const std::string& type) const { for (CaptureBasePtr capture_ptr : getCaptureList())