Main MRPT website > C++ reference
MRPT logo
CCylinder.h
Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                       http://www.mrpt.org/                                |
00005    |                                                                           |
00006    |   Copyright (C) 2005-2011  University of Malaga                           |
00007    |                                                                           |
00008    |    This software was written by the Machine Perception and Intelligent    |
00009    |      Robotics Lab, University of Malaga (Spain).                          |
00010    |    Contact: Jose-Luis Blanco  <jlblanco@ctima.uma.es>                     |
00011    |                                                                           |
00012    |  This file is part of the MRPT project.                                   |
00013    |                                                                           |
00014    |     MRPT is free software: you can redistribute it and/or modify          |
00015    |     it under the terms of the GNU General Public License as published by  |
00016    |     the Free Software Foundation, either version 3 of the License, or     |
00017    |     (at your option) any later version.                                   |
00018    |                                                                           |
00019    |   MRPT is distributed in the hope that it will be useful,                 |
00020    |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |
00021    |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
00022    |     GNU General Public License for more details.                          |
00023    |                                                                           |
00024    |     You should have received a copy of the GNU General Public License     |
00025    |     along with MRPT.  If not, see <http://www.gnu.org/licenses/>.         |
00026    |                                                                           |
00027    +---------------------------------------------------------------------------+ */
00028 #ifndef opengl_CCylinder_H
00029 #define opengl_CCylinder_H
00030 
00031 #include <mrpt/opengl/CRenderizableDisplayList.h>
00032 
00033 namespace mrpt  {
00034 namespace opengl        {
00035         class OPENGL_IMPEXP CCylinder;
00036         // This must be added to any CSerializable derived class:
00037         DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(CCylinder,CRenderizableDisplayList, OPENGL_IMPEXP)
00038         /** A cylinder or cone whose base lies in the XY plane.
00039           * \sa opengl::COpenGLScene,opengl::CDisk
00040           *  
00041           *  <div align="center">
00042           *  <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px; border-style: solid;">
00043           *   <tr> <td> mrpt::opengl::CCylinder </td> <td> \image html preview_CCylinder.png </td> </tr>
00044           *  </table>
00045           *  </div>
00046           *  
00047           * \ingroup mrpt_opengl_grp
00048           */
00049         class OPENGL_IMPEXP CCylinder:public CRenderizableDisplayList   {
00050                 DEFINE_SERIALIZABLE(CCylinder)
00051         protected:
00052                 /**
00053                   * 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.
00054                   */
00055                 float mBaseRadius,mTopRadius;
00056                 /**
00057                   * Cylinder's height
00058                   */
00059                 float mHeight;
00060                 /**
00061                   * Implementation parameters on which depend the number of actually rendered polygons.
00062                   */
00063                 uint32_t mSlices,mStacks;
00064                 /**
00065                   * Boolean parameters about including the bases in the object. If both mHasTopBase and mHasBottomBase are set to false, only the lateral area is displayed.
00066                   */
00067                 bool mHasTopBase,mHasBottomBase;
00068         public:
00069                 /**
00070                   * Constructor with two radii. Allows the construction of any cylinder.
00071                   */
00072                 static CCylinderPtr Create(const float baseRadius,const float topRadius,const float height=1,const int slices=10,const int stacks=10)   {
00073                         return CCylinderPtr(new CCylinder(baseRadius,topRadius,height,slices,stacks));
00074                 }
00075                 /** Render
00076                   * \sa mrpt::opengl::CRenderizable
00077                   */
00078                 void render_dl() const;
00079                 /**
00080                   * Ray tracing.
00081                   * \sa mrpt::opengl::CRenderizable
00082                   */
00083                 virtual bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const;
00084                 /**
00085                   * Configuration of the cylinder's bases display.
00086                   */
00087                 inline void setHasBases(bool top=true,bool bottom=true) {
00088                         mHasTopBase=top;
00089                         mHasBottomBase=bottom;
00090                         CRenderizableDisplayList::notifyChange();
00091                 }
00092                 /**
00093                   * Check whether top base is displayed.
00094                   * \sa hasBottomBase
00095                   */
00096                 inline bool hasTopBase() const  {
00097                         return mHasTopBase;
00098                 }
00099                 /**
00100                   * Check whether bottom base is displayed.
00101                   * \sa hasTopBase
00102                   */
00103                 inline bool hasBottomBase() const       {
00104                         return mHasBottomBase;
00105                 }
00106                 /**
00107                   * Sets both radii to a single value, thus configuring the object as a cylinder.
00108                   * \sa setRadii
00109                   */
00110                 inline void setRadius(float radius)     {
00111                         mBaseRadius=mTopRadius=radius;
00112                         CRenderizableDisplayList::notifyChange();
00113                 }
00114                 /**
00115                   * Sets both radii independently.
00116                   * \sa setRadius
00117                   */
00118                 inline void setRadii(float bottom,float top)    {
00119                         mBaseRadius=bottom;
00120                         mTopRadius=top;
00121                         CRenderizableDisplayList::notifyChange();
00122                 }
00123                 /**
00124                   * Chenges cylinder's height.
00125                   */
00126                 inline void setHeight(float height)     {
00127                         mHeight=height;
00128                         CRenderizableDisplayList::notifyChange();
00129                 }
00130                 /**
00131                   * Gets the bottom radius.
00132                   */
00133                 inline float getBottomRadius() const    {
00134                         return mBaseRadius;
00135                 }
00136                 /**
00137                   * Gets the top radius.
00138                   */
00139                 inline float getTopRadius() const       {
00140                         return mTopRadius;
00141                 }
00142                 /**
00143                   * Gets the cylinder's height.
00144                   */
00145                 inline float getHeight() const  {
00146                         return mHeight;
00147                 }
00148                 /**
00149                   * Gets how many slices are used in the cylinder's lateral area and in its bases.
00150                   */
00151                 inline void setSlicesCount(uint32_t slices)     {
00152                         mSlices=slices;
00153                         CRenderizableDisplayList::notifyChange();
00154                 }
00155                 /**
00156                   * Gets how many stacks are used in the cylinder's lateral area.
00157                   */
00158                 inline void setStacksCount(uint32_t stacks)     {
00159                         mStacks=stacks;
00160                         CRenderizableDisplayList::notifyChange();
00161                 }
00162                 /**
00163                   * Sets the amount of slices used to display the object.
00164                   */
00165                 inline uint32_t getSlicesCount() const  {
00166                         return mSlices;
00167                 }
00168                 /**
00169                   * Sets the amount of stacks used to display the object.
00170                   */
00171                 inline uint32_t getStacksCount() const  {
00172                         return mStacks;
00173                 }
00174         private:
00175                 /**
00176                   * Basic empty constructor. Set all parameters to default.
00177                   */
00178                 CCylinder():mBaseRadius(1),mTopRadius(1),mHeight(1),mSlices(10),mStacks(10),mHasTopBase(true),mHasBottomBase(true)      {};
00179                 /**
00180                   * Complete constructor. Allows the configuration of every parameter.
00181                   */
00182                 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)       {};
00183                 /**
00184                   * Destructor.
00185                   */
00186                 virtual ~CCylinder() {};
00187                 /**
00188                   * Gets the radius of the circunference located at certain height, returning false if the cylinder doesn't get that high.
00189                   */
00190                 inline bool getRadius(float Z,float &r) const   {
00191                         if (!reachesHeight(Z)) return false;
00192                         r=(Z/mHeight)*(mTopRadius-mBaseRadius)+mBaseRadius;
00193                         return true;
00194                 }
00195                 /**
00196                   * Checks whether the cylinder exists at some height.
00197                   */
00198                 inline bool reachesHeight(float Z) const        {
00199                         return (mHeight<0)?(Z>=mHeight&&Z<=0):(Z<=mHeight&&Z>=0);
00200                 }
00201         };
00202 }
00203 }
00204 #endif



Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011