MRPT  2.0.3
CPoint2D.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "poses-precomp.h" // Precompiled headers
11 
12 #include <mrpt/math/TPoint2D.h>
13 #include <mrpt/math/TPoint3D.h>
14 #include <mrpt/poses/CPoint2D.h>
15 #include <mrpt/poses/CPose2D.h>
18 #include <iostream>
19 #include <limits>
20 
21 using namespace mrpt::poses;
22 using namespace mrpt::math;
23 
25 
26 uint8_t CPoint2D::serializeGetVersion() const { return 1; }
28 {
29  out << m_coords[0] << m_coords[1];
30 }
32 {
33  switch (version)
34  {
35  case 0:
36  {
37  // The coordinates:
38  float f;
39  in >> f;
40  m_coords[0] = f;
41  in >> f;
42  m_coords[1] = f;
43  }
44  break;
45  case 1:
46  {
47  // The coordinates:
48  in >> m_coords[0] >> m_coords[1];
49  }
50  break;
51  default:
53  };
54 }
56 {
58  out["x"] = m_coords[0];
59  out["y"] = m_coords[1];
60 }
62 {
63  uint8_t version;
65  switch (version)
66  {
67  case 1:
68  {
69  m_coords[0] = static_cast<double>(in["x"]);
70  m_coords[1] = static_cast<double>(in["y"]);
71  }
72  break;
73  default:
75  }
76 }
77 /*---------------------------------------------------------------
78 The operator D="this"-b is the pose inverse compounding operator.
79  The resulting pose "D" is the diference between this pose and "b"
80  ---------------------------------------------------------------*/
82 {
83  const double ccos = cos(b.phi());
84  const double ssin = sin(b.phi());
85  const double Ax = x() - b.x();
86  const double Ay = y() - b.y();
87 
88  return CPoint2D(Ax * ccos + Ay * ssin, -Ax * ssin + Ay * ccos);
89 }
90 
92 {
93  for (int i = 0; i < 2; i++)
94  m_coords[i] = std::numeric_limits<double>::quiet_NaN();
95 }
96 
98 {
99  return mrpt::math::TPoint2D(x(), y());
100 }
101 
102 std::ostream& mrpt::poses::operator<<(std::ostream& o, const CPoint2D& p)
103 {
104  o << "(" << p[0] << "," << p[1] << ")";
105  return o;
106 }
107 
109 {
110  m_coords[0] = o.x;
111  m_coords[1] = o.y;
112 }
113 
115 {
116  m_coords[0] = o.x;
117  m_coords[1] = o.y;
118  m_coords[2] = 0;
119 }
mrpt::poses::CPoint2D::serializeTo
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
Definition: CPoint2D.cpp:27
CPoint2D.h
poses-precomp.h
mrpt::math::TPoint3D_< double >
TPoint2D.h
mrpt::poses::CPose2D::phi
double phi() const
Get the phi angle of the 2D pose (in radians)
Definition: CPose2D.h:86
mrpt::serialization::CSchemeArchiveBase
Virtual base class for "schematic archives" (JSON, XML,...)
Definition: CSchemeArchiveBase.h:75
mrpt::math::TPoint2D_< double >
mrpt::poses::CPoseOrPoint::x
double x() const
Common members of all points & poses classes.
Definition: CPoseOrPoint.h:143
SCHEMA_DESERIALIZE_DATATYPE_VERSION
#define SCHEMA_DESERIALIZE_DATATYPE_VERSION()
For use inside serializeFrom(CSchemeArchiveBase) methods.
Definition: CSerializable.h:139
out
mrpt::vision::TStereoCalibResults out
Definition: chessboard_stereo_camera_calib_unittest.cpp:25
mrpt::poses::operator<<
std::ostream & operator<<(std::ostream &o, const CPoint2D &p)
Dumps a point as a string (x,y)
Definition: CPoint2D.cpp:102
mrpt::poses
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CHierarchicalMapMHPartition.h:22
CPose2D.h
mrpt::serialization::CArchive
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:54
mrpt::poses::CPoint2D::operator-
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:81
mrpt::poses::CPose2D
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle.
Definition: CPose2D.h:39
mrpt::poses::CPoseOrPoint::y
double y() const
Definition: CPoseOrPoint.h:147
mrpt::poses::CPoint2D::serializeFrom
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
Definition: CPoint2D.cpp:31
CSchemeArchiveBase.h
mrpt::poses::CPoint2D::asTPoint
mrpt::math::TPoint2D asTPoint() const
Definition: CPoint2D.cpp:97
mrpt::math::TPoint2D_data::y
T y
Definition: TPoint2D.h:25
IMPLEMENTS_SERIALIZABLE
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to all CSerializable-classes implementation files.
Definition: CSerializable.h:166
mrpt::math::TPoint3D_data::y
T y
Definition: TPoint3D.h:29
mrpt::poses::CPoint2D::setToNaN
void setToNaN() override
Set all data fields to quiet NaN.
Definition: CPoint2D.cpp:91
mrpt::math::TPoint2D_data::x
T x
X,Y coordinates.
Definition: TPoint2D.h:25
TPoint3D.h
mrpt::math::TPoint3D_data::x
T x
X,Y,Z coordinates.
Definition: TPoint3D.h:29
mrpt::math::TPoint2D
TPoint2D_< double > TPoint2D
Lightweight 2D point.
Definition: TPoint2D.h:213
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:11
mrpt::poses::CPoint2D::CPoint2D
CPoint2D(double x=0, double y=0)
Constructor for initializing point coordinates.
Definition: CPoint2D.h:43
CArchive.h
mrpt::poses::CPoint2D
A class used to store a 2D point.
Definition: CPoint2D.h:32
MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:97
SCHEMA_SERIALIZE_DATATYPE_VERSION
#define SCHEMA_SERIALIZE_DATATYPE_VERSION(ser_version)
For use inside all serializeTo(CSchemeArchiveBase) methods.
Definition: CSerializable.h:131



Page generated by Doxygen 1.8.17 for MRPT 2.0.3 at Fri May 15 23:51:15 UTC 2020