MRPT  2.0.1
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
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
virtual shader_list_t requiredShaders() const override
Returns the ID of the OpenGL shader program required to render this class.
Definition: CBox.h:51
A solid or wireframe box in 3D, defined by 6 rectangular faces parallel to the planes X...
Definition: CBox.h:40
void setLineWidth(float width)
Definition: CBox.h:75
bool isBoxBorderEnabled() const
Definition: CBox.h:92
mrpt::math::TPoint3D m_corner_max
Definition: CBox.h:128
void freeOpenGLResources() override
Free opengl buffers.
void notifyChange() const
Call to enable calling renderUpdateBuffers() before the next render() rendering iteration.
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
bool isWireframe() const
Definition: CBox.h:86
bool m_wireframe
true: wireframe, false (default): solid
Definition: CBox.h:130
bool m_draw_border
Draw line borders to solid box with the given linewidth (default: true)
Definition: CBox.h:134
void setBoxBorderColor(const mrpt::img::TColor &c)
Definition: CBox.h:93
Renderizable generic renderer for objects using the triangles shader.
std::vector< shader_id_t > shader_list_t
A list of shader IDs.
Definition: Shader.h:26
Context for calls to render()
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers, etc.
Definition: CBox.cpp:47
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Ray tracing.
Definition: CBox.cpp:185
CBox()=default
Basic empty constructor.
void getBoxCorners(mrpt::math::TPoint3D &corner1, mrpt::math::TPoint3D &corner2) const
Definition: CBox.h:107
~CBox() override=default
Destructor.
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
void setWireframe(bool is_wireframe=true)
Definition: CBox.h:81
static constexpr shader_id_t WIREFRAME
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
void enableBoxBorder(bool drawBorder=true)
Definition: CBox.h:87
void freeOpenGLResources() override
Free opengl buffers.
Definition: CBox.h:58
static constexpr shader_id_t TRIANGLES
void render(const RenderContext &rc) const override
Implements the rendering of 3D objects in each class derived from CRenderizable.
Definition: CBox.cpp:34
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:85
mrpt::math::TPoint3D m_corner_min
Corners coordinates.
Definition: CBox.h:128
mrpt::img::TColor m_solidborder_color
Color of the solid box borders.
Definition: CBox.h:137
Renderizable generic renderer for objects using the wireframe shader.
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
const auto bb_max
#define DEFINE_SERIALIZABLE(class_name, NS)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
const auto bb_min
float getLineWidth() const
Definition: CBox.h:80
A RGB color - 8bit.
Definition: TColor.h:25
mrpt::img::TColor getBoxBorderColor() const
Definition: CBox.h:98
void freeOpenGLResources() override
Free opengl buffers.



Page generated by Doxygen 1.8.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020