MRPT  2.0.3
CBox.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, 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 #pragma once
10 
11 #include <mrpt/math/TPoint3D.h>
14 
15 namespace mrpt::opengl
16 {
17 /** A solid or wireframe box in 3D, defined by 6 rectangular faces parallel to
18  *the planes X, Y and Z (note that the object can be translated and rotated
19  *afterwards as any other CRenderizable object using the "object pose" in the
20  *base class).
21  * Three drawing modes are possible:
22  * - Wireframe: setWireframe(true). Used color is the CRenderizable color
23  * - Solid box: setWireframe(false). Used color is the CRenderizable color
24  * - Solid box with border: setWireframe(false) + enableBoxBorder(true). Solid
25  *color is the CRenderizable color, border line can be set with
26  *setBoxBorderColor().
27  *
28  * \sa opengl::COpenGLScene,opengl::CRenderizable
29  *
30  * <div align="center">
31  * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px;
32  *border-style: solid;">
33  * <tr> <td> mrpt::opengl::CBox </td> <td> \image html preview_CBox.png </td>
34  *</tr>
35  * </table>
36  * </div>
37  *
38  * \ingroup mrpt_opengl_grp
39  */
42 {
44 
45  public:
46  /** @name Renderizable shader API virtual methods
47  * @{ */
48  void render(const RenderContext& rc) const override;
49  void renderUpdateBuffers() const override;
50 
51  virtual shader_list_t requiredShaders() const override
52  {
53  // May use up to two shaders (triangles and lines):
55  }
56  void onUpdateBuffers_Wireframe() override;
57  void onUpdateBuffers_Triangles() override;
58  void freeOpenGLResources() override
59  {
62  }
63  /** @} */
64 
65  void getBoundingBox(
67  mrpt::math::TPoint3D& bb_max) const override;
68 
69  /**
70  * Ray tracing.
71  * \sa mrpt::opengl::CRenderizable
72  */
73  bool traceRay(const mrpt::poses::CPose3D& o, double& dist) const override;
74 
75  inline void setLineWidth(float width)
76  {
77  m_lineWidth = width;
79  }
80  inline float getLineWidth() const { return m_lineWidth; }
81  inline void setWireframe(bool is_wireframe = true)
82  {
83  m_wireframe = is_wireframe;
85  }
86  inline bool isWireframe() const { return m_wireframe; }
87  inline void enableBoxBorder(bool drawBorder = true)
88  {
89  m_draw_border = drawBorder;
91  }
92  inline bool isBoxBorderEnabled() const { return m_draw_border; }
93  inline void setBoxBorderColor(const mrpt::img::TColor& c)
94  {
97  }
99  {
100  return m_solidborder_color;
101  }
102 
103  /** Set the position and size of the box, from two corners in 3D */
104  void setBoxCorners(
105  const mrpt::math::TPoint3D& corner1,
106  const mrpt::math::TPoint3D& corner2);
108  mrpt::math::TPoint3D& corner1, mrpt::math::TPoint3D& corner2) const
109  {
110  corner1 = m_corner_min;
111  corner2 = m_corner_max;
112  }
113 
114  /** Basic empty constructor. Set all parameters to default. */
115  CBox() = default;
116 
117  /** Constructor with all the parameters */
118  CBox(
119  const mrpt::math::TPoint3D& corner1,
120  const mrpt::math::TPoint3D& corner2, bool is_wireframe = false,
121  float lineWidth = 1.0);
122 
123  /** Destructor */
124  ~CBox() override = default;
125 
126  protected:
127  /** Corners coordinates */
128  mrpt::math::TPoint3D m_corner_min = {-1, -1, -1}, m_corner_max = {1, 1, 1};
129  /** true: wireframe, false (default): solid */
130  bool m_wireframe{false};
131 
132  /** Draw line borders to solid box with the given linewidth (default: true)
133  */
134  bool m_draw_border{true};
135 
136  /** Color of the solid box borders. */
138 };
139 } // namespace mrpt::opengl
mrpt::opengl::CBox::freeOpenGLResources
void freeOpenGLResources() override
Free opengl buffers.
Definition: CBox.h:58
mrpt::opengl::CBox::~CBox
~CBox() override=default
Destructor
mrpt::opengl::CBox::enableBoxBorder
void enableBoxBorder(bool drawBorder=true)
Definition: CBox.h:87
mrpt::opengl::CRenderizable::notifyChange
void notifyChange() const
Call to enable calling renderUpdateBuffers() before the next render() rendering iteration.
Definition: CRenderizable.h:315
mrpt::math::TPoint3D_< double >
DEFINE_SERIALIZABLE
#define DEFINE_SERIALIZABLE(class_name, NS)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
Definition: CSerializable.h:152
mrpt::opengl::CBox::getLineWidth
float getLineWidth() const
Definition: CBox.h:80
mrpt::opengl::CBox::onUpdateBuffers_Wireframe
void onUpdateBuffers_Wireframe() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
Definition: CBox.cpp:53
mrpt::opengl::CBox::isWireframe
bool isWireframe() const
Definition: CBox.h:86
mrpt::opengl::CBox
A solid or wireframe box in 3D, defined by 6 rectangular faces parallel to the planes X,...
Definition: CBox.h:40
mrpt::opengl::CRenderizableShaderWireFrame
Renderizable generic renderer for objects using the wireframe shader.
Definition: CRenderizableShaderWireFrame.h:24
mrpt::opengl::CBox::render
void render(const RenderContext &rc) const override
Implements the rendering of 3D objects in each class derived from CRenderizable.
Definition: CBox.cpp:34
mrpt::opengl::CBox::isBoxBorderEnabled
bool isBoxBorderEnabled() const
Definition: CBox.h:92
mrpt::opengl::CBox::m_corner_max
mrpt::math::TPoint3D m_corner_max
Definition: CBox.h:128
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:134
mrpt::opengl::CRenderizableShaderTriangles::freeOpenGLResources
void freeOpenGLResources() override
Free opengl buffers.
Definition: CRenderizableShaderTriangles.h:45
mrpt::opengl::CBox::getBoxCorners
void getBoxCorners(mrpt::math::TPoint3D &corner1, mrpt::math::TPoint3D &corner2) const
Definition: CBox.h:107
mrpt::opengl::CBox::setLineWidth
void setLineWidth(float width)
Definition: CBox.h:75
mrpt::opengl::CRenderizableShaderWireFrame::freeOpenGLResources
void freeOpenGLResources() override
Free opengl buffers.
Definition: CRenderizableShaderWireFrame.h:57
mrpt::opengl::CBox::renderUpdateBuffers
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers,...
Definition: CBox.cpp:47
mrpt::opengl::CBox::traceRay
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Ray tracing.
Definition: CBox.cpp:185
CRenderizableShaderTriangles.h
bb_max
const auto bb_max
Definition: CPose3DPDFGrid_unittest.cpp:25
mrpt::opengl::DefaultShaderID::WIREFRAME
static constexpr shader_id_t WIREFRAME
Definition: DefaultShaders.h:25
bb_min
const auto bb_min
Definition: CPose3DPDFGrid_unittest.cpp:23
mrpt::opengl::DefaultShaderID::TRIANGLES
static constexpr shader_id_t TRIANGLES
Definition: DefaultShaders.h:27
mrpt::opengl::CBox::getBoxBorderColor
mrpt::img::TColor getBoxBorderColor() const
Definition: CBox.h:98
mrpt::opengl::CBox::m_corner_min
mrpt::math::TPoint3D m_corner_min
Corners coordinates.
Definition: CBox.h:128
mrpt::poses::CPose3D
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:85
CRenderizableShaderWireFrame.h
mrpt::img::TColor
A RGB color - 8bit.
Definition: TColor.h:25
mrpt::opengl::CBox::onUpdateBuffers_Triangles
void onUpdateBuffers_Triangles() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
Definition: CBox.cpp:85
mrpt::opengl::CRenderizable::RenderContext
Context for calls to render()
Definition: CRenderizable.h:266
mrpt::opengl::CRenderizableShaderWireFrame::m_lineWidth
float m_lineWidth
Definition: CRenderizableShaderWireFrame.h:65
mrpt::opengl::CBox::m_solidborder_color
mrpt::img::TColor m_solidborder_color
Color of the solid box borders.
Definition: CBox.h:137
mrpt::opengl::CBox::setBoxBorderColor
void setBoxBorderColor(const mrpt::img::TColor &c)
Definition: CBox.h:93
mrpt::opengl::CBox::CBox
CBox()=default
Basic empty constructor.
TPoint3D.h
mrpt::opengl::shader_list_t
std::vector< shader_id_t > shader_list_t
A list of shader IDs.
Definition: Shader.h:26
mrpt::opengl::CRenderizableShaderTriangles
Renderizable generic renderer for objects using the triangles shader.
Definition: CRenderizableShaderTriangles.h:25
mrpt::opengl::CBox::m_wireframe
bool m_wireframe
true: wireframe, false (default): solid
Definition: CBox.h:130
mrpt::opengl::CBox::requiredShaders
virtual shader_list_t requiredShaders() const override
Returns the ID of the OpenGL shader program required to render this class.
Definition: CBox.h:51
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:169
mrpt::opengl
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
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:192
mrpt::opengl::CBox::setWireframe
void setWireframe(bool is_wireframe=true)
Definition: CBox.h:81



Page generated by Doxygen 1.8.17 for MRPT 2.0.3 at Fri May 29 13:06:46 UTC 2020