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/CRenderizableDisplayList.h>
00032
00033 namespace mrpt {
00034 namespace opengl {
00035 class OPENGL_IMPEXP CCylinder;
00036
00037 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(CCylinder,CRenderizableDisplayList, OPENGL_IMPEXP)
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 class OPENGL_IMPEXP CCylinder:public CRenderizableDisplayList {
00049 DEFINE_SERIALIZABLE(CCylinder)
00050 protected:
00051
00052
00053
00054 float mBaseRadius,mTopRadius;
00055
00056
00057
00058 float mHeight;
00059
00060
00061
00062 uint32_t mSlices,mStacks;
00063
00064
00065
00066 bool mHasTopBase,mHasBottomBase;
00067 public:
00068
00069
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
00075
00076
00077 void render_dl() const;
00078
00079
00080
00081
00082 virtual bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const;
00083
00084
00085
00086 inline void setHasBases(bool top=true,bool bottom=true) {
00087 mHasTopBase=top;
00088 mHasBottomBase=bottom;
00089 CRenderizableDisplayList::notifyChange();
00090 }
00091
00092
00093
00094
00095 inline bool hasTopBase() const {
00096 return mHasTopBase;
00097 }
00098
00099
00100
00101
00102 inline bool hasBottomBase() const {
00103 return mHasBottomBase;
00104 }
00105
00106
00107
00108
00109 inline void setRadius(float radius) {
00110 mBaseRadius=mTopRadius=radius;
00111 CRenderizableDisplayList::notifyChange();
00112 }
00113
00114
00115
00116
00117 inline void setRadii(float bottom,float top) {
00118 mBaseRadius=bottom;
00119 mTopRadius=top;
00120 CRenderizableDisplayList::notifyChange();
00121 }
00122
00123
00124
00125 inline void setHeight(float height) {
00126 mHeight=height;
00127 CRenderizableDisplayList::notifyChange();
00128 }
00129
00130
00131
00132 inline float getBottomRadius() const {
00133 return mBaseRadius;
00134 }
00135
00136
00137
00138 inline float getTopRadius() const {
00139 return mTopRadius;
00140 }
00141
00142
00143
00144 inline float getHeight() const {
00145 return mHeight;
00146 }
00147
00148
00149
00150 inline void setSlicesCount(uint32_t slices) {
00151 mSlices=slices;
00152 CRenderizableDisplayList::notifyChange();
00153 }
00154
00155
00156
00157 inline void setStacksCount(uint32_t stacks) {
00158 mStacks=stacks;
00159 CRenderizableDisplayList::notifyChange();
00160 }
00161
00162
00163
00164 inline uint32_t getSlicesCount() const {
00165 return mSlices;
00166 }
00167
00168
00169
00170 inline uint32_t getStacksCount() const {
00171 return mStacks;
00172 }
00173 private:
00174
00175
00176
00177 CCylinder():mBaseRadius(1),mTopRadius(1),mHeight(1),mSlices(10),mStacks(10),mHasTopBase(true),mHasBottomBase(true) {};
00178
00179
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
00184
00185 virtual ~CCylinder() {};
00186
00187
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
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