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-2017, 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
bool mHasTopBase
Boolean parameters about including the bases in the object.
Definition: CCylinder.h:56
float getBottomRadius() const
Gets the bottom radius.
Definition: CCylinder.h:118
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:71
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
virtual ~CCylinder()
Destructor.
Definition: CCylinder.h:185
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:131
uint32_t getSlicesCount() const
Sets the amount of slices used to display the object.
Definition: CCylinder.h:147
A cylinder or cone whose base lies in the XY plane.
Definition: CCylinder.h:32
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:50
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:219
void setStacksCount(uint32_t stacks)
Gets how many stacks are used in the cylinder&#39;s lateral area.
Definition: CCylinder.h:139
uint32_t getStacksCount() const
Sets the amount of stacks used to display the object.
Definition: CCylinder.h:151
float mHeight
Cylinder&#39;s height.
Definition: CCylinder.h:45
bool hasTopBase() const
Check whether top base is displayed.
Definition: CCylinder.h:81
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#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:92
bool hasBottomBase() const
Check whether bottom base is displayed.
Definition: CCylinder.h:86
GLdouble GLdouble GLdouble r
Definition: glext.h:3705
CCylinder()
Basic empty constructor.
Definition: CCylinder.h:160
float mBaseRadius
Cylinder&#39;s radii.
Definition: CCylinder.h:41
bool reachesHeight(float Z) const
Checks whether the cylinder exists at some height.
Definition: CCylinder.h:201
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Ray tracing.
Definition: CCylinder.cpp:136
float getHeight() const
Gets the cylinder&#39;s height.
Definition: CCylinder.h:126
float getTopRadius() const
Gets the top radius.
Definition: CCylinder.h:122
void setHeight(float height)
Chenges cylinder&#39;s height.
Definition: CCylinder.h:110
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:101
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
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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019