Main MRPT website > C++ reference for MRPT 1.9.9
CBox.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 #include <mrpt/opengl/CBox.h>
12 #include <mrpt/math/geometry.h>
13 #include <mrpt/utils/CStream.h>
14 #include <mrpt/opengl/gl_utils.h>
15 
16 #include "opengl_internals.h"
17 
18 using namespace mrpt;
19 using namespace mrpt::opengl;
20 using namespace mrpt::utils;
21 using namespace mrpt::math;
22 using namespace std;
23 
25 
27  : m_corner_min(-1, -1, -1),
28  m_corner_max(1, 1, 1),
29  m_wireframe(false),
30  m_lineWidth(1),
31  m_draw_border(false),
32  m_solidborder_color(0, 0, 0)
33 {
34 }
35 
37  const mrpt::math::TPoint3D& corner1, const mrpt::math::TPoint3D& corner2,
38  bool is_wireframe, float lineWidth)
39  : m_wireframe(is_wireframe),
40  m_lineWidth(lineWidth),
41  m_draw_border(false),
42  m_solidborder_color(0, 0, 0)
43 {
44  setBoxCorners(corner1, corner2);
45 }
46 
47 /*---------------------------------------------------------------
48  render
49  ---------------------------------------------------------------*/
50 void CBox::render_dl() const
51 {
52 #if MRPT_HAS_OPENGL_GLUT
53  if (m_color.A != 255)
54  {
57  }
58  else
59  {
62  }
63 
64  if (!m_wireframe)
65  {
66  // solid:
68 
71 
72  // Front face:
81 
82  // Back face:
91 
92  // Left face:
101 
102  // Right face:
111 
112  // Bottom face:
121  // Top face:
122 
131 
132  glEnd();
134  }
135 
136  if (m_wireframe || m_draw_border)
137  {
139 
140  if (m_draw_border)
141  {
144  }
145 
146  // wireframe:
149 
151 
152  if (m_wireframe)
154  else
155  {
156  glColor4ub(
159 
160  // Draw lines "a bit" far above the solid surface:
161  /* mrpt::math::TPoint3D d = b-a;
162  d*=0.001;
163  a-=d; b+=d;*/
164  }
165 
167  glVertex3d(a.x, a.y, a.z);
168  glVertex3d(b.x, a.y, a.z);
169  glVertex3d(b.x, a.y, b.z);
170  glVertex3d(a.x, a.y, b.z);
171  glVertex3d(a.x, a.y, a.z);
172  glEnd();
173 
175  glVertex3d(a.x, b.y, a.z);
176  glVertex3d(b.x, b.y, a.z);
177  glVertex3d(b.x, b.y, b.z);
178  glVertex3d(a.x, b.y, b.z);
179  glVertex3d(a.x, b.y, a.z);
180  glEnd();
181 
183  glVertex3d(a.x, a.y, a.z);
184  glVertex3d(a.x, b.y, a.z);
185  glVertex3d(a.x, b.y, b.z);
186  glVertex3d(a.x, a.y, b.z);
187  glEnd();
188 
190  glVertex3d(b.x, a.y, a.z);
191  glVertex3d(b.x, b.y, a.z);
192  glVertex3d(b.x, b.y, b.z);
193  glVertex3d(b.x, a.y, b.z);
194  glEnd();
195 
197  }
198 
200 
201 #endif
202 }
203 
204 /*---------------------------------------------------------------
205  Implements the writing to a CStream capability of
206  CSerializable objects
207  ---------------------------------------------------------------*/
208 void CBox::writeToStream(mrpt::utils::CStream& out, int* version) const
209 {
210  if (version)
211  *version = 1;
212  else
213  {
214  writeToStreamRender(out);
215  // version 0
218  << m_lineWidth;
219  // Version 1:
221  }
222 }
223 
224 /*---------------------------------------------------------------
225  Implements the reading from a CStream capability of
226  CSerializable objects
227  ---------------------------------------------------------------*/
229 {
230  switch (version)
231  {
232  case 0:
233  case 1:
238  // Version 1:
239  if (version >= 1)
241  else
242  {
243  m_draw_border = false;
244  }
245 
246  break;
247  default:
249  };
251 }
252 
254  const mrpt::math::TPoint3D& corner1, const mrpt::math::TPoint3D& corner2)
255 {
257 
258  // Order the coordinates so we always have the min/max in their right
259  // position:
260  m_corner_min.x = std::min(corner1.x, corner2.x);
261  m_corner_min.y = std::min(corner1.y, corner2.y);
262  m_corner_min.z = std::min(corner1.z, corner2.z);
263 
264  m_corner_max.x = std::max(corner1.x, corner2.x);
265  m_corner_max.y = std::max(corner1.y, corner2.y);
266  m_corner_max.z = std::max(corner1.z, corner2.z);
267 }
268 
269 bool CBox::traceRay(const mrpt::poses::CPose3D& o, double& dist) const
270 {
272  MRPT_UNUSED_PARAM(dist);
273  THROW_EXCEPTION("TO DO")
274 }
275 
277  mrpt::math::TPoint3D& bb_min, mrpt::math::TPoint3D& bb_max) const
278 {
279  bb_min = m_corner_min;
280  bb_max = m_corner_max;
281 
282  // Convert to coordinates of my parent:
283  m_pose.composePoint(bb_min, bb_min);
284  m_pose.composePoint(bb_max, bb_max);
285 }
void setBoxCorners(const mrpt::math::TPoint3D &corner1, const mrpt::math::TPoint3D &corner2)
Set the position and size of the box, from two corners in 3D.
Definition: CBox.cpp:253
A solid or wireframe box in 3D, defined by 6 rectangular faces parallel to the planes X...
Definition: CBox.h:42
void renderTriangleWithNormal(const mrpt::math::TPoint3D &p1, const mrpt::math::TPoint3D &p2, const mrpt::math::TPoint3D &p3)
Can be used by derived classes to draw a triangle with a normal vector computed automatically - to be...
Definition: gl_utils.cpp:154
void writeToStreamRender(utils::CStream &out) const
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
#define min(a, b)
mrpt::math::TPoint3D m_corner_max
Definition: CBox.h:48
GLAPI void GLAPIENTRY glEnable(GLenum cap)
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
#define THROW_EXCEPTION(msg)
CBox()
Basic empty constructor.
Definition: CBox.cpp:26
#define GL_TRIANGLES
Definition: glew.h:276
void render_dl() const override
Render.
Definition: CBox.cpp:50
mrpt::utils::TColor m_solidborder_color
Color of the solid box borders.
Definition: CBox.h:57
GLAPI void GLAPIENTRY glVertex3d(GLdouble x, GLdouble y, GLdouble z)
bool m_wireframe
true: wireframe, false: solid
Definition: CBox.h:50
bool m_draw_border
Draw line borders to solid box with the given linewidth (default: true)
Definition: CBox.h:55
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_NORMALIZE
Definition: glew.h:416
float m_lineWidth
For wireframe only.
Definition: CBox.h:52
#define GL_ONE_MINUS_SRC_ALPHA
Definition: glew.h:287
#define GL_DEPTH_TEST
Definition: glew.h:401
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.
Definition: CBox.cpp:208
#define GL_LIGHTING
Definition: glew.h:385
GLAPI void GLAPIENTRY glLineWidth(GLfloat width)
mrpt::poses::CPose3D m_pose
6D pose wrt the parent coordinate reference.
Definition: CRenderizable.h:57
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Ray tracing.
Definition: CBox.cpp:269
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:19
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
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: CBox.cpp:228
void readFromStreamRender(mrpt::utils::CStream &in)
GLubyte GLubyte b
Definition: glext.h:6279
mrpt::utils::TColor m_color
Color components in the range [0,255].
Definition: CRenderizable.h:54
double x
X,Y,Z coordinates.
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: CBox.cpp:276
GLAPI void GLAPIENTRY glBegin(GLenum mode)
#define GL_BLEND
Definition: glew.h:432
GLAPI void GLAPIENTRY glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
#define GL_SRC_ALPHA
Definition: glew.h:286
static void checkOpenGLError()
Checks glGetError and throws an exception if an error situation is found.
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:88
void composePoint(double lx, double ly, double lz, double &gx, double &gy, double &gz, mrpt::math::CMatrixFixedNumeric< double, 3, 3 > *out_jacobian_df_dpoint=nullptr, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dpose=nullptr, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dse3=nullptr, bool use_small_rot_approx=false) const
An alternative, slightly more efficient way of doing with G and L being 3D points and P this 6D pose...
Definition: CPose3D.cpp:453
mrpt::math::TPoint3D m_corner_min
Corners coordinates.
Definition: CBox.h:48
GLuint in
Definition: glext.h:7274
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
GLAPI void GLAPIENTRY glEnd(void)
#define GL_LINE_STRIP
Definition: glew.h:275
Lightweight 3D point.
GLAPI void GLAPIENTRY glDisable(GLenum cap)
GLubyte GLubyte GLubyte a
Definition: glext.h:6279



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