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



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST