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 }
mrpt::opengl::CDisk::getBoundingBox
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
mrpt::opengl::CDisk::serializeFrom
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
mrpt::poses::CPose3D::pitch
double pitch() const
Get the PITCH angle (in radians)
Definition: CPose3D.h:534
GL_SRC_ALPHA
#define GL_SRC_ALPHA
Definition: glew.h:286
GL_BLEND
#define GL_BLEND
Definition: glew.h:432
mrpt::opengl::CRenderizableDisplayList
A renderizable object suitable for rendering with OpenGL's display lists.
Definition: CRenderizableDisplayList.h:39
mrpt::math::TPoint3D::z
double z
Definition: lightweight_geom_data.h:385
obj
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
glDisable
GLAPI void GLAPIENTRY glDisable(GLenum cap)
mrpt::opengl::CRenderizableDisplayList::notifyChange
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated)
Definition: CRenderizableDisplayList.h:57
glEnable
GLAPI void GLAPIENTRY glEnable(GLenum cap)
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
w
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:4178
uint8_t
unsigned char uint8_t
Definition: rptypes.h:41
p
GLfloat GLfloat p
Definition: glext.h:6305
mrpt::serialization::CArchive
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:48
r
GLdouble GLdouble GLdouble r
Definition: glext.h:3705
mrpt::opengl::gl_utils::checkOpenGLError
void checkOpenGLError()
Checks glGetError and throws an exception if an error situation is found.
Definition: gl_utils.cpp:143
mrpt::poses::CPoseOrPoint::y
double y() const
Definition: CPoseOrPoint.h:144
CDisk.h
GL_ONE_MINUS_SRC_ALPHA
#define GL_ONE_MINUS_SRC_ALPHA
Definition: glew.h:287
mrpt::poses::CPoseOrPoint::x
double x() const
Common members of all points & poses classes.
Definition: CPoseOrPoint.h:140
mrpt::poses::CPose3D
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
mrpt::math::TPoint3D::x
double x
X,Y,Z coordinates.
Definition: lightweight_geom_data.h:385
mrpt::poses::CPose3D::roll
double roll() const
Get the ROLL angle (in radians)
Definition: CPose3D.h:540
mrpt::opengl::CDisk
A planar disk in the XY plane.
Definition: CDisk.h:33
IMPLEMENTS_SERIALIZABLE
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
Definition: CSerializable.h:114
mrpt::opengl::CDisk::traceRay
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Ray tracing.
Definition: CDisk.cpp:72
mrpt::math::TPoint3D
Lightweight 3D point.
Definition: lightweight_geom_data.h:378
opengl-precomp.h
mrpt::opengl::CDisk::serializeGetVersion
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
Definition: CDisk.cpp:46
mrpt::math::TPoint3D::y
double y
Definition: lightweight_geom_data.h:385
opengl_internals.h
mrpt::poses::CPose3D::yaw
double yaw() const
Get the YAW angle (in radians)
Definition: CPose3D.h:528
void
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
mrpt::opengl::CDisk::serializeTo
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
Definition: CDisk.cpp:47
z
GLdouble GLdouble z
Definition: glext.h:3872
in
GLuint in
Definition: glext.h:7274
CArchive.h
MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:90
mrpt::opengl
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
y
GLenum GLint GLint y
Definition: glext.h:3538
x
GLenum GLint x
Definition: glext.h:3538
glBlendFunc
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST