Main MRPT website > C++ reference for MRPT 1.5.6
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 
26 CBoxPtr CBox::Create(const mrpt::math::TPoint3D &corner1, const mrpt::math::TPoint3D &corner2, bool is_wireframe , float lineWidth)
27 {
28  return CBoxPtr(new CBox(corner1,corner2,is_wireframe,lineWidth));
29 }
31  m_corner_min(-1,-1,-1),
32  m_corner_max(1,1,1),
33  m_wireframe(false),
34  m_lineWidth(1),
35  m_draw_border(false),
36  m_solidborder_color(0,0,0)
37 {
38 }
39 
40 CBox::CBox(const mrpt::math::TPoint3D &corner1, const mrpt::math::TPoint3D &corner2, bool is_wireframe, float lineWidth) :
41  m_wireframe(is_wireframe) ,
42  m_lineWidth( lineWidth ),
43  m_draw_border(false),
44  m_solidborder_color(0,0,0)
45 {
46  setBoxCorners(corner1,corner2);
47 }
48 
49 /*---------------------------------------------------------------
50  render
51  ---------------------------------------------------------------*/
52 void CBox::render_dl() const {
53 #if MRPT_HAS_OPENGL_GLUT
54  if (m_color.A!=255)
55  {
58  }
59  else
60  {
63  }
64 
65  if (!m_wireframe)
66  {
67  // solid:
69 
72 
73  // Front face:
82 
83  // Back face:
92 
93  // Left face:
102 
103  // Right face:
112 
113  // Bottom face:
122  // Top face:
123 
132 
133  glEnd();
135  }
136 
137  if (m_wireframe || m_draw_border)
138  {
140 
141  if (m_draw_border)
142  {
145  }
146 
147  // wireframe:
149 
151 
152  if (m_wireframe)
154  else
155  {
157 
158  // Draw lines "a bit" far above the solid surface:
159  /* mrpt::math::TPoint3D d = b-a;
160  d*=0.001;
161  a-=d; b+=d;*/
162  }
163 
165  glVertex3d(a.x,a.y,a.z);
166  glVertex3d(b.x,a.y,a.z);
167  glVertex3d(b.x,a.y,b.z);
168  glVertex3d(a.x,a.y,b.z);
169  glVertex3d(a.x,a.y,a.z);
170  glEnd();
171 
173  glVertex3d(a.x,b.y,a.z);
174  glVertex3d(b.x,b.y,a.z);
175  glVertex3d(b.x,b.y,b.z);
176  glVertex3d(a.x,b.y,b.z);
177  glVertex3d(a.x,b.y,a.z);
178  glEnd();
179 
181  glVertex3d(a.x,a.y,a.z);
182  glVertex3d(a.x,b.y,a.z);
183  glVertex3d(a.x,b.y,b.z);
184  glVertex3d(a.x,a.y,b.z);
185  glEnd();
186 
188  glVertex3d(b.x,a.y,a.z);
189  glVertex3d(b.x,b.y,a.z);
190  glVertex3d(b.x,b.y,b.z);
191  glVertex3d(b.x,a.y,b.z);
192  glEnd();
193 
195  }
196 
198 
199 #endif
200 }
201 
202 /*---------------------------------------------------------------
203  Implements the writing to a CStream capability of
204  CSerializable objects
205  ---------------------------------------------------------------*/
207  if (version) *version=1;
208  else {
209  writeToStreamRender(out);
210  //version 0
211  out <<
215  // Version 1:
217  }
218 }
219 
220 /*---------------------------------------------------------------
221  Implements the reading from a CStream capability of
222  CSerializable objects
223  ---------------------------------------------------------------*/
225  switch (version) {
226  case 0:
227  case 1:
229  in >>
233  // Version 1:
234  if (version>=1)
236  else
237  {
238  m_draw_border = false;
239  }
240 
241  break;
242  default:
244  };
246 }
247 
249 {
251 
252  // Order the coordinates so we always have the min/max in their right position:
253  m_corner_min.x = std::min(corner1.x,corner2.x);
254  m_corner_min.y = std::min(corner1.y,corner2.y);
255  m_corner_min.z = std::min(corner1.z,corner2.z);
256 
257  m_corner_max.x = std::max(corner1.x,corner2.x);
258  m_corner_max.y = std::max(corner1.y,corner2.y);
259  m_corner_max.z = std::max(corner1.z,corner2.z);
260 }
261 
262 
263 bool CBox::traceRay(const mrpt::poses::CPose3D &o,double &dist) const
264 {
266  THROW_EXCEPTION("TO DO")
267 }
268 
269 
271 {
272  bb_min = m_corner_min;
273  bb_max = m_corner_max;
274 
275  // Convert to coordinates of my parent:
276  m_pose.composePoint(bb_min, bb_min);
277  m_pose.composePoint(bb_max, bb_max);
278 }
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:248
A solid or wireframe box in 3D, defined by 6 rectangular faces parallel to the planes X...
Definition: CBox.h:37
void OPENGL_IMPEXP 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:147
void writeToStreamRender(utils::CStream &out) const
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Definition: zip.h:16
#define min(a, b)
mrpt::math::TPoint3D m_corner_max
Corners coordinates.
Definition: CBox.h:41
GLAPI void GLAPIENTRY glEnable(GLenum cap)
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const
Introduces a pure virtual method responsible for writing to a CStream.
Definition: CBox.cpp:206
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: CBox.cpp:270
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const MRPT_OVERRIDE
Ray tracing.
Definition: CBox.cpp:263
#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:30
#define GL_TRIANGLES
Definition: glew.h:272
mrpt::utils::TColor m_solidborder_color
Color of the solid box borders.
Definition: CBox.h:45
GLAPI void GLAPIENTRY glVertex3d(GLdouble x, GLdouble y, GLdouble z)
bool m_wireframe
true: wireframe, false: solid
Definition: CBox.h:42
bool m_draw_border
Draw line borders to solid box with the given linewidth (default: true)
Definition: CBox.h:44
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:412
float m_lineWidth
For wireframe only.
Definition: CBox.h:43
#define GL_ONE_MINUS_SRC_ALPHA
Definition: glew.h:283
double z
X,Y,Z coordinates.
#define GL_DEPTH_TEST
Definition: glew.h:397
#define GL_LIGHTING
Definition: glew.h:381
GLAPI void GLAPIENTRY glLineWidth(GLfloat width)
mrpt::poses::CPose3D m_pose
6D pose wrt the parent coordinate reference. This class automatically holds the cached 3x3 rotation m...
Definition: CRenderizable.h:55
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
void composePoint(double lx, double ly, double lz, double &gx, double &gy, double &gz, mrpt::math::CMatrixFixedNumeric< double, 3, 3 > *out_jacobian_df_dpoint=NULL, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dpose=NULL, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dse3=NULL, 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:427
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_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 readFromStreamRender(mrpt::utils::CStream &in)
GLubyte GLubyte b
Definition: glext.h:5575
mrpt::utils::TColor m_color
Color components in the range [0,255].
Definition: CRenderizable.h:54
void render_dl() const MRPT_OVERRIDE
Render.
Definition: CBox.cpp:52
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: CBox.cpp:224
int version
Definition: mrpt_jpeglib.h:898
GLAPI void GLAPIENTRY glBegin(GLenum mode)
#define GL_BLEND
Definition: glew.h:428
GLAPI void GLAPIENTRY glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
#define GL_SRC_ALPHA
Definition: glew.h:282
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:72
mrpt::math::TPoint3D m_corner_min
Definition: CBox.h:41
GLuint in
Definition: glext.h:6301
The namespace for 3D scene representation and rendering.
GLAPI void GLAPIENTRY glEnd(void)
#define GL_LINE_STRIP
Definition: glew.h:271
Lightweight 3D point.
GLAPI void GLAPIENTRY glDisable(GLenum cap)
GLubyte GLubyte GLubyte a
Definition: glext.h:5575



Page generated by Doxygen 1.8.14 for MRPT 1.5.6 Git: 4c65e8431 Tue Apr 24 08:18:17 2018 +0200 at lun oct 28 01:35:26 CET 2019