Main MRPT website > C++ reference for MRPT 1.5.7
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 
18 using namespace mrpt;
19 using namespace mrpt::opengl;
20 using namespace mrpt::utils;
22 using namespace std;
23 
24 
25 
27 
28 CDiskPtr CDisk::Create(float radiusOut,float radiusIn,uint32_t slices,uint32_t loops)
29 {
30  return CDiskPtr(new CDisk(radiusOut,radiusIn,slices,loops));
31 }
32 /*---------------------------------------------------------------
33  render
34  ---------------------------------------------------------------*/
35 void CDisk::render_dl() const
36 {
37 #if MRPT_HAS_OPENGL_GLUT
42 
43  GLUquadricObj *obj = gluNewQuadric();
44 
45  gluDisk(
46  obj,
47  m_radiusIn,
48  m_radiusOut,
49  m_nSlices,
50  m_nLoops );
51 
52  gluDeleteQuadric(obj);
53 
55 #endif
56 }
57 
58 /*---------------------------------------------------------------
59  Implements the writing to a CStream capability of
60  CSerializable objects
61  ---------------------------------------------------------------*/
63 {
64 
65  if (version)
66  *version = 0;
67  else
68  {
69  writeToStreamRender(out);
70  out << m_radiusIn << m_radiusOut;
71  out << m_nSlices << m_nLoops;
72  }
73 }
74 
75 /*---------------------------------------------------------------
76  Implements the reading from a CStream capability of
77  CSerializable objects
78  ---------------------------------------------------------------*/
80 {
81  switch(version)
82  {
83  case 0:
84  {
85  readFromStreamRender(in);
86  in >> m_radiusIn >> m_radiusOut;
87  in >> m_nSlices;
88  in >> m_nLoops;
89  } break;
90  default:
92 
93  };
95 }
96 
97 bool CDisk::traceRay(const mrpt::poses::CPose3D &o,double &dist) const {
98  //The disk is contained initially in a plane which contains (0,0,0), (1,0,0) and (0,1,0)
99  //These points are converted into:
100  //(x,y,z)
101  //( cos(w)*cos(p)+x, sin(w)*cos(p)*y, -sin(p)+z )
102  //( -sin(w)*cos(r)+cos(w)*sin(p)*sin(r)+x, cos(w)*cos(r)+sin(w)*sin(p)*sin(r)+y, cos(p)*sin(r)*z )
103  CPose3D transf=this->m_pose-o;
104  double x=transf.x(),y=transf.y(),z=transf.z(),w=transf.yaw(),p=transf.pitch(),r=transf.roll();
105  double coef=sin(w)*sin(r)+cos(w)*sin(p)*cos(r);
106  //coef is the first component of the normal to the transformed Z plane. So, the scalar product between
107  //this normal and (1,0,0) (which happens to be the beam's vector) equals coef. And if it's 0, then both
108  //are orthogonal, that is, the beam is parallel to the plane.
109  if (coef==0) return false;
110  //The following expression yields the collision point between the plane and the beam (the y and z
111  //coordinates are zero).
112  dist=x+(y*(sin(p)*sin(w)*cos(r)-cos(w)*sin(r))+z*cos(p)*cos(r))/coef;
113  if (dist<0) return false;
114  //Euclidean distance is invariant to rotations...
115  double d2=(x-dist)*(x-dist)+y*y+z*z;
116  return d2>=(m_radiusIn*m_radiusIn)&&d2<=(m_radiusOut*m_radiusOut);
117 
118  //IMPORTANT NOTICE: using geometric intersection between Z plane and CPose's line intersection is SLOWER than the used method.
119 }
120 
122 {
123  bb_min.x = -std::max(m_radiusIn, m_radiusOut);
124  bb_min.y = bb_min.x;
125  bb_min.z = 0;
126 
127  bb_max.x = std::max(m_radiusIn, m_radiusOut);
128  bb_max.y = bb_max.x;
129  bb_max.z = 0;
130 
131  // Convert to coordinates of my parent:
132  m_pose.composePoint(bb_min, bb_min);
133  m_pose.composePoint(bb_max, bb_max);
134 }
double x() const
Common members of all points & poses classes.
Definition: CPoseOrPoint.h:113
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Definition: zip.h:16
GLdouble GLdouble z
Definition: glext.h:3734
GLAPI void GLAPIENTRY glEnable(GLenum cap)
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
double pitch() const
Get the PITCH angle (in radians)
Definition: CPose3D.h:392
double yaw() const
Get the YAW angle (in radians)
Definition: CPose3D.h:391
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:283
void readFromStream(mrpt::utils::CStream &in, int version)
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
Definition: CDisk.cpp:79
double z
X,Y,Z coordinates.
GLsizei GLsizei GLuint * obj
Definition: glext.h:3902
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:3962
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:38
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const
Introduces a pure virtual method responsible for writing to a CStream.
Definition: CDisk.cpp:62
A planar disk in the XY plane.
Definition: CDisk.h:34
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const MRPT_OVERRIDE
Ray tracing.
Definition: CDisk.cpp:97
int version
Definition: mrpt_jpeglib.h:898
#define GL_BLEND
Definition: glew.h:428
double roll() const
Get the ROLL angle (in radians)
Definition: CPose3D.h:393
void render_dl() const MRPT_OVERRIDE
Render.
Definition: CDisk.cpp:35
#define GL_SRC_ALPHA
Definition: glew.h:282
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
GLdouble GLdouble GLdouble r
Definition: glext.h:3618
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:72
void OPENGL_IMPEXP checkOpenGLError()
Checks glGetError and throws an exception if an error situation is found.
Definition: gl_utils.cpp:134
GLuint in
Definition: glext.h:6301
The namespace for 3D scene representation and rendering.
GLenum GLint GLint y
Definition: glext.h:3516
GLenum GLint x
Definition: glext.h:3516
Lightweight 3D point.
unsigned __int32 uint32_t
Definition: rptypes.h:49
GLAPI void GLAPIENTRY glDisable(GLenum cap)
GLfloat GLfloat p
Definition: glext.h:5587
void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const MRPT_OVERRIDE
Evaluates the bounding box of this object (including possible children) in the coordinate frame of th...
Definition: CDisk.cpp:121



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019