MRPT  1.9.9
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-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 #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  protected:
34  /**
35  * Cylinder's radii. If mBaseRadius==mTopRadius, then the object is an
36  * actual cylinder. If both differ, it's a truncated cone. If one of the
37  * radii is zero, the object is a cone.
38  */
39  float mBaseRadius{1}, mTopRadius{1};
40  /**
41  * Cylinder's height
42  */
43  float mHeight{1};
44  /**
45  * Implementation parameters on which depend the number of actually
46  * rendered polygons.
47  */
48  uint32_t mSlices{10}, mStacks{10};
49  /**
50  * Boolean parameters about including the bases in the object. If both
51  * mHasTopBase and mHasBottomBase are set to false, only the lateral area is
52  * displayed.
53  */
54  bool mHasTopBase{true}, mHasBottomBase{true};
55 
56  public:
57  /** Render
58  * \sa mrpt::opengl::CRenderizable
59  */
60  void render_dl() const override;
61  /**
62  * Ray tracing.
63  * \sa mrpt::opengl::CRenderizable
64  */
65  bool traceRay(const mrpt::poses::CPose3D& o, double& dist) const override;
66  /**
67  * Configuration of the cylinder's bases display.
68  */
69  inline void setHasBases(bool top = true, bool bottom = true)
70  {
71  mHasTopBase = top;
72  mHasBottomBase = bottom;
74  }
75  /**
76  * Check whether top base is displayed.
77  * \sa hasBottomBase
78  */
79  inline bool hasTopBase() const { return mHasTopBase; }
80  /**
81  * Check whether bottom base is displayed.
82  * \sa hasTopBase
83  */
84  inline bool hasBottomBase() const { return mHasBottomBase; }
85  /**
86  * Sets both radii to a single value, thus configuring the object as a
87  * cylinder.
88  * \sa setRadii
89  */
90  inline void setRadius(float radius)
91  {
92  mBaseRadius = mTopRadius = radius;
94  }
95  /**
96  * Sets both radii independently.
97  * \sa setRadius
98  */
99  inline void setRadii(float bottom, float top)
100  {
101  mBaseRadius = bottom;
102  mTopRadius = top;
104  }
105  /**
106  * Chenges cylinder's height.
107  */
108  inline void setHeight(float height)
109  {
110  mHeight = height;
112  }
113  /**
114  * Gets the bottom radius.
115  */
116  inline float getBottomRadius() const { return mBaseRadius; }
117  /**
118  * Gets the top radius.
119  */
120  inline float getTopRadius() const { return mTopRadius; }
121  /**
122  * Gets the cylinder's height.
123  */
124  inline float getHeight() const { return mHeight; }
125  /**
126  * Gets how many slices are used in the cylinder's lateral area and in its
127  * bases.
128  */
129  inline void setSlicesCount(uint32_t slices)
130  {
131  mSlices = slices;
133  }
134  /**
135  * Gets how many stacks are used in the cylinder's lateral area.
136  */
137  inline void setStacksCount(uint32_t stacks)
138  {
139  mStacks = stacks;
141  }
142  /**
143  * Sets the amount of slices used to display the object.
144  */
145  inline uint32_t getSlicesCount() const { return mSlices; }
146  /**
147  * Sets the amount of stacks used to display the object.
148  */
149  inline uint32_t getStacksCount() const { return mStacks; }
150  /** Evaluates the bounding box of this object (including possible children)
151  * in the coordinate frame of the object parent. */
152  void getBoundingBox(
154  mrpt::math::TPoint3D& bb_max) const override;
155  /**
156  * Basic empty constructor. Set all parameters to default.
157  */
158  CCylinder()
159 
160  = default;
161  /**
162  * Complete constructor. Allows the configuration of every parameter.
163  */
164  /** Constructor with two radii. Allows the construction of any cylinder. */
166  const float baseRadius, const float topRadius, const float height = 1,
167  const int slices = 10, const int stacks = 10)
168  : mBaseRadius(baseRadius),
169  mTopRadius(topRadius),
170  mHeight(height),
171  mSlices(slices),
172  mStacks(stacks),
173  mHasTopBase(true),
174  mHasBottomBase(true){};
175  /**
176  * Destructor.
177  */
178  ~CCylinder() override = default;
179 
180  private:
181  /**
182  * Gets the radius of the circunference located at certain height,
183  * returning false if the cylinder doesn't get that high.
184  */
185  inline bool getRadius(float Z, float& r) const
186  {
187  if (!reachesHeight(Z)) return false;
188  r = (Z / mHeight) * (mTopRadius - mBaseRadius) + mBaseRadius;
189  return true;
190  }
191  /**
192  * Checks whether the cylinder exists at some height.
193  */
194  inline bool reachesHeight(float Z) const
195  {
196  return (mHeight < 0) ? (Z >= mHeight && Z <= 0)
197  : (Z <= mHeight && Z >= 0);
198  }
199 };
200 } // namespace mrpt::opengl
bool mHasTopBase
Boolean parameters about including the bases in the object.
Definition: CCylinder.h:54
void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
float getBottomRadius() const
Gets the bottom radius.
Definition: CCylinder.h:116
void setHasBases(bool top=true, bool bottom=true)
Configuration of the cylinder&#39;s bases display.
Definition: CCylinder.h:69
#define DEFINE_SCHEMA_SERIALIZABLE()
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
void setSlicesCount(uint32_t slices)
Gets how many slices are used in the cylinder&#39;s lateral area and in its bases.
Definition: CCylinder.h:129
uint32_t getSlicesCount() const
Sets the amount of slices used to display the object.
Definition: CCylinder.h:145
CCylinder()=default
Basic empty constructor.
A cylinder or cone whose base lies in the XY plane.
Definition: CCylinder.h:29
void render_dl() const override
Render.
Definition: CCylinder.cpp:30
uint32_t mSlices
Implementation parameters on which depend the number of actually rendered polygons.
Definition: CCylinder.h:48
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:240
void setStacksCount(uint32_t stacks)
Gets how many stacks are used in the cylinder&#39;s lateral area.
Definition: CCylinder.h:137
uint32_t getStacksCount() const
Sets the amount of stacks used to display the object.
Definition: CCylinder.h:149
float mHeight
Cylinder&#39;s height.
Definition: CCylinder.h:43
bool hasTopBase() const
Check whether top base is displayed.
Definition: CCylinder.h:79
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
void setRadius(float radius)
Sets both radii to a single value, thus configuring the object as a cylinder.
Definition: CCylinder.h:90
bool hasBottomBase() const
Check whether bottom base is displayed.
Definition: CCylinder.h:84
GLdouble GLdouble GLdouble r
Definition: glext.h:3711
float mBaseRadius
Cylinder&#39;s radii.
Definition: CCylinder.h:39
bool reachesHeight(float Z) const
Checks whether the cylinder exists at some height.
Definition: CCylinder.h:194
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:84
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Ray tracing.
Definition: CCylinder.cpp:157
float getHeight() const
Gets the cylinder&#39;s height.
Definition: CCylinder.h:124
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
const auto bb_max
float getTopRadius() const
Gets the top radius.
Definition: CCylinder.h:120
const auto bb_min
~CCylinder() override=default
Destructor.
void setHeight(float height)
Chenges cylinder&#39;s height.
Definition: CCylinder.h:108
Lightweight 3D point.
Definition: TPoint3D.h:90
GLenum GLsizei GLsizei height
Definition: glext.h:3558
void setRadii(float bottom, float top)
Sets both radii independently.
Definition: CCylinder.h:99
CCylinder(const float baseRadius, const float topRadius, const float height=1, const int slices=10, const int stacks=10)
Complete constructor.
Definition: CCylinder.h:165
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:185



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