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  {
54  glEnable(GL_BLEND);
55  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
56  }
57  else
58  {
59  glEnable(GL_DEPTH_TEST);
60  glDisable(GL_BLEND);
61  }
62 
63  if (!m_wireframe)
64  {
65  // solid:
66  glEnable(GL_NORMALIZE);
67 
68  glBegin(GL_TRIANGLES);
69  glColor4ub(m_color.R, m_color.G, m_color.B, m_color.A);
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();
132  glDisable(GL_NORMALIZE);
133  }
134 
135  if (m_wireframe || m_draw_border)
136  {
137  glDisable(GL_LIGHTING);
138 
139  if (m_draw_border)
140  {
141  glEnable(GL_BLEND);
142  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
143  }
144 
145  // wireframe:
146  glLineWidth(m_lineWidth);
148 
150 
151  if (m_wireframe)
152  glColor4ub(m_color.R, m_color.G, m_color.B, m_color.A);
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 
165  glBegin(GL_LINE_STRIP);
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 
173  glBegin(GL_LINE_STRIP);
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 
181  glBegin(GL_LINE_STRIP);
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 
188  glBegin(GL_LINE_STRIP);
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 
195  glEnable(GL_LIGHTING);
196  }
197 
198  glDisable(GL_BLEND);
199 
200 #endif
201 }
202 
203 uint8_t CBox::serializeGetVersion() const { return 1; }
205 {
207  // version 0
210  // Version 1:
212 }
213 
215 {
216  switch (version)
217  {
218  case 0:
219  case 1:
221  in >> m_corner_min.x >> m_corner_min.y >> m_corner_min.z >>
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
#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
void render_dl() const override
Render.
Definition: CBox.cpp:49
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
float m_lineWidth
For wireframe only.
Definition: CBox.h:49
uint8_t G
Definition: TColor.h:46
mrpt::poses::CPose3D m_pose
6D pose wrt the parent coordinate reference.
Definition: CRenderizable.h:54
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
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
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
Definition: CBox.cpp:204
uint8_t R
Definition: TColor.h:46
mrpt::img::TColor m_color
Color components in the range [0,255].
Definition: CRenderizable.h:51
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:85
mrpt::vision::TStereoCalibResults out
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
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
const auto bb_max
void composePoint(double lx, double ly, double lz, double &gx, double &gy, double &gz, mrpt::optional_ref< mrpt::math::CMatrixDouble33 > out_jacobian_df_dpoint=std::nullopt, mrpt::optional_ref< mrpt::math::CMatrixDouble36 > out_jacobian_df_dpose=std::nullopt, mrpt::optional_ref< mrpt::math::CMatrixDouble36 > out_jacobian_df_dse3=std::nullopt, 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...
const auto bb_min
Lightweight 3D point.
Definition: TPoint3D.h:90
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: 7e629e01a Sat Dec 14 00:05:55 2019 +0100 at sáb dic 14 00:15:10 CET 2019