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_CGeneralizedCylinder_H
00029 #define opengl_CGeneralizedCylinder_H
00030
00031 #include <mrpt/opengl/CRenderizable.h>
00032 #include <mrpt/opengl/CPolyhedron.h>
00033
00034 namespace mrpt {
00035 namespace opengl {
00036 class MRPTDLLIMPEXP CGeneralizedCylinder;
00037
00038 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE(CGeneralizedCylinder,CRenderizable)
00039
00040
00041 class MRPTDLLIMPEXP CGeneralizedCylinder:public CRenderizable {
00042 DEFINE_SERIALIZABLE(CGeneralizedCylinder)
00043 public:
00044 struct MRPTDLLIMPEXP TQuadrilateral {
00045 private:
00046 void calculateNormal();
00047 TQuadrilateral() {}
00048 public:
00049 CPoint3D points[4];
00050 float normal[3];
00051 TQuadrilateral(const CPoint3D &p1,const CPoint3D &p2,const CPoint3D &p3,const CPoint3D &p4) {
00052 points[0]=p1;
00053 points[1]=p2;
00054 points[2]=p3;
00055 points[3]=p4;
00056 calculateNormal();
00057 }
00058 TQuadrilateral(const CPoint3D (&p)[4]) {
00059 for (int i=0;i<4;i++) points[i]=p[i];
00060 calculateNormal();
00061 }
00062 };
00063 protected:
00064 vector_serializable<CPoint3D> axis;
00065 vector_serializable<CPoint3D> generatrix;
00066 mutable std::vector<TQuadrilateral> mesh;
00067 mutable bool meshUpToDate;
00068 bool closed;
00069 public:
00070 static CGeneralizedCylinderPtr Create(const std::vector<CPoint3D> &a,const std::vector<CPoint3D> &g) {
00071 return CGeneralizedCylinderPtr(new CGeneralizedCylinder(a,g));
00072 }
00073 void render() const;
00074 virtual bool traceRay(const mrpt::poses::CPose3D &o,float &dist) const;
00075 inline void getAxis(std::vector<CPoint3D> &a) const {
00076 a=axis;
00077 }
00078 inline void setAxis(const std::vector<CPoint3D> &a) {
00079 axis=a;
00080 meshUpToDate=false;
00081 }
00082 inline void getGeneratrix(std::vector<CPoint3D> &g) const {
00083 g=generatrix;
00084 }
00085 inline void setGeneratrix(const std::vector<CPoint3D> g) {
00086 generatrix=g;
00087 meshUpToDate=false;
00088 }
00089 inline bool isClosed() const {
00090 return closed;
00091 }
00092 inline void setClosed(bool c=true) {
00093 closed=c;
00094 meshUpToDate=false;
00095 }
00096 void getOrigin(CPolyhedronPtr &poly) const;
00097 void getEnd(CPolyhedronPtr &poly) const;
00098 private:
00099 void updateMesh() const;
00100 CGeneralizedCylinder():axis(),generatrix(),mesh(),meshUpToDate(false),closed(false) {}
00101 CGeneralizedCylinder(const std::vector<CPoint3D> &a,const std::vector<CPoint3D> &g):axis(a),generatrix(g),mesh(),meshUpToDate(false),closed(false) {}
00102 virtual ~CGeneralizedCylinder() {};
00103 };
00104 }
00105 }
00106 #endif