Main MRPT website > C++ reference for MRPT 1.9.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-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/CSphere.h>
13 //#include <mrpt/poses/CPose3D.h>
15 #include "opengl_internals.h"
16 
17 using namespace mrpt;
18 using namespace mrpt::opengl;
19 using namespace mrpt::poses;
20 
21 using namespace mrpt::math;
22 using namespace std;
23 
25 
26 CSphere::Ptr CSphere::Create(
27  float radius, int nDivsLongitude, int nDivsLatitude)
28 {
29  return CSphere::Ptr(new CSphere(radius, nDivsLongitude, nDivsLatitude));
30 }
31 /*---------------------------------------------------------------
32  render_dl
33  ---------------------------------------------------------------*/
34 void CSphere::render_dl() const
35 {
36 #if MRPT_HAS_OPENGL_GLUT
37  if (m_color.A != 255)
38  {
42  }
43 
44  // Determine radius depending on eye distance?
45  float real_radius;
46  if (m_keepRadiusIndependentEyeDistance)
47  {
48  glRasterPos3f(0.0f, 0.0f, 0.0f);
49 
50  GLfloat raster_pos[4];
52  float eye_distance = raster_pos[3];
53 
54  eye_distance = max(eye_distance, 0.1f);
55 
56  real_radius = 0.01 * m_radius * eye_distance;
57  }
58  else
59  real_radius = m_radius;
60 
61  GLUquadricObj* obj = gluNewQuadric();
63 
64  gluQuadricDrawStyle(obj, GLU_FILL);
65  gluQuadricNormals(obj, GLU_SMOOTH);
66 
67  gluSphere(obj, real_radius, m_nDivsLongitude, m_nDivsLatitude);
69 
70  gluDeleteQuadric(obj);
72 
73  if (m_color.A != 255)
74  {
77  }
78 
79 #endif
80 }
81 
84 {
85  writeToStreamRender(out);
86  out << m_radius;
87  out << (uint32_t)m_nDivsLongitude << (uint32_t)m_nDivsLatitude
88  << m_keepRadiusIndependentEyeDistance;
89 }
91 {
92  switch (version)
93  {
94  case 0:
95  case 1:
96  {
97  readFromStreamRender(in);
98  in >> m_radius;
99  uint32_t i, j;
100  in >> i >> j;
101  m_nDivsLongitude = i;
102  m_nDivsLatitude = j;
103  if (version >= 1)
104  in >> m_keepRadiusIndependentEyeDistance;
105  else
106  m_keepRadiusIndependentEyeDistance = false;
107  }
108  break;
109  default:
111  };
113 }
114 
115 bool CSphere::traceRay(const mrpt::poses::CPose3D& o, double& dist) const
116 {
117  // We need to find the points of the sphere which collide with the laser
118  // beam.
119  // The sphere's equation is invariant to rotations (but not to
120  // translations), and we can take advantage of this;
121  // we'll simply transform the center and then compute the beam's points
122  // whose distance to that transformed point
123  // equals the sphere's radius.
124 
125  CPose3D transf = this->m_pose - o;
126  double x = transf.x(), y = transf.y(), z = transf.z();
127  double r2 = m_radius * m_radius;
128  double dyz = y * y + z * z;
129  if (dyz > r2) return false;
130  double dx = sqrt(r2 - dyz);
131  if (x - dx >= 0)
132  {
133  dist = x - dx;
134  return true;
135  }
136  else if (x + dx >= 0)
137  {
138  dist = x + dx;
139  return true;
140  }
141  else
142  return false;
143 }
144 
146  mrpt::math::TPoint3D& bb_min, mrpt::math::TPoint3D& bb_max) const
147 {
148  bb_min.x = -m_radius;
149  bb_min.y = -m_radius;
150  bb_min.z = -m_radius;
151 
152  bb_max.x = m_radius;
153  bb_max.y = m_radius;
154  bb_max.z = m_radius;
155 
156  // Convert to coordinates of my parent:
157  m_pose.composePoint(bb_min, bb_min);
158  m_pose.composePoint(bb_max, bb_max);
159 }
glGetFloatv
GLAPI void GLAPIENTRY glGetFloatv(GLenum pname, GLfloat *params)
GL_SRC_ALPHA
#define GL_SRC_ALPHA
Definition: glew.h:286
CSphere.h
mrpt::opengl::CSphere::Ptr
std::shared_ptr< CSphere > Ptr
Definition: CSphere.h:33
GL_BLEND
#define GL_BLEND
Definition: glew.h:432
mrpt::opengl::CSphere
A solid or wire-frame sphere.
Definition: CSphere.h:31
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)
glRasterPos3f
GLAPI void GLAPIENTRY glRasterPos3f(GLfloat x, GLfloat y, GLfloat z)
mrpt::opengl::CRenderizable::Ptr
std::shared_ptr< CRenderizable > Ptr
Definition: CRenderizable.h:45
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
uint8_t
unsigned char uint8_t
Definition: rptypes.h:41
mrpt::poses
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CHierarchicalMapMHPartition.h:25
mrpt::serialization::CArchive
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:48
mrpt::opengl::CSphere::serializeGetVersion
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
Definition: CSphere.cpp:82
mrpt::opengl::CSphere::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: CSphere.cpp:145
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
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::opengl::CSphere::serializeTo
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
Definition: CSphere.cpp:83
GL_CURRENT_RASTER_POSITION
#define GL_CURRENT_RASTER_POSITION
Definition: glew.h:360
GL_DEPTH_TEST
#define GL_DEPTH_TEST
Definition: glew.h:401
mrpt::opengl::CSphere::traceRay
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Ray tracing.
Definition: CSphere.cpp:115
IMPLEMENTS_SERIALIZABLE
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
Definition: CSerializable.h:114
mrpt::math::TPoint3D
Lightweight 3D point.
Definition: lightweight_geom_data.h:378
opengl-precomp.h
mrpt::math::TPoint3D::y
double y
Definition: lightweight_geom_data.h:385
opengl_internals.h
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:13
z
GLdouble GLdouble z
Definition: glext.h:3872
GLfloat
float GLfloat
Definition: glew.h:217
in
GLuint in
Definition: glext.h:7274
CArchive.h
mrpt::opengl::CSphere::serializeFrom
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
Definition: CSphere.cpp:90
MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:90
mrpt::opengl::CSphere::render_dl
void render_dl() const override
Render.
Definition: CSphere.cpp:34
mrpt::opengl
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
y
GLenum GLint GLint y
Definition: glext.h:3538
uint32_t
unsigned __int32 uint32_t
Definition: rptypes.h:47
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