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 }
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
A solid or wireframe box in 3D, defined by 6 rectangular faces parallel to the planes X...
Definition: CBox.h:40
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
#define min(a, b)
mrpt::math::TPoint3D m_corner_max
Definition: CBox.h:46
GLAPI void GLAPIENTRY glEnable(GLenum cap)
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:41
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
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
GLAPI void GLAPIENTRY glVertex3d(GLdouble x, GLdouble y, GLdouble z)
bool m_wireframe
true: wireframe, false: solid
Definition: CBox.h:48
bool m_draw_border
Draw line borders to solid box with the given linewidth (default: true)
Definition: CBox.h:53
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.
uint8_t B
Definition: TColor.h:46
#define GL_NORMALIZE
Definition: glew.h:416
float m_lineWidth
For wireframe only.
Definition: CBox.h:50
#define GL_ONE_MINUS_SRC_ALPHA
Definition: glew.h:287
uint8_t G
Definition: TColor.h:46
#define GL_DEPTH_TEST
Definition: glew.h:401
#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:55
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
unsigned char uint8_t
Definition: rptypes.h:41
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:90
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Ray tracing.
Definition: CBox.cpp:256
This base provides a set of functions for maths stuff.
void writeToStreamRender(mrpt::serialization::CArchive &out) const
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
GLubyte GLubyte b
Definition: glext.h:6279
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:263
GLAPI void GLAPIENTRY glBegin(GLenum mode)
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
Definition: CBox.cpp:205
#define GL_BLEND
Definition: glew.h:432
uint8_t R
Definition: TColor.h:46
GLAPI void GLAPIENTRY glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
mrpt::img::TColor m_color
Color components in the range [0,255].
Definition: CRenderizable.h:52
#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.
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:52
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:86
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::math::TPoint3D m_corner_min
Corners coordinates.
Definition: CBox.h:46
mrpt::img::TColor m_solidborder_color
Color of the solid box borders.
Definition: CBox.h:55
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
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
Definition: CBox.cpp:204
void readFromStreamRender(mrpt::serialization::CArchive &in)
uint8_t A
Definition: TColor.h:46
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
Definition: common.h:186



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020