Main MRPT website > C++ reference for MRPT 1.9.9
CDisk.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-2018, 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 "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 +
95  (y * (sin(p) * sin(w) * cos(r) - cos(w) * sin(r)) +
96  z * cos(p) * cos(r)) /
97  coef;
98  if (dist < 0) return false;
99  // Euclidean distance is invariant to rotations...
100  double d2 = (x - dist) * (x - dist) + y * y + z * z;
101  return d2 >= (m_radiusIn * m_radiusIn) && d2 <= (m_radiusOut * m_radiusOut);
102 
103  // IMPORTANT NOTICE: using geometric intersection between Z plane and
104  // CPose's line intersection is SLOWER than the used method.
105 }
106 
108  mrpt::math::TPoint3D& bb_min, mrpt::math::TPoint3D& bb_max) const
109 {
110  bb_min.x = -std::max(m_radiusIn, m_radiusOut);
111  bb_min.y = bb_min.x;
112  bb_min.z = 0;
113 
114  bb_max.x = std::max(m_radiusIn, m_radiusOut);
115  bb_max.y = bb_max.x;
116  bb_max.z = 0;
117 
118  // Convert to coordinates of my parent:
119  m_pose.composePoint(bb_min, bb_min);
120  m_pose.composePoint(bb_max, bb_max);
121 }
double x() const
Common members of all points & poses classes.
Definition: CPoseOrPoint.h:140
GLdouble GLdouble z
Definition: glext.h:3872
GLAPI void GLAPIENTRY glEnable(GLenum cap)
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in 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:107
double pitch() const
Get the PITCH angle (in radians)
Definition: CPose3D.h:534
double yaw() const
Get the YAW angle (in radians)
Definition: CPose3D.h:528
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
STL namespace.
#define GL_ONE_MINUS_SRC_ALPHA
Definition: glew.h:287
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
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:4178
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
unsigned char uint8_t
Definition: rptypes.h:41
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:90
A planar disk in the XY plane.
Definition: CDisk.h:33
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
Definition: CDisk.cpp:47
double x
X,Y,Z coordinates.
#define GL_BLEND
Definition: glew.h:432
double roll() const
Get the ROLL angle (in radians)
Definition: CPose3D.h:540
#define GL_SRC_ALPHA
Definition: glew.h:286
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:48
GLdouble GLdouble GLdouble r
Definition: glext.h:3705
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
void checkOpenGLError()
Checks glGetError and throws an exception if an error situation is found.
Definition: gl_utils.cpp:143
GLuint in
Definition: glext.h:7274
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
GLenum GLint GLint y
Definition: glext.h:3538
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
GLenum GLint x
Definition: glext.h:3538
Lightweight 3D point.
GLAPI void GLAPIENTRY glDisable(GLenum cap)
GLfloat GLfloat p
Definition: glext.h:6305
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: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019