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-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 #include <mrpt/opengl/CBox.h>
12 #include <mrpt/math/geometry.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 
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 uint8_t CBox::serializeGetVersion() const { return 1; }
206 {
207  writeToStreamRender(out);
208  // version 0
211  // Version 1:
213 }
214 
216 {
217  switch (version)
218  {
219  case 0:
220  case 1:
225  // Version 1:
226  if (version >= 1)
228  else
229  {
230  m_draw_border = false;
231  }
232 
233  break;
234  default:
236  };
238 }
239 
241  const mrpt::math::TPoint3D& corner1, const mrpt::math::TPoint3D& corner2)
242 {
244 
245  // Order the coordinates so we always have the min/max in their right
246  // position:
247  m_corner_min.x = std::min(corner1.x, corner2.x);
248  m_corner_min.y = std::min(corner1.y, corner2.y);
249  m_corner_min.z = std::min(corner1.z, corner2.z);
250 
251  m_corner_max.x = std::max(corner1.x, corner2.x);
252  m_corner_max.y = std::max(corner1.y, corner2.y);
253  m_corner_max.z = std::max(corner1.z, corner2.z);
254 }
255 
256 bool CBox::traceRay(const mrpt::poses::CPose3D& o, double& dist) const
257 {
259  MRPT_UNUSED_PARAM(dist);
260  THROW_EXCEPTION("TO DO");
261 }
262 
264  mrpt::math::TPoint3D& bb_min, mrpt::math::TPoint3D& bb_max) const
265 {
266  bb_min = m_corner_min;
267  bb_max = m_corner_max;
268 
269  // Convert to coordinates of my parent:
270  m_pose.composePoint(bb_min, bb_min);
271  m_pose.composePoint(bb_max, bb_max);
272 }
glBegin
GLAPI void GLAPIENTRY glBegin(GLenum mode)
geometry.h
GL_SRC_ALPHA
#define GL_SRC_ALPHA
Definition: glew.h:286
GL_BLEND
#define GL_BLEND
Definition: glew.h:432
glColor4ub
GLAPI void GLAPIENTRY glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
mrpt::opengl::CBox
A solid or wireframe box in 3D, defined by 6 rectangular faces parallel to the planes X,...
Definition: CBox.h:42
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
mrpt::opengl::CBox::CBox
CBox()
Basic empty constructor.
Definition: CBox.cpp:26
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
MRPT_UNUSED_PARAM
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
Definition: common.h:186
mrpt::img::TColor::R
uint8_t R
Definition: TColor.h:48
glEnable
GLAPI void GLAPIENTRY glEnable(GLenum cap)
mrpt::opengl::CBox::m_corner_max
mrpt::math::TPoint3D m_corner_max
Definition: CBox.h:48
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
THROW_EXCEPTION
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:41
GL_LINE_STRIP
#define GL_LINE_STRIP
Definition: glew.h:275
mrpt::opengl::CBox::m_draw_border
bool m_draw_border
Draw line borders to solid box with the given linewidth (default: true)
Definition: CBox.h:55
mrpt::opengl::CBox::serializeGetVersion
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
Definition: CBox.cpp:204
mrpt::serialization::CArchive
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:48
glEnd
GLAPI void GLAPIENTRY glEnd(void)
mrpt::opengl::CBox::traceRay
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Ray tracing.
Definition: CBox.cpp:256
mrpt::opengl::CBox::serializeTo
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
Definition: CBox.cpp:205
mrpt::img::TColor::B
uint8_t B
Definition: TColor.h:48
mrpt::opengl::CRenderizable::m_pose
mrpt::poses::CPose3D m_pose
6D pose wrt the parent coordinate reference.
Definition: CRenderizable.h:57
mrpt::opengl::CRenderizable::m_color
mrpt::img::TColor m_color
Color components in the range [0,255].
Definition: CRenderizable.h:54
mrpt::opengl::CRenderizable::checkOpenGLError
static void checkOpenGLError()
Checks glGetError and throws an exception if an error situation is found.
Definition: CRenderizable.cpp:301
GL_LIGHTING
#define GL_LIGHTING
Definition: glew.h:385
GL_TRIANGLES
#define GL_TRIANGLES
Definition: glew.h:276
glLineWidth
GLAPI void GLAPIENTRY glLineWidth(GLfloat width)
GL_NORMALIZE
#define GL_NORMALIZE
Definition: glew.h:416
GL_ONE_MINUS_SRC_ALPHA
#define GL_ONE_MINUS_SRC_ALPHA
Definition: glew.h:287
mrpt::opengl::CBox::m_corner_min
mrpt::math::TPoint3D m_corner_min
Corners coordinates.
Definition: CBox.h:48
mrpt::opengl::gl_utils::renderTriangleWithNormal
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:157
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
b
GLubyte GLubyte b
Definition: glext.h:6279
mrpt::opengl::CBox::m_lineWidth
float m_lineWidth
For wireframe only.
Definition: CBox.h:52
glVertex3d
GLAPI void GLAPIENTRY glVertex3d(GLdouble x, GLdouble y, GLdouble z)
GL_DEPTH_TEST
#define GL_DEPTH_TEST
Definition: glew.h:401
mrpt::img::TColor::A
uint8_t A
Definition: TColor.h:48
IMPLEMENTS_SERIALIZABLE
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
Definition: CSerializable.h:114
CBox.h
mrpt::opengl::CBox::m_solidborder_color
mrpt::img::TColor m_solidborder_color
Color of the solid box borders.
Definition: CBox.h:57
gl_utils.h
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
mrpt::poses::CPose3D::composePoint
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:379
mrpt::opengl::CBox::render_dl
void render_dl() const override
Render.
Definition: CBox.cpp:50
min
#define min(a, b)
Definition: rplidar_driver.cpp:42
opengl_internals.h
mrpt::img::TColor::G
uint8_t G
Definition: TColor.h:48
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:13
mrpt::opengl::CBox::serializeFrom
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
Definition: CBox.cpp:215
in
GLuint in
Definition: glext.h:7274
mrpt::opengl::CBox::m_wireframe
bool m_wireframe
true: wireframe, false: solid
Definition: CBox.h:50
CArchive.h
MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:90
mrpt::opengl::CRenderizable::writeToStreamRender
void writeToStreamRender(mrpt::serialization::CArchive &out) const
Definition: CRenderizable.cpp:110
mrpt::opengl::CBox::setBoxCorners
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:240
mrpt::opengl
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
mrpt::opengl::CRenderizableDisplayList::readFromStreamRender
void readFromStreamRender(mrpt::serialization::CArchive &in)
Definition: CRenderizableDisplayList.h:65
glBlendFunc
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
a
GLubyte GLubyte GLubyte a
Definition: glext.h:6279
mrpt::opengl::CBox::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: CBox.cpp:263



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