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