MRPT  1.9.9
CBox.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "opengl-precomp.h" // Precompiled header
11 
12 #include <mrpt/math/geometry.h>
13 #include <mrpt/opengl/CBox.h>
14 #include <mrpt/opengl/gl_utils.h>
16 
17 #include "opengl_internals.h"
18 
19 using namespace mrpt;
20 using namespace mrpt::opengl;
21 
22 using namespace mrpt::math;
23 using namespace std;
24 
26 
28  : m_corner_min(-1, -1, -1),
29  m_corner_max(1, 1, 1),
30 
31  m_solidborder_color(0, 0, 0)
32 {
33 }
34 
36  const mrpt::math::TPoint3D& corner1, const mrpt::math::TPoint3D& corner2,
37  bool is_wireframe, float lineWidth)
38  : m_wireframe(is_wireframe),
39  m_lineWidth(lineWidth),
40  m_draw_border(false),
41  m_solidborder_color(0, 0, 0)
42 {
43  setBoxCorners(corner1, corner2);
44 }
45 
46 /*---------------------------------------------------------------
47  render
48  ---------------------------------------------------------------*/
49 void CBox::render_dl() const
50 {
51 #if MRPT_HAS_OPENGL_GLUT
52  if (m_color.A != 255)
53  {
56  }
57  else
58  {
61  }
62 
63  if (!m_wireframe)
64  {
65  // solid:
67 
70 
71  // Front face:
80 
81  // Back face:
90 
91  // Left face:
100 
101  // Right face:
110 
111  // Bottom face:
120  // Top face:
121 
130 
131  glEnd();
133  }
134 
135  if (m_wireframe || m_draw_border)
136  {
138 
139  if (m_draw_border)
140  {
143  }
144 
145  // wireframe:
148 
150 
151  if (m_wireframe)
153  else
154  {
155  glColor4ub(
158 
159  // Draw lines "a bit" far above the solid surface:
160  /* mrpt::math::TPoint3D d = b-a;
161  d*=0.001;
162  a-=d; b+=d;*/
163  }
164 
166  glVertex3d(a.x, a.y, a.z);
167  glVertex3d(b.x, a.y, a.z);
168  glVertex3d(b.x, a.y, b.z);
169  glVertex3d(a.x, a.y, b.z);
170  glVertex3d(a.x, a.y, a.z);
171  glEnd();
172 
174  glVertex3d(a.x, b.y, a.z);
175  glVertex3d(b.x, b.y, a.z);
176  glVertex3d(b.x, b.y, b.z);
177  glVertex3d(a.x, b.y, b.z);
178  glVertex3d(a.x, b.y, a.z);
179  glEnd();
180 
182  glVertex3d(a.x, a.y, a.z);
183  glVertex3d(a.x, b.y, a.z);
184  glVertex3d(a.x, b.y, b.z);
185  glVertex3d(a.x, a.y, b.z);
186  glEnd();
187 
189  glVertex3d(b.x, a.y, a.z);
190  glVertex3d(b.x, b.y, a.z);
191  glVertex3d(b.x, b.y, b.z);
192  glVertex3d(b.x, a.y, b.z);
193  glEnd();
194 
196  }
197 
199 
200 #endif
201 }
202 
203 uint8_t CBox::serializeGetVersion() const { return 1; }
205 {
206  writeToStreamRender(out);
207  // version 0
210  // Version 1:
212 }
213 
215 {
216  switch (version)
217  {
218  case 0:
219  case 1:
224  // Version 1:
225  if (version >= 1)
227  else
228  {
229  m_draw_border = false;
230  }
231 
232  break;
233  default:
235  };
237 }
238 
240  const mrpt::math::TPoint3D& corner1, const mrpt::math::TPoint3D& corner2)
241 {
243 
244  // Order the coordinates so we always have the min/max in their right
245  // position:
246  m_corner_min.x = std::min(corner1.x, corner2.x);
247  m_corner_min.y = std::min(corner1.y, corner2.y);
248  m_corner_min.z = std::min(corner1.z, corner2.z);
249 
250  m_corner_max.x = std::max(corner1.x, corner2.x);
251  m_corner_max.y = std::max(corner1.y, corner2.y);
252  m_corner_max.z = std::max(corner1.z, corner2.z);
253 }
254 
255 bool CBox::traceRay(const mrpt::poses::CPose3D& o, double& dist) const
256 {
258  MRPT_UNUSED_PARAM(dist);
259  THROW_EXCEPTION("TO DO");
260 }
261 
264 {
267 
268  // Convert to coordinates of my parent:
271 }
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:239
A solid or wireframe box in 3D, defined by 6 rectangular faces parallel to the planes X...
Definition: CBox.h:39
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:169
void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
double x
X,Y,Z coordinates.
Definition: TPoint3D.h:83
mrpt::math::TPoint3D m_corner_max
Definition: CBox.h:45
void composePoint(double lx, double ly, double lz, double &gx, double &gy, double &gz, mrpt::math::CMatrixFixed< double, 3, 3 > *out_jacobian_df_dpoint=nullptr, mrpt::math::CMatrixFixed< double, 3, 6 > *out_jacobian_df_dpose=nullptr, mrpt::math::CMatrixFixed< 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:367
GLAPI void GLAPIENTRY glEnable(GLenum cap)
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:67
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to all CSerializable-classes implementation files.
CBox()
Basic empty constructor.
Definition: CBox.cpp:27
#define GL_TRIANGLES
Definition: glew.h:277
void render_dl() const override
Render.
Definition: CBox.cpp:49
GLAPI void GLAPIENTRY glVertex3d(GLdouble x, GLdouble y, GLdouble z)
bool m_wireframe
true: wireframe, false: solid
Definition: CBox.h:47
bool m_draw_border
Draw line borders to solid box with the given linewidth (default: true)
Definition: CBox.h:52
STL namespace.
uint8_t B
Definition: TColor.h:46
#define GL_NORMALIZE
Definition: glew.h:417
float m_lineWidth
For wireframe only.
Definition: CBox.h:49
#define GL_ONE_MINUS_SRC_ALPHA
Definition: glew.h:288
uint8_t G
Definition: TColor.h:46
#define GL_DEPTH_TEST
Definition: glew.h:402
#define GL_LIGHTING
Definition: glew.h:386
GLAPI void GLAPIENTRY glLineWidth(GLfloat width)
mrpt::poses::CPose3D m_pose
6D pose wrt the parent coordinate reference.
Definition: CRenderizable.h:54
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
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:97
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Ray tracing.
Definition: CBox.cpp:255
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:214
GLubyte GLubyte b
Definition: glext.h:6372
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:262
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:204
#define GL_BLEND
Definition: glew.h:433
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:51
#define GL_SRC_ALPHA
Definition: glew.h:287
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:54
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:84
mrpt::math::TPoint3D m_corner_min
Corners coordinates.
Definition: CBox.h:45
mrpt::img::TColor m_solidborder_color
Color of the solid box borders.
Definition: CBox.h:54
GLuint in
Definition: glext.h:7391
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
const auto bb_max
GLAPI void GLAPIENTRY glEnd(void)
const auto bb_min
#define GL_LINE_STRIP
Definition: glew.h:276
Lightweight 3D point.
Definition: TPoint3D.h:90
GLAPI void GLAPIENTRY glDisable(GLenum cap)
GLubyte GLubyte GLubyte a
Definition: glext.h:6372
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
Definition: CBox.cpp:203
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: abb8b1a1e Fri Oct 18 14:19:12 2019 +0200 at vie oct 18 14:20:13 CEST 2019