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



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019