MRPT  1.9.9
CDisk.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-2019, 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/CDisk.h>
14 
15 #include "opengl_internals.h"
16 
17 using namespace mrpt;
18 using namespace mrpt::opengl;
19 
21 using namespace std;
22 
24 
25 /*---------------------------------------------------------------
26  render
27  ---------------------------------------------------------------*/
28 void CDisk::render_dl() const
29 {
30 #if MRPT_HAS_OPENGL_GLUT
35 
36  GLUquadricObj* obj = gluNewQuadric();
37 
38  gluDisk(obj, m_radiusIn, m_radiusOut, m_nSlices, m_nLoops);
39 
40  gluDeleteQuadric(obj);
41 
43 #endif
44 }
45 
46 uint8_t CDisk::serializeGetVersion() const { return 0; }
48 {
49  writeToStreamRender(out);
50  out << m_radiusIn << m_radiusOut;
51  out << m_nSlices << m_nLoops;
52 }
53 
55 {
56  switch (version)
57  {
58  case 0:
59  {
60  readFromStreamRender(in);
61  in >> m_radiusIn >> m_radiusOut;
62  in >> m_nSlices;
63  in >> m_nLoops;
64  }
65  break;
66  default:
68  };
70 }
71 
72 bool CDisk::traceRay(const mrpt::poses::CPose3D& o, double& dist) const
73 {
74  // The disk is contained initially in a plane which contains (0,0,0),
75  // (1,0,0) and (0,1,0)
76  // These points are converted into:
77  //(x,y,z)
78  //( cos(w)*cos(p)+x, sin(w)*cos(p)*y, -sin(p)+z )
79  //( -sin(w)*cos(r)+cos(w)*sin(p)*sin(r)+x,
80  // cos(w)*cos(r)+sin(w)*sin(p)*sin(r)+y, cos(p)*sin(r)*z )
81  CPose3D transf = this->m_pose - o;
82  double x = transf.x(), y = transf.y(), z = transf.z(), w = transf.yaw(),
83  p = transf.pitch(), r = transf.roll();
84  double coef = sin(w) * sin(r) + cos(w) * sin(p) * cos(r);
85  // coef is the first component of the normal to the transformed Z plane. So,
86  // the scalar product between
87  // this normal and (1,0,0) (which happens to be the beam's vector) equals
88  // coef. And if it's 0, then both
89  // are orthogonal, that is, the beam is parallel to the plane.
90  if (coef == 0) return false;
91  // The following expression yields the collision point between the plane and
92  // the beam (the y and z
93  // coordinates are zero).
94  dist = x + (y * (sin(p) * sin(w) * cos(r) - cos(w) * sin(r)) +
95  z * cos(p) * cos(r)) /
96  coef;
97  if (dist < 0) return false;
98  // Euclidean distance is invariant to rotations...
99  double d2 = (x - dist) * (x - dist) + y * y + z * z;
100  return d2 >= (m_radiusIn * m_radiusIn) && d2 <= (m_radiusOut * m_radiusOut);
101 
102  // IMPORTANT NOTICE: using geometric intersection between Z plane and
103  // CPose's line intersection is SLOWER than the used method.
104 }
105 
108 {
109  bb_min.x = -std::max(m_radiusIn, m_radiusOut);
110  bb_min.y = bb_min.x;
111  bb_min.z = 0;
112 
113  bb_max.x = std::max(m_radiusIn, m_radiusOut);
114  bb_max.y = bb_max.x;
115  bb_max.z = 0;
116 
117  // Convert to coordinates of my parent:
118  m_pose.composePoint(bb_min, bb_min);
119  m_pose.composePoint(bb_max, bb_max);
120 }
void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
GLdouble GLdouble z
Definition: glext.h:3879
GLAPI void GLAPIENTRY glEnable(GLenum cap)
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to all CSerializable-classes implementation files.
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
Definition: CDisk.cpp:46
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: CDisk.cpp:106
double pitch() const
Get the PITCH angle (in radians)
Definition: CPose3D.h:548
double yaw() const
Get the YAW angle (in radians)
Definition: CPose3D.h:542
STL namespace.
#define GL_ONE_MINUS_SRC_ALPHA
Definition: glew.h:288
GLsizei GLsizei GLuint * obj
Definition: glext.h:4085
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
Definition: CDisk.cpp:54
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:4199
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
unsigned char uint8_t
Definition: rptypes.h:44
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:97
A planar disk in the XY plane.
Definition: CDisk.h:30
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
Definition: CDisk.cpp:47
double x() const
Common members of all points & poses classes.
Definition: CPoseOrPoint.h:143
#define GL_BLEND
Definition: glew.h:433
double roll() const
Get the ROLL angle (in radians)
Definition: CPose3D.h:554
#define GL_SRC_ALPHA
Definition: glew.h:287
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:53
GLdouble GLdouble GLdouble r
Definition: glext.h:3711
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:84
void checkOpenGLError()
Checks glGetError and throws an exception if an error situation is found.
Definition: gl_utils.cpp:155
GLuint in
Definition: glext.h:7391
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
const auto bb_max
GLenum GLint GLint y
Definition: glext.h:3542
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
const auto bb_min
GLenum GLint x
Definition: glext.h:3542
Lightweight 3D point.
Definition: TPoint3D.h:90
GLAPI void GLAPIENTRY glDisable(GLenum cap)
GLfloat GLfloat p
Definition: glext.h:6398
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Ray tracing.
Definition: CDisk.cpp:72



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019