Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef opengl_CCylinder_H
00029 #define opengl_CCylinder_H
00030
00031 #include <mrpt/opengl/CRenderizable.h>
00032
00033 namespace mrpt {
00034 namespace opengl {
00035 class MRPTDLLIMPEXP CCylinder;
00036
00037 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE(CCylinder,CRenderizable)
00038
00039
00040
00041 class MRPTDLLIMPEXP CCylinder:public CRenderizable {
00042 DEFINE_SERIALIZABLE(CCylinder)
00043 protected:
00044
00045
00046
00047 float mBaseRadius,mTopRadius;
00048
00049
00050
00051 float mHeight;
00052
00053
00054
00055 uint32_t mSlices,mStacks;
00056
00057
00058
00059 bool mHasTopBase,mHasBottomBase;
00060 public:
00061
00062
00063
00064 static CCylinderPtr Create(const float baseRadius,const float topRadius,const float height=1,const int slices=10,const int stacks=10) {
00065 return CCylinderPtr(new CCylinder(baseRadius,topRadius,height,slices,stacks));
00066 }
00067
00068
00069
00070 static CCylinderPtr Create(const float radius,const float height=1,const int slices=10,const int stacks=10) {
00071 return CCylinderPtr(new CCylinder(radius,radius,height,slices,stacks));
00072 }
00073
00074
00075
00076 void render() const;
00077
00078
00079
00080
00081 virtual bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const;
00082
00083
00084
00085 inline void setHasBases(bool top=true,bool bottom=true) {
00086 mHasTopBase=top;
00087 mHasBottomBase=bottom;
00088 }
00089
00090
00091
00092
00093 inline bool hasTopBase() const {
00094 return mHasTopBase;
00095 }
00096
00097
00098
00099
00100 inline bool hasBottomBase() const {
00101 return mHasBottomBase;
00102 }
00103
00104
00105
00106
00107 inline void setRadius(float radius) {
00108 mBaseRadius=mTopRadius=radius;
00109 }
00110
00111
00112
00113
00114 inline void setRadii(float bottom,float top) {
00115 mBaseRadius=bottom;
00116 mTopRadius=top;
00117 }
00118
00119
00120
00121 inline void setHeight(float height) {
00122 mHeight=height;
00123 }
00124
00125
00126
00127 inline float getBottomRadius() const {
00128 return mBaseRadius;
00129 }
00130
00131
00132
00133 inline float getTopRadius() const {
00134 return mTopRadius;
00135 }
00136
00137
00138
00139 inline float getHeight() const {
00140 return mHeight;
00141 }
00142
00143
00144
00145 inline void setSlicesCount(uint32_t slices) {
00146 mSlices=slices;
00147 }
00148
00149
00150
00151 inline void setStacksCount(uint32_t stacks) {
00152 mStacks=stacks;
00153 }
00154
00155
00156
00157 inline uint32_t getSlicesCount() const {
00158 return mSlices;
00159 }
00160
00161
00162
00163 inline uint32_t getStacksCount() const {
00164 return mStacks;
00165 }
00166 private:
00167
00168
00169
00170 CCylinder():mBaseRadius(1),mTopRadius(1),mHeight(1),mSlices(10),mStacks(10),mHasTopBase(true),mHasBottomBase(true) {};
00171
00172
00173
00174 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) {};
00175
00176
00177
00178 virtual ~CCylinder() {};
00179
00180
00181
00182 inline bool getRadius(float Z,float &r) const {
00183 if (!reachesHeight(Z)) return false;
00184 r=(Z/mHeight)*(mTopRadius-mBaseRadius)+mBaseRadius;
00185 return true;
00186 }
00187
00188
00189
00190 inline bool reachesHeight(float Z) const {
00191 return (mHeight<0)?(Z>=mHeight&&Z<=0):(Z<=mHeight&&Z>=0);
00192 }
00193 };
00194 }
00195 }
00196 #endif