Main MRPT website > C++ reference for MRPT 1.9.9
CPoint3D.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/CPoint3D.h>
13 #include <mrpt/poses/CPose3D.h>
14 #include <mrpt/poses/CPoint2D.h>
15 #include <mrpt/poses/CPose2D.h>
16 #include <mrpt/utils/CStream.h>
17 #include <limits>
18 
19 using namespace mrpt;
20 using namespace mrpt::poses;
21 using namespace mrpt::math;
22 using namespace mrpt::utils;
23 
25 
26 /** Constructor from an CPoint2D object. */ // Here instead of in the .h to
27 // avoid headers include loops.
29 {
30  m_coords[0] = p.x();
31  m_coords[1] = p.y();
32  m_coords[2] = 0;
33 }
34 /** Constructor from an CPose2D object. */
36 {
37  m_coords[0] = p.x();
38  m_coords[1] = p.y();
39  m_coords[2] = 0;
40 }
41 
42 /** Constructor from an CPose3D object. */
44 {
45  m_coords[0] = p.x();
46  m_coords[1] = p.y();
47  m_coords[2] = p.z();
48 }
49 
50 /*---------------------------------------------------------------
51  Implements the writing to a CStream capability of
52  CSerializable objects
53  ---------------------------------------------------------------*/
54 void CPoint3D::writeToStream(mrpt::utils::CStream& out, int* version) const
55 {
56  if (version)
57  *version = 1;
58  else
59  {
60  // The coordinates:
61  out << m_coords[0] << m_coords[1] << m_coords[2];
62  }
63 }
64 
65 /*---------------------------------------------------------------
66  Implements the reading from a CStream capability of
67  CSerializable objects
68  ---------------------------------------------------------------*/
70 {
71  switch (version)
72  {
73  case 0:
74  {
75  float f;
76  in >> f;
77  m_coords[0] = f;
78  in >> f;
79  m_coords[1] = f;
80  in >> f;
81  m_coords[2] = f;
82  }
83  break;
84  case 1:
85  {
86  // The coordinates:
87  in >> m_coords[0] >> m_coords[1] >> m_coords[2];
88  }
89  break;
90  default:
92  };
93 }
94 
95 /*---------------------------------------------------------------
96  point3D = point3D - pose3D
97  ---------------------------------------------------------------*/
99 {
100  // JLBC: 7-FEB-2008: Why computing the whole matrix multiplication?? ;-)
101  // 5.7us -> 4.1us -> 3.1us (with optimization of HM matrices by reference)
102  // JLBC: 10-APR-2009: Usage of fixed-size 4x4 matrix, should be even faster
103  // now.
105  b.getInverseHomogeneousMatrix(B_INV);
106 
107  return CPoint3D(
108  B_INV.get_unsafe(0, 0) * m_coords[0] +
109  B_INV.get_unsafe(0, 1) * m_coords[1] +
110  B_INV.get_unsafe(0, 2) * m_coords[2] + B_INV.get_unsafe(0, 3),
111  B_INV.get_unsafe(1, 0) * m_coords[0] +
112  B_INV.get_unsafe(1, 1) * m_coords[1] +
113  B_INV.get_unsafe(1, 2) * m_coords[2] + B_INV.get_unsafe(1, 3),
114  B_INV.get_unsafe(2, 0) * m_coords[0] +
115  B_INV.get_unsafe(2, 1) * m_coords[1] +
116  B_INV.get_unsafe(2, 2) * m_coords[2] + B_INV.get_unsafe(2, 3));
117 }
118 
119 /*---------------------------------------------------------------
120  point3D = point3D - point3D
121  ---------------------------------------------------------------*/
123 {
124  return CPoint3D(
125  m_coords[0] - b.m_coords[0], m_coords[1] - b.m_coords[1],
126  m_coords[2] - b.m_coords[2]);
127 }
128 
129 /*---------------------------------------------------------------
130  point3D = point3D + point3D
131  ---------------------------------------------------------------*/
133 {
134  return CPoint3D(
135  m_coords[0] + b.m_coords[0], m_coords[1] + b.m_coords[1],
136  m_coords[2] + b.m_coords[2]);
137 }
138 
139 /*---------------------------------------------------------------
140  pose3D = point3D + pose3D
141  ---------------------------------------------------------------*/
143 {
144  return CPose3D(
145  m_coords[0] + b.x(), m_coords[1] + b.y(), m_coords[2] + b.z(), b.yaw(),
146  b.pitch(), b.roll());
147 }
148 
150 {
151  for (int i = 0; i < 3; i++)
152  m_coords[i] = std::numeric_limits<double>::quiet_NaN();
153 }
double x() const
Common members of all points & poses classes.
Definition: CPoseOrPoint.h:135
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.
Definition: CPoint3D.cpp:54
void setToNaN() override
Set all data fields to quiet NaN.
Definition: CPoint3D.cpp:149
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.
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: CPoint3D.cpp:69
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
A numeric matrix of compile-time fixed size.
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
A class used to store a 3D point.
Definition: CPoint3D.h:32
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
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
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
CPoint3D operator-(const CPose3D &b) const
Returns this point as seen from "b", i.e.
Definition: CPoint3D.cpp:98
CPoint3D(const double x=0, const double y=0, const double z=0)
Constructor for initializing point coordinates.
Definition: CPoint3D.h:42
GLuint in
Definition: glext.h:7274
CPoint3D operator+(const CPoint3D &b) const
Returns this point plus point "b", i.e.
Definition: CPoint3D.cpp:132
GLfloat GLfloat p
Definition: glext.h:6305



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