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_CGeneralizedCylinder_H
00029 #define opengl_CGeneralizedCylinder_H
00030
00031 #include <mrpt/opengl/CRenderizableDisplayList.h>
00032 #include <mrpt/opengl/CPolyhedron.h>
00033 #include <mrpt/opengl/CSetOfTriangles.h>
00034 #include <mrpt/math/geometry.h>
00035 #include <mrpt/math/CMatrixTemplate.h>
00036
00037 namespace mrpt {
00038 namespace opengl {
00039 using namespace std;
00040 using namespace mrpt::math;
00041 class OPENGL_IMPEXP CGeneralizedCylinder;
00042
00043 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(CGeneralizedCylinder,CRenderizableDisplayList, OPENGL_IMPEXP)
00044
00045
00046
00047 class OPENGL_IMPEXP CGeneralizedCylinder:public CRenderizableDisplayList {
00048 DEFINE_SERIALIZABLE(CGeneralizedCylinder)
00049 public:
00050
00051
00052
00053 struct OPENGL_IMPEXP TQuadrilateral {
00054 private:
00055
00056
00057
00058 void calculateNormal();
00059 public:
00060
00061
00062
00063 TPoint3D points[4];
00064
00065
00066
00067 double normal[3];
00068
00069
00070
00071
00072 inline void getAsPolygonUnsafe(mrpt::math::TPolygon3D &vec) const {
00073 vec[0]=points[0];
00074 vec[1]=points[1];
00075 vec[2]=points[2];
00076 vec[3]=points[3];
00077 }
00078
00079
00080
00081 TQuadrilateral(const TPoint3D &p1,const TPoint3D &p2,const TPoint3D &p3,const TPoint3D &p4) {
00082 points[0]=p1;
00083 points[1]=p2;
00084 points[2]=p3;
00085 points[3]=p4;
00086 calculateNormal();
00087 }
00088
00089
00090
00091 template<class T> TQuadrilateral(const T (&p)[4]) {
00092 for (int i=0;i<4;i++) points[i]=p[i];
00093 calculateNormal();
00094 }
00095
00096
00097
00098 TQuadrilateral() {}
00099
00100
00101
00102 ~TQuadrilateral() {}
00103 };
00104 protected:
00105
00106
00107
00108 vector<CPose3D> axis;
00109
00110
00111
00112 vector<TPoint3D> generatrix;
00113
00114
00115
00116 mutable std::vector<TQuadrilateral> mesh;
00117
00118
00119
00120 mutable CMatrixTemplate<TPoint3D> pointsMesh;
00121
00122
00123
00124 mutable bool meshUpToDate;
00125
00126
00127
00128
00129 mutable vector<TPolygonWithPlane> polys;
00130
00131
00132
00133 mutable bool polysUpToDate;
00134
00135
00136
00137 bool closed;
00138
00139
00140
00141 bool fullyVisible;
00142
00143
00144
00145
00146 size_t firstSection;
00147
00148
00149
00150
00151 size_t lastSection;
00152 public:
00153
00154
00155
00156 static CGeneralizedCylinderPtr Create(const std::vector<TPoint3D> &axis,const std::vector<TPoint3D> &generatrix) {
00157 return CGeneralizedCylinderPtr(new CGeneralizedCylinder(axis,generatrix));
00158 }
00159
00160
00161
00162
00163 void render_dl() const;
00164
00165
00166
00167
00168 virtual bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const;
00169
00170
00171
00172 inline void getAxis(std::vector<TPoint3D> &a) const {
00173
00174 size_t N=axis.size();
00175 a.resize(N);
00176 for (size_t i=0;i<N;i++) {
00177 a[i].x=axis[i].x();
00178 a[i].y=axis[i].y();
00179 a[i].z=axis[i].z();
00180 }
00181 }
00182
00183
00184
00185 inline void getAxis(std::vector<CPose3D> &a) const {
00186 a=axis;
00187 }
00188
00189
00190
00191 inline void setAxis(const std::vector<TPoint3D> &a) {
00192 generatePoses(a,axis);
00193 meshUpToDate=false;
00194 fullyVisible=true;
00195 CRenderizableDisplayList::notifyChange();
00196 }
00197
00198
00199
00200 inline void getGeneratrix(std::vector<TPoint3D> &g) const {
00201 g=generatrix;
00202 }
00203
00204
00205
00206 inline void setGeneratrix(const std::vector<TPoint3D> g) {
00207 generatrix=g;
00208 meshUpToDate=false;
00209 CRenderizableDisplayList::notifyChange();
00210 }
00211
00212
00213
00214 inline bool isClosed() const {
00215 return closed;
00216 }
00217
00218
00219
00220 inline void setClosed(bool c=true) {
00221 closed=c;
00222 meshUpToDate=false;
00223 CRenderizableDisplayList::notifyChange();
00224 }
00225
00226
00227
00228
00229 void getOrigin(CPolyhedronPtr &poly) const;
00230
00231
00232
00233
00234 void getEnd(CPolyhedronPtr &poly) const;
00235
00236
00237
00238
00239 void generateSetOfPolygons(std::vector<TPolygon3D> &res) const;
00240
00241
00242
00243
00244 void getClosedSection(size_t index1,size_t index2,CPolyhedronPtr &poly) const;
00245
00246
00247
00248
00249 inline void getClosedSection(size_t index,CPolyhedronPtr &poly) const {
00250 getClosedSection(index,index,poly);
00251 }
00252
00253
00254
00255 inline size_t getNumberOfSections() const {
00256 return axis.size()?(axis.size()-1):0;
00257 }
00258
00259
00260
00261 inline size_t getVisibleSections() const {
00262 return fullyVisible?getNumberOfSections():(lastSection-firstSection);
00263 }
00264
00265
00266
00267 void getVisibleSections(size_t &first,size_t &last) const {
00268 if (fullyVisible) {
00269 first=0;
00270 last=getNumberOfSections();
00271 } else {
00272 first=firstSection;
00273 last=lastSection;
00274 }
00275 }
00276
00277
00278
00279 inline void setAllSectionsVisible() {
00280 fullyVisible=true;
00281 CRenderizableDisplayList::notifyChange();
00282 }
00283
00284
00285
00286 inline void setAllSectionsInvisible(size_t pointer=0) {
00287 fullyVisible=false;
00288 firstSection=pointer;
00289 lastSection=pointer;
00290 CRenderizableDisplayList::notifyChange();
00291 }
00292
00293
00294
00295
00296 inline void setVisibleSections(size_t first,size_t last) {
00297 fullyVisible=false;
00298 if (first>last||last>getNumberOfSections()) throw std::logic_error("Wrong bound definition");
00299 firstSection=first;
00300 lastSection=last;
00301 CRenderizableDisplayList::notifyChange();
00302 }
00303
00304
00305
00306
00307
00308 inline void addVisibleSectionAtStart() {
00309 if (fullyVisible||firstSection==0) throw std::logic_error("No more sections");
00310 firstSection--;
00311 CRenderizableDisplayList::notifyChange();
00312 }
00313
00314
00315
00316
00317
00318 inline void addVisibleSectionAtEnd() {
00319 if (fullyVisible||lastSection==getNumberOfSections()) throw std::logic_error("No more sections");
00320 lastSection++;
00321 CRenderizableDisplayList::notifyChange();
00322 }
00323
00324
00325
00326
00327
00328 void removeVisibleSectionAtStart();
00329
00330
00331
00332
00333
00334 void removeVisibleSectionAtEnd();
00335
00336
00337
00338 bool getFirstSectionPose(mrpt::poses::CPose3D &p);
00339
00340
00341
00342 bool getLastSectionPose(mrpt::poses::CPose3D &p);
00343
00344
00345
00346 bool getFirstVisibleSectionPose(mrpt::poses::CPose3D &p);
00347
00348
00349
00350 bool getLastVisibleSectionPose(mrpt::poses::CPose3D &p);
00351
00352
00353
00354 void updatePolys() const;
00355 private:
00356
00357
00358
00359 void generatePoses(const std::vector<TPoint3D> &pIn,std::vector<CPose3D> &pOut);
00360
00361
00362
00363 void updateMesh() const;
00364
00365
00366
00367 void getMeshIterators(const vector<TQuadrilateral> &m,vector<TQuadrilateral>::const_iterator &begin,vector<TQuadrilateral>::const_iterator &end) const;
00368
00369
00370
00371 CGeneralizedCylinder():axis(),generatrix(),mesh(),meshUpToDate(false),polysUpToDate(false),closed(false),fullyVisible(true) {}
00372
00373
00374
00375 CGeneralizedCylinder(const std::vector<TPoint3D> &a,const std::vector<TPoint3D> &g):generatrix(g),mesh(),meshUpToDate(false),polysUpToDate(false),closed(false),fullyVisible(true) {
00376 generatePoses(a,axis);
00377 }
00378
00379
00380
00381 virtual ~CGeneralizedCylinder() {};
00382 };
00383 }
00384 }
00385 #endif