Main MRPT website > C++ reference for MRPT 1.9.9
CSimpleMap.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 
12 #include <mrpt/maps/CSimpleMap.h>
15 #include <mrpt/utils/CStream.h>
16 
17 using namespace mrpt::obs;
18 using namespace mrpt::maps;
19 using namespace mrpt::utils;
20 using namespace mrpt::poses;
21 using namespace mrpt::poses;
22 using namespace std;
23 
25 using namespace mrpt::utils::metaprogramming;
26 
28 
29 /*---------------------------------------------------------------
30  Constructor
31  ---------------------------------------------------------------*/
32 CSimpleMap::CSimpleMap() : m_posesObsPairs() {}
33 /*---------------------------------------------------------------
34  Copy
35  ---------------------------------------------------------------*/
36 CSimpleMap::CSimpleMap(const CSimpleMap& o) : m_posesObsPairs(o.m_posesObsPairs)
37 {
38  for_each(
40 }
41 
42 /*---------------------------------------------------------------
43  Copy
44  ---------------------------------------------------------------*/
46 {
48 
49  // TPosePDFSensFramePair pair;
50 
51  if (this == &o) return *this; // It may be used sometimes
52 
54  for_each(
56 
57  return *this;
58 
59  MRPT_END
60 }
61 
62 /*---------------------------------------------------------------
63  size
64  ---------------------------------------------------------------*/
65 size_t CSimpleMap::size() const { return m_posesObsPairs.size(); }
66 bool CSimpleMap::empty() const { return m_posesObsPairs.empty(); }
67 /*---------------------------------------------------------------
68  clear
69  ---------------------------------------------------------------*/
71 /*---------------------------------------------------------------
72  Destructor
73  ---------------------------------------------------------------*/
75 /*---------------------------------------------------------------
76  get const
77  ---------------------------------------------------------------*/
79  size_t index, CPose3DPDF::Ptr& out_posePDF,
80  CSensoryFrame::Ptr& out_SF) const
81 {
82  if (index >= m_posesObsPairs.size()) THROW_EXCEPTION("Index out of bounds");
83 
84  out_posePDF = m_posesObsPairs[index].first;
85  out_SF = m_posesObsPairs[index].second;
86 }
87 
88 /*---------------------------------------------------------------
89  remove
90  ---------------------------------------------------------------*/
92 {
94 
95  if (index >= m_posesObsPairs.size()) THROW_EXCEPTION("Index out of bounds");
96 
97  m_posesObsPairs.erase(m_posesObsPairs.begin() + index);
98 
99  MRPT_END
100 }
101 
102 /*---------------------------------------------------------------
103  set
104  ---------------------------------------------------------------*/
106  size_t index, const CPose3DPDF::Ptr& in_posePDF,
107  const CSensoryFrame::Ptr& in_SF)
108 {
109  MRPT_START
110 
111  if (index >= m_posesObsPairs.size()) THROW_EXCEPTION("Index out of bounds");
112 
113  if (in_posePDF) m_posesObsPairs[index].first = in_posePDF;
114  if (in_SF) m_posesObsPairs[index].second = in_SF;
115 
116  MRPT_END
117 }
118 
119 /*---------------------------------------------------------------
120  set 2D
121  ---------------------------------------------------------------*/
123  size_t index, const CPosePDF::Ptr& in_posePDF,
124  const CSensoryFrame::Ptr& in_SF)
125 {
126  MRPT_START
127 
128  if (index >= m_posesObsPairs.size()) THROW_EXCEPTION("Index out of bounds");
129 
130  if (in_posePDF)
131  m_posesObsPairs[index].first =
132  CPose3DPDF::Ptr(CPose3DPDF::createFrom2D(*in_posePDF));
133  if (in_SF) m_posesObsPairs[index].second = in_SF;
134 
135  MRPT_END
136 }
137 
138 /*---------------------------------------------------------------
139  insert
140  ---------------------------------------------------------------*/
142  const CPose3DPDF* in_posePDF, const CSensoryFrame::Ptr& in_SF)
143 {
144  MRPT_START
145 
147 
148  pair.second = in_SF;
149  pair.first = CPose3DPDF::Ptr(static_cast<CPose3DPDF*>(in_posePDF->clone()));
150 
151  m_posesObsPairs.push_back(pair);
152 
153  MRPT_END
154 }
155 
156 /*---------------------------------------------------------------
157  insert
158  ---------------------------------------------------------------*/
160  const CPose3DPDF::Ptr& in_posePDF, const CSensoryFrame::Ptr& in_SF)
161 {
162  MRPT_START
163 
165 
166  pair.second = in_SF;
167  pair.first = in_posePDF;
168 
169  m_posesObsPairs.push_back(pair);
170 
171  MRPT_END
172 }
173 
174 /*---------------------------------------------------------------
175  insert
176  ---------------------------------------------------------------*/
178  const CPose3DPDF* in_posePDF, const CSensoryFrame& in_SF)
179 {
180  MRPT_START
181 
183 
184  pair.second = CSensoryFrame::Ptr(new CSensoryFrame(in_SF));
185  pair.first = CPose3DPDF::Ptr(static_cast<CPose3DPDF*>(in_posePDF->clone()));
186 
187  m_posesObsPairs.push_back(pair);
188 
189  MRPT_END
190 }
191 
192 /*---------------------------------------------------------------
193  insert
194  ---------------------------------------------------------------*/
195 void CSimpleMap::insert(const CPosePDF* in_posePDF, const CSensoryFrame& in_SF)
196 {
197  MRPT_START
198 
200 
201  pair.second = CSensoryFrame::Ptr(new CSensoryFrame(in_SF));
202  pair.first = CPose3DPDF::Ptr(static_cast<CPose3DPDF*>(in_posePDF->clone()));
203 
204  m_posesObsPairs.push_back(pair);
205 
206  MRPT_END
207 }
208 
209 /*---------------------------------------------------------------
210  insert
211  ---------------------------------------------------------------*/
213  const CPosePDF* in_posePDF, const CSensoryFrame::Ptr& in_SF)
214 {
215  MRPT_START
216 
218 
219  pair.second = in_SF;
220  pair.first = CPose3DPDF::Ptr(static_cast<CPose3DPDF*>(in_posePDF->clone()));
221 
222  m_posesObsPairs.push_back(pair);
223 
224  MRPT_END
225 }
226 
227 /*---------------------------------------------------------------
228  insert 2D
229  ---------------------------------------------------------------*/
231  const CPosePDF::Ptr& in_posePDF, const CSensoryFrame::Ptr& in_SF)
232 {
233  insert(CPose3DPDF::Ptr(CPose3DPDF::createFrom2D(*in_posePDF)), in_SF);
234 }
235 
237  size_t index, const CPose3DPDF::Ptr& in_posePDF,
238  const CSensoryFrame::Ptr& in_SF)
239 {
240  if (index >= m_posesObsPairs.size()) return;
241 
242  MRPT_START
243 
245 
246  pair.second = in_SF;
247  pair.first = in_posePDF;
248 
249  auto iter = m_posesObsPairs.begin() + index;
250  m_posesObsPairs.insert(iter, pair);
251 
252  MRPT_END
253 }
254 
255 /*---------------------------------------------------------------
256  writeToStream
257  Implements the writing to a CStream capability of
258  CSerializable objects
259  ---------------------------------------------------------------*/
260 void CSimpleMap::writeToStream(mrpt::utils::CStream& out, int* version) const
261 {
262  if (version)
263  *version = 1;
264  else
265  {
266  uint32_t i, n;
267  n = m_posesObsPairs.size();
268  out << n;
269  for (i = 0; i < n; i++)
270  out << *m_posesObsPairs[i].first << *m_posesObsPairs[i].second;
271  }
272 }
273 
274 /*---------------------------------------------------------------
275  readFromStream
276  ---------------------------------------------------------------*/
278 {
279  switch (version)
280  {
281  case 1:
282  {
283  uint32_t i, n;
284  clear();
285  in >> n;
286  m_posesObsPairs.resize(n);
287  for (i = 0; i < n; i++)
288  in >> m_posesObsPairs[i].first >> m_posesObsPairs[i].second;
289  }
290  break;
291  case 0:
292  {
293  // There are 2D poses PDF instead of 3D: transform them:
294  uint32_t i, n;
295  clear();
296  in >> n;
297  m_posesObsPairs.resize(n);
298  for (i = 0; i < n; i++)
299  {
300  CPosePDF::Ptr aux2Dpose;
301  in >> aux2Dpose >> m_posesObsPairs[i].second;
302  m_posesObsPairs[i].first =
303  CPose3DPDF::Ptr(CPose3DPDF::createFrom2D(*aux2Dpose));
304  }
305  }
306  break;
307  default:
309  };
310 }
311 
312 /*---------------------------------------------------------------
313  changeCoordinatesOrigin
314  ---------------------------------------------------------------*/
316 {
318  it != m_posesObsPairs.end(); ++it)
319  it->first->changeCoordinatesReference(newOrigin);
320 }
321 
322 /** Save this object to a .simplemap binary file (compressed with gzip)
323 * \sa loadFromFile
324 * \return false on any error.
325 */
326 bool CSimpleMap::saveToFile(const std::string& filName) const
327 {
328  try
329  {
331  f << *this;
332  return true;
333  }
334  catch (...)
335  {
336  return false;
337  }
338 }
339 
340 /** Load the contents of this object from a .simplemap binary file (possibly
341 * compressed with gzip)
342 * \sa saveToFile
343 * \return false on any error.
344 */
346 {
347  try
348  {
350  f >> *this;
351  return true;
352  }
353  catch (...)
354  {
355  return false;
356  }
357 }
bool empty() const
Returns size()!=0.
Definition: CSimpleMap.cpp:66
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
This class stores a sequence of <Probabilistic Pose,SensoryFrame> pairs, thus a "metric map" can be t...
Definition: CSimpleMap.h:35
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:44
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
GLint * first
Definition: glext.h:3827
#define THROW_EXCEPTION(msg)
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...
Definition: CSimpleMap.cpp:277
virtual CObject * clone() const =0
Returns a deep copy (clone) of the object, indepently of its class.
GLenum GLsizei n
Definition: glext.h:5074
Scalar * iterator
Definition: eigen_plugins.h:26
STL namespace.
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.
Definition: CSimpleMap.cpp:260
CSimpleMap & operator=(const CSimpleMap &o)
Copy.
Definition: CSimpleMap.cpp:45
bool loadFromFile(const std::string &filName)
Load the contents of this object from a .simplemap binary file (possibly compressed with gzip) ...
Definition: CSimpleMap.cpp:345
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
std::shared_ptr< CPosePDF > Ptr
Definition: CPosePDF.h:44
#define MRPT_END
GLuint index
Definition: glext.h:4054
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Transparently opens a compressed "gz" file and reads uncompressed data from it.
std::shared_ptr< CPose3DPDF > Ptr
Definition: CPose3DPDF.h:45
This namespace contains representation of robot actions and observations.
Declares a class for storing a "sensory frame", a set of "observations" taken by the robot approximat...
Definition: CSensoryFrame.h:54
std::shared_ptr< CSensoryFrame > Ptr
Definition: CSensoryFrame.h:56
A set of utility objects for metaprogramming with STL algorithms.
void set(size_t index, const mrpt::poses::CPose3DPDF::Ptr &in_posePDF, const mrpt::obs::CSensoryFrame::Ptr &in_SF)
Changes the i&#39;th pair, first one is index &#39;0&#39;.
Definition: CSimpleMap.cpp:105
size_t size() const
Returns the count of pairs (pose,sensory data)
Definition: CSimpleMap.cpp:65
void get(size_t index, mrpt::poses::CPose3DPDF::Ptr &out_posePDF, mrpt::obs::CSensoryFrame::Ptr &out_SF) const
Access to the i&#39;th pair, first one is index &#39;0&#39;.
Definition: CSimpleMap.cpp:78
GLsizei const GLchar ** string
Definition: glext.h:4101
Declares a class that represents a probability density function (pdf) of a 2D pose (x...
Definition: CPosePDF.h:41
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
#define MRPT_START
An object for making smart pointers unique (ie, making copies if necessary), intended for being used ...
#define CFileGZOutputStream
Saves data to a file and transparently compress the data using the given compression level...
virtual ~CSimpleMap()
Destructor:
Definition: CSimpleMap.cpp:74
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
std::pair< mrpt::poses::CPose3DPDF::Ptr, mrpt::obs::CSensoryFrame::Ptr > TPosePDFSensFramePair
Definition: CSimpleMap.h:182
void insertToPos(size_t index, const mrpt::poses::CPose3DPDF::Ptr &in_posePDF, const mrpt::obs::CSensoryFrame::Ptr &in_SF)
Insert a new pair to the sequence, making a copy of the smart pointer (it&#39;s not made unique) to...
Definition: CSimpleMap.cpp:236
GLuint in
Definition: glext.h:7274
void insert(const mrpt::poses::CPose3DPDF *in_posePDF, const mrpt::obs::CSensoryFrame &in_SF)
Add a new pair to the sequence.
Definition: CSimpleMap.cpp:177
unsigned __int32 uint32_t
Definition: rptypes.h:47
void changeCoordinatesOrigin(const mrpt::poses::CPose3D &newOrigin)
Change the coordinate origin of all stored poses, for consistency with future new poses to enter in t...
Definition: CSimpleMap.cpp:315
TPosePDFSensFramePairList m_posesObsPairs
The stored data.
Definition: CSimpleMap.h:209
Declares a class that represents a Probability Density Function (PDF) of a 3D pose (6D actually)...
Definition: CPose3DPDF.h:42
bool saveToFile(const std::string &filName) const
Save this object to a .simplemap binary file (compressed with gzip)
Definition: CSimpleMap.cpp:326
void clear()
Remove all stored pairs.
Definition: CSimpleMap.cpp:70
void remove(size_t index)
Deletes the i&#39;th pair, first one is index &#39;0&#39;.
Definition: CSimpleMap.cpp:91



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