Main MRPT website > C++ reference for 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 
16 namespace mrpt
17 {
18 namespace obs
19 {
20 namespace utils
21 {
22 /**\brief Given an mrpt::obs::CSensoryFrame and a mrpt::obs::CObservation
23  * pointer if a OBSERVATION_T type observation is included and return a
24  * pointer to that instance.
25  *
26  * \note Pointer to a single instance is going to be returned. If a suitable
27  * observation exists in both the CSensoryFrame and CObservation the outcome
28  * is decided by the \a priority_to_sf flag
29  *
30  * \return Pointer to the observation of the given type. Otherwise, an empty
31  * Ptr object is returned if a valid observation is not found.
32  *
33  * \ingroup mrpt_obs_grp
34  */
35 template <class OBSERVATION_T>
36 typename OBSERVATION_T::Ptr getObservation(
37  mrpt::obs::CSensoryFrame::Ptr& observations,
38  mrpt::obs::CObservation::Ptr& observation, bool priority_to_sf = true)
39 {
40  using obs_t = typename OBSERVATION_T::Ptr;
41 
42  obs_t cobs_ptr;
43  obs_t sf_ptr;
44  obs_t obs_out;
45 
46  // CObservation
47  const mrpt::rtti::TRuntimeClassId* class_ID =
48  &OBSERVATION_T::GetRuntimeClassIdStatic();
49  if (observation && observation->GetRuntimeClass()->derivedFrom(class_ID))
50  {
51  cobs_ptr = std::dynamic_pointer_cast<OBSERVATION_T>(observation);
52  }
53 
54  // CSensoryFrame
55  if (observations)
56  {
57  cobs_ptr = observations->getObservationByClass<OBSERVATION_T>();
58  }
59 
60  // decide on which one to return
61  if (cobs_ptr && sf_ptr)
62  {
63  obs_out = priority_to_sf ? sf_ptr : cobs_ptr;
64  }
65  else if (cobs_ptr)
66  {
67  obs_out = cobs_ptr;
68  }
69  else if (sf_ptr)
70  {
71  obs_out = sf_ptr;
72  }
73  else
74  {
75  obs_out = typename OBSERVATION_T::Ptr();
76  }
77 
78  return obs_out;
79 }
80 }
81 }
82 } // end of namespaces
83 
84 #endif /* end of include guard: OBS_UTILS_H */
A structure that holds runtime class type information.
Definition: CObject.h:30
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
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:36



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019