MRPT  2.0.0
obs_utils.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #pragma once
11 
12 #include <mrpt/obs/CObservation.h>
13 #include <mrpt/obs/CSensoryFrame.h>
14 
16 {
17 /**\brief Given an mrpt::obs::CSensoryFrame and a mrpt::obs::CObservation
18  * pointer if a OBSERVATION_T type observation is included and return a
19  * pointer to that instance.
20  *
21  * \note Pointer to a single instance is going to be returned. If a suitable
22  * observation exists in both the CSensoryFrame and CObservation the outcome
23  * is decided by the \a priority_to_sf flag
24  *
25  * \return Pointer to the observation of the given type. Otherwise, an empty
26  * Ptr object is returned if a valid observation is not found.
27  *
28  * \ingroup mrpt_obs_grp
29  */
30 template <class OBSERVATION_T>
31 typename OBSERVATION_T::Ptr getObservation(
32  mrpt::obs::CSensoryFrame::Ptr& observations,
33  mrpt::obs::CObservation::Ptr& observation, bool priority_to_sf = true)
34 {
35  using obs_t = typename OBSERVATION_T::Ptr;
36 
37  obs_t cobs_ptr;
38  obs_t sf_ptr;
39  obs_t obs_out;
40 
41  // CObservation
42  const mrpt::rtti::TRuntimeClassId* class_ID =
43  &OBSERVATION_T::GetRuntimeClassIdStatic();
44  if (observation && observation->GetRuntimeClass()->derivedFrom(class_ID))
45  {
46  cobs_ptr = std::dynamic_pointer_cast<OBSERVATION_T>(observation);
47  }
48 
49  // CSensoryFrame
50  if (observations)
51  {
52  cobs_ptr = observations->getObservationByClass<OBSERVATION_T>();
53  }
54 
55  // decide on which one to return
56  if (cobs_ptr && sf_ptr)
57  {
58  obs_out = priority_to_sf ? sf_ptr : cobs_ptr;
59  }
60  else if (cobs_ptr)
61  {
62  obs_out = cobs_ptr;
63  }
64  else if (sf_ptr)
65  {
66  obs_out = sf_ptr;
67  }
68  else
69  {
70  obs_out = typename OBSERVATION_T::Ptr();
71  }
72 
73  return obs_out;
74 }
75 } // namespace mrpt::obs::utils
A structure that holds runtime class type information.
Definition: CObject.h:31
OBSERVATION_T::Ptr getObservation(mrpt::obs::CSensoryFrame::Ptr &observations, mrpt::obs::CObservation::Ptr &observation, bool priority_to_sf=true)
Given an mrpt::obs::CSensoryFrame and a mrpt::obs::CObservation pointer if a OBSERVATION_T type obser...
Definition: obs_utils.h:31



Page generated by Doxygen 1.8.14 for MRPT 2.0.0 Git: b38439d21 Tue Mar 31 19:58:06 2020 +0200 at miƩ abr 1 00:50:30 CEST 2020