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