Main MRPT website > C++ reference for MRPT 1.5.9
CSphere.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/CSphere.h>
13 //#include <mrpt/poses/CPose3D.h>
14 #include <mrpt/utils/CStream.h>
15 #include "opengl_internals.h"
16 
17 using namespace mrpt;
18 using namespace mrpt::opengl;
19 using namespace mrpt::poses;
20 using namespace mrpt::utils;
21 using namespace mrpt::math;
22 using namespace std;
23 
24 
26 
27 CSpherePtr CSphere::Create(
28  float radius, int nDivsLongitude, int nDivsLatitude)
29 {
30  return CSpherePtr( new CSphere(radius,nDivsLongitude,nDivsLatitude) );
31 }
32 /*---------------------------------------------------------------
33  render_dl
34  ---------------------------------------------------------------*/
35 void CSphere::render_dl() const
36 {
37 #if MRPT_HAS_OPENGL_GLUT
38  if ( m_color.A != 255 )
39  {
43  }
44 
45  // Determine radius depending on eye distance?
46  float real_radius;
47  if (m_keepRadiusIndependentEyeDistance)
48  {
49  glRasterPos3f(0.0f,0.0f,0.0f);
50 
51  GLfloat raster_pos[4];
53  float eye_distance= raster_pos[3];
54 
55  eye_distance = max( eye_distance , 0.1f);
56 
57  real_radius = 0.01*m_radius * eye_distance;
58  }
59  else real_radius = m_radius;
60 
61 
62  GLUquadricObj *obj = gluNewQuadric();
64 
65  gluQuadricDrawStyle(obj,GLU_FILL);
66  gluQuadricNormals(obj,GLU_SMOOTH);
67 
68  gluSphere( obj, real_radius ,m_nDivsLongitude,m_nDivsLatitude);
70 
71  gluDeleteQuadric(obj);
73 
74  if ( m_color.A != 255 )
75  {
78  }
79 
80 #endif
81 }
82 /*---------------------------------------------------------------
83  Implements the writing to a CStream capability of
84  CSerializable objects
85  ---------------------------------------------------------------*/
87 {
88  if (version)
89  *version = 1;
90  else
91  {
92  writeToStreamRender(out);
93  out << m_radius;
94  out << (uint32_t)m_nDivsLongitude << (uint32_t)m_nDivsLatitude
95  << m_keepRadiusIndependentEyeDistance;
96  }
97 }
98 
99 /*---------------------------------------------------------------
100  Implements the reading from a CStream capability of
101  CSerializable objects
102  ---------------------------------------------------------------*/
104 {
105 
106  switch(version)
107  {
108  case 0:
109  case 1:
110  {
111  readFromStreamRender(in);
112  in >> m_radius;
113  uint32_t i,j;
114  in >> i >> j;
115  m_nDivsLongitude = i;
116  m_nDivsLatitude = j;
117  if (version>=1)
118  in >> m_keepRadiusIndependentEyeDistance;
119  else m_keepRadiusIndependentEyeDistance = false;
120  } break;
121  default:
123 
124  };
126 }
127 
128 bool CSphere::traceRay(const mrpt::poses::CPose3D &o,double &dist) const {
129  //We need to find the points of the sphere which collide with the laser beam.
130  //The sphere's equation is invariant to rotations (but not to translations), and we can take advantage of this;
131  //we'll simply transform the center and then compute the beam's points whose distance to that transformed point
132  //equals the sphere's radius.
133 
134  CPose3D transf=this->m_pose-o;
135  double x=transf.x(),y=transf.y(),z=transf.z();
136  double r2=m_radius*m_radius;
137  double dyz=y*y+z*z;
138  if (dyz>r2) return false;
139  double dx=sqrt(r2-dyz);
140  if (x-dx>=0) {
141  dist=x-dx;
142  return true;
143  } else if (x+dx>=0) {
144  dist=x+dx;
145  return true;
146  } else return false;
147 }
148 
150 {
151  bb_min.x = -m_radius;
152  bb_min.y = -m_radius;
153  bb_min.z = -m_radius;
154 
155  bb_max.x = m_radius;
156  bb_max.y = m_radius;
157  bb_max.z = m_radius;
158 
159  // Convert to coordinates of my parent:
160  m_pose.composePoint(bb_min, bb_min);
161  m_pose.composePoint(bb_max, bb_max);
162 }
double x() const
Common members of all points & poses classes.
Definition: CPoseOrPoint.h:113
void render_dl() const MRPT_OVERRIDE
Render.
Definition: CSphere.cpp:35
GLAPI void GLAPIENTRY glGetFloatv(GLenum pname, GLfloat *params)
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)
GLAPI void GLAPIENTRY glRasterPos3f(GLfloat x, GLfloat y, GLfloat z)
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
double z
X,Y,Z coordinates.
#define GL_DEPTH_TEST
Definition: glew.h:397
IMPLEMENTS_SERIALIZABLE(CLogFileRecord_FullEval, CHolonomicLogFileRecord, mrpt::nav) IMPLEMENTS_SERIALIZABLE(CHolonomicFullEval
GLsizei GLsizei GLuint * obj
Definition: glext.h:3902
#define GL_CURRENT_RASTER_POSITION
Definition: glew.h:356
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const MRPT_OVERRIDE
Ray tracing.
Definition: CSphere.cpp:128
float GLfloat
Definition: glew.h:213
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
Introduces a pure virtual method responsible for writing to a CStream.
Definition: CSphere.cpp:86
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:38
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:19
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
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: CSphere.cpp:103
int version
Definition: mrpt_jpeglib.h:898
#define GL_BLEND
Definition: glew.h:428
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
#define GL_SRC_ALPHA
Definition: glew.h:282
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
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
A solid or wire-frame sphere.
Definition: CSphere.h:34
GLuint in
Definition: glext.h:6301
The namespace for 3D scene representation and rendering.
GLenum GLint GLint y
Definition: glext.h:3516
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: CSphere.cpp:149
GLenum GLint x
Definition: glext.h:3516
Lightweight 3D point.
unsigned __int32 uint32_t
Definition: rptypes.h:49
GLAPI void GLAPIENTRY glDisable(GLenum cap)



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020