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-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 "opengl-precomp.h" // Precompiled header
11 
12 #include <mrpt/opengl/CDisk.h>
13 #include <mrpt/utils/CStream.h>
14 
15 #include "opengl_internals.h"
16 
17 using namespace mrpt;
18 using namespace mrpt::opengl;
19 using namespace mrpt::utils;
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 /*---------------------------------------------------------------
47  Implements the writing to a CStream capability of
48  CSerializable objects
49  ---------------------------------------------------------------*/
50 void CDisk::writeToStream(mrpt::utils::CStream& out, int* version) const
51 {
52  if (version)
53  *version = 0;
54  else
55  {
56  writeToStreamRender(out);
57  out << m_radiusIn << m_radiusOut;
58  out << m_nSlices << m_nLoops;
59  }
60 }
61 
62 /*---------------------------------------------------------------
63  Implements the reading from a CStream capability of
64  CSerializable objects
65  ---------------------------------------------------------------*/
67 {
68  switch (version)
69  {
70  case 0:
71  {
72  readFromStreamRender(in);
73  in >> m_radiusIn >> m_radiusOut;
74  in >> m_nSlices;
75  in >> m_nLoops;
76  }
77  break;
78  default:
80  };
82 }
83 
84 bool CDisk::traceRay(const mrpt::poses::CPose3D& o, double& dist) const
85 {
86  // The disk is contained initially in a plane which contains (0,0,0),
87  // (1,0,0) and (0,1,0)
88  // These points are converted into:
89  //(x,y,z)
90  //( cos(w)*cos(p)+x, sin(w)*cos(p)*y, -sin(p)+z )
91  //( -sin(w)*cos(r)+cos(w)*sin(p)*sin(r)+x,
92  // cos(w)*cos(r)+sin(w)*sin(p)*sin(r)+y, cos(p)*sin(r)*z )
93  CPose3D transf = this->m_pose - o;
94  double x = transf.x(), y = transf.y(), z = transf.z(), w = transf.yaw(),
95  p = transf.pitch(), r = transf.roll();
96  double coef = sin(w) * sin(r) + cos(w) * sin(p) * cos(r);
97  // coef is the first component of the normal to the transformed Z plane. So,
98  // the scalar product between
99  // this normal and (1,0,0) (which happens to be the beam's vector) equals
100  // coef. And if it's 0, then both
101  // are orthogonal, that is, the beam is parallel to the plane.
102  if (coef == 0) return false;
103  // The following expression yields the collision point between the plane and
104  // the beam (the y and z
105  // coordinates are zero).
106  dist = x +
107  (y * (sin(p) * sin(w) * cos(r) - cos(w) * sin(r)) +
108  z * cos(p) * cos(r)) /
109  coef;
110  if (dist < 0) return false;
111  // Euclidean distance is invariant to rotations...
112  double d2 = (x - dist) * (x - dist) + y * y + z * z;
113  return d2 >= (m_radiusIn * m_radiusIn) && d2 <= (m_radiusOut * m_radiusOut);
114 
115  // IMPORTANT NOTICE: using geometric intersection between Z plane and
116  // CPose's line intersection is SLOWER than the used method.
117 }
118 
120  mrpt::math::TPoint3D& bb_min, mrpt::math::TPoint3D& bb_max) const
121 {
122  bb_min.x = -std::max(m_radiusIn, m_radiusOut);
123  bb_min.y = bb_min.x;
124  bb_min.z = 0;
125 
126  bb_max.x = std::max(m_radiusIn, m_radiusOut);
127  bb_max.y = bb_max.x;
128  bb_max.z = 0;
129 
130  // Convert to coordinates of my parent:
131  m_pose.composePoint(bb_min, bb_min);
132  m_pose.composePoint(bb_max, bb_max);
133 }
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.
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.
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:119
double pitch() const
Get the PITCH angle (in radians)
Definition: CPose3D.h:539
double yaw() const
Get the YAW angle (in radians)
Definition: CPose3D.h:533
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
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:4178
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.
Definition: CDisk.cpp:50
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
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: CDisk.cpp:66
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
A planar disk in the XY plane.
Definition: CDisk.h:33
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:545
#define GL_SRC_ALPHA
Definition: glew.h:286
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
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:140
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:84



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