MRPT  1.9.9
CCylinder.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #ifndef opengl_CCylinder_H
10 #define opengl_CCylinder_H
11 
13 
14 namespace mrpt::opengl
15 {
16 class CCylinder;
17 /** A cylinder or cone whose base lies in the XY plane.
18  * \sa opengl::COpenGLScene,opengl::CDisk
19  *
20  * <div align="center">
21  * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px;
22  * border-style: solid;">
23  * <tr> <td> mrpt::opengl::CCylinder </td> <td> \image html
24  * preview_CCylinder.png </td> </tr>
25  * </table>
26  * </div>
27  *
28  * \ingroup mrpt_opengl_grp
29  */
31 {
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  */
40  /**
41  * Cylinder's height
42  */
43  float mHeight;
44  /**
45  * Implementation parameters on which depend the number of actually
46  * rendered polygons.
47  */
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  */
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(
153  mrpt::math::TPoint3D& bb_min,
154  mrpt::math::TPoint3D& bb_max) const override;
155  /**
156  * Basic empty constructor. Set all parameters to default.
157  */
159  : mBaseRadius(1),
160  mTopRadius(1),
161  mHeight(1),
162  mSlices(10),
163  mStacks(10),
164  mHasTopBase(true),
165  mHasBottomBase(true){};
166  /**
167  * Complete constructor. Allows the configuration of every parameter.
168  */
169  /** Constructor with two radii. Allows the construction of any cylinder. */
171  const float baseRadius, const float topRadius, const float height = 1,
172  const int slices = 10, const int stacks = 10)
173  : mBaseRadius(baseRadius),
174  mTopRadius(topRadius),
175  mHeight(height),
176  mSlices(slices),
177  mStacks(stacks),
178  mHasTopBase(true),
179  mHasBottomBase(true){};
180  /**
181  * Destructor.
182  */
183  virtual ~CCylinder(){};
184 
185  private:
186  /**
187  * Gets the radius of the circunference located at certain height,
188  * returning false if the cylinder doesn't get that high.
189  */
190  inline bool getRadius(float Z, float& r) const
191  {
192  if (!reachesHeight(Z)) return false;
193  r = (Z / mHeight) * (mTopRadius - mBaseRadius) + mBaseRadius;
194  return true;
195  }
196  /**
197  * Checks whether the cylinder exists at some height.
198  */
199  inline bool reachesHeight(float Z) const
200  {
201  return (mHeight < 0) ? (Z >= mHeight && Z <= 0)
202  : (Z <= mHeight && Z >= 0);
203  }
204 };
205 }
206 #endif
207 
208 
bool mHasTopBase
Boolean parameters about including the bases in the object.
Definition: CCylinder.h:54
float getBottomRadius() const
Gets the bottom radius.
Definition: CCylinder.h:116
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
void setHasBases(bool top=true, bool bottom=true)
Configuration of the cylinder&#39;s bases display.
Definition: CCylinder.h:69
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
virtual ~CCylinder()
Destructor.
Definition: CCylinder.h:183
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
A cylinder or cone whose base lies in the XY plane.
Definition: CCylinder.h:30
void render_dl() const override
Render.
Definition: CCylinder.cpp:28
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:207
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:3705
CCylinder()
Basic empty constructor.
Definition: CCylinder.h:158
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:199
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:86
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Ray tracing.
Definition: CCylinder.cpp:124
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
float getTopRadius() const
Gets the top radius.
Definition: CCylinder.h:120
void setHeight(float height)
Chenges cylinder&#39;s height.
Definition: CCylinder.h:108
Lightweight 3D point.
GLenum GLsizei GLsizei height
Definition: glext.h:3554
unsigned __int32 uint32_t
Definition: rptypes.h:47
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:170
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:190



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020