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-2017, 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  typedef typename OBSERVATION_T::Ptr obs_t;
41 
42  obs_t cobs_ptr;
43  obs_t sf_ptr;
44  obs_t obs_out;
45 
46  // CObservation
47  const mrpt::utils::TRuntimeClassId* class_ID = &OBSERVATION_T::GetRuntimeClassIdStatic();
48  if (observation && observation->GetRuntimeClass()->derivedFrom(class_ID))
49  {
50  cobs_ptr = std::dynamic_pointer_cast<OBSERVATION_T>(observation);
51  }
52 
53  // CSensoryFrame
54  if (observations)
55  {
56  cobs_ptr = observations->getObservationByClass<OBSERVATION_T>();
57  }
58 
59  // decide on which one to return
60  if (cobs_ptr && sf_ptr)
61  {
62  obs_out = priority_to_sf ? sf_ptr : cobs_ptr;
63  }
64  else if (cobs_ptr)
65  {
66  obs_out = cobs_ptr;
67  }
68  else if (sf_ptr)
69  {
70  obs_out = sf_ptr;
71  }
72  else
73  {
74  obs_out = typename OBSERVATION_T::Ptr();
75  }
76 
77  return obs_out;
78 }
79 }
80 }
81 } // end of namespaces
82 
83 #endif /* end of include guard: OBS_UTILS_H */
std::shared_ptr< CSensoryFrame > Ptr
Definition: CSensoryFrame.h:56
std::shared_ptr< CObservation > Ptr
Definition: CObservation.h:43
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
A structure that holds runtime class type information.
Definition: CObject.h:31



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019