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