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://mrpt.sourceforge.net/                            |
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           */
00048         class OPENGL_IMPEXP CCylinder:public CRenderizableDisplayList   {
00049                 DEFINE_SERIALIZABLE(CCylinder)
00050         protected:
00051                 /**
00052                   * 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.
00053                   */
00054                 float mBaseRadius,mTopRadius;
00055                 /**
00056                   * Cylinder's height
00057                   */
00058                 float mHeight;
00059                 /**
00060                   * Implementation parameters on which depend the number of actually rendered polygons.
00061                   */
00062                 uint32_t mSlices,mStacks;
00063                 /**
00064                   * Boolean parameters about including the bases in the object. If both mHasTopBase and mHasBottomBase are set to false, only the lateral area is displayed.
00065                   */
00066                 bool mHasTopBase,mHasBottomBase;
00067         public:
00068                 /**
00069                   * Constructor with two radii. Allows the construction of any cylinder.
00070                   */
00071                 static CCylinderPtr Create(const float baseRadius,const float topRadius,const float height=1,const int slices=10,const int stacks=10)   {
00072                         return CCylinderPtr(new CCylinder(baseRadius,topRadius,height,slices,stacks));
00073                 }
00074                 /** Render
00075                   * \sa mrpt::opengl::CRenderizable
00076                   */
00077                 void render_dl() const;
00078                 /**
00079                   * Ray tracing.
00080                   * \sa mrpt::opengl::CRenderizable
00081                   */
00082                 virtual bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const;
00083                 /**
00084                   * Configuration of the cylinder's bases display.
00085                   */
00086                 inline void setHasBases(bool top=true,bool bottom=true) {
00087                         mHasTopBase=top;
00088                         mHasBottomBase=bottom;
00089                         CRenderizableDisplayList::notifyChange();
00090                 }
00091                 /**
00092                   * Check whether top base is displayed.
00093                   * \sa hasBottomBase
00094                   */
00095                 inline bool hasTopBase() const  {
00096                         return mHasTopBase;
00097                 }
00098                 /**
00099                   * Check whether bottom base is displayed.
00100                   * \sa hasTopBase
00101                   */
00102                 inline bool hasBottomBase() const       {
00103                         return mHasBottomBase;
00104                 }
00105                 /**
00106                   * Sets both radii to a single value, thus configuring the object as a cylinder.
00107                   * \sa setRadii
00108                   */
00109                 inline void setRadius(float radius)     {
00110                         mBaseRadius=mTopRadius=radius;
00111                         CRenderizableDisplayList::notifyChange();
00112                 }
00113                 /**
00114                   * Sets both radii independently.
00115                   * \sa setRadius
00116                   */
00117                 inline void setRadii(float bottom,float top)    {
00118                         mBaseRadius=bottom;
00119                         mTopRadius=top;
00120                         CRenderizableDisplayList::notifyChange();
00121                 }
00122                 /**
00123                   * Chenges cylinder's height.
00124                   */
00125                 inline void setHeight(float height)     {
00126                         mHeight=height;
00127                         CRenderizableDisplayList::notifyChange();
00128                 }
00129                 /**
00130                   * Gets the bottom radius.
00131                   */
00132                 inline float getBottomRadius() const    {
00133                         return mBaseRadius;
00134                 }
00135                 /**
00136                   * Gets the top radius.
00137                   */
00138                 inline float getTopRadius() const       {
00139                         return mTopRadius;
00140                 }
00141                 /**
00142                   * Gets the cylinder's height.
00143                   */
00144                 inline float getHeight() const  {
00145                         return mHeight;
00146                 }
00147                 /**
00148                   * Gets how many slices are used in the cylinder's lateral area and in its bases.
00149                   */
00150                 inline void setSlicesCount(uint32_t slices)     {
00151                         mSlices=slices;
00152                         CRenderizableDisplayList::notifyChange();
00153                 }
00154                 /**
00155                   * Gets how many stacks are used in the cylinder's lateral area.
00156                   */
00157                 inline void setStacksCount(uint32_t stacks)     {
00158                         mStacks=stacks;
00159                         CRenderizableDisplayList::notifyChange();
00160                 }
00161                 /**
00162                   * Sets the amount of slices used to display the object.
00163                   */
00164                 inline uint32_t getSlicesCount() const  {
00165                         return mSlices;
00166                 }
00167                 /**
00168                   * Sets the amount of stacks used to display the object.
00169                   */
00170                 inline uint32_t getStacksCount() const  {
00171                         return mStacks;
00172                 }
00173         private:
00174                 /**
00175                   * Basic empty constructor. Set all parameters to default.
00176                   */
00177                 CCylinder():mBaseRadius(1),mTopRadius(1),mHeight(1),mSlices(10),mStacks(10),mHasTopBase(true),mHasBottomBase(true)      {};
00178                 /**
00179                   * Complete constructor. Allows the configuration of every parameter.
00180                   */
00181                 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)       {};
00182                 /**
00183                   * Destructor.
00184                   */
00185                 virtual ~CCylinder() {};
00186                 /**
00187                   * Gets the radius of the circunference located at certain height, returning false if the cylinder doesn't get that high.
00188                   */
00189                 inline bool getRadius(float Z,float &r) const   {
00190                         if (!reachesHeight(Z)) return false;
00191                         r=(Z/mHeight)*(mTopRadius-mBaseRadius)+mBaseRadius;
00192                         return true;
00193                 }
00194                 /**
00195                   * Checks whether the cylinder exists at some height.
00196                   */
00197                 inline bool reachesHeight(float Z) const        {
00198                         return (mHeight<0)?(Z>=mHeight&&Z<=0):(Z<=mHeight&&Z>=0);
00199                 }
00200         };
00201 }
00202 }
00203 #endif



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN:exported at Tue Jan 25 21:56:31 UTC 2011