Main MRPT website > C++ reference for MRPT 1.9.9
CPoint2D.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 "base-precomp.h" // Precompiled headers
11 
12 #include <mrpt/poses/CPoint2D.h>
13 #include <mrpt/poses/CPose2D.h>
14 #include <mrpt/utils/CStream.h>
15 #include <limits>
16 
17 using namespace mrpt::poses;
18 using namespace mrpt::utils;
19 using namespace mrpt::math;
20 
22 
23 /*---------------------------------------------------------------
24  Implements the writing to a CStream capability of
25  CSerializable objects
26  ---------------------------------------------------------------*/
27 void CPoint2D::writeToStream(mrpt::utils::CStream& out, int* version) const
28 {
29  if (version)
30  *version = 1;
31  else
32  {
33  // The coordinates:
34  out << m_coords[0] << m_coords[1];
35  }
36 }
37 
38 /*---------------------------------------------------------------
39  Implements the reading from a CStream capability of
40  CSerializable objects
41  ---------------------------------------------------------------*/
43 {
44  switch (version)
45  {
46  case 0:
47  {
48  // The coordinates:
49  float f;
50  in >> f;
51  m_coords[0] = f;
52  in >> f;
53  m_coords[1] = f;
54  }
55  break;
56  case 1:
57  {
58  // The coordinates:
59  in >> m_coords[0] >> m_coords[1];
60  }
61  break;
62  default:
64  };
65 }
66 
67 /*---------------------------------------------------------------
68 The operator D="this"-b is the pose inverse compounding operator.
69  The resulting pose "D" is the diference between this pose and "b"
70  ---------------------------------------------------------------*/
72 {
73  const double ccos = cos(b.phi());
74  const double ssin = sin(b.phi());
75  const double Ax = x() - b.x();
76  const double Ay = y() - b.y();
77 
78  return CPoint2D(Ax * ccos + Ay * ssin, -Ax * ssin + Ay * ccos);
79 }
80 
82 {
83  for (int i = 0; i < 2; i++)
84  m_coords[i] = std::numeric_limits<double>::quiet_NaN();
85 }
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: CPoint2D.cpp:42
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
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.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:19
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
GLubyte GLubyte b
Definition: glext.h:6279
A class used to store a 2D point.
Definition: CPoint2D.h:36
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
void setToNaN() override
Set all data fields to quiet NaN.
Definition: CPoint2D.cpp:81
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
Definition: CPose2D.h:40
GLuint in
Definition: glext.h:7274
CPoint2D operator-(const CPose2D &b) const
The operator D="this"-b is the pose inverse compounding operator, the resulting points "D" fulfils: "...
Definition: CPoint2D.cpp:71
GLenum GLint GLint y
Definition: glext.h:3538
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
GLenum GLint x
Definition: glext.h:3538



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