Main MRPT website > C++ reference for MRPT 1.5.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-2016, 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 { namespace obs { namespace utils {
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::CSensoryFramePtr& observations,
34  mrpt::obs::CObservationPtr& observation,
35  bool priority_to_sf=true) {
36 
37  typedef typename OBSERVATION_T::Ptr obs_t;
38 
39  obs_t cobs_ptr;
40  obs_t sf_ptr;
41  obs_t obs_out;
42 
43  // CObservation
44  const mrpt::utils::TRuntimeClassId* class_ID = OBSERVATION_T::classinfo;
45  if (observation.present() &&
46  observation->GetRuntimeClass()->derivedFrom(class_ID)) {
47  cobs_ptr =
48  static_cast<obs_t>(observation);
49  }
50 
51  // CSensoryFrame
52  if (observations.present()) {
53  cobs_ptr = observations->getObservationByClass<OBSERVATION_T>();
54  }
55 
56  // decide on which one to return
57  if (cobs_ptr.present() && sf_ptr.present()) {
58  obs_out = priority_to_sf? sf_ptr : cobs_ptr;
59  }
60  else if (cobs_ptr.present()) {
61  obs_out = cobs_ptr;
62  }
63  else if (sf_ptr.present()) {
64  obs_out = sf_ptr;
65  }
66  else {
67  obs_out = typename OBSERVATION_T::Ptr();
68  }
69 
70  return obs_out;
71  }
72 
73 } } } // end of namespaces
74 
75 #endif /* end of include guard: OBS_UTILS_H */
76 
OBSERVATION_T::Ptr getObservation(mrpt::obs::CSensoryFramePtr &observations, mrpt::obs::CObservationPtr &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
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A structure that holds runtime class type information.
Definition: CObject.h:36



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020