Main MRPT website > C++ reference
MRPT logo
CCylinder.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef opengl_CCylinder_H
29 #define opengl_CCylinder_H
30 
32 
33 namespace mrpt {
34 namespace opengl {
36  // This must be added to any CSerializable derived class:
38  /** A cylinder or cone whose base lies in the XY plane.
39  * \sa opengl::COpenGLScene,opengl::CDisk
40  *
41  * <div align="center">
42  * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px; border-style: solid;">
43  * <tr> <td> mrpt::opengl::CCylinder </td> <td> \image html preview_CCylinder.png </td> </tr>
44  * </table>
45  * </div>
46  *
47  * \ingroup mrpt_opengl_grp
48  */
51  protected:
52  /**
53  * 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.
54  */
55  float mBaseRadius,mTopRadius;
56  /**
57  * Cylinder's height
58  */
59  float mHeight;
60  /**
61  * Implementation parameters on which depend the number of actually rendered polygons.
62  */
63  uint32_t mSlices,mStacks;
64  /**
65  * Boolean parameters about including the bases in the object. If both mHasTopBase and mHasBottomBase are set to false, only the lateral area is displayed.
66  */
67  bool mHasTopBase,mHasBottomBase;
68  public:
69  /**
70  * Constructor with two radii. Allows the construction of any cylinder.
71  */
72  static CCylinderPtr Create(const float baseRadius,const float topRadius,const float height=1,const int slices=10,const int stacks=10) {
73  return CCylinderPtr(new CCylinder(baseRadius,topRadius,height,slices,stacks));
74  }
75  /** Render
76  * \sa mrpt::opengl::CRenderizable
77  */
78  void render_dl() const;
79  /**
80  * Ray tracing.
81  * \sa mrpt::opengl::CRenderizable
82  */
83  virtual bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const;
84  /**
85  * Configuration of the cylinder's bases display.
86  */
87  inline void setHasBases(bool top=true,bool bottom=true) {
88  mHasTopBase=top;
89  mHasBottomBase=bottom;
91  }
92  /**
93  * Check whether top base is displayed.
94  * \sa hasBottomBase
95  */
96  inline bool hasTopBase() const {
97  return mHasTopBase;
98  }
99  /**
100  * Check whether bottom base is displayed.
101  * \sa hasTopBase
102  */
103  inline bool hasBottomBase() const {
104  return mHasBottomBase;
105  }
106  /**
107  * Sets both radii to a single value, thus configuring the object as a cylinder.
108  * \sa setRadii
109  */
110  inline void setRadius(float radius) {
111  mBaseRadius=mTopRadius=radius;
113  }
114  /**
115  * Sets both radii independently.
116  * \sa setRadius
117  */
118  inline void setRadii(float bottom,float top) {
119  mBaseRadius=bottom;
120  mTopRadius=top;
122  }
123  /**
124  * Chenges cylinder's height.
125  */
126  inline void setHeight(float height) {
127  mHeight=height;
129  }
130  /**
131  * Gets the bottom radius.
132  */
133  inline float getBottomRadius() const {
134  return mBaseRadius;
135  }
136  /**
137  * Gets the top radius.
138  */
139  inline float getTopRadius() const {
140  return mTopRadius;
141  }
142  /**
143  * Gets the cylinder's height.
144  */
145  inline float getHeight() const {
146  return mHeight;
147  }
148  /**
149  * Gets how many slices are used in the cylinder's lateral area and in its bases.
150  */
151  inline void setSlicesCount(uint32_t slices) {
152  mSlices=slices;
154  }
155  /**
156  * Gets how many stacks are used in the cylinder's lateral area.
157  */
158  inline void setStacksCount(uint32_t stacks) {
159  mStacks=stacks;
161  }
162  /**
163  * Sets the amount of slices used to display the object.
164  */
165  inline uint32_t getSlicesCount() const {
166  return mSlices;
167  }
168  /**
169  * Sets the amount of stacks used to display the object.
170  */
171  inline uint32_t getStacksCount() const {
172  return mStacks;
173  }
174  private:
175  /**
176  * Basic empty constructor. Set all parameters to default.
177  */
178  CCylinder():mBaseRadius(1),mTopRadius(1),mHeight(1),mSlices(10),mStacks(10),mHasTopBase(true),mHasBottomBase(true) {};
179  /**
180  * Complete constructor. Allows the configuration of every parameter.
181  */
182  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) {};
183  /**
184  * Destructor.
185  */
186  virtual ~CCylinder() {};
187  /**
188  * Gets the radius of the circunference located at certain height, returning false if the cylinder doesn't get that high.
189  */
190  inline bool getRadius(float Z,float &r) const {
191  if (!reachesHeight(Z)) return false;
192  r=(Z/mHeight)*(mTopRadius-mBaseRadius)+mBaseRadius;
193  return true;
194  }
195  /**
196  * Checks whether the cylinder exists at some height.
197  */
198  inline bool reachesHeight(float Z) const {
199  return (mHeight<0)?(Z>=mHeight&&Z<=0):(Z<=mHeight&&Z>=0);
200  }
201  };
202 }
203 }
204 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013