MRPT  2.0.1
CSphere.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 "opengl-precomp.h" // Precompiled header
11 
12 #include <mrpt/opengl/CSphere.h>
14 
15 using namespace mrpt;
16 using namespace mrpt::opengl;
17 using namespace mrpt::poses;
18 using namespace mrpt::math;
19 using namespace std;
20 
22 
23 uint8_t CSphere::serializeGetVersion() const { return 2; }
25 {
26  writeToStreamRender(out);
27  out << m_radius;
28  out << (uint32_t)m_nDivsLongitude << (uint32_t)m_nDivsLatitude;
29 }
31 {
32  switch (version)
33  {
34  case 0:
35  case 1:
36  case 2:
37  {
38  readFromStreamRender(in);
39  in >> m_radius;
40  uint32_t i, j;
41  in >> i >> j;
42  m_nDivsLongitude = i;
43  m_nDivsLatitude = j;
44  if (version == 1)
45  {
46  bool keepRadiusIndependentEyeDistance;
47  in >> keepRadiusIndependentEyeDistance;
48  }
49 
50  regenerateBaseParams();
51  }
52  break;
53  default:
55  };
57 }
58 
59 bool CSphere::traceRay(const mrpt::poses::CPose3D& o, double& dist) const
60 {
61  // We need to find the points of the sphere which collide with the laser
62  // beam.
63  // The sphere's equation is invariant to rotations (but not to
64  // translations), and we can take advantage of this;
65  // we'll simply transform the center and then compute the beam's points
66  // whose distance to that transformed point
67  // equals the sphere's radius.
68 
69  CPose3D transf = this->m_pose - o;
70  double x = transf.x(), y = transf.y(), z = transf.z();
71  double r2 = m_radius * m_radius;
72  double dyz = y * y + z * z;
73  if (dyz > r2) return false;
74  double dx = sqrt(r2 - dyz);
75  if (x - dx >= 0)
76  {
77  dist = x - dx;
78  return true;
79  }
80  else if (x + dx >= 0)
81  {
82  dist = x + dx;
83  return true;
84  }
85  else
86  return false;
87 }
88 
91 {
92  bb_min.x = -m_radius;
93  bb_min.y = -m_radius;
94  bb_min.z = -m_radius;
95 
96  bb_max.x = m_radius;
97  bb_max.y = m_radius;
98  bb_max.z = m_radius;
99 
100  // Convert to coordinates of my parent:
101  m_pose.composePoint(bb_min, bb_min);
102  m_pose.composePoint(bb_max, bb_max);
103 }
104 
106 {
107  const_cast<CSphere*>(this)->regenerateBaseParams();
108  BASE::renderUpdateBuffers();
109 }
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Simulation of ray-trace, given a pose.
Definition: CSphere.cpp:59
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to all CSerializable-classes implementation files.
void notifyChange() const
Call to enable calling renderUpdateBuffers() before the next render() rendering iteration.
The base class of 3D objects that can be directly rendered through OpenGL.
Definition: CRenderizable.h:48
STL namespace.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:97
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers, etc.
Definition: CSphere.cpp:105
This base provides a set of functions for maths stuff.
double x() const
Common members of all points & poses classes.
Definition: CPoseOrPoint.h:143
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:54
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
Definition: CSphere.cpp:24
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:85
mrpt::vision::TStereoCalibResults out
A solid or wire-frame sphere.
Definition: CSphere.h:28
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
const auto bb_max
const auto bb_min
virtual void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const override
Evaluates the bounding box of this object (including possible children) in the coordinate frame of th...
Definition: CSphere.cpp:89
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
Definition: CSphere.cpp:30



Page generated by Doxygen 1.8.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020