MRPT  2.0.2
CCylinder.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 
12 
13 namespace mrpt::opengl
14 {
15 class CCylinder;
16 /** A cylinder or cone whose base lies in the XY plane.
17  * \sa opengl::COpenGLScene,opengl::CDisk
18  *
19  * <div align="center">
20  * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px;
21  * border-style: solid;">
22  * <tr> <td> mrpt::opengl::CCylinder </td> <td> \image html
23  * preview_CCylinder.png </td> </tr>
24  * </table>
25  * </div>
26  *
27  * \ingroup mrpt_opengl_grp
28  */
30 {
33  public:
34  /** @name Renderizable shader API virtual methods
35  * @{ */
36  void onUpdateBuffers_Triangles() override;
37  /** @} */
38 
39  bool traceRay(const mrpt::poses::CPose3D& o, double& dist) const override;
40  /**
41  * Configuration of the cylinder's bases display.
42  */
43  inline void setHasBases(bool top = true, bool bottom = true)
44  {
45  m_hasTopBase = top;
46  m_hasBottomBase = bottom;
48  }
49  /**
50  * Check whether top base is displayed.
51  * \sa hasBottomBase
52  */
53  inline bool hasTopBase() const { return m_hasTopBase; }
54  /**
55  * Check whether bottom base is displayed.
56  * \sa hasTopBase
57  */
58  inline bool hasBottomBase() const { return m_hasBottomBase; }
59  /**
60  * Sets both radii to a single value, thus configuring the object as a
61  * cylinder.
62  * \sa setRadii
63  */
64  inline void setRadius(float radius)
65  {
66  m_baseRadius = m_topRadius = radius;
68  }
69  /**
70  * Sets both radii independently.
71  * \sa setRadius
72  */
73  inline void setRadii(float bottom, float top)
74  {
75  m_baseRadius = bottom;
76  m_topRadius = top;
78  }
79  /**
80  * Chenges cylinder's height.
81  */
82  inline void setHeight(float height)
83  {
84  m_height = height;
86  }
87  /**
88  * Gets the bottom radius.
89  */
90  inline float getBottomRadius() const { return m_baseRadius; }
91  /**
92  * Gets the top radius.
93  */
94  inline float getTopRadius() const { return m_topRadius; }
95  /**
96  * Gets the cylinder's height.
97  */
98  inline float getHeight() const { return m_height; }
99 
100  /** Number of radial divisions */
101  inline void setSlicesCount(uint32_t slices)
102  {
103  m_slices = slices;
105  }
106 
107  /** Number of radial divisions */
108  inline uint32_t getSlicesCount() const { return m_slices; }
109 
110  /** Evaluates the bounding box of this object (including possible children)
111  * in the coordinate frame of the object parent. */
112  void getBoundingBox(
114  mrpt::math::TPoint3D& bb_max) const override;
115 
116  CCylinder() = default;
117  /**
118  * Complete constructor. Allows the configuration of every parameter.
119  */
120  /** Constructor with two radii. Allows the construction of any cylinder. */
122  const float baseRadius, const float topRadius, const float height = 1,
123  const int slices = 10)
124  : m_baseRadius(baseRadius),
125  m_topRadius(topRadius),
126  m_height(height),
127  m_slices(slices),
128  m_hasTopBase(true),
129  m_hasBottomBase(true)
130  {
131  }
132  /** Destructor */
133  ~CCylinder() override = default;
134 
135  protected:
136  /**
137  * Cylinder's radii. If m_baseRadius==m_topRadius, then the object is an
138  * actual cylinder. If both differ, it's a truncated cone. If one of the
139  * radii is zero, the object is a cone.
140  */
141  float m_baseRadius{1}, m_topRadius{1};
142  /**
143  * Cylinder's height
144  */
145  float m_height{1};
146 
147  /** Number of radial divisions. */
148  uint32_t m_slices{10};
149 
150  /**
151  * Boolean parameters about including the bases in the object. If both
152  * m_hasTopBase and m_hasBottomBase are set to false, only the lateral area
153  * is displayed.
154  */
155  bool m_hasTopBase{true}, m_hasBottomBase{true};
156 
157  private:
158  /**
159  * Gets the radius of the circunference located at certain height,
160  * returning false if the cylinder doesn't get that high.
161  */
162  inline bool getRadius(float Z, float& r) const
163  {
164  if (!reachesHeight(Z)) return false;
165  r = (Z / m_height) * (m_topRadius - m_baseRadius) + m_baseRadius;
166  return true;
167  }
168  /**
169  * Checks whether the cylinder exists at some height.
170  */
171  inline bool reachesHeight(float Z) const
172  {
173  return (m_height < 0) ? (Z >= m_height && Z <= 0)
174  : (Z <= m_height && Z >= 0);
175  }
176  inline bool reachesHeight(double Z) const { return reachesHeight(d2f(Z)); }
177 };
178 } // namespace mrpt::opengl
float m_height
Cylinder&#39;s height.
Definition: CCylinder.h:145
uint32_t m_slices
Number of radial divisions.
Definition: CCylinder.h:148
void notifyChange() const
Call to enable calling renderUpdateBuffers() before the next render() rendering iteration.
float m_baseRadius
Cylinder&#39;s radii.
Definition: CCylinder.h:141
float getBottomRadius() const
Gets the bottom radius.
Definition: CCylinder.h:90
Renderizable generic renderer for objects using the triangles shader.
void setHasBases(bool top=true, bool bottom=true)
Configuration of the cylinder&#39;s bases display.
Definition: CCylinder.h:43
#define DEFINE_SCHEMA_SERIALIZABLE()
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
bool m_hasTopBase
Boolean parameters about including the bases in the object.
Definition: CCylinder.h:155
float d2f(const double d)
shortcut for static_cast<float>(double)
void setSlicesCount(uint32_t slices)
Number of radial divisions.
Definition: CCylinder.h:101
uint32_t getSlicesCount() const
Number of radial divisions.
Definition: CCylinder.h:108
CCylinder(const float baseRadius, const float topRadius, const float height=1, const int slices=10)
Complete constructor.
Definition: CCylinder.h:121
A cylinder or cone whose base lies in the XY plane.
Definition: CCylinder.h:29
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: CCylinder.cpp:279
bool hasTopBase() const
Check whether top base is displayed.
Definition: CCylinder.h:53
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void setRadius(float radius)
Sets both radii to a single value, thus configuring the object as a cylinder.
Definition: CCylinder.h:64
bool hasBottomBase() const
Check whether bottom base is displayed.
Definition: CCylinder.h:58
bool reachesHeight(float Z) const
Checks whether the cylinder exists at some height.
Definition: CCylinder.h:171
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Simulation of ray-trace, given a pose.
Definition: CCylinder.cpp:192
float getHeight() const
Gets the cylinder&#39;s height.
Definition: CCylinder.h:98
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...
float getTopRadius() const
Gets the top radius.
Definition: CCylinder.h:94
const auto bb_min
~CCylinder() override=default
Destructor.
void setHeight(float height)
Chenges cylinder&#39;s height.
Definition: CCylinder.h:82
void setRadii(float bottom, float top)
Sets both radii independently.
Definition: CCylinder.h:73
void onUpdateBuffers_Triangles() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
Definition: CCylinder.cpp:25
bool reachesHeight(double Z) const
Definition: CCylinder.h:176
bool getRadius(float Z, float &r) const
Gets the radius of the circunference located at certain height, returning false if the cylinder doesn...
Definition: CCylinder.h:162



Page generated by Doxygen 1.8.14 for MRPT 2.0.2 Git: 9b4fd2465 Mon May 4 16:59:08 2020 +0200 at lun may 4 17:26:07 CEST 2020