MRPT  2.0.4
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 }
TPoint2D_< double > TPoint2D
Lightweight 2D point.
Definition: TPoint2D.h:213
T x
X,Y coordinates.
Definition: TPoint2D.h:25
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to all CSerializable-classes implementation files.
std::ostream & operator<<(std::ostream &o, const CPoint2D &p)
Dumps a point as a string (x,y)
Definition: CPoint2D.cpp:102
Virtual base class for "schematic archives" (JSON, XML,...)
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:97
This base provides a set of functions for maths stuff.
double phi() const
Get the phi angle of the 2D pose (in radians)
Definition: CPose2D.h:86
CPoint2D(double x=0, double y=0)
Constructor for initializing point coordinates.
Definition: CPoint2D.h:43
double x() const
Common members of all points & poses classes.
Definition: CPoseOrPoint.h:143
A class used to store a 2D point.
Definition: CPoint2D.h:32
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
#define SCHEMA_DESERIALIZE_DATATYPE_VERSION()
For use inside serializeFrom(CSchemeArchiveBase) methods.
void setToNaN() override
Set all data fields to quiet NaN.
Definition: CPoint2D.cpp:91
T x
X,Y,Z coordinates.
Definition: TPoint3D.h:29
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:54
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
Definition: CPose2D.h:39
mrpt::vision::TStereoCalibResults out
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::math::TPoint2D asTPoint() const
Definition: CPoint2D.cpp:97
#define SCHEMA_SERIALIZE_DATATYPE_VERSION(ser_version)
For use inside all serializeTo(CSchemeArchiveBase) methods.
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
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
Definition: CPoint2D.cpp:27



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020