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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020