Main MRPT website > C++ reference for MRPT 1.9.9
CObservationRange.cpp
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 #include "obs-precomp.h" // Precompiled headers
11 
13 #include <mrpt/utils/CStream.h>
14 
15 using namespace mrpt::obs;
16 using namespace mrpt::utils;
17 using namespace mrpt::poses;
18 
19 // This must be added to any CSerializable class implementation file.
21 
22 /** Default constructor.
23  */
25  : minSensorDistance(0),
26  maxSensorDistance(5),
27  sensorConeApperture(DEG2RAD(20)),
28  sensedData()
29 {
30 }
31 
32 /*---------------------------------------------------------------
33  Implements the writing to a CStream capability of CSerializable objects
34  ---------------------------------------------------------------*/
36  mrpt::utils::CStream& out, int* version) const
37 {
38  if (version)
39  *version = 3;
40  else
41  {
42  uint32_t i, n;
43 
44  // The data
45  out << minSensorDistance << maxSensorDistance << sensorConeApperture;
46 
47  n = sensedData.size();
48  out << n;
49  for (i = 0; i < n; i++)
50  out << sensedData[i].sensorID << CPose3D(sensedData[i].sensorPose)
51  << sensedData[i].sensedDistance;
52 
53  out << sensorLabel << timestamp;
54  }
55 }
56 
57 /*---------------------------------------------------------------
58  Implements the reading from a CStream capability of CSerializable objects
59  ---------------------------------------------------------------*/
61 {
62  switch (version)
63  {
64  case 0:
65  case 1:
66  case 2:
67  case 3:
68  {
69  uint32_t i, n;
70 
71  // The data
72  in >> minSensorDistance >> maxSensorDistance >> sensorConeApperture;
73 
74  in >> n;
75  sensedData.resize(n);
76  CPose3D aux;
77  for (i = 0; i < n; i++)
78  {
79  if (version >= 3)
80  in >> sensedData[i].sensorID;
81  else
82  sensedData[i].sensorID = i;
83 
84  in >> aux >> sensedData[i].sensedDistance;
85  sensedData[i].sensorPose = aux;
86  }
87 
88  if (version >= 1)
89  in >> sensorLabel;
90  else
91  sensorLabel = "";
92 
93  if (version >= 2)
94  in >> timestamp;
95  else
96  timestamp = INVALID_TIMESTAMP;
97  }
98  break;
99  default:
101  };
102 }
103 
104 /*---------------------------------------------------------------
105  getSensorPose
106  ---------------------------------------------------------------*/
107 void CObservationRange::getSensorPose(CPose3D& out_sensorPose) const
108 {
109  if (!sensedData.empty())
110  out_sensorPose = CPose3D(sensedData[0].sensorPose);
111  else
112  out_sensorPose = CPose3D(0, 0, 0);
113 }
114 
115 /*---------------------------------------------------------------
116  setSensorPose
117  ---------------------------------------------------------------*/
118 void CObservationRange::setSensorPose(const CPose3D& newSensorPose)
119 {
120  size_t i, n = sensedData.size();
121  if (n)
122  for (i = 0; i < n; i++) sensedData[i].sensorPose = newSensorPose;
123 }
124 
125 void CObservationRange::getDescriptionAsText(std::ostream& o) const
126 {
127  using namespace std;
129 
130  o << "minSensorDistance = " << minSensorDistance << " m" << endl;
131  o << "maxSensorDistance = " << maxSensorDistance << " m" << endl;
132  o << "sensorConeApperture = " << RAD2DEG(sensorConeApperture) << " deg"
133  << endl;
134 
135  // For each entry in this sequence:
136  o << " SENSOR_ID RANGE (m) SENSOR POSE (on the robot)" << endl;
137  o << "-------------------------------------------------------" << endl;
138  for (size_t q = 0; q < sensedData.size(); q++)
139  {
140  o << format(" %7u", (unsigned int)sensedData[q].sensorID);
141  o << format(" %4.03f ", sensedData[q].sensedDistance);
142  o << sensedData[q].sensorPose << endl;
143  }
144 }
Declares a class derived from "CObservation" that encapsules a single range measurement, and associated parameters.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
GLdouble GLdouble GLdouble GLdouble q
Definition: glext.h:3721
GLenum GLsizei n
Definition: glext.h:5074
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.
STL namespace.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
This namespace contains representation of robot actions and observations.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:19
void readFromStream(mrpt::utils::CStream &in, int version) override
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
#define DEG2RAD
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
#define INVALID_TIMESTAMP
Represents an invalid timestamp, where applicable.
Definition: datetime.h:16
#define RAD2DEG
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
Declares a class that represents any robot&#39;s observation.
Definition: CObservation.h:41
GLuint in
Definition: glext.h:7274
void setSensorPose(const mrpt::poses::CPose3D &newSensorPose) override
A general method to change the sensor pose on the robot.
void getDescriptionAsText(std::ostream &o) const override
Build a detailed, multi-line textual description of the observation contents and dump it to the outpu...
unsigned __int32 uint32_t
Definition: rptypes.h:47
void getSensorPose(mrpt::poses::CPose3D &out_sensorPose) const override
A general method to retrieve the sensor pose on the robot.
virtual void getDescriptionAsText(std::ostream &o) const
Build a detailed, multi-line textual description of the observation contents and dump it to the outpu...



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